Skip to content

Commit 9eb5eeb

Browse files
authored
Fix order of libraries in CcInfo (#623)
While there run buildifier again (Bazel folks are figuring out why it's not running reliably on the CI).
1 parent 1b7885a commit 9eb5eeb

File tree

15 files changed

+86
-10
lines changed

15 files changed

+86
-10
lines changed

rust/private/rustc.bzl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -688,8 +688,10 @@ def establish_cc_info(ctx, crate_info, toolchain, cc_toolchain, feature_configur
688688
linker_inputs = depset([link_input]),
689689
)
690690

691-
cc_infos = [dep[CcInfo] for dep in ctx.attr.deps if CcInfo in dep]
692-
cc_infos.append(CcInfo(linking_context = linking_context))
691+
cc_infos = [CcInfo(linking_context = linking_context)]
692+
for dep in ctx.attr.deps:
693+
if CcInfo in dep:
694+
cc_infos.append(dep[CcInfo])
693695

694696
return [cc_common.merge_cc_infos(cc_infos = cc_infos)]
695697

rust/private/rustdoc_test.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def _build_rustdoc_flags(dep_info, crate):
104104
is_static = bool(lib_to_link.static_library or lib_to_link.pic_static_library)
105105
f = get_preferred_artifact(lib_to_link)
106106
if not is_static:
107-
link_flags.append("-ldylib=" + get_lib_name(f))
107+
link_flags.append("-ldylib=" + get_lib_name(f))
108108
else:
109109
link_flags.append("-lstatic=" + get_lib_name(f))
110110
link_flags.append("-Lnative={}".format(_dirname(f.short_path)))

rust/repositories.bzl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,6 @@ def BUILD_for_rustc_src():
284284

285285
return _build_file_for_rustc_src
286286

287-
288287
_build_file_for_clippy_template = """\
289288
load("@rules_rust//rust:toolchain.bzl", "rust_toolchain")
290289

rust/rust.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
load(
1818
"//rust:defs.bzl",
1919
_error_format = "error_format",
20+
_rust_analyzer = "rust_analyzer",
21+
_rust_analyzer_aspect = "rust_analyzer_aspect",
2022
_rust_benchmark = "rust_benchmark",
2123
_rust_binary = "rust_binary",
2224
_rust_clippy = "rust_clippy",
@@ -30,8 +32,6 @@ load(
3032
_rust_static_library = "rust_static_library",
3133
_rust_test = "rust_test",
3234
_rust_test_binary = "rust_test_binary",
33-
_rust_analyzer = "rust_analyzer",
34-
_rust_analyzer_aspect = "rust_analyzer_aspect",
3535
)
3636

3737
def rust_library(**args):

test/rustc_env_files/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ package(default_visibility = ["//visibility:public"])
88
rust_binary(
99
name = "hello_env",
1010
srcs = ["src/main.rs"],
11-
deps = ["@examples//hello_lib"],
1211
rustc_env_files = [":generate_rustc_env_file"],
12+
deps = ["@examples//hello_lib"],
1313
)
1414

1515
genrule(

test/unit/cc_info/cc_info_test.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def _assert_cc_info_has_library_to_link(env, tut, type):
2020
asserts.equals(env, [], library_to_link.objects)
2121
asserts.equals(env, [], library_to_link.pic_objects)
2222

23-
if type == "cdylib":
23+
if type == "cdylib":
2424
asserts.true(env, library_to_link.dynamic_library != None)
2525
asserts.equals(env, None, library_to_link.interface_library)
2626
if _is_dylib_on_windows(env.ctx):

test/unit/interleaved_cc_info/BUILD

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
load(":interleaved_cc_info_test.bzl", "interleaved_cc_info_test_suite")
2+
3+
############################ UNIT TESTS #############################
4+
interleaved_cc_info_test_suite(name = "interleaved_cc_info_test_suite")

test/unit/interleaved_cc_info/a.rs

Whitespace-only changes.

test/unit/interleaved_cc_info/b.cc

Whitespace-only changes.

test/unit/interleaved_cc_info/c.rs

Whitespace-only changes.

test/unit/interleaved_cc_info/d.cc

Whitespace-only changes.

test/unit/interleaved_cc_info/e.rs

Whitespace-only changes.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
"""Unittests for rust rules."""
2+
3+
load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
4+
load("@rules_cc//cc:defs.bzl", "cc_library")
5+
load("//rust:defs.bzl", "rust_library")
6+
7+
def _interleaving_cc_link_order_test_impl(ctx):
8+
env = analysistest.begin(ctx)
9+
tut = analysistest.target_under_test(env)
10+
cc_info = tut[CcInfo]
11+
linker_inputs = cc_info.linking_context.linker_inputs.to_list()
12+
a = linker_inputs[0]
13+
b = linker_inputs[1]
14+
c = linker_inputs[2]
15+
d = linker_inputs[3]
16+
e = linker_inputs[4]
17+
18+
asserts.equals(env, "a", a.owner.name)
19+
asserts.equals(env, "b", b.owner.name)
20+
asserts.equals(env, "c", c.owner.name)
21+
asserts.equals(env, "d", d.owner.name)
22+
asserts.equals(env, "e", e.owner.name)
23+
24+
return analysistest.end(env)
25+
26+
interleaving_cc_link_order_test = analysistest.make(_interleaving_cc_link_order_test_impl)
27+
28+
def _interleaving_link_order_test():
29+
rust_library(
30+
name = "a",
31+
srcs = ["a.rs"],
32+
deps = [":b"],
33+
)
34+
cc_library(
35+
name = "b",
36+
srcs = ["b.cc"],
37+
deps = [":c"],
38+
)
39+
rust_library(
40+
name = "c",
41+
srcs = ["c.rs"],
42+
deps = [":d"],
43+
)
44+
cc_library(
45+
name = "d",
46+
srcs = ["d.cc"],
47+
deps = [":e"],
48+
)
49+
rust_library(
50+
name = "e",
51+
srcs = ["e.rs"],
52+
)
53+
54+
interleaving_cc_link_order_test(
55+
name = "interleaving_cc_link_order_test",
56+
target_under_test = ":a",
57+
)
58+
59+
def interleaved_cc_info_test_suite(name):
60+
"""Entry-point macro called from the BUILD file.
61+
62+
Args:
63+
name: Name of the macro.
64+
"""
65+
_interleaving_link_order_test()
66+
67+
native.test_suite(
68+
name = name,
69+
tests = [
70+
":interleaving_cc_link_order_test",
71+
],
72+
)

test/unit/native_deps/native_deps_test.bzl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ def _cdylib_has_native_dep_and_alwayslink_test_impl(ctx):
158158
asserts.equals(env, want, _extract_linker_args(action.argv))
159159
return analysistest.end(env)
160160

161-
162161
rlib_has_no_native_libs_test = analysistest.make(_rlib_has_no_native_libs_test_impl)
163162
staticlib_has_native_libs_test = analysistest.make(_staticlib_has_native_libs_test_impl)
164163
cdylib_has_native_libs_test = analysistest.make(_cdylib_has_native_libs_test_impl)

tools/rust_analyzer/deps.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ The dependencies for running the gen_rust_project binary.
55
load("//tools/rust_analyzer/raze:crates.bzl", "rules_rust_tools_rust_analyzer_fetch_remote_crates")
66

77
def gen_rust_project_dependencies():
8-
rules_rust_tools_rust_analyzer_fetch_remote_crates()
8+
rules_rust_tools_rust_analyzer_fetch_remote_crates()

0 commit comments

Comments
 (0)