Skip to content

Commit e29a4d6

Browse files
committed
Require 'api_version' and allow extensions to provide a 'default_api_version'
1 parent eb006b6 commit e29a4d6

13 files changed

Lines changed: 55 additions & 30 deletions

File tree

.github/workflows/ci-cmake.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ env:
77
GODOT_BASE_BRANCH: master
88
# Used to select the version of Godot to run the tests with.
99
GODOT_TEST_VERSION: master
10+
# The Godot API version to build against.
11+
DEFAULT_API_VERSION: "4.7"
1012
# Use UTF-8 on Linux.
1113
LANG: en_US.UTF-8
1214
LC_ALL: en_US.UTF-8
@@ -121,16 +123,15 @@ jobs:
121123

122124
- name: Configure godot-cpp-test with template_debug
123125
run: >
124-
cmake --log-level=VERBOSE -S . -B cmake-build ${{ env.config-flags }} ${{ matrix.config-flags }}
126+
cmake --log-level=VERBOSE -S . -B cmake-build '-DGODOTCPP_API_VERSION=${{ env.DEFAULT_API_VERSION }}' ${{ env.config-flags }} ${{ matrix.config-flags }}
125127
126128
- name: Build godot-cpp-test (template_debug)
127129
run: >
128130
cmake --build cmake-build --verbose --target godot-cpp-test ${{ matrix.build-flags }}
129131
130132
- name: Configure godot-cpp-test with template_release
131133
run: >
132-
cmake --fresh --log-level=VERBOSE -S . -B cmake-build
133-
-DGODOTCPP_TARGET=template_release ${{ env.config-flags }} ${{ matrix.config-flags }}
134+
cmake --fresh --log-level=VERBOSE -S . -B cmake-build -DGODOTCPP_TARGET=template_release '-DGODOTCPP_API_VERSION=${{ env.DEFAULT_API_VERSION }}' ${{ env.config-flags }} ${{ matrix.config-flags }}
134135
135136
- name: Build godot-cpp-test (template_release)
136137
run: >

.github/workflows/ci-scons.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ on:
55
env:
66
# Only used for the cache key. Increment version to force clean build.
77
GODOT_BASE_BRANCH: master
8+
# The Godot API version used by jobs that don't target a specific one.
9+
DEFAULT_API_VERSION: "4.7"
810
# Use UTF-8 on Linux.
911
LANG: en_US.UTF-8
1012
LC_ALL: en_US.UTF-8
@@ -29,7 +31,6 @@ jobs:
2931
artifact-name: godot-cpp-linux-glibc2.27-x86_64-release
3032
artifact-path: bin/libgodot-cpp.linux.template_release.x86_64.a
3133
run-tests: true
32-
api-version: 4.7
3334
cache-name: linux-x86_64
3435

3536
- name: 🐧 Linux (GCC) for Godot 4.6
@@ -149,23 +150,23 @@ jobs:
149150

150151
- name: Generate godot-cpp sources only
151152
run: |
152-
scons platform=${{ matrix.platform }} verbose=yes build_library=no ${{ matrix.flags }} ${{ matrix.api-version && format('api_version={0}', matrix.api-version) || '' }}
153-
scons -c
153+
scons platform=${{ matrix.platform }} verbose=yes build_library=no ${{ matrix.flags }} api_version=${{ matrix.api-version || env.DEFAULT_API_VERSION }}
154+
scons -c platform=${{ matrix.platform }} ${{ matrix.flags }} api_version=${{ matrix.api-version || env.DEFAULT_API_VERSION }}
154155
155156
- name: Build godot-cpp (debug)
156157
run: |
157-
scons platform=${{ matrix.platform }} verbose=yes target=template_debug ${{ matrix.flags }} ${{ matrix.api-version && format('api_version={0}', matrix.api-version) || '' }}
158+
scons platform=${{ matrix.platform }} verbose=yes target=template_debug ${{ matrix.flags }} api_version=${{ matrix.api-version || env.DEFAULT_API_VERSION }}
158159
159160
160161
- name: Build test without rebuilding godot-cpp (debug)
161162
run: |
162163
cd test
163-
scons platform=${{ matrix.platform }} verbose=yes build_library=no target=template_debug ${{ matrix.flags }} ${{ matrix.api-version && format('api_version={0}', matrix.api-version) || '' }}
164+
scons platform=${{ matrix.platform }} verbose=yes build_library=no target=template_debug ${{ matrix.flags }} api_version=${{ matrix.api-version || env.DEFAULT_API_VERSION }}
164165
165166
- name: Build test and godot-cpp (release)
166167
run: |
167168
cd test
168-
scons platform=${{ matrix.platform }} verbose=yes target=template_release ${{ matrix.flags }} ${{ matrix.api-version && format('api_version={0}', matrix.api-version) || '' }}
169+
scons platform=${{ matrix.platform }} verbose=yes target=template_release ${{ matrix.flags }} api_version=${{ matrix.api-version || env.DEFAULT_API_VERSION }}
169170
170171
- name: Save Godot build cache
171172
uses: ./.github/actions/godot-cache-save

.github/workflows/runner.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
- '**/*.h'
3939
- '**/*.inc'
4040
- 'test/build_profile.json'
41-
- 'gdextension/extension_api.json'
41+
- 'gdextension/extension_api-*.json'
4242
scons:
4343
- '**/SConstruct'
4444
- '**/SCsub'

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ default_language_version:
33

44
exclude: |
55
(?x)^(
6-
gdextension/extension_api\.json|
6+
gdextension/extension_api-[0-9]+-[0-9]+\.json|
77
gdextension/gdextension_interface\.json
88
)$
99

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ project(
6161
LANGUAGES CXX
6262
)
6363

64+
# Set the default API version for the test project.
65+
if(GODOTCPP_ENABLE_TESTING)
66+
set(GODOTCPP_DEFAULT_API_VERSION "4.7")
67+
endif()
68+
6469
compiler_detection()
6570
godotcpp_generate()
6671

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
TARGET = template_debug
2+
API_VERSION = 4.7
23

3-
BASE = scons target=$(TARGET) $(EXTRA_ARGS)
4+
BASE = scons target=$(TARGET) api_version=$(API_VERSION) $(EXTRA_ARGS)
45
LINUX = $(BASE) platform=linux
56
WINDOWS = $(BASE) platform=windows
67
MACOS = $(BASE) platform=macos
@@ -11,7 +12,7 @@ usage:
1112
@echo -e "Specify one of the available targets:\n"
1213
# https://stackoverflow.com/a/26339924
1314
@LC_ALL=C $(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/(^|\n)# Files(\n|$$)/,/(^|\n)# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | grep -E -v -e '^[^[:alnum:]]' -e '^$@$$'
14-
@echo -e "\nDefine the SCons target with TARGET, and pass extra SCons arguments with EXTRA_ARGS."
15+
@echo -e "\nDefine the SCons target with TARGET, the Godot API version to target with API_VERSION, and pass extra SCons arguments with EXTRA_ARGS."
1516

1617

1718
linux:

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,15 @@ godot --dump-extension-api
4848
scons custom_api_file=extension_api.json
4949
```
5050

51-
If you don't provide `api_version` or `custom_api_file`, then, by default, godot-cpp will
52-
target the latest stable Godot version that it's aware of.
51+
Extension authors can provide a default target API version by passing it to godot-cpp's
52+
`SConstruct`, for example:
53+
54+
```python
55+
env = SConscript("../SConstruct", {"default_api_version": "4.7"})
56+
```
57+
58+
This is highly recommended! It allows the extension author to ensure that their extension
59+
is built with a version that provides all the necessary features by default.
5360

5461
## Contributing
5562

SConstruct

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ except Exception:
1717
# We apply platform specific toolchains via our custom tools.
1818
env = Environment(tools=["default"], PLATFORM="")
1919

20+
try:
21+
Import("default_api_version")
22+
env["default_api_version"] = default_api_version
23+
except Exception:
24+
pass
25+
2026
env.PrependENVPath("PATH", os.getenv("PATH"))
2127

2228
# Custom options and profile flags.

cmake/godotcpp.cmake

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,18 +264,20 @@ function(godotcpp_generate)
264264
math(EXPR BITS "${CMAKE_SIZEOF_VOID_P} * 8") # CMAKE_SIZEOF_VOID_P refers to target architecture.
265265

266266
# API json File
267-
set(GODOTCPP_LATEST_API_VERSION "4.7")
268-
if(GODOTCPP_API_VERSION STREQUAL "" OR GODOTCPP_API_VERSION STREQUAL GODOTCPP_LATEST_API_VERSION)
269-
set(GODOTCPP_GDEXTENSION_API_FILE "${GODOTCPP_GDEXTENSION_DIR}/extension_api.json")
267+
if(GODOTCPP_CUSTOM_API_FILE) # User-defined override.
268+
set(GODOTCPP_GDEXTENSION_API_FILE "${GODOTCPP_CUSTOM_API_FILE}")
270269
else()
270+
if(GODOTCPP_API_VERSION STREQUAL "")
271+
set(GODOTCPP_API_VERSION "${GODOTCPP_DEFAULT_API_VERSION}")
272+
endif()
273+
if(GODOTCPP_API_VERSION STREQUAL "")
274+
message(FATAL_ERROR "'GODOTCPP_API_VERSION' must be provided")
275+
endif()
271276
string(REPLACE "." "-" GODOTCPP_API_VERSION_DASHED "${GODOTCPP_API_VERSION}")
272277
set(GODOTCPP_GDEXTENSION_API_FILE
273278
"${GODOTCPP_GDEXTENSION_DIR}/extension_api-${GODOTCPP_API_VERSION_DASHED}.json"
274279
)
275280
endif()
276-
if(GODOTCPP_CUSTOM_API_FILE) # User-defined override.
277-
set(GODOTCPP_GDEXTENSION_API_FILE "${GODOTCPP_CUSTOM_API_FILE}")
278-
endif()
279281

280282
# Interface json file.
281283
set(GODOTCPP_GDEXTENSION_INTERFACE_FILE "${GODOTCPP_GDEXTENSION_DIR}/gdextension_interface.json")

0 commit comments

Comments
 (0)