Skip to content

Require 'api_version' and allow extensions to provide a default - #2034

Open
dsnopek wants to merge 1 commit into
godotengine:masterfrom
dsnopek:require-api-version
Open

Require 'api_version' and allow extensions to provide a default#2034
dsnopek wants to merge 1 commit into
godotengine:masterfrom
dsnopek:require-api-version

Conversation

@dsnopek

@dsnopek dsnopek commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

At a few GDExtension meetings, we've discussed not defaulting the api_version to the latest Godot API that godot-cpp is aware of, but instead requiring the extension developer to provide the default.

This PR attempts to implement that!

AI disclosure: I used AI to help with the CMake code, and to double check if I forgot anything that needed to be updated.

@enetheru I'd really appreciate review of the CMake stuff. I had to put the GODOTCPP_DEFAULT_API_VERSION define in the top-level CMakeLists.txt, because I couldn't figure out a better way to do it for how the test project is built. But I think a normal extension should be able to define that in their CMakeLists.txt before including the godot-cpp one, right?

@dsnopek dsnopek added this to the 10.x milestone Jul 29, 2026
@dsnopek
dsnopek requested review from a team as code owners July 29, 2026 14:10
@dsnopek dsnopek added enhancement This is an enhancement on the current functionality cmake topic:buildsystem Related to the buildsystem or CI setup labels Jul 29, 2026
@dsnopek
dsnopek force-pushed the require-api-version branch 4 times, most recently from e29a4d6 to a986acf Compare July 29, 2026 16:29
Comment thread .github/workflows/ci-scons.yml
Comment thread README.md Outdated
`SConstruct`, for example:

```python
env = SConscript("godot-cpp/SConstruct", {"default_api_version": "4.7"})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need to differentiate between default_api_version and api_version.
If the user SConstruct places api_version="4.7" into the env, I think the one running the command can still override it with api_version=4.6 in the bash command. I think that's how it works, anyway.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, good point! I don't know why I thought I needed to have a separate default variable. I've updated this in my latest push!

Unfortunately, I couldn't figure out how to do the same thing with CMake, so it still uses a GODOTCPP_DEFAULT_API_VERSION to set the default.

@enetheru Is there an easy way to make it so that the developer can set GODOTCPP_API_VERSION, which is the default for the extension, and that gets overridden by -DGODOTCPP_API_VERSION=... passed on the command-line? If the answer is "no" or making that work is sufficiently more complicated, I'll just leave the CMake changes as they are

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in a plugin developers project, before they consume godot-cpp they can do this

if( GODOTCPP_API_VERSION STREQUAL  "" )
    set(GODOTCPP_API_VERSION "4.7")
endif()

@dsnopek
dsnopek force-pushed the require-api-version branch from a986acf to 4f12588 Compare July 30, 2026 14:24
@dsnopek dsnopek changed the title Require 'api_version' and allow extensions to provide a 'default_api_version' Require 'api_version' and allow extensions to provide a default Jul 30, 2026

@Ivorforce Ivorforce left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

Can't judge the CMake code.

@enetheru enetheru left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get it now. yeah its all good.

Comment thread .github/workflows/ci-scons.yml
Comment thread CMakeLists.txt
if(GODOTCPP_ENABLE_TESTING)
set(GODOTCPP_DEFAULT_API_VERSION "4.7")
endif()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whatever the godot-cpp is compiled with, so will the test. so this isn't necessary. setting it in the github yaml takes care of both.

@dsnopek dsnopek Jul 30, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, the idea is that the test project is an extension, and the imaginary author of that extension wants to set the default API version to "4.7". If you look in test/SConstruct we're setting the default to "4.7" there as well.

Similarly, I would love for the code referenced above to be in test/CMakeLists.txt, but I couldn't make that work because the test project is built weird, and I had to put it in the top-level CMakeLists.txt. If you know a way to put the default in test/CMakeLists.txt that would be awesome!

In a real project, I think the extension developer can set GODOTCPP_DEFAULT_API_VERSION before they include godot-cpp's CMakeLists.txt and it should work?

This doesn't really relate to what we're doing on CI (where we may test multiple different versions). This is attempting to set the default used for tests when the user doesn't explicitly set an API version, including when building locally

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just added an additional comment by this code to explain that this only done this way because the test project is built weird :-)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For cmake the integration testing is just another target in the godot-cpp project.

@dsnopek
dsnopek force-pushed the require-api-version branch from 4f12588 to 9d050a9 Compare July 30, 2026 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cmake enhancement This is an enhancement on the current functionality topic:buildsystem Related to the buildsystem or CI setup

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants