fix link flags of suffix versioned libs#3908
Open
xiaopeng-tranxmart wants to merge 2 commits intobazelbuild:mainfrom
Open
fix link flags of suffix versioned libs#3908xiaopeng-tranxmart wants to merge 2 commits intobazelbuild:mainfrom
xiaopeng-tranxmart wants to merge 2 commits intobazelbuild:mainfrom
Conversation
krasimirgg
reviewed
Mar 19, 2026
rust/private/rustc.bzl
Outdated
| "-ldylib=%s" % get_lib_name(artifact), | ||
| ] | ||
| lib_file_name = artifact.basename | ||
| if lib_file_name.startswith("lib") and lib_file_name.endswith(".so"): |
Collaborator
There was a problem hiding this comment.
Could you check how this interacts with get_lib_name_for_windows? (I'm a bit worried that this check is overly specific to linux and may regress windows.)
Author
There was a problem hiding this comment.
Good catch. It appears that the library search behavior on Windows and Darwin differs from Linux. Since I’m not familiar with those platforms, this change is currently limited to Linux only.
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.
Problem
When a versioned shared library (e.g.
libcheryl.so.3.8) is used, the current behavior generates linker flags such as:rustc -dylib=cherylgcc -lcherylThese flags assume the presence of an unversioned shared library (
libcheryl.so). As a result, linking fails when only versioned libraries (e.g.,libcheryl.so.3.8) are available:The correct linker options in this case should explicitly reference the versioned
.so:rustc -Clink-arg=-l:libcheryl.so.3.8gcc -l:libcheryl.so.3.8Solution
IMO, the current implementation assumes that users always provide unversioned shared libraries (
libxxx.so). This assumption is too restrictive:.sosymlink (e.g., onlylibxxx.so.X.Yexists)libxxx.soconvention (e.g.,xxx.so.1)This PR updates the linking behavior as follows:
lib<name>.so, generate-ldylib=<name>-Clink-arg=-l:<filename>