@@ -65,6 +65,7 @@ pub fn write_gdextension_headers(
65
65
66
66
// Regenerate API JSON if first time or Godot version is different.
67
67
// Note: read_godot_version() already panics if 4.0 is still in use; no need to check again.
68
+ // This also validates whether we run a Debug build.
68
69
let _version = read_godot_version ( & godot_bin) ;
69
70
70
71
// if !c_header_path.exists() || has_version_changed(&version) {
@@ -110,7 +111,7 @@ pub(crate) fn read_godot_version(godot_bin: &Path) -> GodotVersion {
110
111
let output = execute ( cmd, "read Godot version" ) ;
111
112
let stdout = std:: str:: from_utf8 ( & output. stdout ) . expect ( "convert Godot version to UTF-8" ) ;
112
113
113
- match parse_godot_version ( stdout) {
114
+ let version = match parse_godot_version ( stdout) {
114
115
Ok ( parsed) => {
115
116
assert_eq ! (
116
117
parsed. major,
@@ -131,7 +132,35 @@ pub(crate) fn read_godot_version(godot_bin: &Path) -> GodotVersion {
131
132
// Don't treat this as fatal error
132
133
panic ! ( "failed to parse Godot version '{stdout}': {e}" )
133
134
}
135
+ } ;
136
+
137
+ // `--dump-extension-api`, `--dump-gdextension-interface` etc. are only available in Debug builds (editor, debug export template).
138
+ // If we try to run them in release builds, Godot tries to run, causing a popup alert with an unhelpful message:
139
+ // Error: Couldn't load project data at path ".". Is the .pck file missing?
140
+ //
141
+ // Thus, we check early and exit with a helpful message.
142
+ if !is_godot_debug_build ( godot_bin) {
143
+ panic ! ( "`api-custom` needs a Godot debug build (editor or debug export template); detected release build" ) ;
134
144
}
145
+
146
+ version
147
+ }
148
+
149
+ /// True if Godot is a debug build (editor or debug export template), false otherwise (release export template).
150
+ fn is_godot_debug_build ( godot_bin : & Path ) -> bool {
151
+ // The `--version` command does not contain information about debug/release, but we can see if the `--help` output lists the command
152
+ // `--dump-extension-api`. This seems to be reliable down to Godot 4.1.
153
+
154
+ let mut cmd = Command :: new ( godot_bin) ;
155
+ cmd. arg ( "--help" ) ;
156
+
157
+ let haystack = execute ( cmd, "Godot CLI help to check debug/release" ) ;
158
+ let needle = b"--dump-extension-api" ;
159
+
160
+ haystack
161
+ . stdout
162
+ . windows ( needle. len ( ) )
163
+ . any ( |window| window == needle)
135
164
}
136
165
137
166
fn dump_extension_api ( godot_bin : & Path , out_file : & Path ) {
0 commit comments