blob: 2db2793182e9693b2428cfc0669fdaa21799f0e4 [file] [log] [blame]
Jan Schär0fd36f42025-04-29 10:26:03 +00001load("//osbase/build:def.bzl", "build_static_transition")
Tim Windelschmidtbed76d92025-02-18 03:04:14 +01002load("//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(
Jan Schär0fd36f42025-04-29 10:26:03 +000014 # Attach static transition to ensure all binaries added to the initramfs are static binaries.
15 cfg = build_static_transition,
Tim Windelschmidtbed76d92025-02-18 03:04:14 +010016 implementation = _node_initramfs_impl,
17 doc = """
18 Build a node initramfs. The initramfs will contain a basic /dev directory and all the files specified by the
19 `files` attribute. Executable files will have their permissions set to 0755, non-executable files will have
20 their permissions set to 0444. All parent directories will be created with 0755 permissions.
21 """,
22 attrs = {
23 "files": attr.string_keyed_label_dict(
24 mandatory = True,
25 allow_files = True,
26 doc = """
27 Dictionary of Labels to String, placing a given Label's output file in the initramfs at the location
28 specified by the String value. The specified labels must only have a single output.
29 """,
Tim Windelschmidtbed76d92025-02-18 03:04:14 +010030 ),
31 "symlinks": attr.string_dict(
32 default = {},
33 doc = """
Jan Schär0fd36f42025-04-29 10:26:03 +000034 Symbolic links to create. Similar format as in `files`, so the key is the location of the
Tim Windelschmidtad4d9542025-03-24 20:20:13 +010035 symlink itself and the value of it is target of the symlink. Only raw strings are allowed as targets,
Jan Schär0fd36f42025-04-29 10:26:03 +000036 labels are not permitted. Include the file using `files`, then symlink to its location.
Tim Windelschmidtbed76d92025-02-18 03:04:14 +010037 """,
38 ),
39 "fsspecs": attr.label_list(
40 default = [],
41 doc = """
42 List of file system specs (osbase.build.fsspec.FSSpec) to also include in the resulting image.
43 These will be merged with all other given attributes.
44 """,
45 providers = [FSSpecInfo],
46 allow_files = True,
47 ),
48
49 # Tool
50 "_mkcpio": attr.label(
51 default = Label("//osbase/build/mkcpio"),
52 executable = True,
53 cfg = "exec",
54 ),
55 },
56)