| Tim Windelschmidt | bed76d9 | 2025-02-18 03:04:14 +0100 | [diff] [blame] | 1 | load("//osbase/build:def.bzl", "build_pure_transition", "build_static_transition") |
| 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( |
| 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 = """ |
| 42 | Symbolic links to create. Similar format as in files and files_cc, so the target of the symlink is the |
| 43 | key and the value of it is the location of the symlink itself. Only raw strings are allowed as targets, |
| 44 | labels are not permitted. Include the file using files or files_cc, then symlink to its location. |
| 45 | """, |
| 46 | ), |
| 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 | ) |