@@ -56,10 +56,9 @@ RUN --mount=type=cache,sharing=locked,target=$CARGO_HOME/git \
5656# Build application
5757COPY . /build
5858
59- RUN --mount=type=cache,sharing=locked,target=$CARGO_HOME/git \
60- --mount=type=cache,sharing=locked,target=$CARGO_HOME/registry \
61- --mount=type=cache,sharing=locked,target=/build/target \
62- cargo run --release --features=$RUNTIME --bin snapshot
59+ # Note: We do NOT generate the snapshot here anymore because it would be
60+ # generated for the build platform (e.g. x86_64), but we might need it for
61+ # the target platform (e.g. aarch64). V8 snapshots are architecture-dependent.
6362
6463FROM builder AS platform
6564
@@ -79,14 +78,29 @@ RUN --mount=type=cache,id=cargo-$TARGETPLATFORM-$RUNTIME,sharing=locked,target=$
7978 esac
8079
8180# Build application for target platform
81+ # 1. Build the snapshot generator for the TARGET platform
82+ # 2. Run it (via QEMU emulation if needed) to generate the snapshot.bin
83+ # 3. Build the final runner which embeds the snapshot.bin
8284RUN --mount=type=cache,id=cargo-$TARGETPLATFORM-$RUNTIME,sharing=locked,target=$CARGO_HOME/git \
8385 --mount=type=cache,id=cargo-$TARGETPLATFORM-$RUNTIME,sharing=locked,target=$CARGO_HOME/registry \
8486 --mount=type=cache,id=cargo-$TARGETPLATFORM-$RUNTIME,sharing=locked,target=/build/target \
8587 case "$TARGETPLATFORM" in \
86- "linux/arm64") cargo build --release --features=$RUNTIME --target aarch64-unknown-linux-gnu && \
87- mv /build/target/aarch64-unknown-linux-gnu/release/openworkers-runner /build/output ;; \
88- "linux/amd64") cargo build --release --features=$RUNTIME --target x86_64-unknown-linux-gnu && \
89- mv /build/target/x86_64-unknown-linux-gnu/release/openworkers-runner /build/output ;; \
88+ "linux/arm64") \
89+ # Build snapshot generator for target \
90+ cargo build --release --features=$RUNTIME --bin snapshot --target aarch64-unknown-linux-gnu && \
91+ # Generate snapshot (runs via QEMU) \
92+ /build/target/aarch64-unknown-linux-gnu/release/snapshot && \
93+ # Build runner \
94+ cargo build --release --features=$RUNTIME --target aarch64-unknown-linux-gnu && \
95+ mv /build/target/aarch64-unknown-linux-gnu/release/openworkers-runner /build/output ;; \
96+ "linux/amd64") \
97+ # Build snapshot generator for target \
98+ cargo build --release --features=$RUNTIME --bin snapshot --target x86_64-unknown-linux-gnu && \
99+ # Generate snapshot \
100+ /build/target/x86_64-unknown-linux-gnu/release/snapshot && \
101+ # Build runner \
102+ cargo build --release --features=$RUNTIME --target x86_64-unknown-linux-gnu && \
103+ mv /build/target/x86_64-unknown-linux-gnu/release/openworkers-runner /build/output ;; \
90104 *) echo "Unsupported platform: $TARGETPLATFORM" && exit 1 ;; \
91105 esac
92106
0 commit comments