| Jan Schär | 0fd36f4 | 2025-04-29 10:26:03 +0000 | [diff] [blame] | 1 | load("//osbase/build:def.bzl", "build_static_transition") |
| Tim Windelschmidt | bed76d9 | 2025-02-18 03:04:14 +0100 | [diff] [blame] | 2 | load("//osbase/build/fsspec:def.bzl", "FSSpecInfo", "fsspec_core_impl") |
| 3 | |
| 4 | def _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 | |
| 12 | erofs_image = rule( |
| Jan Schär | 0fd36f4 | 2025-04-29 10:26:03 +0000 | [diff] [blame] | 13 | # Attach static transition to ensure all binaries added to the EROFS are static binaries. |
| 14 | cfg = build_static_transition, |
| Tim Windelschmidt | bed76d9 | 2025-02-18 03:04:14 +0100 | [diff] [blame] | 15 | implementation = _erofs_image_impl, |
| 16 | doc = """ |
| Jan Schär | 0fd36f4 | 2025-04-29 10:26:03 +0000 | [diff] [blame] | 17 | Build an EROFS. All files specified in files and all specified symlinks will be contained. |
| Tim Windelschmidt | bed76d9 | 2025-02-18 03:04:14 +0100 | [diff] [blame] | 18 | 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 Windelschmidt | bed76d9 | 2025-02-18 03:04:14 +0100 | [diff] [blame] | 29 | ), |
| 30 | "symlinks": attr.string_dict( |
| 31 | default = {}, |
| 32 | doc = """ |
| Jan Schär | 0fd36f4 | 2025-04-29 10:26:03 +0000 | [diff] [blame] | 33 | Symbolic links to create. Similar format as in `files`, so the key is the location of the |
| Tim Windelschmidt | ad4d954 | 2025-03-24 20:20:13 +0100 | [diff] [blame] | 34 | symlink itself and the value of it is target of the symlink. Only raw strings are allowed as targets, |
| Jan Schär | 0fd36f4 | 2025-04-29 10:26:03 +0000 | [diff] [blame] | 35 | labels are not permitted. Include the file using `files`, then symlink to its location. |
| Tim Windelschmidt | ad4d954 | 2025-03-24 20:20:13 +0100 | [diff] [blame] | 36 | """, |
| Tim Windelschmidt | bed76d9 | 2025-02-18 03:04:14 +0100 | [diff] [blame] | 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 | # Tools, implicit dependencies. |
| 49 | "_mkerofs": attr.label( |
| 50 | default = Label("//osbase/build/mkerofs"), |
| 51 | executable = True, |
| 52 | cfg = "exec", |
| 53 | ), |
| 54 | }, |
| 55 | ) |