paddy-exe/GDExtensionSummator

Enhance `.vscode` folder for complete configuration to develop and debug the extension

ozzr opened this issue Β· 13 comments

ozzr commented

To debug the extension either from the godot editor or launching the demo project, it is important to

  1. Create a debug build of the extension by creating at least one dev_build library to test with this can be done just by adding the code below to the task.json:
{
            "label": "build-extension [dev build]",
            "type": "shell",
            "command": "scons target=template_debug dev_build=yes",
            "presentation": {
                "echo": true,
                "revealProblems": "onProblem",
                "focus": false,
                "panel": "shared",
                "showReuseMessage": true,
                "clear": false
            },
            "problemMatcher": "$msCompile"
}
  1. Add the below code in a launch.json file in the .vscode folder in the root folder
{
    "version": "0.2.0",
    "configurations": [
        {
			"name": "Run Demo Project in Editor",
			"type": "cppvsdbg",
			"request": "launch",
			"program": "C:/godot.exe",  // Your absolute path to the godot executable
			"args": [
				"--editor",
				"--path",
				"${workspaceFolder}/demo",
				"--verbose",
				"--debug",
				"--stdout"
			],
			"stopAtEntry": false,
			"cwd": "${workspaceFolder}",
			"environment": [],
			"console": "internalConsole",
			//"preLaunchTask": "build godot editor in debug mode"
		},
        {
			"name": "Run Demo Project in Game",
			"type": "cppvsdbg",
			"request": "launch",
			"program": "C:/godot.exe",  // Your absolute path to the godot executable
			"args": [
				"--path",
				"${workspaceFolder}/demo",
				"--verbose",
				"--debug",
				"--stdout"
			],
			"stopAtEntry": false,
			"cwd": "${workspaceFolder}",
			"environment": [],
			"console": "internalConsole",
			//"preLaunchTask": "build godot editor in debug mode"
		},
    ]
}
  1. slightly modify the .gdextension file to find the dev library while developing it. The code below is an example of how I do it for my upcoming terrain extension:
    windows.debug.x86_64 = "bin/libgd.landscape.windows.template_debug.dev.x86_64.dll"

With this we get to properly test and debug the code

@ozzr Hey, thanks for giving out this info. Do you want to open a PR? Also, do you think the debugging functionality could be added without changing the .gdextension file?

ozzr commented

Hi, sorry for the delayed response.
OK, I will open a PR later today

The only way to debug the extension code is by forcing the engine to load a debug build of the extension by modifing temporarily the path to the "template_debug" library. What is needed is de .pdb file generated with the dev_build flag so the vscode debugger can find the code in our extension. The other builds do not inlcude it and I havent find a way to explicitly tell the engine to load de dev_build version of the engine

Also it could be nice to modify the c_cpp_proprtirs.json like this so the editor can properly load the include files:

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "${workspaceFolder}/godot-cpp/gen/include",
                "${workspaceFolder}/etxtension/src"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.22000.0",
            "compilerPath": "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.34.31933/bin/Hostx64/x64/cl.exe",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "windows-msvc-x64"
        }
    ],
    "version": 4
}
ozzr commented

Maybe we could write the .gdextension file on every build so the user dont have to do it manually. Maybe doing it from the same SCons script? and create a task like "Generate Poduction Builds" and "Create DEV build"

Hey, sorry @ozzr for the late answer as well. Your proposal sounds very interesting. However, does this mean that the changes will be only compatible with Windows or also with the other desktop platforms?

About the different tasks for production and dev builds: YesπŸ‘πŸ» sounds good. Not sure though if we should meddle with the generation of the .gdextension file... this would mostly confuse users since it's more complicated to change the system to their needs then.

ozzr commented

the changes should be compatible with other platforms too. It would only requires to update the corresponding paths to follow specific OS notation.

In the case of the .gdextension file we could just tell about it in the main page README so the user knows that it can be done, but then it has to be done manually

the changes should be compatible with other platforms too. It would only requires to update the corresponding paths to follow specific OS notation.

In the case of the .gdextension file we could just tell about it in the main page README so the user knows that it can be done, but then it has to be done manually

Okay, sounds good to me πŸ‘πŸ»

Bump :) @ozzr Would you still like to add a PR for this? I'd appreciate it immensely since I won't have that much time to work on this

ozzr commented

Sorry, I will do it today

ozzr commented

Done, please check the pull request.
I will properly update the README tomorrow once I have some time, to point to how to properly modify the .gdextension file when debugging or simply you can point in the main page to this issue.
The configuration was done in Windows but it should work as long as the user replaces with their global path to godot executable

@ozzr I think it's important that the information is on the README. There is no hurry with it so take your time if you needπŸ‘πŸ» I appreciate your contribution

ozzr commented

Ok, I will update the readme and restart the pull request

I'm using a macbook now. vscode reports an error:
process exited with status -1 (Error 1)

console infomation:
Console is in 'commands' mode, prefix expressions with '?'.
Launching: /Applications/Godot.app/Contents/MacOS/Godot --editor --path /Users/Desktop/godot-rpgbuilder/plugin --verbose --debug --stdout

How should I deal with it, thank you

my launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Run Demo Project in Editor",
"type": "lldb",
"request": "launch",
"program": "/Applications/Godot.app/Contents/MacOS/Godot", // Your absolute path to the godot executable
"args": [
"--editor",
"--path",
"${workspaceFolder}/plugin",
"--verbose",
"--debug",
"--stdout"
],
"cwd": "${workspaceFolder}",
//"preLaunchTask": "build godot editor in debug mode"
},
]
}

ozzr commented

Hi, try creating a task using the VScode command and see how it is organized, maybe, the task should look different in MacOs