Conversation
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.
This branch has not been deployed
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.
Build scripts emitting binary or cdylib linker arguments currently lose those arguments. This recreates #4097 by @ashi009 on current main, retaining the original author’s commit and updating the implementation and regression coverage.
Both
rustc-link-arg-cdyliband its legacyrustc-cdylib-link-argalias reach cdylib consumers. Binary directives remain direct-only and exclude test harnesses.rustc-link-arg-bin=BIN=FLAGmatches the exact Cargo binary name; generated targets can setcargo_bin_namewhen their Bazel name differs. Interleaved named and all-binary arguments retain their emission order, including flags containing equals signs. The new flag files use the current build-script path substitution mechanism.André’s requested binary/library regression coverage now includes cdylibs, rlibs, two binary names, a test harness, transitive build scripts, and actual compiler/linker execution. An invalid flag for an unrelated binary must be filtered out for those builds to succeed. Buildifier formatting is corrected.
Related: #1062. The new binary-scoped argument format is internal to the runner/process-wrapper pair; existing general argument files retain their format.
The real-build regression also passes with
--experimental_output_paths=stripon macOS.Fixes #4299.
Validation:
bazel test //cargo/tests/cargo_build_script/cdylib_bin_link_args:all //cargo/private/cargo_build_script_runner:all //util/process_wrapper:process_wrapper_test(10 tests passed); formatting and whitespace checks passed.