Skip to content

Commit e01b23c

Browse files
committed
chore: add build step timings + minor build/install tweaks
1 parent 3cb21cd commit e01b23c

File tree

4 files changed

+108
-29
lines changed

4 files changed

+108
-29
lines changed

nix/scripts/gateway-build.sh

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
#!/bin/sh
22
set -e
33

4+
log_step() {
5+
if [ "${OPENCLAW_NIX_TIMINGS:-1}" != "1" ]; then
6+
"$@"
7+
return
8+
fi
9+
10+
name="$1"
11+
shift
12+
13+
start=$(date +%s)
14+
printf '>> [timing] %s...\n' "$name" >&2
15+
"$@"
16+
end=$(date +%s)
17+
printf '>> [timing] %s: %ss\n' "$name" "$((end - start))" >&2
18+
}
19+
420
if [ -z "${GATEWAY_PREBUILD_SH:-}" ]; then
521
echo "GATEWAY_PREBUILD_SH is not set" >&2
622
exit 1
@@ -27,28 +43,39 @@ export NPM_CONFIG_STORE_DIR="$store_path"
2743
export NPM_CONFIG_STORE_PATH="$store_path"
2844
export HOME="$(mktemp -d)"
2945

30-
pnpm install --offline --frozen-lockfile --ignore-scripts --store-dir "$store_path"
31-
chmod -R u+w node_modules
46+
log_step "pnpm install (offline, frozen, ignore-scripts)" pnpm install --offline --frozen-lockfile --ignore-scripts --store-dir "$store_path"
47+
48+
log_step "chmod node_modules writable" chmod -R u+w node_modules
49+
50+
# sharp may leave build artifacts around; remove to keep output smaller + avoid stale builds.
3251
rm -rf node_modules/.pnpm/sharp@*/node_modules/sharp/src/build
52+
3353
# Rebuild only native deps (avoid `pnpm rebuild` over the entire workspace).
3454
# node-llama-cpp postinstall attempts to download/compile llama.cpp (network blocked in Nix).
3555
# Also defensively disable other common downloaders.
3656
rebuild_list="$(jq -r '.pnpm.onlyBuiltDependencies // [] | .[]' package.json 2>/dev/null || true)"
3757
if [ -n "$rebuild_list" ]; then
38-
NODE_LLAMA_CPP_SKIP_DOWNLOAD=1 \
39-
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 \
40-
PUPPETEER_SKIP_DOWNLOAD=1 \
41-
ELECTRON_SKIP_BINARY_DOWNLOAD=1 \
42-
pnpm rebuild $rebuild_list
58+
log_step "pnpm rebuild (onlyBuiltDependencies)" env \
59+
NODE_LLAMA_CPP_SKIP_DOWNLOAD=1 \
60+
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 \
61+
PUPPETEER_SKIP_DOWNLOAD=1 \
62+
ELECTRON_SKIP_BINARY_DOWNLOAD=1 \
63+
pnpm rebuild $rebuild_list
4364
else
44-
NODE_LLAMA_CPP_SKIP_DOWNLOAD=1 \
45-
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 \
46-
PUPPETEER_SKIP_DOWNLOAD=1 \
47-
ELECTRON_SKIP_BINARY_DOWNLOAD=1 \
48-
pnpm rebuild
65+
log_step "pnpm rebuild (all)" env \
66+
NODE_LLAMA_CPP_SKIP_DOWNLOAD=1 \
67+
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=1 \
68+
PUPPETEER_SKIP_DOWNLOAD=1 \
69+
ELECTRON_SKIP_BINARY_DOWNLOAD=1 \
70+
pnpm rebuild
4971
fi
50-
bash -e -c ". \"$STDENV_SETUP\"; patchShebangs node_modules/.bin"
51-
pnpm build
52-
pnpm ui:build
53-
CI=true pnpm prune --prod
72+
73+
log_step "patchShebangs node_modules/.bin" bash -e -c ". \"$STDENV_SETUP\"; patchShebangs node_modules/.bin"
74+
75+
log_step "pnpm build" pnpm build
76+
log_step "pnpm ui:build" pnpm ui:build
77+
78+
log_step "pnpm prune --prod" env CI=true pnpm prune --prod
79+
80+
# Reduce output size (pnpm implementation detail; safe to remove)
5481
rm -rf node_modules/.pnpm/node_modules

nix/scripts/gateway-install.sh

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,32 @@
11
#!/bin/sh
22
set -e
3+
4+
log_step() {
5+
if [ "${OPENCLAW_NIX_TIMINGS:-1}" != "1" ]; then
6+
"$@"
7+
return
8+
fi
9+
10+
name="$1"
11+
shift
12+
13+
start=$(date +%s)
14+
printf '>> [timing] %s...\n' "$name" >&2
15+
"$@"
16+
end=$(date +%s)
17+
printf '>> [timing] %s: %ss\n' "$name" "$((end - start))" >&2
18+
}
19+
320
mkdir -p "$out/lib/openclaw" "$out/bin"
421

5-
cp -r dist node_modules package.json ui "$out/lib/openclaw/"
22+
log_step "copy build outputs" cp -r dist node_modules package.json "$out/lib/openclaw/"
623
if [ -d extensions ]; then
7-
cp -r extensions "$out/lib/openclaw/"
24+
log_step "copy extensions" cp -r extensions "$out/lib/openclaw/"
825
fi
926

1027
if [ -d docs/reference/templates ]; then
1128
mkdir -p "$out/lib/openclaw/docs/reference"
12-
cp -r docs/reference/templates "$out/lib/openclaw/docs/reference/"
29+
log_step "copy reference templates" cp -r docs/reference/templates "$out/lib/openclaw/docs/reference/"
1330
fi
1431

1532
if [ -z "${STDENV_SETUP:-}" ]; then
@@ -21,10 +38,7 @@ if [ ! -f "$STDENV_SETUP" ]; then
2138
exit 1
2239
fi
2340

24-
bash -e -c '. "$STDENV_SETUP"; patchShebangs "$out/lib/openclaw/node_modules/.bin"'
25-
if [ -d "$out/lib/openclaw/ui/node_modules/.bin" ]; then
26-
bash -e -c '. "$STDENV_SETUP"; patchShebangs "$out/lib/openclaw/ui/node_modules/.bin"'
27-
fi
41+
log_step "patchShebangs node_modules/.bin" bash -e -c '. "$STDENV_SETUP"; patchShebangs "$out/lib/openclaw/node_modules/.bin"'
2842

2943
# Work around missing dependency declaration in pi-coding-agent (strip-ansi).
3044
# Ensure it is resolvable at runtime without changing upstream.

nix/scripts/gateway-prebuild.sh

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,43 @@
11
#!/bin/sh
22
set -e
33

4+
log_step() {
5+
if [ "${OPENCLAW_NIX_TIMINGS:-1}" != "1" ]; then
6+
"$@"
7+
return
8+
fi
9+
10+
name="$1"
11+
shift
12+
13+
start=$(date +%s)
14+
printf '>> [timing] %s...\n' "$name" >&2
15+
"$@"
16+
end=$(date +%s)
17+
printf '>> [timing] %s: %ss\n' "$name" "$((end - start))" >&2
18+
}
19+
420
store_path_file="${PNPM_STORE_PATH_FILE:-.pnpm-store-path}"
521
store_path="$(mktemp -d)"
622

723
printf "%s" "$store_path" > "$store_path_file"
824

925
fetcherVersion=$(cat "$PNPM_DEPS/.fetcher-version" 2>/dev/null || echo 1)
1026
if [ "$fetcherVersion" -ge 3 ]; then
11-
tar --zstd -xf "$PNPM_DEPS/pnpm-store.tar.zst" -C "$store_path"
27+
# tar --zstd uses libzstd; on some platforms it ends up single-threaded.
28+
# Use zstd directly to enable multi-threaded decompression.
29+
log_step "extract pnpm store (fetcherVersion=${fetcherVersion})" sh -c '
30+
zstd -d --threads=0 < "$1" | tar -xf - -C "$2"
31+
' sh "$PNPM_DEPS/pnpm-store.tar.zst" "$store_path"
1232
else
13-
cp -Tr "$PNPM_DEPS" "$store_path"
33+
log_step "copy pnpm store (fetcherVersion=${fetcherVersion})" cp -Tr "$PNPM_DEPS" "$store_path"
1434
fi
1535

16-
chmod -R +w "$store_path"
36+
log_step "chmod pnpm store writable" chmod -R +w "$store_path"
1737

1838
# pnpm --ignore-scripts marks tarball deps as "not built" and offline install
1939
# later refuses to use them; if a dep doesn't require build, promote it.
20-
"$PROMOTE_PNPM_INTEGRITY_SH" "$store_path"
40+
log_step "promote pnpm integrity" "$PROMOTE_PNPM_INTEGRITY_SH" "$store_path"
2141

2242
export REAL_NODE_GYP="$(command -v node-gyp)"
2343
wrapper_dir="$(mktemp -d)"

nix/scripts/gateway-tests-build.sh

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
#!/bin/sh
22
set -e
33

4+
log_step() {
5+
if [ "${OPENCLAW_NIX_TIMINGS:-1}" != "1" ]; then
6+
"$@"
7+
return
8+
fi
9+
10+
name="$1"
11+
shift
12+
13+
start=$(date +%s)
14+
printf '>> [timing] %s...\n' "$name" >&2
15+
"$@"
16+
end=$(date +%s)
17+
printf '>> [timing] %s: %ss\n' "$name" "$((end - start))" >&2
18+
}
19+
420
if [ -z "${GATEWAY_PREBUILD_SH:-}" ]; then
521
echo "GATEWAY_PREBUILD_SH is not set" >&2
622
exit 1
@@ -19,7 +35,8 @@ export NPM_CONFIG_STORE_DIR="$store_path"
1935
export NPM_CONFIG_STORE_PATH="$store_path"
2036
export HOME="$(mktemp -d)"
2137

22-
pnpm install --offline --frozen-lockfile --ignore-scripts --store-dir "$store_path"
38+
log_step "pnpm install (tests/config)" pnpm install --offline --frozen-lockfile --ignore-scripts --store-dir "$store_path"
39+
2340
if [ -z "${STDENV_SETUP:-}" ]; then
2441
echo "STDENV_SETUP is not set" >&2
2542
exit 1
@@ -28,4 +45,5 @@ if [ ! -f "$STDENV_SETUP" ]; then
2845
echo "STDENV_SETUP not found: $STDENV_SETUP" >&2
2946
exit 1
3047
fi
31-
bash -e -c ". \"$STDENV_SETUP\"; patchShebangs node_modules/.bin"
48+
49+
log_step "patchShebangs node_modules/.bin" bash -e -c ". \"$STDENV_SETUP\"; patchShebangs node_modules/.bin"

0 commit comments

Comments
 (0)