diff --git a/.justfile b/.justfile index 9ebbacd..aa53c66 100644 --- a/.justfile +++ b/.justfile @@ -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-.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}" @@ -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 diff --git a/README.md b/README.md index 043a841..9681c76 100644 --- a/README.md +++ b/README.md @@ -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 | diff --git a/erofs/README.md b/erofs/README.md index 8873b06..c6d2baa 100644 --- a/erofs/README.md +++ b/erofs/README.md @@ -1,15 +1,21 @@ # erofs `mkfs.erofs`, from [erofs-utils](https://github.com/erofs/erofs-utils)' release tag `pins.yaml` -pins (`v`, sha256), linking [lz4](https://github.com/lz4/lz4) from its pinned tag, +pins (`v`, 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 @@ -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. @@ -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 diff --git a/erofs/build.sh b/erofs/build.sh index 17a42e0..e476d27 100755 --- a/erofs/build.sh +++ b/erofs/build.sh @@ -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 +# 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 # 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 @@ -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 @@ -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) @@ -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-*) ;; @@ -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. @@ -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 diff --git a/erofs/config.h b/erofs/config.h index 6d2b0ce..bd2cbfe 100644 --- a/erofs/config.h +++ b/erofs/config.h @@ -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. */ diff --git a/erofs/smoke.sh b/erofs/smoke.sh index 5047189..0127579 100755 --- a/erofs/smoke.sh +++ b/erofs/smoke.sh @@ -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 @@ -62,7 +61,7 @@ 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") @@ -70,13 +69,13 @@ for c in "${cases[@]}"; do 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 diff --git a/pins.yaml b/pins.yaml index c0c4360..bd6483f 100644 --- a/pins.yaml +++ b/pins.yaml @@ -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(?[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