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
5Ship 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
36 return `@libsql/${target}`;36 return `@libsql/${target}`;
37};37};
38 38
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.
44const 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
39const externalPackages = [63const externalPackages = [
40 "@cloudflare/worker-bundler",64 "@cloudflare/worker-bundler",
41 "quickjs-emscripten",65 "quickjs-emscripten",
@@ -46,6 +70,7 @@ const externalPackages = [ · 4 unmodified lines
46 "@jitl/quickjs-wasmfile-release-asyncify",70 "@jitl/quickjs-wasmfile-release-asyncify",
47 "@jitl/quickjs-wasmfile-debug-asyncify",71 "@jitl/quickjs-wasmfile-debug-asyncify",
48 "workerd",72 "workerd",
73 workerdPlatformPackage(),
49 libsqlNativePackage(),74 libsqlNativePackage(),
50] as const;75] as const;
51 76