forked from raspberrypi/pico-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpico_linker_scripts.bzl
More file actions
38 lines (33 loc) · 1.39 KB
/
Copy pathpico_linker_scripts.bzl
File metadata and controls
38 lines (33 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "use_cpp_toolchain")
def _linker_scripts_impl(ctx):
link_flags = []
for script in ctx.attr.include_scripts:
link_include_dir = script.label.package
if ctx.label.workspace_root:
link_include_dir = "/".join((ctx.label.workspace_root, link_include_dir))
link_flag = "-L" + str(link_include_dir)
if not (link_flag in link_flags):
link_flags.append(link_flag)
for script in ctx.files.link_scripts:
link_flags.append("-T" + str(script.path))
all_scripts = ctx.files.link_scripts + ctx.files.include_scripts
linking_inputs = cc_common.create_linker_input(
owner = ctx.label,
user_link_flags = depset(
direct = link_flags,
),
additional_inputs = depset(direct = all_scripts),
)
return [
DefaultInfo(files = depset(direct = all_scripts)),
CcInfo(linking_context = cc_common.create_linking_context(linker_inputs = depset(direct = [linking_inputs]))),
]
linker_scripts = rule(
implementation = _linker_scripts_impl,
attrs = {
"link_scripts": attr.label_list(allow_files = [".ld"], doc = "List of scripts to explicitly link"),
"include_scripts": attr.label_list(allow_files = [".incl"], doc = "List of scripts to include"),
},
toolchains = use_cpp_toolchain(),
fragments = ["cpp"],
)