From 6de1b9fac3408509285e16c341b607eb99c4c867 Mon Sep 17 00:00:00 2001 From: PhysShell Date: Sun, 19 Jul 2026 07:36:46 +0500 Subject: [PATCH] build(nix): reproducible dev shell for the local wasm build + Playwright web-test (3C-B0) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A repo-root flake so `nix develop` gives an environment where the existing commands run unchanged and cockpit-web-test is a local check, not a cloud-only oracle: nix develop ./cockpit/build-web.sh cd cockpit/web-test && npm ci && npm test The flake provides, without duplicating any repo-pinned version: - Rust via rustup (toolchain from rust-toolchain.toml); - wasm-bindgen-cli installed at exactly cockpit/Cargo.toml's version (build-web.sh still enforces the match); - Node 22 and a Playwright Chromium — nixpkgs pinned to nixos-25.11, whose playwright-driver is 1.56.1, the exact version in web-test/package.json, so the Nix browser revision matches the npm Playwright; - a target-scoped wasm C toolchain: an unwrapped clang driven only for wasm32-unknown-unknown (CC_wasm32_unknown_unknown / AR_ / CFLAGS_), which fixes the zstd-to-x86 miscompile that left ZSTD_* undefined at the wasm link. Being target-scoped, native cargo in the same shell keeps host gcc with no wasm flags. Proven end to end on NixOS/WSL: build-web.sh links a full 5.4 MiB wasm bundle and `npm test` runs the real cockpit in Chromium (15/16 pass, 0 fail). CI stays on its own working setup — this is a local-dev convenience, not a CI rewrite. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_01NkqJUU6d1sW1RAfvyHrqVM --- cockpit/web-test/README.md | 58 +++++++++++++++++++++++++++++++++++ flake.lock | 27 +++++++++++++++++ flake.nix | 62 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 147 insertions(+) create mode 100644 cockpit/web-test/README.md create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/cockpit/web-test/README.md b/cockpit/web-test/README.md new file mode 100644 index 00000000..368a401c --- /dev/null +++ b/cockpit/web-test/README.md @@ -0,0 +1,58 @@ +# cockpit web-test — running it locally + +The `cockpit-web-test` suite builds the cockpit to wasm, serves it, and drives +the **real** cockpit in headless Chromium (Playwright). CI runs it on every PR; +the repo-root `flake.nix` makes the *exact same* run reproducible locally, so +browser acceptance is a normal local check rather than a cloud-only oracle. + +## Run it + +From the repository root, with a flakes-enabled Nix: + +```sh +nix develop # the toolchain shell (see "What the shell provides") +./cockpit/build-web.sh # cargo build wasm + version-matched wasm-bindgen → cockpit/dist +cd cockpit/web-test +npm ci +npm test # Playwright + Chromium against cockpit/dist +``` + +The flake does **not** replace those commands or duplicate any version — it only +provides an environment in which the existing scripts work unchanged. + +## What the shell provides + +- **Rust via `rustup`** — the toolchain and components come from the repo's + `rust-toolchain.toml`; `build-web.sh` adds the `wasm32-unknown-unknown` target. +- **`wasm-bindgen-cli`** — the shell hook installs *exactly* the version pinned + in `cockpit/Cargo.toml` (read from there, not re-pinned here); `build-web.sh` + still enforces the version match itself. +- **Node 22** and the **Playwright browser** — `nixpkgs` is pinned to + `nixos-25.11`, whose `playwright-driver` is **1.56.1**, the exact version in + `cockpit/web-test/package.json`. So the Nix-provided Chromium revision matches + what the npm Playwright expects, and the downloaded (non-NixOS-runnable) browser + is skipped (`PLAYWRIGHT_BROWSERS_PATH`). +- **A target-scoped wasm C toolchain.** The C in the Guitar Pro reader's `zstd` + subtree must be cross-compiled to wasm. The standard Nix cc-wrapper forces the + *host* target, which silently produces x86 objects and an undefined-`ZSTD_*` + link failure. The fix is an *unwrapped* `clang` driven only for the wasm + target: + + ``` + CC_wasm32_unknown_unknown = clang + AR_wasm32_unknown_unknown = llvm-ar + CFLAGS_wasm32_unknown_unknown = --target=wasm32-unknown-unknown + ``` + + These are **target-scoped** (`*_wasm32_unknown_unknown`), so a plain native + `cargo test` / `cargo clippy` in the same shell uses the host `gcc` with no + wasm flags — the host build is untouched. + +## Notes + +- CI is **not** on Nix; it keeps its own working setup. The flake is a local-dev + convenience, not a CI rewrite. +- `cockpit/dist/`, `node_modules/`, and `target/` are gitignored build outputs. +- Without Nix, replicate the shell by hand: a matching Rust toolchain, the pinned + `wasm-bindgen-cli`, Node 22, a Playwright-1.56 Chromium, and a wasm-target C + compiler. diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..227b2120 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1782847189, + "narHash": "sha256-twXPFqFsrrY5r28Zh7Homgcp2gUMBgQ6WDS98Q/3xFI=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b6018f87da91d19d0ab4cf979885689b469cdd41", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-25.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..cdb1eb38 --- /dev/null +++ b/flake.nix @@ -0,0 +1,62 @@ +{ + description = "griff cockpit web-test dev shell — full local wasm build + Playwright (3C-B0)"; + + # Pinned to nixos-25.11: its `playwright-driver` is 1.56.1 — the exact version + # cockpit/web-test/package.json pins — so the Nix-provided Chromium revision + # matches what the npm Playwright expects. Its clang cross-compiles wasm too, + # so one input covers the whole flow. + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11"; + + outputs = + { self, nixpkgs }: + let + system = "x86_64-linux"; + pkgs = import nixpkgs { inherit system; }; + # Unwrapped clang for the wasm C cross-compile: the standard Nix cc-wrapper + # forces the host target, which silently compiled zstd's C to x86 objects + # (undefined ZSTD_* at the wasm link). The wasm target must get a plain + # `clang --target=wasm32-unknown-unknown`, and only that target. + wasmClang = pkgs.llvmPackages.clang-unwrapped; + in + { + devShells.${system}.default = pkgs.mkShell { + packages = [ + pkgs.rustup # the repo's rust-toolchain.toml pins stable + rustfmt/clippy + pkgs.nodejs_22 # match CI + pkgs.clang # host cc for native cargo builds inside the shell + pkgs.lld + pkgs.llvm # llvm-ar for the wasm archive + pkgs.pkg-config + pkgs.cacert # cargo install / npm fetch over TLS + pkgs.git + wasmClang + ]; + + # Target-scoped so host (x86_64) builds are untouched — cc-rs reads the + # `*_wasm32_unknown_unknown` triples only when building for that target. + CC_wasm32_unknown_unknown = "${wasmClang}/bin/clang"; + AR_wasm32_unknown_unknown = "${pkgs.llvm}/bin/llvm-ar"; + CFLAGS_wasm32_unknown_unknown = "--target=wasm32-unknown-unknown"; + + # Playwright runs the Nix-provided browser instead of downloading a + # dynamically-linked one that will not run on NixOS. + PLAYWRIGHT_BROWSERS_PATH = "${pkgs.playwright-driver.browsers}"; + PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS = "true"; + PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD = "1"; + + shellHook = '' + # rustup/cargo installs land here; put it ahead of the Nix rustup shim. + export PATH="$HOME/.cargo/bin:$PATH" + # wasm-bindgen-cli must match the crate version build-web.sh checks. We + # do not pin it in the flake (that would duplicate cockpit/Cargo.toml); + # we install exactly what the repo asks for, once. + want=$(grep -m1 -E '^wasm-bindgen[[:space:]]*=' cockpit/Cargo.toml | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' || true) + have=$(wasm-bindgen --version 2>/dev/null | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -n1 || true) + if [ -n "$want" ] && [ "$have" != "$want" ]; then + echo "flake: installing wasm-bindgen-cli $want (matching cockpit/Cargo.toml)…" + cargo install wasm-bindgen-cli --version "$want" --locked + fi + ''; + }; + }; +}