Skip to content

Build

These instructions show how to build the GDExtension for Godot version 4.4 on Linux.

Version compatibility

GDExtensions targeting an earlier version of Godot should work in later minor versions, so GDExtension for 4.4 should work in any minor version above it (4.5, 4.6, 4.7, ...).

The opposite is not guaranteed. For example, version 4.7 changed how to use memnew(RefCounted).

This means that our Python script generate an invalid C++ code for versions >= 4.7, which block us from building the GDExtension with newer versions.

Before After
DiscordObject *obj Ref<DiscordObject> obj

Making our Python script generate different code for specifics version would add a lot of complexity. So the recomentation is to built with old version because it will work in the newer.

Environment variables

The Python script expect that any tool can be accessed by it name alone, but you can also indicates the correct location throught environment variables:

export CLANG_FORMAT=clang-format
export DOXYGEN=doxygen
export GODOT=godot

Note

  • Do not use relative paths because we use execute $GODOT from different directories.
  • Save to an .env file so you can always load with source .env.

Setup Repository

These will build for your current operating system (adapt it to your use case):

# Clone repository, submodules and only file needed.
git clone --recurse-submodules --filter=blob:none https://github.com/thiagola92/discord-social-sdk.git
cd discord-social-sdk

# Manually download the DiscordSocialSdk zip to the project directory.

# Unzip libraries and headers to correct directories.
unzip DiscordSocialSdk*.zip -d /tmp/
cp -r /tmp/discord_social_sdk/* sdk/
rm -rf /tmp/discord_social_sdk

# Generate GDExtension API files.
cd godot-cpp
$GODOT --headless --dump-extension-api
scons custom_api_file=extension_api.json
cd ..

# Generate GDExtension source code.
python scripts/main.py --code

# Generate GDExtension library.
scons custom_api_file=godot-cpp/extension_api.json

# Open project, at least once, to be able to generate GDExtension documentation.
$GODOT --headless --quit ./demo/project.godot

# Generate GDExtension documentations.
python scripts/main.py --docs

# Link documentation to GDExtension library.
scons custom_api_file=godot-cpp/extension_api.json

# Open project (may need to open two times for the documentation to load).
$GODOT ./demo/project.godot

Note

  • Make sure that Godot version match with godot-cpp repository
  • Custom builds should add their extra arguments to all scons calls (e.g. precision=double)

Rebuild

Run these steps every time that you modify the Python code:

python scripts/main.py --code --docs
scons custom_api_file=godot-cpp/extension_api.json
$GODOT ./demo/project.godot