blob: 402314ec47572b3aed93a8bb89f0bf3b3dbf38f7 [file] [log] [blame]
Tim Windelschmidtbed76d92025-02-18 03:04:14 +01001load("//osbase/build:def.bzl", "build_pure_transition", "build_static_transition")
2load("//osbase/build/fsspec:def.bzl", "FSSpecInfo", "fsspec_core_impl")
3
4def _node_initramfs_impl(ctx):
5 initramfs_name = ctx.label.name + ".cpio.zst"
6 initramfs = ctx.actions.declare_file(initramfs_name)
7
8 fsspec_core_impl(ctx, ctx.executable._mkcpio, initramfs)
9
10 # TODO(q3k): Document why this is needed
11 return [DefaultInfo(runfiles = ctx.runfiles(files = [initramfs]), files = depset([initramfs]))]
12
13node_initramfs = rule(
14 implementation = _node_initramfs_impl,
15 doc = """
16 Build a node initramfs. The initramfs will contain a basic /dev directory and all the files specified by the
17 `files` attribute. Executable files will have their permissions set to 0755, non-executable files will have
18 their permissions set to 0444. All parent directories will be created with 0755 permissions.
19 """,
20 attrs = {
21 "files": attr.string_keyed_label_dict(
22 mandatory = True,
23 allow_files = True,
24 doc = """
25 Dictionary of Labels to String, placing a given Label's output file in the initramfs at the location
26 specified by the String value. The specified labels must only have a single output.
27 """,
28 # Attach pure transition to ensure all binaries added to the initramfs are pure/static binaries.
29 cfg = build_pure_transition,
30 ),
31 "files_cc": attr.string_keyed_label_dict(
32 allow_files = True,
33 doc = """
34 Special case of 'files' for compilation targets that need to be built with the musl toolchain like
35 go_binary targets which need cgo or cc_binary targets.
36 """,
37 # Attach static transition to all files_cc inputs to ensure they are built with musl and static.
38 cfg = build_static_transition,
39 ),
40 "symlinks": attr.string_dict(
41 default = {},
42 doc = """
43 Symbolic links to create. Similar format as in files and files_cc, so the target of the symlink is the
44 key and the value of it is the location of the symlink itself. Only raw strings are allowed as targets,
45 labels are not permitted. Include the file using files or files_cc, then symlink to its location.
46 """,
47 ),
48 "fsspecs": attr.label_list(
49 default = [],
50 doc = """
51 List of file system specs (osbase.build.fsspec.FSSpec) to also include in the resulting image.
52 These will be merged with all other given attributes.
53 """,
54 providers = [FSSpecInfo],
55 allow_files = True,
56 ),
57
58 # Tool
59 "_mkcpio": attr.label(
60 default = Label("//osbase/build/mkcpio"),
61 executable = True,
62 cfg = "exec",
63 ),
64 },
65)