# Browser archive engine rebuild

This recipe rebuilds the self-hosted archive engine from the pinned upstream sources and applies the local stack-cleanup patch. It produces `sevenzip-wasm.mjs` and its matching `sevenzip-wasm.wasm`; keep these files paired. The Emscripten module exports `stackSave` and `stackRestore`, which `archive-core.ts` uses around every `callMain` invocation.

From a checkout with dependencies installed, prepare the pinned source downloads and build from the repository root:

```sh
bun scripts/prepare-engine-sources.ts
docker --context colima-localfile-engines buildx build --platform linux/arm64 \
  -f services/browser-archive/Dockerfile \
  --output type=local,dest=.cache/archive-engine-build .
```

The build verifies both source archive hashes before unpacking. It applies upstream `7zip-26.03.patch` unchanged, then applies [`stack-apis.patch`](stack-apis.patch). The Emscripten image digest, fixed source epoch, fixed build name, source and output hashes are recorded in [`build-manifest.json`](build-manifest.json). The Node smoke check in the image fails unless the ESM module loads and exposes all three required APIs.

The generated module and WASM live together under `apps/web/src/lib/converter/archive-engine/`. Vite emits the WASM as one content-hashed same-origin asset; the worker imports that URL, and the generated Emscripten loader's `new URL` reference resolves to the same file. The browser downloads that asset from Filepuli when an archive operation needs it.

The three files in `licenses/` retain the wrapper, 7-Zip, and unRAR notices. The original wrapper and 7-Zip source archives are available from the [engine source page](/engine-sources/v4/index.html); this rebuild recipe, local patch, build manifest, and notices are linked there too.
