-
Notifications
You must be signed in to change notification settings - Fork 474
Do not pass --Clink-arg=-l
for libstd and libtest
#1500
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
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
krasimirgg
approved these changes
Aug 5, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Thank you!
scentini
added a commit
that referenced
this pull request
Aug 9, 2022
#1500 added an additional `for_windows` parameter to `get_lib_name`. I missed the fact that we also pass that function to `map_each` here: https://github.com/bazelbuild/rules_rust/blob/main/rust/private/rustc.bzl#L1671 and as such, this code does not always work correctly (we don't get to pass the `for_windows` parameter, and internally at Google it ended up evaluating to `True` on Linux builds). I tried to avoid flattening the `cc_toolchain.dynamic_runtime_lib` and `cc_toolchain.static_runtime_lib` depsets by using a lambda: ``` args.add_all( cc_toolchain.dynamic_runtime_lib(feature_configuration = feature_configuration), map_each = lambda x: get_lib_name(x, for_windows = toolchain.os.startswith("windows)), format_each = "-ldylib=%s", ) ``` However it looks like such usage of lambdas is not allowed: ``` Error in add_all: to avoid unintended retention of analysis data structures, the map_each function (declared at ...) must be declared by a top-level def statement ``` So instead of `get_lib_name` we now have `get_lib_name_default` and `get_lib_name_for_windows`.
This was referenced May 3, 2024
Merged
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 #1374
We skip adding
-Clink-arg=-l...
for libstd and libtest from the standard library, as these two libraries are present both as an.rlib
and a.so
format. On linux, Rustc adds a -Bdynamic to the linker command line before the libraries specified with-Clink-arg
, which leads to us linking against the.so
s but not putting the corresponding value to the runtime library search paths, which results in a "cannot open shared object file: No such file or directory" error at exectuion time. We can fix this by adding a-Clink-arg=-Bstatic
on linux, but we don't have that option for macos. The proper solution for this issue would be to removelibtest-{hash}.so
andlibstd-{hash}.so
from the toolchain. However, it is not enough to change the toolchain'srust_std_{...}
filegroups here:rules_rust/rust/private/repository_utils.bzl
Line 144 in a9d5d89
This PR also fixes the following issues for Windows:
libc
-Clink-arg
should point to the library name with extension included for windows.