Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2252,9 +2252,20 @@ def _portable_link_flags(lib, use_pic, ambiguous_libs, get_lib_name, for_windows
"-Clink-arg=-l{}".format(get_lib_name(artifact)),
]
elif _is_dylib(lib):
return [
"-ldylib=%s" % get_lib_name(artifact),
]
if for_windows or for_darwin:
use_lib_name = True
else:
lib_file_name = artifact.basename
use_lib_name = (lib_file_name.startswith("lib") and lib_file_name.endswith(".so"))

if use_lib_name:
return [
"-ldylib=%s" % get_lib_name(artifact),
]
else:
return [
"-Clink-arg=-l:{}".format(lib_file_name),
]

return []

Expand Down
15 changes: 3 additions & 12 deletions test/unit/versioned_libs/versioned_libs_analysis_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_import")
load("//rust:defs.bzl", "rust_shared_library")

LIBNAMES = ["sterling", "cheryl", "lana", "pam", "malory", "cyril"]
LIBNAMES = ["sterling", "lana", "pam", "malory", "cyril"]

def _is_in_argv(argv, version = None):
return any(["-ldylib={}{}".format(name, version or "") in argv for name in LIBNAMES])
Expand Down Expand Up @@ -33,7 +33,7 @@ def _suffix_version_test_impl(ctx):
tut = analysistest.target_under_test(env)
argv = tut.actions[0].argv

asserts.true(env, _is_in_argv(argv))
asserts.true(env, "-Clink-arg=-l:libcheryl.so.3.8" in argv)

return analysistest.end(env)

Expand Down Expand Up @@ -68,7 +68,7 @@ def _test_linux():
name = "linux_suffix_version",
srcs = ["a.rs"],
edition = "2018",
deps = [":import_libcheryl.so.3.8", ":import_libcheryl.so"],
deps = [":import_libcheryl.so.3.8"],
target_compatible_with = ["@platforms//os:linux"],
)
cc_import(
Expand All @@ -80,15 +80,6 @@ def _test_linux():
srcs = ["b.c"],
linkshared = True,
)
cc_import(
name = "import_libcheryl.so",
shared_library = "libcheryl.so",
)
copy_file(
name = "copy_unversioned",
src = ":libcheryl.so.3.8",
out = "libcheryl.so",
)
suffix_version_test(
name = "linux_suffix_version_test",
target_under_test = ":linux_suffix_version",
Expand Down