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