fix: gate bindgen layout tests on 64-bit pointer width#69
Open
kylebarron wants to merge 1 commit into
Open
Conversation
bindgen emits struct size/offset layout assertions using the host pointer
width. On 32-bit targets (e.g. wasm32-unknown-emscripten) the pointer-
containing structs are smaller, so the hard-coded sizes underflow at
const-eval and the crate fails to compile:
error[E0080]: attempt to compute `12_usize - 16_usize`, which would overflow
--> src/ffi.rs ["Size of DLPackExchangeAPIHeader"][size_of::<_>() - 16usize];
Gate every layout-test block on `target_pointer_width = "64"` so the checks
still run where they were generated but no longer break 32-bit builds. Also
update the bindgen post-processing so regeneration reproduces the gate.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Disclaimer: This was auto-generated by Claude, and I haven't looked at it yet.
Problem
The bindgen-generated
src/ffi.rsemits struct size/offset layout testsusing the host pointer width (64-bit). On 32-bit targets these hard-coded
sizes underflow at const-eval and the crate fails to compile. This breaks, for
example,
wasm32-unknown-emscripten(the Pyodide wheel target):Every pointer-containing struct (
DLTensor,DLManagedTensor,DLManagedTensorVersioned,DLPackExchangeAPIHeader,DLPackExchangeAPI) isaffected, since function/data pointers are 4 bytes on wasm32 vs 8 on x86-64.
The struct layouts are correct on 32-bit (
#[repr(C)]follows the target CABI) — only the generated size assertions, baked in from a 64-bit host, are
wrong.
Fix
Gate every layout-test block on
#[cfg(target_pointer_width = "64")], so thechecks still run where they were generated (64-bit) but no longer break 32-bit
builds. The bindgen post-processing in
dlpark-bindgenis updated to reproducethe gate on regeneration, and
src/ffi.rsis updated to match.Verification
🤖 Generated with Claude Code