Skip to content

Conversation

@vaibhav-1207
Copy link
Contributor

@vaibhav-1207 vaibhav-1207 commented Dec 19, 2025

The libclang attr is currently used to set env variables for the underlying clang-sys crate to dynamically link libclang. In build systems that use static linking, these are redundant. Making libclang attr optional simplifies the toolchain config for static linking.

@krasimirgg krasimirgg self-requested a review December 19, 2025 11:18
Copy link
Collaborator

@UebelAndre UebelAndre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some rationale for why?

@vaibhav-1207
Copy link
Contributor Author

I've updated the description with the rationale. LMK if you have any questions.

Copy link
Collaborator

@UebelAndre UebelAndre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't bindgen require libclang to work at all? I'm concerned that if it's not provided by the rule then it's picked up on the host. Is this not the case?

Can you also add a test for this?

@vaibhav-1207
Copy link
Contributor Author

Doesn't bindgen require libclang to work at all?

Yes, bindgen requires libclang to parse headers. However, if the bindgen binary is statically linked with libclang, it is fully self-contained and does not need to load libclang as a shared library at runtime, making the libclang attr redundant.

I'm concerned that if it's not provided by the rule then it's picked up on the host. Is this not the case?

From the clang-sys crate documentation- link, lt appears that crate may indeed fallback to searching on the host if the libclang path is omitted for a dynamically linked bindgen binary.

Can you also add a test for this?

I believe adding a test case would require setting up the build infra for a statically linked bindgen binary, which would be a significant undertaking?

Do you have any suggestions on how else we might document that the libclang attribute is mandatory for dynamically linked systems?

@krasimirgg
Copy link
Collaborator

I think we should be very explicit in the docs that this is really only useful for a custom bindgen that was built by statically linking libclang.

@UebelAndre
Copy link
Collaborator

I believe adding a test case would require setting up the build infra for a statically linked bindgen binary, which would be a significant undertaking?

Why? Surely it's just a change to some cargo_build_script somewhere?

Do you have any suggestions on how else we might document that the libclang attribute is mandatory for dynamically linked systems?

Is it possible to have a process wrapper query the bidngen binary to see if clang is either statically linked or explicitly available?

Clarify that the libclang attribute in rust_bindgen_toolchain is only
optional when the bindgen binary is statically linked. This ensures
users are aware that omitting it for dynamically linked binaries
may lead to non-hermetic builds by falling back to system libraries.
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.

3 participants