Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .justfile
Original file line number Diff line number Diff line change
Expand Up @@ -274,21 +274,22 @@ flake-test: flac-test

# Build mkfs.erofs (erofs-utils, patched, linking lz4) for the given platforms,
# with fsck.erofs beside it where it builds (not windows), archived with
# erofs-utils' and lz4's licence notices into
# erofs-utils', lz4's and libdeflate's licence notices into
# $LIMEN_BUILD/dist/erofs-<platform>.tar.gz.
erofs +targets: (_fetch "erofs-utils") (_fetch "lz4")
erofs +targets: (_fetch "erofs-utils") (_fetch "lz4") (_fetch "libdeflate")
#!/usr/bin/env bash
set -euo pipefail
export ZIG_GLOBAL_CACHE_DIR="${LIMEN_BUILD}/zig/global" ZIG_LOCAL_CACHE_DIR="${LIMEN_BUILD}/zig/local"
version=$(limen pins get erofs-utils version)
src="${LIMEN_BUILD}/src/erofs-utils-${version}"
lz4="${LIMEN_BUILD}/src/lz4-$(limen pins get lz4 version)"
libdeflate="${LIMEN_BUILD}/src/libdeflate-$(limen pins get libdeflate version)"
mkdir -p "${LIMEN_BUILD}/dist"
set -- {{ targets }}
for platform in "$@"; do
out="${LIMEN_BUILD}/erofs/${platform}"
rm -rf "${out}"
erofs/build.sh "${src}" "${lz4}" "${version}" "$(just _zig-target "${platform}")" "${out}"
erofs/build.sh "${src}" "${lz4}" "${libdeflate}" "${version}" "$(just _zig-target "${platform}")" "${out}"
x=""
case "${platform}" in windows-*) x=".exe" ;; esac
name="erofs-${platform}"
Expand All @@ -300,6 +301,7 @@ erofs +targets: (_fetch "erofs-utils") (_fetch "lz4")
cp "${src}/COPYING" "${stage}/"
cp "${src}/LICENSES/GPL-2.0" "${src}/LICENSES/MIT" "${stage}/LICENSES/"
cp "${lz4}/lib/LICENSE" "${stage}/LICENSE.lz4"
cp "${libdeflate}/COPYING" "${stage}/LICENSE.libdeflate"
scripts/archive.sh "${LIMEN_BUILD}/stage" "${name}" "${LIMEN_BUILD}/dist"
done

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ other uses, or covered by any compatibility promise.
| [`microflac/`](microflac/) | `microflac`, a FLAC decoder on microFLAC | [esphome-libs/micro-flac](https://github.com/esphome-libs/micro-flac) |
| [`flake/`](flake/) | `CUETools.Flake`, CUETools' FLAC encoder | [gchudov/cuetools.net](https://github.com/gchudov/cuetools.net) |
| [`cscoreflac/`](cscoreflac/) | `cscoreflac`, a FLAC decoder on CSCore's | [filoe/cscore](https://github.com/filoe/cscore) |
| [`erofs/`](erofs/) | `mkfs.erofs`, `fsck.erofs` (not windows) | [erofs/erofs-utils](https://github.com/erofs/erofs-utils), with [lz4](https://github.com/lz4/lz4) |
| [`erofs/`](erofs/) | `mkfs.erofs`, `fsck.erofs` (not windows) | [erofs/erofs-utils](https://github.com/erofs/erofs-utils), with [lz4](https://github.com/lz4/lz4) and [libdeflate](https://github.com/ebiggers/libdeflate) |
| [`xz/`](xz/) | `xz` | [tukaani-project/xz](https://github.com/tukaani-project/xz) |
| [`graphviz/`](graphviz/) | `dot` | [graphviz](https://gitlab.com/graphviz/graphviz), with [expat](https://github.com/libexpat/libexpat) |
| [`hadolint/`](hadolint/) | `hadolint` (linux alone; a GPL-3 binary, published to be run by tests and linked by nothing) | [hadolint/hadolint](https://github.com/hadolint/hadolint), at a commit, not a release |
Expand Down
16 changes: 11 additions & 5 deletions erofs/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
# erofs

`mkfs.erofs`, from [erofs-utils](https://github.com/erofs/erofs-utils)' release tag `pins.yaml`
pins (`v<version>`, sha256), linking [lz4](https://github.com/lz4/lz4) from its pinned tag,
pins (`v<version>`, sha256), linking [lz4](https://github.com/lz4/lz4) and
[libdeflate](https://github.com/ebiggers/libdeflate) from their pinned tags,
built with the pinned zig for linux and windows, amd64 and arm64, and darwin arm64; `fsck.erofs` beside it
on linux and darwin, where it builds.

The build is configured as forkcloser/erofs's image-backed tests need it: lz4 and lz4hc, the
built-in deflate compressor, no other compression library (zlib, liblzma, libdeflate, libzstd),
built-in deflate compressor, libdeflate, no other compression library (zlib, liblzma, libzstd),
no libuuid, libselinux, curl, openssl, libxml2, json-c, liburing or fuse, and a maximum block size
of 16 KiB on every platform. Multi-threaded compression is on except on windows.

erofs-utils compresses deflate with code of its own (`-zdeflate`) and reads it back with zlib or
libdeflate: libdeflate is there so that `fsck.erofs` extracts the deflate images `mkfs.erofs`
writes. With it `mkfs.erofs` also takes `-zlibdeflate`, erofs-utils' second deflate compressor;
`-zdeflate` writes the same images as without it.

- `build.sh` compiles it for one zig target, straight from the sources configure would pick,
without autotools. It also builds `fsck.erofs` where it compiles (not windows): the smoke
test reads the images back with it, and a consumer's tests can hold their own images to its
Expand All @@ -32,7 +38,7 @@ of 16 KiB on every platform. Multi-threaded compression is on except on windows.
fixes every name, mode, owner and time, the root directory's included (without its entry,
mkfs.erofs gives the root the uid and gid of whoever runs it), and `-T0` and `-U` fix the rest
(`SOURCE_DATE_EPOCH`, which overrides `-T`, is cleared). Where `fsck.erofs` sits beside it,
each image readable without zlib is also extracted and compared with the tar's files. A tar
each image is also extracted and compared with the tar's files. A tar
read from a pipe must give the same image as the file.
- `testdata/fixture.py` writes `testdata/fixture.tar` byte for byte. CI never runs it; the tar
is committed.
Expand All @@ -44,8 +50,8 @@ differs between an x86 and an arm64 host. The smoke test always passes it.

erofs-utils is upstream's, under upstream's terms: its library under GPL-2.0-or-later or MIT,
`mkfs.erofs` under MIT, the bundled xxhash under BSD-2-Clause or GPL-2.0-only (`COPYING`,
`LICENSES/GPL-2.0`, `LICENSES/MIT`). lz4's library is under BSD-2-Clause (`LICENSE.lz4`). Each
release archive carries these four files. `patches/` and `mingw-compat/` change and stand in for
`LICENSES/GPL-2.0`, `LICENSES/MIT`). lz4's library is under BSD-2-Clause (`LICENSE.lz4`),
libdeflate under MIT (`LICENSE.libdeflate`). Each release archive carries these five files. `patches/` and `mingw-compat/` change and stand in for
erofs-utils' library and are under the same terms, GPL-2.0-or-later or MIT. The corresponding
source is upstream's release tarballs, pinned in `pins.yaml` (url and sha256), with `patches/`
and `mingw-compat/` at the release's tag. This directory's other files are under the
Expand Down
32 changes: 21 additions & 11 deletions erofs/build.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env bash
# Build mkfs.erofs for one zig target from unpacked erofs-utils and lz4 trees,
# and fsck.erofs beside it for the tests where it builds (not windows).
# build.sh <erofs-utils tree> <lz4 tree> <version> <zig target> <output directory>
# Build mkfs.erofs for one zig target from unpacked erofs-utils, lz4 and
# libdeflate trees, and fsck.erofs beside it for the tests where it builds
# (not windows).
# build.sh <erofs-utils tree> <lz4 tree> <libdeflate tree> <version> <zig target> <output directory>
# The trees are the release tarballs pins.yaml pins, fetched, verified and
# freshly unpacked by the recipe that calls this; the erofs-utils tree is
# patched here with patches/. Every target is cross-compiled with the pinned
Expand All @@ -11,9 +12,10 @@ set -euo pipefail

src=${1:?erofs-utils tree}
lz4=${2:?lz4 tree}
version=${3:?version}
target=${4:?zig target}
out=${5:?output directory}
libdeflate=${3:?libdeflate tree}
version=${4:?version}
target=${5:?zig target}
out=${6:?output directory}

here=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=scripts/jobs.sh
Expand All @@ -38,6 +40,7 @@ cflags=(
-D_FILE_OFFSET_BITS=64 -DNDEBUG
-DHAVE_CONFIG_H "-DPACKAGE_VERSION=\"${version}\""
-I "${here}" -I "${src}/include" -I "${src}/lib" -I "${lz4}/lib"
-I "${libdeflate}"
)
exe=""
libs=(-lpthread)
Expand All @@ -55,14 +58,14 @@ case "${target}" in
esac

# lib/Makefile.am's liberofs sources for this configuration: lz4 and lz4hc,
# the built-in deflate compressor, the bundled xxhash, multi-threading where
# there are pthreads, the nbd backend on linux.
# the built-in deflate compressor, libdeflate, the bundled xxhash,
# multi-threading where there are pthreads, the nbd backend on linux.
lib=(
config io cache super inode xattr exclude namei data compress compressor zmap
decompress compress_hints hashmap sha256 blobchunk dir fragments dedupe
uuid_unparse uuid tar block_list rebuild diskbuf bitops dedupe_ext vmdk
metabox global importer base64 compressor_lz4 compressor_lz4hc kite_deflate
compressor_deflate xxhash remotes/oci remotes/docker_config gzran
compressor_deflate compressor_libdeflate xxhash remotes/oci remotes/docker_config gzran
)
case "${target}" in
*-windows-*) ;;
Expand All @@ -81,10 +84,17 @@ for name in lz4 lz4hc; do
spawn zig cc -target "${target}" -O3 "${repro_cflags[@]}" -c "${lz4}/lib/${name}.c" -o "${work}/lz4-${name}.o"
done

# libdeflate's raw deflate alone, as its own build compiles it; the feature
# detection of the other architecture compiles to nothing.
for name in utils deflate_compress deflate_decompress arm/cpu_features x86/cpu_features; do
spawn zig cc -target "${target}" -O2 -std=gnu11 -DNDEBUG "${repro_cflags[@]}" \
-I "${libdeflate}" -c "${libdeflate}/lib/${name}.c" -o "${work}/libdeflate-${name//\//-}.o"
done

spawn zig cc "${cflags[@]}" -c "${src}/mkfs/main.c" -o "${work}/mkfs.o"
join
zig cc -target "${target}" "${repro_ldflags[@]}" -o "${out}/bin/mkfs.erofs${exe}" \
"${work}/mkfs.o" "${work}"/lib-*.o "${work}"/lz4-*.o ${libs[@]+"${libs[@]}"}
"${work}/mkfs.o" "${work}"/lib-*.o "${work}"/lz4-*.o "${work}"/libdeflate-*.o ${libs[@]+"${libs[@]}"}

# fsck.erofs extracts what mkfs.erofs wrote, for the smoke test; it needs more
# of POSIX than the windows patches provide, so it is not built there.
Expand All @@ -93,6 +103,6 @@ case "${target}" in
*)
zig cc "${cflags[@]}" -c "${src}/fsck/main.c" -o "${work}/fsck.o"
zig cc -target "${target}" "${repro_ldflags[@]}" -o "${out}/bin/fsck.erofs" \
"${work}/fsck.o" "${work}"/lib-*.o "${work}"/lz4-*.o "${libs[@]}"
"${work}/fsck.o" "${work}"/lib-*.o "${work}"/lz4-*.o "${work}"/libdeflate-*.o "${libs[@]}"
;;
esac
6 changes: 4 additions & 2 deletions erofs/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
* PACKAGE_VERSION comes from build.sh, which reads it from pins.yaml.
*
* The build is configured as forkcloser/erofs's was: lz4 and lz4hc on, the
* built-in deflate compressor (kite_deflate), every optional library off
* (zlib, liblzma, libdeflate, libzstd, libuuid, libselinux, xxhash, curl,
* built-in deflate compressor (kite_deflate), libdeflate to read deflate
* back, every other optional library off
* (zlib, liblzma, libzstd, libuuid, libselinux, xxhash, curl,
* openssl, libxml2, json-c, liburing, fuse), the block size up to 16 KiB on
* every target. */

#define LZ4_ENABLED 1
#define LZ4HC_ENABLED 1
#define HAVE_LIBDEFLATE 1

/* configure pins it from the build host's page size; forkcloser/erofs sets
* MAX_BLOCK_SIZE=16384 so every platform's mkfs writes the same images. */
Expand Down
19 changes: 9 additions & 10 deletions erofs/smoke.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,13 @@ fi
"${mkfs}" -V | head -n 1

common=(-T0 -U 6f8d1b52-6c5e-4b0a-9d1c-2b6f0d3e4a71 --quiet --tar=f)
# name | options | sha256 of the image | whether fsck.erofs can read it back
# (the deflate decompressor needs zlib, which this build leaves out).
# name | options | sha256 of the image
cases=(
"plain|-b4096|b8cd2965f6d9b87b4f851af8b8e5e576cf5fbb2967f1eb2fb02159adf6d22a0d|yes"
"noinline|-b4096 -Enoinline_data|0222f0a597cbbf7c3cf6e80f2532c6ad011dc60882639caaaf14af39d6768ba6|yes"
"lz4|-b4096 -zlz4|1efae009642fb2aafd8da59e95ae496af57193b81973ea9873425dbac16654b2|yes"
"lz4hc|-b16384 -zlz4hc,12 -Ededupe|215d19f1bf35a106c9934c729fcd0f6096249f7fe1cbcedfa37ca57a99ea5674|yes"
"deflate|-b512 -zdeflate|499572aad78d062d54a8b25b0b6926c6498e98bdc4fdda9e0f43ce16bdeb108c|no"
"plain|-b4096|b8cd2965f6d9b87b4f851af8b8e5e576cf5fbb2967f1eb2fb02159adf6d22a0d"
"noinline|-b4096 -Enoinline_data|0222f0a597cbbf7c3cf6e80f2532c6ad011dc60882639caaaf14af39d6768ba6"
"lz4|-b4096 -zlz4|1efae009642fb2aafd8da59e95ae496af57193b81973ea9873425dbac16654b2"
"lz4hc|-b16384 -zlz4hc,12 -Ededupe|215d19f1bf35a106c9934c729fcd0f6096249f7fe1cbcedfa37ca57a99ea5674"
"deflate|-b512 -zdeflate|499572aad78d062d54a8b25b0b6926c6498e98bdc4fdda9e0f43ce16bdeb108c"
)

if [ -x "${fsck}" ]; then
Expand All @@ -62,21 +61,21 @@ if [ -x "${fsck}" ]; then
fi

for c in "${cases[@]}"; do
IFS='|' read -r name opts want readable <<< "${c}"
IFS='|' read -r name opts want <<< "${c}"
read -r -a o <<< "${opts}"
"${mkfs}" "${common[@]}" "${o[@]}" "${name}.img" fixture.tar
have=$(sha256 "${name}.img")
if [ "${have}" != "${want}" ]; then
echo "${name} (${opts}): sha256 ${have}, want ${want}" >&2
exit 1
fi
if [ -x "${fsck}" ] && [ "${readable}" = yes ]; then
if [ -x "${fsck}" ]; then
rm -rf out
"${fsck}" --extract=out --no-preserve "${name}.img"
diff -r ref out
[ "$(readlink out/dir/link)" = small.txt ]
fi
echo "mkfs.erofs ${opts}: the expected image$([ -x "${fsck}" ] && [ "${readable}" = yes ] && echo ", extracted identical to the tar")"
echo "mkfs.erofs ${opts}: the expected image$([ -x "${fsck}" ] && echo ", extracted identical to the tar")"
done

# The tar from a pipe, as from a file: the stream path the windows patches
Expand Down
13 changes: 13 additions & 0 deletions pins.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,19 @@ pins:
version: 1.11.1
source: 3d79e491d1520c1511726a815e95c933e1d76a07ca7ea04cb23c3cea2a68c1e9
sha256: 683fed08a844ad012196381e40badf80c0bbe4962959761416d41c9e67d77ec7
# libdeflate's release tag: the inflater fsck.erofs reads deflate images
# with (erofs-utils compresses deflate itself and decompresses it with
# zlib or libdeflate).
- name: libdeflate
renovate: github-tags ebiggers/libdeflate
extract-version: ^v(?<version>[0-9]+\.[0-9]+)$
version: "1.26"
url: https://github.com/ebiggers/libdeflate/archive/refs/tags/v${version}.tar.gz
verify: download
digest:
version: 1.26
source: 50e178e9b7d5597ad5fe119498a010e9559d7d7324457daea9752677327b6daf
sha256: bba03fffc5538576213675ce6968fcff6ce2e67d82e4d5febea2d05f9f13cf85
# XZ Utils' release tarball, held to the signature upstream publishes
# beside it: Lasse Collin's key, by the fingerprint the project gives at
# https://tukaani.org/contact.html. The key's URL is transport, the
Expand Down
Loading