Fil-C on Nix

Filnix wiki

mbrock/filnix

nanofil/nix/bzip2.nix

bzip2 1.0.8 built entirely by nanofil. Every object of bzip2 and bzip2recover (libbz2 included) is compiled through nanofil-cc, bzip2's own maketest round-trips its three samples, and bzip2's output must be byte for byte the same as a filcc-built bzip2's at block sizes 1, 5 and 9, on text and on random data, with each build decompressing the other's output. Once per middle-end, register and check-reuse choice, each in its own derivation (configurations.nix); the comparisons also run under FUGC_SCRIBBLE and FUGC_VERIFY.

λpkgs, filcc
assert pkgs.bzip2.version ≡ "1.0.8"
let
12src=
pkgs.bzip2.src
13unpack=
unpack() {
mkdir $1
tar -xf $src -C $1 --strip-components=1
}
used by reference
19reference=
pkgs.runCommandCC"nanofil-bzip2-reference" inherit src;
unpack ref
make -C ref -j$NIX_BUILD_CORES CC=${filcc}/bin/clang bzip2 bzip2recover >/dev/null
mkdir -p $out/bin
cp ref/bzip2 ref/bzip2recover $out/bin/
uses unpack
26configurations=
27plain=
""
28O=
"-O"
29O-branches-reference=
"-O --branches=reference"
30O-stack=
"-O --registers=stack"
31reuse=
"--checks=reuse"
32O-reuse=
"-O --checks=reuse"
33O-refchecks=
"-O --checks=reference"
34O-half=
"-O --checks=half"
35O-temps=
"-O --registers=temps"
in
import./configurations.nix inherit pkgs; "nanofil-bzip2" configurations
λlabel opt
pkgs.runCommandCC"nanofil-bzip2-${label}" inherit src;
cc=${import./nanofil-cc.nix inherit pkgs filcc;}
ref=${reference}/bin
cat ${../.}/src/*.pl ${../.}/docs/*.md > text
head -c 1000000 /dev/urandom > random
echo "== bzip2, nanofil ${opt}"
unpack nf
export NANOFIL_OPT="${opt}" NANOFIL_LOG=$PWD/nanofil.log
make -C nf -j$NIX_BUILD_CORES CC=$cc bzip2 bzip2recover
# Compare names, not just counts: no object may come from clang.
find nf -name '*.o' -printf '%f\n' | sort >objects
sed 's|.*/||' nanofil.log | sort -u >compiled
test -s objects
diff -u objects compiled
echo "nanofil compiled every one of $(wc -l <objects) bzip2 objects"
make -C nf CC=$cc test >test.log 2>&1 || { cat test.log; exit 1; }
! grep -q differ test.log
for env in "" "FUGC_SCRIBBLE=1 FUGC_VERIFY=1"; do
for f in text random; do
for level in 1 5 9; do
$ref/bzip2 -$level <$f >$f.ref.bz2
env $env nf/bzip2 -$level <$f >$f.nf.bz2
cmp $f.ref.bz2 $f.nf.bz2
env $env nf/bzip2 -d <$f.ref.bz2 | cmp - $f
$ref/bzip2 -d <$f.nf.bz2 | cmp - $f
done
done
# bzip2recover splits a damaged-free file into its blocks the same way.
rm -rf rec.ref rec.nf && mkdir rec.ref rec.nf
cp text.ref.bz2 rec.ref/t.bz2 && cp text.ref.bz2 rec.nf/t.bz2
(cd rec.ref && $ref/bzip2recover t.bz2 >/dev/null 2>&1)
(cd rec.nf && env $env ../nf/bzip2recover t.bz2 >/dev/null 2>&1)
diff -r rec.ref rec.nf
echo "bzip2 matches filcc's bzip2 byte for byte ($env)"
done
touch $out