🔧 Allow skipping renderer build setup via env. var (#12882)

Set PENPOT_WASM_PREPARED=1 to speed up repeated builds
This commit is contained in:
Miguel de Benito Delgado 2026-11-09 12:53:18 +01:00 committed by GitHub
parent 943e63a99e
commit 33602b9114
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 68 additions and 1 deletions

View File

@ -52,6 +52,11 @@ Each target keeps its own `CARGO_TARGET_DIR` (`target/<target>`), so switching
between them does not invalidate the other's cache. Set `BUILD_MODE=release`
(or `NODE_ENV=production`) for an optimized build; the default is `debug`.
Set `PENPOT_WASM_PREPARED=1` when the pinned Rust toolchain is selected, its
Emscripten target is installed, and this package's Node dependencies are
installed. `./build` and `./test` then skip `rustup` setup and `pnpm install`.
Benchmark preparation sets this flag for each retained build.
### Serialize builds in one checkout
All targets in one checkout share one `flock` lock stored at

View File

@ -164,6 +164,11 @@ function setup_rust {
}
function setup {
if [ "${PENPOT_WASM_PREPARED:-}" = "1" ]; then
echo "Skipping rustup and pnpm setup (PENPOT_WASM_PREPARED=1)" >&2
return 0
fi
setup_rust
pnpm install;
}

View File

@ -3,7 +3,9 @@
# Usage: ./build [frontend|export] [extra cargo params...]
#
# With no target, builds both. Set BUILD_MODE=release (or NODE_ENV=production)
# for an optimized build. See `_build_env` for what each target changes.
# for an optimized build. Set PENPOT_WASM_PREPARED=1 when the pinned toolchain
# and Node dependencies are prepared to skip their setup. See `_build_env` for
# what each target changes.
_SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
_RENDER_TARGET=${1:-}

View File

@ -347,3 +347,58 @@ test("rejects malformed Cargo JSON and removes stale build facts", (t) => {
assert.match(result.stderr, /ERROR:/);
assert.equal(fs.existsSync(f.info), false);
});
function runSetup(t, prepared) {
const root = fs.mkdtempSync(path.join(os.tmpdir(), "render-wasm-setup-"));
t.after(() => fs.rmSync(root, { recursive: true, force: true }));
const bin = path.join(root, "bin");
const marker = path.join(root, "calls");
fs.mkdirSync(bin);
for (const name of ["rustup", "pnpm"]) {
fs.writeFileSync(
path.join(bin, name),
`#!/bin/sh\nprintf '%s\\n' "${name} $*" >> "$MARKER"\n`,
{ mode: 0o755 },
);
}
const env = {
...process.env,
MARKER: marker,
PATH: `${bin}:${process.env.PATH}`,
};
if (prepared === undefined) {
delete env.PENPOT_WASM_PREPARED;
} else {
env.PENPOT_WASM_PREPARED = prepared;
}
const result = spawnSync(
"bash",
[
"--noprofile",
"--norc",
"-c",
'source "$1" frontend; setup',
"setup-test",
path.resolve(__dirname, "..", "_build_env"),
],
{
cwd: path.resolve(__dirname, ".."),
env,
encoding: "utf8",
},
);
assert.equal(result.status, 0, result.stderr);
return fs.existsSync(marker) ? fs.readFileSync(marker, "utf8") : "";
}
test("prepared setup skips rustup and pnpm", (t) => {
const normal = runSetup(t);
assert.match(normal, /^rustup default /m);
assert.match(normal, /^pnpm install$/m);
const disabled = runSetup(t, "0");
assert.match(disabled, /^rustup default /m);
assert.match(disabled, /^pnpm install$/m);
assert.equal(runSetup(t, "1"), "");
});