Fix static native library trailing link arg#3993
Open
wi-adam wants to merge 2 commits intobazelbuild:mainfrom
Open
Fix static native library trailing link arg#3993wi-adam wants to merge 2 commits intobazelbuild:mainfrom
wi-adam wants to merge 2 commits intobazelbuild:mainfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
ff3b783 to
915e999
Compare
915e999 to
05d26c0
Compare
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.
Motivation
I ran into this while adding Rust FFI for Tink through native static libraries with
alwayslink = Falsewhile usingzig ccas the C/C++ toolchain. In that setup, rules_rust currently emits two references for the same static native library: an early-lstatic=<name>and a trailing-Clink-arg=-l<name>used by the native/Rust/native link-order sandwich.On Linux, rustc restores dynamic linker mode before appending
-Clink-argvalues. The early-lstatic=<name>selects the static archive, but the trailing-l<name>is handed to the linker after that mode change, so it is no longer tied to the archive artifact that rules_rust already selected. Withzig cc, this can fail even when Bazel has a concrete.ainput available: Zig treats the trailing-l<name>as a dynamic library lookup and searches forlib<name>.so.Minimal Repro
This reproduces with a
cc_import(static_library = ...)dependency and no shared library artifact.MODULE.bazel:BUILD.bazel:native.c:main.rs:Use a
zig ccwrapper as the configured C compiler. The cache exports avoid Zig failing inside Bazel's sanitized/sandboxed Rust actions:Then run:
Before this change, the Rust action contains:
The link fails under
zig ccbecause the trailing-lnativeis processed after rustc has restored dynamic mode, so Zig reports that it is unable to find dynamic system librarynativeand searches forlibnative.so.With this change, the trailing sandwich arg is the selected archive path instead:
and the repro builds and runs.
Summary
Verification
bazel test //test/unit/proc_macro:proc_macro_does_not_leak_deps_test //test/unit/native_deps:native_deps_test_suite //test/unit/linker_inputs_propagation:linker_inputs_propagation_test_suite //test/unit/windows_lib_name:windows_lib_name_test_suitebazel test //test/unit/proc_macro:proc_macro_does_not_leak_deps_test --test_output=errorsbazel test //test/unit/native_deps:native_deps_test_suite //test/unit/linker_inputs_propagation:linker_inputs_propagation_test_suiteNotes
I reviewed
CONTRIBUTING.md: this is a focused bug fix with tests and no user-facing API/doc change, so I did not add docs or release notes.