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
49 lines (43 loc) · 1.5 KB
/
pico_linker_scripts.bzl
File metadata and controls
49 lines (43 loc) · 1.5 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
39
40
41
42
43
44
45
46
47
48
49
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "use_cpp_toolchain")
def _include_linker_script_dir_impl(ctx):
link_include_dir = str(ctx.label.package)
depset_direct = ["-L" + str(link_include_dir)]
if len(ctx.files.use_scripts):
for script in ctx.files.use_scripts:
depset_direct.append("-T" + str(script.path))
linking_inputs = cc_common.create_linker_input(
owner = ctx.label,
user_link_flags = depset(
direct = depset_direct,
),
)
return [
CcInfo(linking_context = cc_common.create_linking_context(linker_inputs = depset(direct = [linking_inputs]))),
]
include_linker_script_dir = rule(
implementation = _include_linker_script_dir_impl,
attrs = {
"use_scripts": attr.label_list(allow_files = [".ld"]),
},
toolchains = use_cpp_toolchain(),
fragments = ["cpp"],
)
def _use_linker_script_file_impl(ctx):
link_file = ctx.file.script.path
linking_inputs = cc_common.create_linker_input(
owner = ctx.label,
user_link_flags = depset(
direct = ["-T" + str(link_file)],
),
)
return [
CcInfo(linking_context = cc_common.create_linking_context(linker_inputs = depset(direct = [linking_inputs]))),
]
use_linker_script_file = rule(
implementation = _use_linker_script_file_impl,
attrs = {
"script": attr.label(mandatory = True, allow_single_file = [".ld"]),
},
toolchains = use_cpp_toolchain(),
fragments = ["cpp"],
)