History

fix(selfhost): ship the platform workerd binary in the docker runtime (#1394)

The workerd npm package's bin/workerd is a Node shim that execs the real binary from the per-platform optional dependency (@cloudflare/workerd-<os>-<arch>), which package-runtime.ts never copied into the image. Custom app tools failed to sync or invoke with 'workerd is unavailable on this platform'. Copy the platform package alongside the shim, derived per build platform like the libsql native addon.

Rhys Sullivan committed 4 months ago

Commit 1ca51111 parent 93614db2 files · +30 −0Browse files

Unified · Split

2 files
  1. .changeset/selfhost-workerd-platform-binary.md +5 −0
  2. apps/host-selfhost/scripts/package-runtime.ts +25 −0
.changeset/selfhost-workerd-platform-binary.md+5−0
@@ -0,0 +1,5 @@
1+---
2+"executor": patch
3+---
4+
5+Ship the platform workerd binary in the self-host Docker runtime; without it custom app tools failed to sync or invoke with "workerd is unavailable on this platform".
apps/host-selfhost/scripts/package-runtime.ts+25−0
@@ -36,6 +36,30 @@ const libsqlNativePackage = (): string => { · 35 unmodified lines
3636 return `@libsql/${target}`;
3737 };
3838
39+// The `workerd` package's bin/workerd is a Node shim that execs the real
40+// binary from the per-platform optional dependency
41+// (`@cloudflare/workerd-<os>-<arch>`); without it the runtime throws
42+// "workerd is unavailable on this platform" on first app-tool bundle or
43+// invoke. Same per-platform shape as libsql above.
44+const workerdPlatformPackage = (): string => {
45+ const platformMap: Record<string, string> = {
46+ "darwin-arm64": "workerd-darwin-arm64",
47+ "darwin-x64": "workerd-darwin-64",
48+ "linux-arm64": "workerd-linux-arm64",
49+ "linux-x64": "workerd-linux-64",
50+ "win32-x64": "workerd-windows-64",
51+ };
52+ const key = `${process.platform}-${process.arch}`;
53+ const target = platformMap[key];
54+ if (!target) {
55+ throw new Error(
56+ `package-runtime: no workerd platform package mapped for ${key}. ` +
57+ "Add it to the platform map in apps/host-selfhost/scripts/package-runtime.ts.",
58+ );
59+ }
60+ return `@cloudflare/${target}`;
61+};
62+
3963 const externalPackages = [
4064 "@cloudflare/worker-bundler",
4165 "quickjs-emscripten",
@@ -46,6 +70,7 @@ const externalPackages = [ · 4 unmodified lines
4670 "@jitl/quickjs-wasmfile-release-asyncify",
4771 "@jitl/quickjs-wasmfile-debug-asyncify",
4872 "workerd",
73+ workerdPlatformPackage(),
4974 libsqlNativePackage(),
5075 ] as const;
5176