diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl index d71c629dde..165c09b20f 100644 --- a/rust/private/rustc.bzl +++ b/rust/private/rustc.bzl @@ -688,8 +688,10 @@ def establish_cc_info(ctx, crate_info, toolchain, cc_toolchain, feature_configur linker_inputs = depset([link_input]), ) - cc_infos = [dep[CcInfo] for dep in ctx.attr.deps if CcInfo in dep] - cc_infos.append(CcInfo(linking_context = linking_context)) + cc_infos = [CcInfo(linking_context = linking_context)] + for dep in ctx.attr.deps: + if CcInfo in dep: + cc_infos.append(dep[CcInfo]) return [cc_common.merge_cc_infos(cc_infos = cc_infos)] diff --git a/rust/private/rustdoc_test.bzl b/rust/private/rustdoc_test.bzl index b407900fe8..b71b7a473b 100644 --- a/rust/private/rustdoc_test.bzl +++ b/rust/private/rustdoc_test.bzl @@ -104,7 +104,7 @@ def _build_rustdoc_flags(dep_info, crate): is_static = bool(lib_to_link.static_library or lib_to_link.pic_static_library) f = get_preferred_artifact(lib_to_link) if not is_static: - link_flags.append("-ldylib=" + get_lib_name(f)) + link_flags.append("-ldylib=" + get_lib_name(f)) else: link_flags.append("-lstatic=" + get_lib_name(f)) link_flags.append("-Lnative={}".format(_dirname(f.short_path))) diff --git a/rust/repositories.bzl b/rust/repositories.bzl index 99c9cd4b9a..4c9dbf74fc 100644 --- a/rust/repositories.bzl +++ b/rust/repositories.bzl @@ -284,7 +284,6 @@ def BUILD_for_rustc_src(): return _build_file_for_rustc_src - _build_file_for_clippy_template = """\ load("@rules_rust//rust:toolchain.bzl", "rust_toolchain") diff --git a/rust/rust.bzl b/rust/rust.bzl index 6da41269ba..47952515a7 100644 --- a/rust/rust.bzl +++ b/rust/rust.bzl @@ -17,6 +17,8 @@ load( "//rust:defs.bzl", _error_format = "error_format", + _rust_analyzer = "rust_analyzer", + _rust_analyzer_aspect = "rust_analyzer_aspect", _rust_benchmark = "rust_benchmark", _rust_binary = "rust_binary", _rust_clippy = "rust_clippy", @@ -30,8 +32,6 @@ load( _rust_static_library = "rust_static_library", _rust_test = "rust_test", _rust_test_binary = "rust_test_binary", - _rust_analyzer = "rust_analyzer", - _rust_analyzer_aspect = "rust_analyzer_aspect", ) def rust_library(**args): diff --git a/test/rustc_env_files/BUILD b/test/rustc_env_files/BUILD index 0528e7f630..7b303ff75f 100644 --- a/test/rustc_env_files/BUILD +++ b/test/rustc_env_files/BUILD @@ -8,8 +8,8 @@ package(default_visibility = ["//visibility:public"]) rust_binary( name = "hello_env", srcs = ["src/main.rs"], - deps = ["@examples//hello_lib"], rustc_env_files = [":generate_rustc_env_file"], + deps = ["@examples//hello_lib"], ) genrule( diff --git a/test/unit/cc_info/cc_info_test.bzl b/test/unit/cc_info/cc_info_test.bzl index c645f15197..f655486099 100644 --- a/test/unit/cc_info/cc_info_test.bzl +++ b/test/unit/cc_info/cc_info_test.bzl @@ -20,7 +20,7 @@ def _assert_cc_info_has_library_to_link(env, tut, type): asserts.equals(env, [], library_to_link.objects) asserts.equals(env, [], library_to_link.pic_objects) - if type == "cdylib": + if type == "cdylib": asserts.true(env, library_to_link.dynamic_library != None) asserts.equals(env, None, library_to_link.interface_library) if _is_dylib_on_windows(env.ctx): diff --git a/test/unit/interleaved_cc_info/BUILD b/test/unit/interleaved_cc_info/BUILD new file mode 100644 index 0000000000..1ba122276f --- /dev/null +++ b/test/unit/interleaved_cc_info/BUILD @@ -0,0 +1,4 @@ +load(":interleaved_cc_info_test.bzl", "interleaved_cc_info_test_suite") + +############################ UNIT TESTS ############################# +interleaved_cc_info_test_suite(name = "interleaved_cc_info_test_suite") diff --git a/test/unit/interleaved_cc_info/a.rs b/test/unit/interleaved_cc_info/a.rs new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/unit/interleaved_cc_info/b.cc b/test/unit/interleaved_cc_info/b.cc new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/unit/interleaved_cc_info/c.rs b/test/unit/interleaved_cc_info/c.rs new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/unit/interleaved_cc_info/d.cc b/test/unit/interleaved_cc_info/d.cc new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/unit/interleaved_cc_info/e.rs b/test/unit/interleaved_cc_info/e.rs new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/unit/interleaved_cc_info/interleaved_cc_info_test.bzl b/test/unit/interleaved_cc_info/interleaved_cc_info_test.bzl new file mode 100644 index 0000000000..6afe6048e4 --- /dev/null +++ b/test/unit/interleaved_cc_info/interleaved_cc_info_test.bzl @@ -0,0 +1,72 @@ +"""Unittests for rust rules.""" + +load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts") +load("@rules_cc//cc:defs.bzl", "cc_library") +load("//rust:defs.bzl", "rust_library") + +def _interleaving_cc_link_order_test_impl(ctx): + env = analysistest.begin(ctx) + tut = analysistest.target_under_test(env) + cc_info = tut[CcInfo] + linker_inputs = cc_info.linking_context.linker_inputs.to_list() + a = linker_inputs[0] + b = linker_inputs[1] + c = linker_inputs[2] + d = linker_inputs[3] + e = linker_inputs[4] + + asserts.equals(env, "a", a.owner.name) + asserts.equals(env, "b", b.owner.name) + asserts.equals(env, "c", c.owner.name) + asserts.equals(env, "d", d.owner.name) + asserts.equals(env, "e", e.owner.name) + + return analysistest.end(env) + +interleaving_cc_link_order_test = analysistest.make(_interleaving_cc_link_order_test_impl) + +def _interleaving_link_order_test(): + rust_library( + name = "a", + srcs = ["a.rs"], + deps = [":b"], + ) + cc_library( + name = "b", + srcs = ["b.cc"], + deps = [":c"], + ) + rust_library( + name = "c", + srcs = ["c.rs"], + deps = [":d"], + ) + cc_library( + name = "d", + srcs = ["d.cc"], + deps = [":e"], + ) + rust_library( + name = "e", + srcs = ["e.rs"], + ) + + interleaving_cc_link_order_test( + name = "interleaving_cc_link_order_test", + target_under_test = ":a", + ) + +def interleaved_cc_info_test_suite(name): + """Entry-point macro called from the BUILD file. + + Args: + name: Name of the macro. + """ + _interleaving_link_order_test() + + native.test_suite( + name = name, + tests = [ + ":interleaving_cc_link_order_test", + ], + ) diff --git a/test/unit/native_deps/native_deps_test.bzl b/test/unit/native_deps/native_deps_test.bzl index 5803f77940..3902b77df9 100644 --- a/test/unit/native_deps/native_deps_test.bzl +++ b/test/unit/native_deps/native_deps_test.bzl @@ -158,7 +158,6 @@ def _cdylib_has_native_dep_and_alwayslink_test_impl(ctx): asserts.equals(env, want, _extract_linker_args(action.argv)) 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) diff --git a/tools/rust_analyzer/deps.bzl b/tools/rust_analyzer/deps.bzl index 322588488b..096b3550ec 100644 --- a/tools/rust_analyzer/deps.bzl +++ b/tools/rust_analyzer/deps.bzl @@ -5,4 +5,4 @@ The dependencies for running the gen_rust_project binary. load("//tools/rust_analyzer/raze:crates.bzl", "rules_rust_tools_rust_analyzer_fetch_remote_crates") def gen_rust_project_dependencies(): - rules_rust_tools_rust_analyzer_fetch_remote_crates() \ No newline at end of file + rules_rust_tools_rust_analyzer_fetch_remote_crates()