Skip to content

Validate that api-custom is run for Godot Debug binary #1071

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion godot-bindings/src/godot_exe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ pub fn write_gdextension_headers(

// Regenerate API JSON if first time or Godot version is different.
// Note: read_godot_version() already panics if 4.0 is still in use; no need to check again.
// This also validates whether we run a Debug build.
let _version = read_godot_version(&godot_bin);

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

match parse_godot_version(stdout) {
let version = match parse_godot_version(stdout) {
Ok(parsed) => {
assert_eq!(
parsed.major,
Expand All @@ -131,7 +132,35 @@ pub(crate) fn read_godot_version(godot_bin: &Path) -> GodotVersion {
// Don't treat this as fatal error
panic!("failed to parse Godot version '{stdout}': {e}")
}
};

// `--dump-extension-api`, `--dump-gdextension-interface` etc. are only available in Debug builds (editor, debug export template).
// If we try to run them in release builds, Godot tries to run, causing a popup alert with an unhelpful message:
// Error: Couldn't load project data at path ".". Is the .pck file missing?
//
// Thus, we check early and exit with a helpful message.
if !is_godot_debug_build(godot_bin) {
panic!("`api-custom` needs a Godot debug build (editor or debug export template); detected release build");
}

version
}

/// True if Godot is a debug build (editor or debug export template), false otherwise (release export template).
fn is_godot_debug_build(godot_bin: &Path) -> bool {
// The `--version` command does not contain information about debug/release, but we can see if the `--help` output lists the command
// `--dump-extension-api`. This seems to be reliable down to Godot 4.1.

let mut cmd = Command::new(godot_bin);
cmd.arg("--help");

let haystack = execute(cmd, "Godot CLI help to check debug/release");
let needle = b"--dump-extension-api";

haystack
.stdout
.windows(needle.len())
.any(|window| window == needle)
}

fn dump_extension_api(godot_bin: &Path, out_file: &Path) {
Expand Down
Loading