blob: b91750693067deac7ab94e53059b42bb9850032d [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
Tim Windelschmidtbed76d92025-02-18 03:04:14 +010010 return [DefaultInfo(runfiles = ctx.runfiles(files = [initramfs]), files = depset([initramfs]))]
11
12node_initramfs = rule(
Jan Schär0fd36f42025-04-29 10:26:03 +000013 # Attach static transition to ensure all binaries added to the initramfs are static binaries.
14 cfg = build_static_transition,
Tim Windelschmidtbed76d92025-02-18 03:04:14 +010015 implementation = _node_initramfs_impl,
16 doc = """
17 Build a node initramfs. The initramfs will contain a basic /dev directory and all the files specified by the
18 `files` attribute. Executable files will have their permissions set to 0755, non-executable files will have
19 their permissions set to 0444. All parent directories will be created with 0755 permissions.
20 """,
21 attrs = {
22 "files": attr.string_keyed_label_dict(
23 mandatory = True,
24 allow_files = True,
25 doc = """
26 Dictionary of Labels to String, placing a given Label's output file in the initramfs at the location
27 specified by the String value. The specified labels must only have a single output.
28 """,
Tim Windelschmidtbed76d92025-02-18 03:04:14 +010029 ),
30 "symlinks": attr.string_dict(
31 default = {},
32 doc = """
Jan Schär0fd36f42025-04-29 10:26:03 +000033 Symbolic links to create. Similar format as in `files`, so the key is the location of the
Tim Windelschmidtad4d9542025-03-24 20:20:13 +010034 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 +000035 labels are not permitted. Include the file using `files`, then symlink to its location.
Tim Windelschmidtbed76d92025-02-18 03:04:14 +010036 """,
37 ),
38 "fsspecs": attr.label_list(
39 default = [],
40 doc = """
41 List of file system specs (osbase.build.fsspec.FSSpec) to also include in the resulting image.
42 These will be merged with all other given attributes.
43 """,
44 providers = [FSSpecInfo],
45 allow_files = True,
46 ),
47
48 # Tool
49 "_mkcpio": attr.label(
50 default = Label("//osbase/build/mkcpio"),
51 executable = True,
52 cfg = "exec",
53 ),
54 },
55)