Lightpanda: the headless browser designed for AI and automation
#!/usr/bin/env bash
set -euo pipefail
repo="${1:-"$(dirname "${BASH_SOURCE[0]}")/.."}"
cd "$repo"
repo="$PWD"
OUT=nix/zig-deps.nix
workdir=$(mktemp -d)
trap 'rm -rf "$workdir"' EXIT
# `--fetch=all` walks build.zig.zon's dependency tree regardless of what
# build.zig references, so only the manifest is needed to reproduce the
# fetch — paired with an empty build.zig so `zig build` has a valid root
# module to run against.
cd "$workdir"
cp "$repo/build.zig.zon" build.zig.zon
printf 'const std = @import("std");\npub fn build(b: *std.Build) void {\n _ = b;\n}\n' > build.zig
export HOME="$workdir/home"
mkdir -p "$HOME"
export ZIG_GLOBAL_CACHE_DIR="$workdir/cache"
export ZIG_LOCAL_CACHE_DIR="$ZIG_GLOBAL_CACHE_DIR"
echo "fetching build.zig.zon deps..." >&2
zig build --fetch=all
# nix/package.nix's zigDeps derivation copies $ZIG_GLOBAL_CACHE_DIR/p to
# $out with outputHashMode = "recursive" — hash that same directory the
# same way (NAR serialisation) to predict the fixed-output hash exactly,
# without needing to build anything.
hash=$(nix hash path "$ZIG_GLOBAL_CACHE_DIR/p")
{
echo "# Generated by nix/update-zig-deps-hash.sh — do not edit by hand."
echo "#"
echo "# The fixed-output hash of \`zig build --fetch=all\`'s cache (every"
echo "# build.zig.zon dependency). Rerun the generator whenever build.zig.zon"
echo "# changes."
echo "{"
echo " hash = \"${hash}\";"
echo "}"
} > "$repo/$OUT"
echo "wrote ${hash} to ${OUT}"