Skip to content

Commit 489b1f1

Browse files
authored
Merge pull request #1071 from godot-rust/qol/check-godot-debug-binary
Validate that `api-custom` is run for Godot Debug binary
2 parents 911cb28 + 438ec3f commit 489b1f1

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

godot-bindings/src/godot_exe.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ pub fn write_gdextension_headers(
6565

6666
// Regenerate API JSON if first time or Godot version is different.
6767
// 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.
6869
let _version = read_godot_version(&godot_bin);
6970

7071
// if !c_header_path.exists() || has_version_changed(&version) {
@@ -110,7 +111,7 @@ pub(crate) fn read_godot_version(godot_bin: &Path) -> GodotVersion {
110111
let output = execute(cmd, "read Godot version");
111112
let stdout = std::str::from_utf8(&output.stdout).expect("convert Godot version to UTF-8");
112113

113-
match parse_godot_version(stdout) {
114+
let version = match parse_godot_version(stdout) {
114115
Ok(parsed) => {
115116
assert_eq!(
116117
parsed.major,
@@ -131,7 +132,35 @@ pub(crate) fn read_godot_version(godot_bin: &Path) -> GodotVersion {
131132
// Don't treat this as fatal error
132133
panic!("failed to parse Godot version '{stdout}': {e}")
133134
}
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");
134144
}
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)
135164
}
136165

137166
fn dump_extension_api(godot_bin: &Path, out_file: &Path) {

0 commit comments

Comments
 (0)