blob: ff4e137c0c69700017e500a0165f29d5271c949e [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 _erofs_image_impl(ctx):
5 fs_name = ctx.label.name + ".img"
6 fs_out = ctx.actions.declare_file(fs_name)
7
8 fsspec_core_impl(ctx, ctx.executable._mkerofs, fs_out)
9
10 return [DefaultInfo(files = depset([fs_out]))]
11
12erofs_image = rule(
13 implementation = _erofs_image_impl,
14 doc = """
15 Build an EROFS. All files specified in files, files_cc and all specified symlinks will be contained.
16 Executable files will have their permissions set to 0555, non-executable files will have
17 their permissions set to 0444. All parent directories will be created with 0555 permissions.
18 """,
19 attrs = {
20 "files": attr.string_keyed_label_dict(
21 mandatory = True,
22 allow_files = True,
23 doc = """
24 Dictionary of Labels to String, placing a given Label's output file in the EROFS at the location
25 specified by the String value. The specified labels must only have a single output.
26 """,
27 # Attach pure transition to ensure all binaries added to the initramfs are pure/static binaries.
28 cfg = build_pure_transition,
29 ),
30 "files_cc": attr.string_keyed_label_dict(
31 allow_files = True,
32 doc = """
33 Special case of 'files' for compilation targets that need to be built with the musl toolchain like
34 go_binary targets which need cgo or cc_binary targets.
35 """,
36 # Attach static transition to all files_cc inputs to ensure they are built with musl and static.
37 cfg = build_static_transition,
38 ),
39 "symlinks": attr.string_dict(
40 default = {},
41 doc = """
Tim Windelschmidtad4d9542025-03-24 20:20:13 +010042 Symbolic links to create. Similar format as in files and files_cc, so the key is the location of the
43 symlink itself and the value of it is target of the symlink. Only raw strings are allowed as targets,
Tim Windelschmidtbed76d92025-02-18 03:04:14 +010044 labels are not permitted. Include the file using files or files_cc, then symlink to its location.
Tim Windelschmidtad4d9542025-03-24 20:20:13 +010045 """,
Tim Windelschmidtbed76d92025-02-18 03:04:14 +010046 ),
47 "fsspecs": attr.label_list(
48 default = [],
49 doc = """
50 List of file system specs (osbase.build.fsspec.FSSpec) to also include in the resulting image.
51 These will be merged with all other given attributes.
52 """,
53 providers = [FSSpecInfo],
54 allow_files = True,
55 ),
56
57 # Tools, implicit dependencies.
58 "_mkerofs": attr.label(
59 default = Label("//osbase/build/mkerofs"),
60 executable = True,
61 cfg = "exec",
62 ),
63 },
64)