blob: 0be0568b5824fa7d939621e95f4a289b45538def [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 _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(
Jan Schär0fd36f42025-04-29 10:26:03 +000013 # Attach static transition to ensure all binaries added to the EROFS are static binaries.
14 cfg = build_static_transition,
Tim Windelschmidtbed76d92025-02-18 03:04:14 +010015 implementation = _erofs_image_impl,
16 doc = """
Jan Schär0fd36f42025-04-29 10:26:03 +000017 Build an EROFS. All files specified in files and all specified symlinks will be contained.
Tim Windelschmidtbed76d92025-02-18 03:04:14 +010018 Executable files will have their permissions set to 0555, non-executable files will have
19 their permissions set to 0444. All parent directories will be created with 0555 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 EROFS 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 Windelschmidtad4d9542025-03-24 20:20:13 +010036 """,
Tim Windelschmidtbed76d92025-02-18 03:04:14 +010037 ),
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 # Tools, implicit dependencies.
49 "_mkerofs": attr.label(
50 default = Label("//osbase/build/mkerofs"),
51 executable = True,
52 cfg = "exec",
53 ),
54 },
55)