diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index 17dc2ba..e03f760 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -139,7 +139,7 @@ "moduleExtensions": { "//:extensions.bzl%arm_toolchain": { "general": { - "bzlTransitiveDigest": "u/MHEDqrY6t5zvDArzdCUgXwMLBgC0k67ZL2eV4eOtY=", + "bzlTransitiveDigest": "t3cHywM6dCabqw7xBNJN+O3csA16VA/X6g/5Yqx9Tqc=", "usagesDigest": "P/3UnhHe8mBjAHhQOgY8IbRzO7gyGHPkTqDB/W/U9qY=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, diff --git a/examples/bzlmod/custom/toolchain/BUILD b/examples/bzlmod/custom/toolchain/BUILD index 50cf458..ad3960c 100644 --- a/examples/bzlmod/custom/toolchain/BUILD +++ b/examples/bzlmod/custom/toolchain/BUILD @@ -46,12 +46,19 @@ arm_none_eabi_toolchain( ], ) +# this dummy is used to test that transitive deps are included +cc_library( + name = "start_dep", + srcs = ["dummy.c"], +) + # always linked in with the toolchain below cc_library( name = "start", srcs = ["start.c"], additional_linker_inputs = ["link.ld"], linkopts = ["-T $(location :link.ld)"], + deps = [":start_dep"], ) # Cortex-M4 toolchain that always links `:start` diff --git a/examples/bzlmod/custom/toolchain/dummy.c b/examples/bzlmod/custom/toolchain/dummy.c new file mode 100644 index 0000000..24bac39 --- /dev/null +++ b/examples/bzlmod/custom/toolchain/dummy.c @@ -0,0 +1 @@ +void dummy() {} diff --git a/toolchain/transitions.bzl b/toolchain/transitions.bzl index 8c6ff0f..b9089c8 100644 --- a/toolchain/transitions.bzl +++ b/toolchain/transitions.bzl @@ -14,13 +14,26 @@ _toolchain_transition = transition( ) def _toolchain_transition_library_impl(ctx): + to_list = lambda x: [x] if x else [] + default_info = ctx.attr.src[DefaultInfo] cc_info = ctx.attr.src[CcInfo] linker_input_files = [] + + # We need to recreate default_info since not all files are propagated with + # the transition. Specifically, the following are known to not propagate: + # * additional_linker_inputs (e.g. linker scripts) + # * deps (i.e. other libraries this one depends on) for linker_input in cc_info.linking_context.linker_inputs.to_list(): linker_input_files.extend(linker_input.additional_inputs) + for lib in linker_input.libraries: + linker_input_files.extend(to_list(lib.static_library)) + # I'm not sure if these below are needed + linker_input_files.extend(to_list(lib.pic_static_library)) + linker_input_files.extend(to_list(lib.dynamic_library)) + return [ DefaultInfo( files = depset(