Repository navigation
3C-B0: reproducible Nix dev shell for the local wasm build + Playwright #143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
| ''; | ||
| }; | ||
| }; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a contributor's Nix system is anything other than
x86_64-linux(for exampleaarch64-linuxor Darwin),nix developwill look fordevShells.<system>.default(as documented by the Nix manual), but this flake only emitsdevShells.x86_64-linux.default. That makes the documented local web-test shell unavailable on those hosts even though the toolchain is otherwise not inherently x86-only; please generate shells for the supported systems or document the shell as Linux x86_64-only.Useful? React with 👍 / 👎.