From 74ef87d664cd7e394437e3c5aca73fdf7f1fb622 Mon Sep 17 00:00:00 2001 From: Rosica Dejanovska Date: Fri, 5 Aug 2022 13:53:50 +0200 Subject: [PATCH 1/6] Fix #1374 --- rust/private/rustc.bzl | 18 ++++++++++++++++++ test/native_deps/BUILD.bazel | 26 ++++++++++++++++++++++++++ test/native_deps/direct.cc | 6 ++++++ test/native_deps/direct.h | 4 ++++ test/native_deps/main.rs | 3 +++ test/native_deps/transitive.rs | 2 ++ test/native_deps/user.rs | 0 7 files changed, 59 insertions(+) create mode 100644 test/native_deps/BUILD.bazel create mode 100644 test/native_deps/direct.cc create mode 100644 test/native_deps/direct.h create mode 100644 test/native_deps/main.rs create mode 100644 test/native_deps/transitive.rs create mode 100644 test/native_deps/user.rs diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl index 0fe072b8e1..f87261f42c 100644 --- a/rust/private/rustc.bzl +++ b/rust/private/rustc.bzl @@ -1544,6 +1544,24 @@ def _portable_link_flags(lib, use_pic, ambiguous_libs): # and adding references to these symlinks in the native section A. # We rely in the behavior of -Clink-arg to put the linker args # at the end of the linker invocation constructed by rustc. + + # 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 agains 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 remove `libtest-{hash}.so` and `libstd-{hash}.so` + # from the toolchain. However, it is not enough to change the toolchain's `rust_std_{...}` filegroups + # here: https://github.com/bazelbuild/rules_rust/blob/a9d5d894ad801002d007b858efd154e503796b9f/rust/private/repository_utils.bzl#L144 + # because rustc manages to escape the sandbox and still finds them at linking time. + # We need to modify the repository rules to erase those files completely. + if "lib/rustlib" in artifact.path and ( + artifact.basename.startswith("libtest-") or artifact.basename.startswith("libstd-") or + artifact.basename.startswith("test-") or artifact.basename.startswith("std-") + ): + return ["-lstatic=%s" % get_lib_name(artifact)] return [ "-lstatic=%s" % get_lib_name(artifact), "-Clink-arg=-l%s" % get_lib_name(artifact), diff --git a/test/native_deps/BUILD.bazel b/test/native_deps/BUILD.bazel new file mode 100644 index 0000000000..5c5d57a6da --- /dev/null +++ b/test/native_deps/BUILD.bazel @@ -0,0 +1,26 @@ +load("@rules_cc//cc:defs.bzl", "cc_library") +load( + "@rules_rust//rust:defs.bzl", + "rust_library", + "rust_test", +) + +rust_library( + name = "transitive", + srcs = ["transitive.rs"], + edition = "2018", +) + +cc_library( + name = "direct", + srcs = ["direct.cc"], + hdrs = ["direct.h"], + deps = ["transitive"], +) + +rust_test( + name = "main", + srcs = ["main.rs"], + edition = "2018", + deps = ["direct"], +) diff --git a/test/native_deps/direct.cc b/test/native_deps/direct.cc new file mode 100644 index 0000000000..a809ae8340 --- /dev/null +++ b/test/native_deps/direct.cc @@ -0,0 +1,6 @@ +#include "direct.h" + +RustStruct MakeRustStruct() { + RustStruct result; + return result; +} diff --git a/test/native_deps/direct.h b/test/native_deps/direct.h new file mode 100644 index 0000000000..f4f4b92397 --- /dev/null +++ b/test/native_deps/direct.h @@ -0,0 +1,4 @@ +struct RustStruct{}; + +extern "C" RustStruct MakeRustStruct(); + diff --git a/test/native_deps/main.rs b/test/native_deps/main.rs new file mode 100644 index 0000000000..103d3744b8 --- /dev/null +++ b/test/native_deps/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Done!"); +} diff --git a/test/native_deps/transitive.rs b/test/native_deps/transitive.rs new file mode 100644 index 0000000000..987bc30e0d --- /dev/null +++ b/test/native_deps/transitive.rs @@ -0,0 +1,2 @@ +#[repr(C)] +pub struct RustStruct {} diff --git a/test/native_deps/user.rs b/test/native_deps/user.rs new file mode 100644 index 0000000000..e69de29bb2 From c14cd1af3a64050aa9ebffe200080bdb381b4fdd Mon Sep 17 00:00:00 2001 From: Rosica Dejanovska Date: Fri, 5 Aug 2022 14:06:10 +0200 Subject: [PATCH 2/6] Fix windows CI --- rust/private/rustc.bzl | 16 ++++++++-------- rust/private/utils.bzl | 5 +++-- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl index f87261f42c..131c37c40e 100644 --- a/rust/private/rustc.bzl +++ b/rust/private/rustc.bzl @@ -425,7 +425,7 @@ def _symlink_for_ambiguous_lib(actions, toolchain, crate_info, lib): # Take the absolute value of hash() since it could be negative. path_hash = abs(hash(lib.path)) - lib_name = get_lib_name(lib) + lib_name = get_lib_name(lib, for_windows = toolchain.os.startswith("windows")) prefix = "lib" extension = ".a" @@ -488,7 +488,7 @@ def _disambiguate_libs(actions, toolchain, crate_info, dep_info, use_pic): if _is_dylib(lib): continue artifact = get_preferred_artifact(lib, use_pic) - name = get_lib_name(artifact) + name = get_lib_name(artifact, for_windows = toolchain.os.startswith("windows")) # On Linux-like platforms, normally library base names start with # `lib`, following the pattern `lib[name].(a|lo)` and we pass @@ -1523,7 +1523,7 @@ def _get_crate_dirname(crate): """ return crate.output.dirname -def _portable_link_flags(lib, use_pic, ambiguous_libs): +def _portable_link_flags(lib, use_pic, ambiguous_libs, for_windows = False): artifact = get_preferred_artifact(lib, use_pic) if ambiguous_libs and artifact.path in ambiguous_libs: artifact = ambiguous_libs[artifact.path] @@ -1561,14 +1561,14 @@ def _portable_link_flags(lib, use_pic, ambiguous_libs): artifact.basename.startswith("libtest-") or artifact.basename.startswith("libstd-") or artifact.basename.startswith("test-") or artifact.basename.startswith("std-") ): - return ["-lstatic=%s" % get_lib_name(artifact)] + return ["-lstatic=%s" % get_lib_name(artifact, for_windows)] return [ - "-lstatic=%s" % get_lib_name(artifact), - "-Clink-arg=-l%s" % get_lib_name(artifact), + "-lstatic=%s" % get_lib_name(artifact, for_windows), + "-Clink-arg=-l%s" % get_lib_name(artifact) if not for_windows else artifact.basename, ] elif _is_dylib(lib): return [ - "-ldylib=%s" % get_lib_name(artifact), + "-ldylib=%s" % get_lib_name(artifact, for_windows), ] return [] @@ -1580,7 +1580,7 @@ def _make_link_flags_windows(linker_input_and_use_pic_and_ambiguous_libs): if lib.alwayslink: ret.extend(["-C", "link-arg=/WHOLEARCHIVE:%s" % get_preferred_artifact(lib, use_pic).path]) else: - ret.extend(_portable_link_flags(lib, use_pic, ambiguous_libs)) + ret.extend(_portable_link_flags(lib, use_pic, ambiguous_libs, for_windows = True)) return ret def _make_link_flags_darwin(linker_input_and_use_pic_and_ambiguous_libs): diff --git a/rust/private/utils.bzl b/rust/private/utils.bzl index 633c90a00f..eff961e2c6 100644 --- a/rust/private/utils.bzl +++ b/rust/private/utils.bzl @@ -97,7 +97,7 @@ def _path_parts(path): path_parts = path.split("/") return [part for part in path_parts if part != "."] -def get_lib_name(lib): +def get_lib_name(lib, for_windows = False): """Returns the name of a library artifact, eg. libabc.a -> abc Args: @@ -105,6 +105,7 @@ def get_lib_name(lib): Returns: str: The name of the library + for_windows: Whether we're building on Windows. """ # On macos and windows, dynamic/static libraries always end with the # extension and potential versions will be before the extension, and should @@ -125,7 +126,7 @@ def get_lib_name(lib): # The library name is now everything minus the extension. libname = ".".join(comps[:-1]) - if libname.startswith("lib"): + if not for_windows: return libname[3:] else: return libname From b4e244ef1129c1f0114890edb13c5df662f69621 Mon Sep 17 00:00:00 2001 From: Rosica Dejanovska Date: Fri, 5 Aug 2022 14:16:18 +0200 Subject: [PATCH 3/6] Fix unit tests --- rust/private/rustc.bzl | 2 +- rust/private/utils.bzl | 2 +- test/unit/native_deps/native_deps_test.bzl | 33 ++++++++++++------- .../proc_macro_does_not_leak_deps.bzl | 13 ++++++-- 4 files changed, 34 insertions(+), 16 deletions(-) diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl index 131c37c40e..cf61f16a3d 100644 --- a/rust/private/rustc.bzl +++ b/rust/private/rustc.bzl @@ -1564,7 +1564,7 @@ def _portable_link_flags(lib, use_pic, ambiguous_libs, for_windows = False): return ["-lstatic=%s" % get_lib_name(artifact, for_windows)] return [ "-lstatic=%s" % get_lib_name(artifact, for_windows), - "-Clink-arg=-l%s" % get_lib_name(artifact) if not for_windows else artifact.basename, + "-Clink-arg=-l%s" % (get_lib_name(artifact) if not for_windows else artifact.basename), ] elif _is_dylib(lib): return [ diff --git a/rust/private/utils.bzl b/rust/private/utils.bzl index eff961e2c6..bb503d62a1 100644 --- a/rust/private/utils.bzl +++ b/rust/private/utils.bzl @@ -102,10 +102,10 @@ def get_lib_name(lib, for_windows = False): Args: lib (File): A library file + for_windows: Whether we're building on Windows. Returns: str: The name of the library - for_windows: Whether we're building on Windows. """ # On macos and windows, dynamic/static libraries always end with the # extension and potential versions will be before the extension, and should diff --git a/test/unit/native_deps/native_deps_test.bzl b/test/unit/native_deps/native_deps_test.bzl index d066c80158..c855fd1198 100644 --- a/test/unit/native_deps/native_deps_test.bzl +++ b/test/unit/native_deps/native_deps_test.bzl @@ -30,7 +30,8 @@ def _cdylib_has_native_libs_test_impl(ctx): assert_argv_contains_prefix_suffix(env, action, "-Lnative=", "/native_deps") assert_argv_contains(env, action, "--crate-type=cdylib") assert_argv_contains(env, action, "-lstatic=native_dep") - assert_argv_contains(env, action, "-Clink-arg=-lnative_dep") + native_link_arg = "-Clink-arg=native_dep.lib" if ctx.target_platform_has_constraint(ctx.attr._windows_constraint[platform_common.ConstraintValueInfo]) else "-Clink-arg=-lnative_dep" + assert_argv_contains(env, action, native_link_arg) assert_argv_contains_prefix(env, action, "--codegen=linker=") return analysistest.end(env) @@ -41,22 +42,21 @@ def _staticlib_has_native_libs_test_impl(ctx): assert_argv_contains_prefix_suffix(env, action, "-Lnative=", "/native_deps") assert_argv_contains(env, action, "--crate-type=staticlib") assert_argv_contains(env, action, "-lstatic=native_dep") - assert_argv_contains(env, action, "-Clink-arg=-lnative_dep") + native_link_arg = "-Clink-arg=native_dep.lib" if ctx.target_platform_has_constraint(ctx.attr._windows_constraint[platform_common.ConstraintValueInfo]) else "-Clink-arg=-lnative_dep" + assert_argv_contains(env, action, native_link_arg) assert_argv_contains_prefix(env, action, "--codegen=linker=") return analysistest.end(env) def _proc_macro_has_native_libs_test_impl(ctx): env = analysistest.begin(ctx) tut = analysistest.target_under_test(env) - if ctx.configuration.coverage_enabled: - asserts.equals(env, 2, len(tut.actions)) - else: - asserts.equals(env, 1, len(tut.actions)) + asserts.equals(env, 1, len(tut.actions)) action = tut.actions[0] assert_argv_contains_prefix_suffix(env, action, "-Lnative=", "/native_deps") assert_argv_contains(env, action, "--crate-type=proc-macro") assert_argv_contains(env, action, "-lstatic=native_dep") - assert_argv_contains(env, action, "-Clink-arg=-lnative_dep") + native_link_arg = "-Clink-arg=native_dep.lib" if ctx.target_platform_has_constraint(ctx.attr._windows_constraint[platform_common.ConstraintValueInfo]) else "-Clink-arg=-lnative_dep" + assert_argv_contains(env, action, native_link_arg) assert_argv_contains_prefix(env, action, "--codegen=linker=") return analysistest.end(env) @@ -66,7 +66,8 @@ def _bin_has_native_libs_test_impl(ctx): action = tut.actions[0] assert_argv_contains_prefix_suffix(env, action, "-Lnative=", "/native_deps") assert_argv_contains(env, action, "-lstatic=native_dep") - assert_argv_contains(env, action, "-Clink-arg=-lnative_dep") + native_link_arg = "-Clink-arg=native_dep.lib" if ctx.target_platform_has_constraint(ctx.attr._windows_constraint[platform_common.ConstraintValueInfo]) else "-Clink-arg=-lnative_dep" + assert_argv_contains(env, action, native_link_arg) assert_argv_contains_prefix(env, action, "--codegen=linker=") return analysistest.end(env) @@ -143,10 +144,18 @@ def _cdylib_has_native_dep_and_alwayslink_test_impl(ctx): return analysistest.end(env) rlib_has_no_native_libs_test = analysistest.make(_rlib_has_no_native_libs_test_impl) -staticlib_has_native_libs_test = analysistest.make(_staticlib_has_native_libs_test_impl) -cdylib_has_native_libs_test = analysistest.make(_cdylib_has_native_libs_test_impl) -proc_macro_has_native_libs_test = analysistest.make(_proc_macro_has_native_libs_test_impl) -bin_has_native_libs_test = analysistest.make(_bin_has_native_libs_test_impl) +staticlib_has_native_libs_test = analysistest.make(_staticlib_has_native_libs_test_impl, attrs = { + "_windows_constraint": attr.label(default = Label("@platforms//os:windows")), +}) +cdylib_has_native_libs_test = analysistest.make(_cdylib_has_native_libs_test_impl, attrs = { + "_windows_constraint": attr.label(default = Label("@platforms//os:windows")), +}) +proc_macro_has_native_libs_test = analysistest.make(_proc_macro_has_native_libs_test_impl, attrs = { + "_windows_constraint": attr.label(default = Label("@platforms//os:windows")), +}) +bin_has_native_libs_test = analysistest.make(_bin_has_native_libs_test_impl, attrs = { + "_windows_constraint": attr.label(default = Label("@platforms//os:windows")), +}) bin_has_native_dep_and_alwayslink_test = analysistest.make(_bin_has_native_dep_and_alwayslink_test_impl, attrs = { "_macos_constraint": attr.label(default = Label("@platforms//os:macos")), "_windows_constraint": attr.label(default = Label("@platforms//os:windows")), diff --git a/test/unit/proc_macro/leaks_deps/proc_macro_does_not_leak_deps.bzl b/test/unit/proc_macro/leaks_deps/proc_macro_does_not_leak_deps.bzl index db86506305..1373a5d603 100644 --- a/test/unit/proc_macro/leaks_deps/proc_macro_does_not_leak_deps.bzl +++ b/test/unit/proc_macro/leaks_deps/proc_macro_does_not_leak_deps.bzl @@ -14,6 +14,10 @@ def _proc_macro_does_not_leak_deps_impl(ctx): asserts.false(env, rustc_action == None) + link_arg_prefix = "-Clink-arg=native" if ctx.target_platform_has_constraint( + ctx.attr._windows_constraint[platform_common.ConstraintValueInfo], + ) else "-Clink-arg=-lnative" + # Our test target has a dependency on "proc_macro_dep" via a rust_proc_macro target, # so the proc_macro_dep rlib should not appear as an input to the Rustc action, nor as -Ldependency on the command line. proc_macro_dep_inputs = [i for i in rustc_action.inputs.to_list() if "proc_macro_dep" in i.path] @@ -25,7 +29,7 @@ def _proc_macro_does_not_leak_deps_impl(ctx): # Our test target depends on proc_macro_dep:native directly, as well as transitively through the # proc_macro. The proc_macro should not leak its dependency, so we should only get the "native" # library once on the command line. - native_deps = [arg for arg in rustc_action.argv if arg.startswith("-Clink-arg=-lnative")] + native_deps = [arg for arg in rustc_action.argv if arg.startswith(link_arg_prefix)] asserts.equals(env, 1, len(native_deps)) return analysistest.end(env) @@ -66,7 +70,12 @@ def _proc_macro_does_not_leak_deps_test(): target_under_test = ":deps_not_leaked", ) -proc_macro_does_not_leak_deps_test = analysistest.make(_proc_macro_does_not_leak_deps_impl) +proc_macro_does_not_leak_deps_test = analysistest.make( + _proc_macro_does_not_leak_deps_impl, + attrs = { + "_windows_constraint": attr.label(default = Label("@platforms//os:windows")), + }, +) # Tests that a lib_a -> proc_macro -> lib_b does not propagate lib_b to the inputs of lib_a def _proc_macro_does_not_leak_lib_deps_impl(ctx): From 7e50ebf9bc0f235c5b051d1ccd1402f61cf0e5f6 Mon Sep 17 00:00:00 2001 From: Rosica Dejanovska Date: Fri, 5 Aug 2022 14:21:03 +0200 Subject: [PATCH 4/6] Fix get_lib_name --- rust/private/utils.bzl | 2 +- .../leaks_deps/proc_macro_does_not_leak_deps.bzl | 13 ++----------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/rust/private/utils.bzl b/rust/private/utils.bzl index bb503d62a1..e342b3bef8 100644 --- a/rust/private/utils.bzl +++ b/rust/private/utils.bzl @@ -126,7 +126,7 @@ def get_lib_name(lib, for_windows = False): # The library name is now everything minus the extension. libname = ".".join(comps[:-1]) - if not for_windows: + if libname.startswith("lib") and not for_windows: return libname[3:] else: return libname diff --git a/test/unit/proc_macro/leaks_deps/proc_macro_does_not_leak_deps.bzl b/test/unit/proc_macro/leaks_deps/proc_macro_does_not_leak_deps.bzl index 1373a5d603..db86506305 100644 --- a/test/unit/proc_macro/leaks_deps/proc_macro_does_not_leak_deps.bzl +++ b/test/unit/proc_macro/leaks_deps/proc_macro_does_not_leak_deps.bzl @@ -14,10 +14,6 @@ def _proc_macro_does_not_leak_deps_impl(ctx): asserts.false(env, rustc_action == None) - link_arg_prefix = "-Clink-arg=native" if ctx.target_platform_has_constraint( - ctx.attr._windows_constraint[platform_common.ConstraintValueInfo], - ) else "-Clink-arg=-lnative" - # Our test target has a dependency on "proc_macro_dep" via a rust_proc_macro target, # so the proc_macro_dep rlib should not appear as an input to the Rustc action, nor as -Ldependency on the command line. proc_macro_dep_inputs = [i for i in rustc_action.inputs.to_list() if "proc_macro_dep" in i.path] @@ -29,7 +25,7 @@ def _proc_macro_does_not_leak_deps_impl(ctx): # Our test target depends on proc_macro_dep:native directly, as well as transitively through the # proc_macro. The proc_macro should not leak its dependency, so we should only get the "native" # library once on the command line. - native_deps = [arg for arg in rustc_action.argv if arg.startswith(link_arg_prefix)] + native_deps = [arg for arg in rustc_action.argv if arg.startswith("-Clink-arg=-lnative")] asserts.equals(env, 1, len(native_deps)) return analysistest.end(env) @@ -70,12 +66,7 @@ def _proc_macro_does_not_leak_deps_test(): target_under_test = ":deps_not_leaked", ) -proc_macro_does_not_leak_deps_test = analysistest.make( - _proc_macro_does_not_leak_deps_impl, - attrs = { - "_windows_constraint": attr.label(default = Label("@platforms//os:windows")), - }, -) +proc_macro_does_not_leak_deps_test = analysistest.make(_proc_macro_does_not_leak_deps_impl) # Tests that a lib_a -> proc_macro -> lib_b does not propagate lib_b to the inputs of lib_a def _proc_macro_does_not_leak_lib_deps_impl(ctx): From 7029937d06e38b8608280245280695ebb8ebbefc Mon Sep 17 00:00:00 2001 From: Rosica Dejanovska Date: Fri, 5 Aug 2022 14:34:05 +0200 Subject: [PATCH 5/6] Fix windows flag --- test/unit/native_deps/native_deps_test.bzl | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/test/unit/native_deps/native_deps_test.bzl b/test/unit/native_deps/native_deps_test.bzl index c855fd1198..43b1c07539 100644 --- a/test/unit/native_deps/native_deps_test.bzl +++ b/test/unit/native_deps/native_deps_test.bzl @@ -30,7 +30,7 @@ def _cdylib_has_native_libs_test_impl(ctx): assert_argv_contains_prefix_suffix(env, action, "-Lnative=", "/native_deps") assert_argv_contains(env, action, "--crate-type=cdylib") assert_argv_contains(env, action, "-lstatic=native_dep") - native_link_arg = "-Clink-arg=native_dep.lib" if ctx.target_platform_has_constraint(ctx.attr._windows_constraint[platform_common.ConstraintValueInfo]) else "-Clink-arg=-lnative_dep" + native_link_arg = "-Clink-arg=-lnative_dep.lib" if ctx.target_platform_has_constraint(ctx.attr._windows_constraint[platform_common.ConstraintValueInfo]) else "-Clink-arg=-lnative_dep" assert_argv_contains(env, action, native_link_arg) assert_argv_contains_prefix(env, action, "--codegen=linker=") return analysistest.end(env) @@ -42,7 +42,7 @@ def _staticlib_has_native_libs_test_impl(ctx): assert_argv_contains_prefix_suffix(env, action, "-Lnative=", "/native_deps") assert_argv_contains(env, action, "--crate-type=staticlib") assert_argv_contains(env, action, "-lstatic=native_dep") - native_link_arg = "-Clink-arg=native_dep.lib" if ctx.target_platform_has_constraint(ctx.attr._windows_constraint[platform_common.ConstraintValueInfo]) else "-Clink-arg=-lnative_dep" + native_link_arg = "-Clink-arg=-lnative_dep.lib" if ctx.target_platform_has_constraint(ctx.attr._windows_constraint[platform_common.ConstraintValueInfo]) else "-Clink-arg=-lnative_dep" assert_argv_contains(env, action, native_link_arg) assert_argv_contains_prefix(env, action, "--codegen=linker=") return analysistest.end(env) @@ -50,12 +50,11 @@ def _staticlib_has_native_libs_test_impl(ctx): def _proc_macro_has_native_libs_test_impl(ctx): env = analysistest.begin(ctx) tut = analysistest.target_under_test(env) - asserts.equals(env, 1, len(tut.actions)) action = tut.actions[0] assert_argv_contains_prefix_suffix(env, action, "-Lnative=", "/native_deps") assert_argv_contains(env, action, "--crate-type=proc-macro") assert_argv_contains(env, action, "-lstatic=native_dep") - native_link_arg = "-Clink-arg=native_dep.lib" if ctx.target_platform_has_constraint(ctx.attr._windows_constraint[platform_common.ConstraintValueInfo]) else "-Clink-arg=-lnative_dep" + native_link_arg = "-Clink-arg=-lnative_dep.lib" if ctx.target_platform_has_constraint(ctx.attr._windows_constraint[platform_common.ConstraintValueInfo]) else "-Clink-arg=-lnative_dep" assert_argv_contains(env, action, native_link_arg) assert_argv_contains_prefix(env, action, "--codegen=linker=") return analysistest.end(env) @@ -66,7 +65,7 @@ def _bin_has_native_libs_test_impl(ctx): action = tut.actions[0] assert_argv_contains_prefix_suffix(env, action, "-Lnative=", "/native_deps") assert_argv_contains(env, action, "-lstatic=native_dep") - native_link_arg = "-Clink-arg=native_dep.lib" if ctx.target_platform_has_constraint(ctx.attr._windows_constraint[platform_common.ConstraintValueInfo]) else "-Clink-arg=-lnative_dep" + native_link_arg = "-Clink-arg=-lnative_dep.lib" if ctx.target_platform_has_constraint(ctx.attr._windows_constraint[platform_common.ConstraintValueInfo]) else "-Clink-arg=-lnative_dep" assert_argv_contains(env, action, native_link_arg) assert_argv_contains_prefix(env, action, "--codegen=linker=") return analysistest.end(env) From b17a8a45d2f2ecbd690e46b96adcbbff8c565b2e Mon Sep 17 00:00:00 2001 From: Rosica Dejanovska Date: Fri, 5 Aug 2022 14:40:45 +0200 Subject: [PATCH 6/6] Fix typos --- rust/private/rustc.bzl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl index cf61f16a3d..97b8a17220 100644 --- a/rust/private/rustc.bzl +++ b/rust/private/rustc.bzl @@ -1545,10 +1545,10 @@ def _portable_link_flags(lib, use_pic, ambiguous_libs, for_windows = False): # We rely in the behavior of -Clink-arg to put the linker args # at the end of the linker invocation constructed by rustc. - # We skip adding `-Clink-arg=-l for libstd and libtest from the standard library, as + # 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 agains the `.so`s but not putting the + # 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