Skip to content

Commit 96b4185

Browse files
committed
test(rust): CI guard — cargo tests + Rust<->Zig byte-identical cross-check
Builds the crate in the sandbox, runs cargo test (round-trip + zero-alloc), and asserts Rust encode == Zig encode and Rust decode(Zig encode) == original across all 256 bytes — the transport-critical parity property.
1 parent b13827e commit 96b4185

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

flake.nix

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,29 @@
415415
installPhase = "mkdir -p $out && touch $out/passed";
416416
};
417417

418+
# Rust crate: in-crate tests + the transport-critical cross-impl guard
419+
# (Rust encode must be byte-identical to Zig over all 256 bytes).
420+
test-rust = pkgs.stdenv.mkDerivation {
421+
name = "test-rust";
422+
src = ./.;
423+
nativeBuildInputs = with pkgs; [ cargo rustc zig ];
424+
buildPhase = ''
425+
export HOME=$TMPDIR
426+
export CARGO_HOME=$TMPDIR/cargo
427+
cargo test --release --offline --manifest-path rust/Cargo.toml
428+
cargo build --release --offline --manifest-path rust/Cargo.toml
429+
zig build
430+
for i in $(seq 0 255); do printf "\\$(printf '%03o' "$i")"; done > allbytes
431+
./rust/target/release/printable-binary-rs < allbytes > r.out
432+
PRINTABLE_BINARY_MUTE_STATS=1 ./zig-out/bin/printable-binary-zig < allbytes > z.out
433+
cmp r.out z.out || { echo "FAIL: Rust encode != Zig encode" >&2; exit 1; }
434+
./rust/target/release/printable-binary-rs -d < z.out > rt.out
435+
cmp allbytes rt.out || { echo "FAIL: Rust decode(Zig encode) != original" >&2; exit 1; }
436+
echo "Rust <-> Zig byte-identical across all 256 bytes"
437+
'';
438+
installPhase = "mkdir -p $out && touch $out/passed";
439+
};
440+
418441
# Dogfood the C FFI boundary: build the C FFI CLI against the Zig static
419442
# lib and round-trip through it (encode/decode + hexlike).
420443
test-ffi-cli = pkgs.stdenv.mkDerivation {

0 commit comments

Comments
 (0)