Gunnar

nordisk/heimdall

guests/verify-bundle/openzl/vendor.sh

#!/bin/sh
# SPDX-License-Identifier: AGPL-3.0-only
# Heimdall is a defensive sandbox. Re-creates guests/verify-bundle/openzl/src
# (the OpenZL DECODER subset the verify-bundle guest compiles for wasm32) from
# the published openzl-sys-rs crate, so the vendored tree can be audited:
#   openzl/vendor.sh ~/.cargo/registry/src/*/openzl-sys-rs-0.4.1+openzl.0.3.0
# c-files.txt  = the translation units wasm-ld pulls in for ZL_decompress +
#                ZL_getDecompressedSize (generated with `wasm-ld --trace`);
# h-files.txt  = every header those include (clang -MM);
# wasm32.patch = the one change (OpenZL asserts a 64-bit size_t only to keep
#                its heap-arena header 16 bytes; wasm32 pads it instead).
set -eu
crate=${1:?usage: vendor.sh <path to openzl-sys-rs-0.4.1+openzl.0.3.0>}
here=$(cd "$(dirname "$0")" && pwd)
src="$crate/openzl"
[ -f "$src/VENDOR.md" ] || { echo "no openzl/ under $crate" >&2; exit 1; }
rm -rf "$here/src"
mkdir -p "$here/src"
for f in $(cat "$here/c-files.txt" "$here/h-files.txt") LICENSE deps/zstd/LICENSE deps/lz4/LICENSE; do
  mkdir -p "$here/src/$(dirname "$f")"
  cp "$src/$f" "$here/src/$f"
done
(cd "$here/src" && patch -p1 --quiet < "$here/wasm32.patch")
echo "vendored $(wc -l < "$here/c-files.txt") .c + $(wc -l < "$here/h-files.txt") .h into $here/src"