cargo_build_script: propagate cdylib and bin link args#4097
Open
ashi009 wants to merge 1 commit into
Open
Conversation
A build script's cargo::rustc-cdylib-link-arg, cargo::rustc-link-arg-bin 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/dylib 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-bin[s] is collected into BuildInfo.bin_link_flags and applied only to the owning crate's bin targets. The build-script runner writes each set to its own flag file, added to the relevant rustc action as an --arg-file, so a non-matching crate type never reads it. Fixes bazelbuild#1062.
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?
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-arg,cargo::rustc-link-arg-binandcargo::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/dylib crates and propagated transitively (matching cargo, Tracking issue forrustc-cdylib-link-argtransitive warning rust-lang/cargo#9562).rustc-link-arg-bin[s]→BuildInfo.bin_link_flags, applied only to the owning crate's bin targets.The build-script runner writes each set to its own flag file, added to the rustc action as an
--arg-file, so a non-matching crate type never reads it.