forked from rivosinc/salus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
objcopy.bzl
83 lines (72 loc) · 2.12 KB
/
objcopy.bzl
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# SPDX-FileCopyrightText: 2023 Rivos Inc.
#
# SPDX-License-Identifier: Apache-2.0
load(
"@bazel_tools//tools/cpp:toolchain_utils.bzl",
"find_cpp_toolchain",
"use_cpp_toolchain",
)
def _objcopy_to_object_impl(ctx):
cc_toolchain = find_cpp_toolchain(ctx)
src = ctx.files.src[0]
out = ctx.outputs.out
command_line = ["-I", "binary", "-O", "elf64-littleriscv", src.path, out.path]
ctx.actions.run(
mnemonic = "ObjCopyElfToBinary",
executable = cc_toolchain.objcopy_executable,
arguments = command_line,
inputs = depset(
[src],
transitive = [cc_toolchain.all_files],
),
outputs = [out],
)
return [DefaultInfo(files = depset([out]))]
objcopy_to_object = rule(
implementation = _objcopy_to_object_impl,
attrs = {
"src": attr.label(
mandatory = True,
allow_single_file = True,
executable = True,
cfg = "target",
),
"_cc_toolchain": attr.label(
default = Label("@bazel_tools//tools/cpp:current_cc_toolchain"),
),
"out": attr.output(),
},
toolchains = use_cpp_toolchain(),
)
def _objcopy_to_bin_impl(ctx):
cc_toolchain = find_cpp_toolchain(ctx)
src = ctx.files.src[0]
out = ctx.outputs.out
command_line = ["-O", "binary", src.path, out.path]
ctx.actions.run(
mnemonic = "ObjCopyToBinary",
executable = cc_toolchain.objcopy_executable,
arguments = command_line,
inputs = depset(
[src],
transitive = [cc_toolchain.all_files],
),
outputs = [out],
)
return [DefaultInfo(files = depset([out]))]
objcopy_to_bin = rule(
implementation = _objcopy_to_bin_impl,
attrs = {
"src": attr.label(
mandatory = True,
allow_single_file = True,
executable = True,
cfg = "target",
),
"_cc_toolchain": attr.label(
default = Label("@bazel_tools//tools/cpp:current_cc_toolchain"),
),
"out": attr.output(),
},
toolchains = use_cpp_toolchain(),
)