Select the types of activity you want to include in your feed.
feat: add ocaml-initramfs package, use it in space and uniboot
Extract initramfs building into a standalone package with Dir, File, and Tree entry types. Replaces duplicated cpio logic in space/lib/build.ml and uniboot/lib/uniboot.ml.
···11+(*---------------------------------------------------------------------------
22+ Copyright (c) 2025 Thomas Gazagnaire. All rights reserved.
33+ SPDX-License-Identifier: ISC
44+ ---------------------------------------------------------------------------*)
55+66+type entry =
77+ | Dir of string
88+ | File of { name : string; path : string }
99+ | Tree of string
1010+1111+let read_file path =
1212+ let ic = open_in_bin path in
1313+ let len = in_channel_length ic in
1414+ let s = Bytes.create len in
1515+ really_input ic s 0 len;
1616+ close_in ic;
1717+ Bytes.unsafe_to_string s
1818+1919+let file_perm path =
2020+ let st = Unix.stat path in
2121+ st.Unix.st_perm
2222+2323+let rec walk acc prefix dir =
2424+ let items = Sys.readdir dir |> Array.to_list in
2525+ List.fold_left
2626+ (fun acc name ->
2727+ let full = Filename.concat dir name in
2828+ let cpio_name = Filename.concat prefix name in
2929+ if Sys.is_directory full then
3030+ let acc = Cpio.directory ~perm:0o755 cpio_name :: acc in
3131+ walk acc cpio_name full
3232+ else
3333+ let data = read_file full in
3434+ let perm = file_perm full in
3535+ Cpio.regular ~perm ~name:cpio_name data :: acc)
3636+ acc items
3737+3838+let entries_of entry =
3939+ match entry with
4040+ | Dir name -> [ Cpio.directory ~perm:0o755 name ]
4141+ | File { name; path } ->
4242+ let data = read_file path in
4343+ let perm = file_perm path in
4444+ [ Cpio.regular ~perm ~name data ]
4545+ | Tree path ->
4646+ let base = Filename.basename path in
4747+ let acc = [ Cpio.directory ~perm:0o755 base ] in
4848+ List.rev (walk acc base path)
4949+5050+let build entries =
5151+ let cpio_entries = List.concat_map entries_of entries in
5252+ Cpio.to_string cpio_entries
+24
lib/initramfs.mli
···11+(*---------------------------------------------------------------------------
22+ Copyright (c) 2025 Thomas Gazagnaire. All rights reserved.
33+ SPDX-License-Identifier: ISC
44+ ---------------------------------------------------------------------------*)
55+66+(** Build initramfs cpio archives.
77+88+ High-level API for creating Linux initramfs images (cpio newc format) from
99+ directories, files, and recursive directory trees. *)
1010+1111+type entry =
1212+ | Dir of string (** Empty directory. *)
1313+ | File of { name : string; path : string }
1414+ (** File from disk, renamed to [name] in the archive. *)
1515+ | Tree of string (** Recursive directory tree. *)
1616+1717+val build : entry list -> string
1818+(** [build entries] builds a cpio newc archive from [entries].
1919+2020+ - [Dir name] creates an empty directory with permissions 0o755.
2121+ - [File { name; path }] reads a file from [path] and stores it as [name],
2222+ preserving the original file permissions.
2323+ - [Tree path] recursively walks [path], adding all files and subdirectories
2424+ as cpio entries, preserving permissions. *)