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
21 changes: 17 additions & 4 deletions rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2252,6 +2252,7 @@ def portable_link_flags(
use_pic,
ambiguous_libs,
get_lib_name,
for_windows = False,
for_darwin = False,
flavor_msvc = False):
"""_summary_
Expand All @@ -2261,6 +2262,7 @@ def portable_link_flags(
use_pic (_type_): _description_
ambiguous_libs (_type_): _description_
get_lib_name (_type_): _description_
for_windows (bool, optional): _description_. Defaults to False.
for_darwin (bool, optional): _description_. Defaults to False.
flavor_msvc (bool, optional): _description_. Defaults to False.

Expand Down Expand Up @@ -2317,9 +2319,20 @@ def portable_link_flags(
"-Clink-arg=-l{}".format(get_lib_name(artifact)),
]
elif _is_dylib(lib):
return [
"-ldylib=%s" % get_lib_name(artifact),
]
lib_file_name = artifact.basename
if for_windows or for_darwin:
use_lib_name = True
else:
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 All @@ -2342,7 +2355,7 @@ def _make_link_flags_windows(make_link_flags_args, flavor_msvc, use_direct_drive
])
elif include_link_flags:
get_lib_name = get_lib_name_for_windows if flavor_msvc else get_lib_name_default
ret.extend(portable_link_flags(lib, use_pic, ambiguous_libs, get_lib_name, flavor_msvc = flavor_msvc))
ret.extend(portable_link_flags(lib, use_pic, ambiguous_libs, get_lib_name, for_windows = True, flavor_msvc = flavor_msvc))

# Windows toolchains can inherit POSIX defaults like -pthread from C deps,
# which fails to link with the MinGW/LLD toolchain. Drop them here.
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
Loading