Skip to content

codegen: Serialize named opaque types in static function wrappers - #3554

Open
cleoanka wants to merge 1 commit into
rust-lang:mainfrom
cleoanka:fix/wrap-static-fns-va-list-aarch64-3234
Open

cleoanka wants to merge 1 commit into
rust-lang:mainfrom
cleoanka:fix/wrap-static-fns-va-list-aarch64-3234

Conversation

@cleoanka

Copy link
Copy Markdown

On aarch64-linux, clang defines __builtin_va_list as a typedef of an implicit struct __va_list. bindgen ends up turning that typedef into a TypeKind::Opaque that still carries the name __builtin_va_list (this is also why va_list_aarch64_linux.rs shows an opaque blob). The Rust side handles it, but the C serializer used by --wrap-static-fns has no arm for Opaque, so any static function taking a __builtin_va_list fails with Cannot serialize type kind Opaque.

Fix

bindgen/codegen/serialize.rs: a named opaque type is now written by its name (with const if needed), the same way the Alias arm does it. For the case above this prints __builtin_va_list, the same text the x86_64 path already emits. Unnamed opaque types still return the existing error. The generated Rust bindings do not change.

With the bug fixed, this PR also removes the aarch64-linux workarounds that were marked "remove when #3234 is solved": the DISABLE_VA guard in wrap-static-fns.h, the cfg blocks in test_wrap_static_fns, bindgen-integration/build.rs and bindgen-integration/src/lib.rs, and generated/wrap_static_fns_aarch64_linux.c. Those spots are restored to what they were before the workaround.

Tests

New header test wrap_static_fns_va_list_aarch64_linux.h (--wrap-static-fns -- --target=aarch64-unknown-linux-gnu, plus the wrap-as-variadic-fn callback), so it runs on every host:

  • Without the serializer change it fails: the generated output is /* error generating bindings */. With the change it passes.
  • For a one-off local check I forced --target=aarch64-unknown-linux-gnu in test_wrap_static_fns (not committed). Without the fix it fails with Cannot serialize type kind Opaque at wrap-static-fns.h:71:56. With the fix the output matches generated/wrap_static_fns.c exactly, including the variadic wrappers.

Run locally on aarch64-apple-darwin with stable Rust 1.93.0 and the libclang that clang-sys finds by default:

  • cargo test -p bindgen-tests --test tests: 641 passed, 3 failed. The failures are header_issue_544_stylo_creduce_2_hpp, header_nsbasehashtable_hpp and header_objc_template_h, and the same three fail on unmodified main in this environment (libclang version differences).
  • cargo test in bindgen-tests/tests/expectations: passes, so the new expectation compiles.
  • cargo test in bindgen-integration: 24 passed.
  • cargo clippy --all-targets --workspace --exclude bindgen-integration --exclude tests_expectations -- -D warnings: clean.
  • Nightly rustfmt was not available. Stable rustfmt --edition 2021 --check reports nothing in the changed lines.

Not tested on an aarch64-linux host. The removed workarounds in test_wrap_static_fns and bindgen-integration only change behaviour there, so the ubuntu-24.04-arm CI jobs are the real check for that part.

Fixes #3234

AI disclosure: this pull request was prepared and opened by an AI coding agent (Claude Code) on behalf of the account owner. The agent wrote the change and ran the checks listed above; no human has reviewed or manually tested it yet. Follow-up commits may also come from the agent; replies posted here may be written and sent by the agent without the account owner reviewing them first.

On aarch64-linux, clang defines `__builtin_va_list` as a typedef of an implicit `struct __va_list`. bindgen resolves that typedef to an opaque type that keeps its name, and the C serializer used by `--wrap-static-fns` rejected it with "Cannot serialize type kind Opaque". Refer to such named opaque types by their name in the generated C, and drop the aarch64-linux workarounds added for this issue in the tests.

Fixes rust-lang#3234

This branch has not been deployed

No deployments
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.

Cannot serialize type kind Opaque with valists and wrap-static-fns

1 participant