cargo_build_script: propagate cdylib and binary link args#4097
Open
ashi009 wants to merge 2 commits into
Open
Conversation
UebelAndre
requested changes
Jun 23, 2026
UebelAndre
left a comment
Collaborator
There was a problem hiding this comment.
Thanks! Can you add a test for somewhere under //cargo/tests/cargo_build_script that confirms the new flags are behaving as expected for binary and library consumers?
789335d to
b85b7a9
Compare
b98b5a3 to
516df28
Compare
516df28 to
6a51b3e
Compare
6e59649 to
b0105ac
Compare
A build script's cargo::rustc-cdylib-link-arg and cargo::rustc-link-arg-bins directives were dropped with a warning, so flags like napi-rs's `-undefined dynamic_lookup` never reached the linker. Route them through BuildInfo to the targets cargo applies them to: * rustc-cdylib-link-arg is collected into BuildInfo.cdylib_link_flags and applied to cdylib crates. Matching cargo, it propagates transitively: a cdylib picks up the cdylib link args of every build script in its transitive dependencies (rust-lang/cargo#9562). * rustc-link-arg-bins is collected into BuildInfo.bin_link_flags and applied to binary crates. Each set is written to its own flag file, added to the relevant rustc action as an --arg-file, so a non-matching crate type never reads it. The per-binary cargo::rustc-link-arg-bin=BIN=FLAG stays unsupported: a build script's outputs are shared by every target that depends on it, so a flag cannot be scoped to one named binary. Fixes bazelbuild#1062.
b0105ac to
83887c4
Compare
Author
|
@UebelAndre added |
0d941d4 to
1a4497f
Compare
UebelAndre
approved these changes
Jun 24, 2026
UebelAndre
left a comment
Collaborator
There was a problem hiding this comment.
Thank you! Looking good! Just need to fix buildifier
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.
Fixes #1062.
A build script's
cargo::rustc-cdylib-link-argandcargo::rustc-link-arg-binswere dropped with a warning, so flags like napi-rs's-undefined dynamic_lookupnever reached the linker.Route them through
BuildInfoto the targets cargo applies them to:rustc-cdylib-link-arg→BuildInfo.cdylib_link_flags, applied to cdylib crates and propagated transitively (matching cargo, Tracking issue forrustc-cdylib-link-argtransitive warning rust-lang/cargo#9562).rustc-link-arg-bins→BuildInfo.bin_link_flags, applied to binary crates.Each set is written to its own flag file, added to the rustc action as an
--arg-file, so a non-matching crate type never reads it. The per-binaryrustc-link-arg-bin=BIN=FLAGstays unsupported — a build script's outputs are shared by every consumer, so a flag can't be scoped to one named binary.