Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix order of libraries in CcInfo #623

Merged
merged 1 commit into from
Mar 3, 2021
Merged
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
6 changes: 4 additions & 2 deletions rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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)]

Expand Down
2 changes: 1 addition & 1 deletion rust/private/rustdoc_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
1 change: 0 additions & 1 deletion rust/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
4 changes: 2 additions & 2 deletions rust/rust.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion test/rustc_env_files/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion test/unit/cc_info/cc_info_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 4 additions & 0 deletions test/unit/interleaved_cc_info/BUILD
Original file line number Diff line number Diff line change
@@ -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")
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
72 changes: 72 additions & 0 deletions test/unit/interleaved_cc_info/interleaved_cc_info_test.bzl
Original file line number Diff line number Diff line change
@@ -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",
],
)
1 change: 0 additions & 1 deletion test/unit/native_deps/native_deps_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tools/rust_analyzer/deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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()
rules_rust_tools_rust_analyzer_fetch_remote_crates()