Skip to content

Commit edfe4f9

Browse files
committed
handle transitive deps of additional_link_libraries
When defining an `additional_link_library` that uses `deps`, e.g. ```starlark cc_library( name = "start", srcs = ["start.c"], ... deps = [":registers"], ) ``` where the `start` library depends on a separate `registers` library, libraries in `deps` are not compiled. Similar to `additional_linker_inputs`, these files must be explicitly forwarded in the DefaultInfo returned by the transition implementation function.
1 parent c1a148a commit edfe4f9

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

MODULE.bazel.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/bzlmod/custom/toolchain/BUILD

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,19 @@ arm_none_eabi_toolchain(
4646
],
4747
)
4848

49+
# this dummy is used to test that transitive deps are included
50+
cc_library(
51+
name = "start_dep",
52+
srcs = ["dummy.c"],
53+
)
54+
4955
# always linked in with the toolchain below
5056
cc_library(
5157
name = "start",
5258
srcs = ["start.c"],
5359
additional_linker_inputs = ["link.ld"],
5460
linkopts = ["-T $(location :link.ld)"],
61+
deps = [":start_dep"],
5562
)
5663

5764
# Cortex-M4 toolchain that always links `:start`
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
void dummy() {}

toolchain/transitions.bzl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,26 @@ _toolchain_transition = transition(
1414
)
1515

1616
def _toolchain_transition_library_impl(ctx):
17+
to_list = lambda x: [x] if x else []
18+
1719
default_info = ctx.attr.src[DefaultInfo]
1820
cc_info = ctx.attr.src[CcInfo]
1921

2022
linker_input_files = []
23+
24+
# We need to recreate default_info since not all files are propagated with
25+
# the transition. Specifically, the following are known to not propagate:
26+
# * additional_linker_inputs (e.g. linker scripts)
27+
# * deps (i.e. other libraries this one depends on)
2128
for linker_input in cc_info.linking_context.linker_inputs.to_list():
2229
linker_input_files.extend(linker_input.additional_inputs)
2330

31+
for lib in linker_input.libraries:
32+
linker_input_files.extend(to_list(lib.static_library))
33+
# I'm not sure if these below are needed
34+
linker_input_files.extend(to_list(lib.pic_static_library))
35+
linker_input_files.extend(to_list(lib.dynamic_library))
36+
2437
return [
2538
DefaultInfo(
2639
files = depset(

0 commit comments

Comments
 (0)