Skip to content

Conversation

@ufoot
Copy link

@ufoot ufoot commented Dec 16, 2025

Trying to elaborate on godot-rust/gdext#1444 and prepare ground for a proper fix.

Generate separate bindings for 32-bit and 64-bit targets to ensure correct layout tests on both architectures. This should fix compilation on wasm32 and other 32-bit platforms without runtime workarounds.

Targets supported:

  • 64-bit: platform-specific (windows, macos, linux_64 as a catch-all)
  • 32-bit: shared linux_32 for all 32-bit targets (wasm32, i686)

Questions @Bromeon before I move further on this one, this PR renames stuff that was _linux.rs to _linux_64.rs or _linux_32.rs. And generally speaking appends 32/64 to anything that was "just the default linux path" before. This is likely going to be a breaking change. My view on this is that it's safer to have explicit _64 and _32 when there could be a differnce. As opposed to _linux.rs is 64-bit implicitly and _linux_32.rs is here for the exceptional case we want 32-bit. But migration would be smoother if we were to just introduce _32.rs and keep the rest unchanged.

TL;DR I am not sure about naming ;)

Generate separate bindings for 32-bit and 64-bit targets to ensure
correct layout tests on both architectures. This should fix compilation
on wasm32 and other 32-bit platforms without runtime workarounds.

Targets supported:

- 64-bit: platform-specific (windows, macos, linux_64 as a catch-all)
- 32-bit: shared linux_32 for all 32-bit targets (wasm32, i686)
- Add load_gdextension_header_rs_32() and load_gdextension_header_rs_64()
  which allow build scripts to select bindings based on CARGO_CFG_TARGET_POINTER_WIDTH
- Deprecate load_gdextension_header_rs() which uses compile-time cfg
ufoot added a commit to ufoot/gdext that referenced this pull request Dec 16, 2025
Prebuilt bindings previously used a runtime workaround that stripped layout
tests when cross-compiling to 32-bit. This was fragile and didn't validate
struct layouts on 32-bit targets.

Changes:
- Add TargetPointerWidth enum and generate_rust_binding_for_target() for
  generating bindings for a specific architecture via clang's --target flag
- Export write_gdextension_headers_for_target() for godot4-prebuilt to
  generate both 32-bit and 64-bit bindings from a single host
- Update prebuilt mode to select bindings using CARGO_CFG_TARGET_POINTER_WIDTH
  (the actual cross-compile target, not the host)
- Remove strip_bindgen_layout_tests() workaround - no longer needed since
  prebuilt artifacts now include proper architecture-specific bindings.
  This should be squashed with previous commits, but until this is validated
  let's keep full history of what's there.

Requirements:
- this requires godot-rust/godot4-prebuilt#2
  or similar, will not work with current tip-of-master.
@Bromeon
Copy link
Member

Bromeon commented Dec 16, 2025

Hi, like I wrote in the downstream PR:

Unfortunately this is not as simple as opening a PR, I have to modify the generator itself and adjust some scripts.

This repo is not meant for pull requests. Please have some patience until I find time to update the generator 🙂

May I ask if you have used AI tools in the generation of this or the gdext pull request?

ufoot added a commit to ufoot/gdext that referenced this pull request Dec 16, 2025
Prebuilt bindings previously used a runtime workaround that stripped layout
tests when cross-compiling to 32-bit. This was fragile and didn't validate
struct layouts on 32-bit targets.

Changes:
- Add TargetPointerWidth enum and generate_rust_binding_for_target() for
  generating bindings for a specific architecture via clang's --target flag
- Export write_gdextension_headers_for_target() for godot4-prebuilt to
  generate both 32-bit and 64-bit bindings from a single host
- Update prebuilt mode to select bindings using CARGO_CFG_TARGET_POINTER_WIDTH
  (the actual cross-compile target, not the host)
- Remove strip_bindgen_layout_tests() workaround - no longer needed since
  prebuilt artifacts now include proper architecture-specific bindings.
  This should be squashed with previous commits, but until this is validated
  let's keep full history of what's there.

Requirements:
- this requires godot-rust/godot4-prebuilt#2
  or similar, will not work with current tip-of-master.
@ufoot
Copy link
Author

ufoot commented Dec 16, 2025

Ah OK, sorry, my bad, I probably did not RTFM enough about contributing guidelines etc. Will close this PR if that's not the way to go, no worries.

@ufoot ufoot closed this Dec 16, 2025
@ufoot
Copy link
Author

ufoot commented Dec 16, 2025

May I ask if you have used AI tools in the generation of this or the gdext pull request?

I do have some AI completion enabled on my editor so implicitly yes, I do use AI tools unless I explicitly disable my default dev workflow.

More precisely I am using this copilot.el

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