Skip to content

Commit aed9539

Browse files
committed
Make wasm dev work!
1 parent 424cc2f commit aed9539

8 files changed

Lines changed: 2095 additions & 176 deletions

File tree

packages/pdf-runtime/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@
5151
"generate:runtime-methods": "node ./build/generate-runtime-methods.mjs",
5252
"lint": "eslint src --color",
5353
"lint:fix": "eslint src --color --fix",
54-
"runtime:build-local": "bash ./scripts/runtime-build-local.sh",
55-
"runtime:package-local": "bash ./scripts/runtime-package-local.sh",
56-
"runtime:sync": "bash ./scripts/runtime-sync.sh",
5754
"runtime:use-local": "bash ./scripts/runtime-use-local.sh",
5855
"test:parity": "node --test ./test/*.test.mjs",
5956
"verify:packages": "bash ./scripts/verify-packages.sh",
@@ -84,6 +81,7 @@
8481
"@rollup/plugin-typescript": "^12.3.0",
8582
"@types/emscripten": "^1.39.13",
8683
"@types/node": "latest",
84+
"chokidar-cli": "^3.0.0",
8785
"cmake-js": "^7.3.1",
8886
"magic-string": "^0.30.17",
8987
"rollup": "^4.53.5",

packages/pdf-runtime/scripts/fetch-libpdfium.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,14 @@ ARCHIVE="$CACHE/libembedpdf-pdf-runtime-$TARGET.tar.gz"
4848

4949
mkdir -p "$CACHE" "$DEST"
5050

51-
if [[ ! -f "$ARCHIVE" ]]; then
51+
needs_refresh() {
52+
[[ ! -f "$ARCHIVE" ]] && return 0
53+
local cached_sha
54+
cached_sha="$(sha256_file "$ARCHIVE")"
55+
[[ "$cached_sha" != "$SHA256" ]]
56+
}
57+
58+
if needs_refresh; then
5259
echo "Downloading $TARGET from $URL"
5360
if [[ "$URL" == file://* ]]; then
5461
LOCAL_PATH="${URL#file://}"

packages/pdf-runtime/scripts/runtime-build-local.sh

Lines changed: 0 additions & 40 deletions
This file was deleted.

packages/pdf-runtime/scripts/runtime-package-local.sh

Lines changed: 0 additions & 55 deletions
This file was deleted.

packages/pdf-runtime/scripts/runtime-sync.sh

Lines changed: 0 additions & 30 deletions
This file was deleted.

packages/pdf-runtime/scripts/wasm-dev.sh

Lines changed: 73 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,89 @@
22
set -euo pipefail
33

44
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
5+
SCRIPT="$ROOT/scripts/wasm-dev.sh"
56
SRC="$ROOT/runtime-src"
67
TARGET="wasm32"
8+
EMSDK_VERSION="3.1.72"
9+
LOCK_DIR="$ROOT/.cache/wasm-dev"
10+
RUNNING="$LOCK_DIR/running"
11+
PENDING="$LOCK_DIR/pending"
12+
13+
mkdir -p "$LOCK_DIR"
14+
15+
if [[ ! -d "$SRC/.git" && ! -f "$SRC/.git" ]]; then
16+
echo "runtime-src missing; run: git submodule update --init --recursive packages/pdf-runtime/runtime-src" >&2
17+
exit 1
18+
fi
19+
20+
for cmd in gn ninja gclient; do
21+
if ! command -v "$cmd" >/dev/null 2>&1; then
22+
echo "missing $cmd on PATH; install depot_tools and add it to PATH" >&2
23+
echo "see: https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html#_setting_up" >&2
24+
exit 1
25+
fi
26+
done
27+
28+
ensure_emsdk() {
29+
local emsdk_dir="$SRC/third_party/emsdk"
30+
if [[ ! -d "$emsdk_dir/.git" ]]; then
31+
git clone https://github.com/emscripten-core/emsdk.git "$emsdk_dir"
32+
fi
33+
"$emsdk_dir/emsdk" install "$EMSDK_VERSION"
34+
"$emsdk_dir/emsdk" activate "$EMSDK_VERSION"
35+
# shellcheck disable=SC1091
36+
source "$emsdk_dir/emsdk_env.sh"
37+
}
38+
39+
case "$(uname -s)" in
40+
Darwin) export PDF_RUNTIME_TARGET_OS_LIST="mac emscripten" ;;
41+
Linux) export PDF_RUNTIME_TARGET_OS_LIST="linux emscripten" ;;
42+
*) echo "wasm:dev only supports Darwin or Linux hosts" >&2; exit 1 ;;
43+
esac
744

845
build_once() {
9-
"$ROOT/scripts/runtime-build-local.sh" "$TARGET"
46+
ensure_emsdk
47+
"$SRC/scripts/embedpdf-runtime/build-target.sh" "$TARGET"
1048
local artifact
11-
artifact="$("$ROOT/scripts/runtime-package-local.sh" "$TARGET")"
49+
artifact="$("$SRC/scripts/embedpdf-runtime/package-target.sh" "$TARGET" | tail -n1)"
1250
"$ROOT/scripts/runtime-use-local.sh" "$TARGET" "$artifact"
13-
PDF_RUNTIME_BUILD_FILE="$ROOT/pdf-runtime-build.local.json" "$ROOT/scripts/build-target.sh" "$TARGET"
51+
PDF_RUNTIME_BUILD_FILE="$ROOT/pdf-runtime-build.local.json" \
52+
"$ROOT/scripts/build-target.sh" "$TARGET"
1453
echo "pdf-runtime wasm refreshed"
1554
}
1655

17-
build_once
18-
19-
if ! command -v watchexec >/dev/null 2>&1; then
20-
echo "watchexec not found; ran one build and exiting"
56+
if [[ "${WASM_DEV_BUILD_ONCE:-}" == "1" ]]; then
57+
if [[ -f "$RUNNING" ]]; then
58+
touch "$PENDING"
59+
echo "build already running; queued rebuild"
60+
exit 0
61+
fi
62+
trap 'rm -f "$RUNNING"' EXIT
63+
while :; do
64+
touch "$RUNNING"
65+
rm -f "$PENDING"
66+
build_once
67+
[[ -f "$PENDING" ]] || break
68+
echo "rebuild requested while building; running again"
69+
done
2170
exit 0
2271
fi
2372

73+
CHOKIDAR_BIN="$ROOT/node_modules/.bin/chokidar"
74+
if [[ ! -x "$CHOKIDAR_BIN" ]]; then
75+
echo "chokidar binary missing at $CHOKIDAR_BIN; run: pnpm install --filter @embedpdf/pdf-runtime" >&2
76+
exit 1
77+
fi
78+
2479
cd "$SRC"
25-
watchexec --exts cc,cpp,h --ignore 'third_party/**' --restart --shell bash -- "$(declare -f build_once); ROOT='$ROOT'; TARGET='$TARGET'; build_once"
80+
exec "$CHOKIDAR_BIN" \
81+
"core/**/*.{cc,cpp,h}" \
82+
"fpdfsdk/**/*.{cc,cpp,h}" \
83+
"fxbarcode/**/*.{cc,cpp,h}" \
84+
"fxjs/**/*.{cc,cpp,h}" \
85+
"xfa/**/*.{cc,cpp,h}" \
86+
"public/**/*.h" \
87+
"constants/**/*.h" \
88+
--initial \
89+
--debounce 2000 \
90+
-c "WASM_DEV_BUILD_ONCE=1 bash '$SCRIPT'"

0 commit comments

Comments
 (0)