Skip to content

Conversation

AllenDang
Copy link

What's the problem?

When gdextension-api is used as a build dependency during cross-compilation, dependent crates can't reliably locate platform-specific binding files. The #[cfg] attributes in load_gdextension_header_rs() get evaluated for the HOST platform, not the TARGET, causing builds to fail with the wrong bindings.

The solution

This PR adds a simple build script that exports the crate's manifest directory via cargo:root=.... This lets dependent crates access platform-specific files directly using the standard DEP_GDEXTENSION_API_ROOT environment variable.

What changed?

  • Added build.rs that exports CARGO_MANIFEST_DIR as cargo:root
  • No changes to existing code or API
  • Cargo automatically detects build.rs, no Cargo.toml changes needed

Testing

  • ✅ Builds successfully with no changes to existing functionality
  • cargo:root properly exported and available to dependents as DEP_GDEXTENSION_API_ROOT
  • ✅ Tested with godot-rust/gdext cross-compilation scenarios

Related

This enables godot-rust/gdext#1361 to fix cross-compilation in a clean way without file system searching.

@Bromeon
Copy link
Member

Bromeon commented Oct 13, 2025

Thanks! Note that this isn't a repo with contributions in the classical sense: it's mostly for artifact storage, partly generated code, and the Git history may be rewritten if that serves the needs of the project. As such I won't merge PRs for now, but I can see if I can integrate your approach in a way so that releases would benefit from this.

We'd need a way to verify that this approach indeed works in downstream godot-rust though. The downstream PR godot-rust/gdext#1361 doesn't mention this environment variable yet... How can we test this?

@AllenDang
Copy link
Author

I tested it at my local MacBook with cross compile to windows gnu/msvc/linux/android.

@Bromeon
Copy link
Member

Bromeon commented Oct 13, 2025

But with which code? Your current PR in godot-rust does not mention this environment variable.

We need to be able to reproduce this. Please update godot-rust/gdext#1361 and also keep all unrelated changes out of the diff (like here, there are 2 changes that have nothing to do with the problem).

@AllenDang
Copy link
Author

gdext#1361 is updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants