diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl index d12900cb28..03c979515b 100644 --- a/rust/private/rustc.bzl +++ b/rust/private/rustc.bzl @@ -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_ @@ -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. @@ -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 [] @@ -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. diff --git a/test/unit/versioned_libs/versioned_libs_analysis_test.bzl b/test/unit/versioned_libs/versioned_libs_analysis_test.bzl index 4545b14e13..d396a8f1ce 100644 --- a/test/unit/versioned_libs/versioned_libs_analysis_test.bzl +++ b/test/unit/versioned_libs/versioned_libs_analysis_test.bzl @@ -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]) @@ -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) @@ -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( @@ -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",