Skip to content

Commit 8e08917

Browse files
committed
Fix build
1 parent 1fcd5d7 commit 8e08917

5 files changed

Lines changed: 27 additions & 36 deletions

File tree

.github/workflows/docker.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ jobs:
5050
tags: ${{ steps.metadata.outputs.tags }}
5151
build-args: |
5252
RUNTIME=${{ matrix.runtime }}
53-
# cache-from: type=gha,scope=${{ matrix.runtime }}
54-
# cache-to: type=gha,mode=max,scope=${{ matrix.runtime }}
53+
cache-from: type=gha,scope=${{ matrix.runtime }}
54+
cache-to: type=gha,mode=max,scope=${{ matrix.runtime }}
5555
platforms: linux/amd64,linux/arm64

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
.DS_Store
44

55
.env
6+
.env.*

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ swc_ecma_visit = "18.0.1"
5454
# https://doc.rust-lang.org/cargo/reference/profiles.html
5555
# https://github.com/johnthagen/min-sized-rust?tab=readme-ov-file#minimizing-rust-binary-size
5656
[profile.release]
57-
strip = true # Automatically strip symbols from the binary.
58-
opt-level = "z" # Optimize for size.
59-
incremental = true # Enable incremental compilation.
60-
codegen-units = 1 # Use a single codegen unit to optimize for size.
61-
lto = true # Enable link-time optimization.
57+
strip = false # Debugging size issue
58+
opt-level = 3 # Standard optimization
59+
incremental = false # Disable incremental in CI
60+
codegen-units = 16 # Standard codegen
61+
lto = "thin" # Faster LTO
6262

6363
[[bin]]
6464
name = "openworkers-runner"

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM rust:1.91 AS chef
1+
FROM rust:1.91-bookworm AS chef
22
RUN cargo install cargo-chef
33
WORKDIR /build
44

Dockerfile.multi

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ RUN apt-get update \
55
&& apt-get install -y ca-certificates wget \
66
&& rm -rf /var/lib/apt/lists/*
77

8-
FROM --platform=$BUILDPLATFORM rust:1.91 AS prepare
8+
FROM --platform=$BUILDPLATFORM rust:1.91-bookworm AS prepare
99

1010
ARG RUNTIME=deno
1111

1212
RUN apt-get update && apt-get install -y \
1313
gcc-aarch64-linux-gnu \
1414
gcc-x86-64-linux-gnu \
1515
libc6-dev-amd64-cross \
16-
libc6-dev-arm64-cross
16+
libc6-dev-arm64-cross \
17+
qemu-user-static
1718

1819
ENV CC_x86_64_unknown_linux_gnu=x86_64-linux-gnu-gcc
1920
ENV CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc
@@ -32,11 +33,10 @@ WORKDIR /build
3233
COPY . .
3334
RUN cargo chef prepare --recipe-path recipe.json
3435

35-
FROM prepare AS builder
36+
FROM prepare AS platform
3637

3738
ARG RUNTIME=deno
38-
39-
RUN mkdir -p /build
39+
ARG TARGETPLATFORM
4040

4141
ENV RUST_BACKTRACE=1
4242
ENV RUNTIME_SNAPSHOT_PATH=/build/snapshot.bin
@@ -45,26 +45,9 @@ WORKDIR /build
4545

4646
RUN touch $RUNTIME_SNAPSHOT_PATH
4747

48+
# Copy recipe from planner
4849
COPY --from=planner /build/recipe.json recipe.json
4950

50-
# Build dependencies - this is the caching Docker layer!
51-
RUN --mount=type=cache,sharing=locked,target=$CARGO_HOME/git \
52-
--mount=type=cache,sharing=locked,target=$CARGO_HOME/registry \
53-
--mount=type=cache,sharing=locked,target=/build/target \
54-
cargo chef cook --release --features=$RUNTIME --recipe-path recipe.json
55-
56-
# Build application
57-
COPY . /build
58-
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.
62-
63-
FROM builder AS platform
64-
65-
ARG RUNTIME=deno
66-
ARG TARGETPLATFORM
67-
6851
RUN echo "Building for $TARGETPLATFORM with runtime $RUNTIME"
6952

7053
# Build dependencies for target platform
@@ -77,9 +60,12 @@ RUN --mount=type=cache,id=cargo-$TARGETPLATFORM-$RUNTIME,sharing=locked,target=$
7760
*) echo "Unsupported platform: $TARGETPLATFORM" && exit 1 ;; \
7861
esac
7962

63+
# Copy source code AFTER cooking dependencies
64+
COPY . /build
65+
8066
# Build application for target platform
8167
# 1. Build the snapshot generator for the TARGET platform
82-
# 2. Run it (via QEMU emulation if needed) to generate the snapshot.bin
68+
# 2. Run it (via QEMU emulation explicitly) to generate the snapshot.bin
8369
# 3. Build the final runner which embeds the snapshot.bin
8470
RUN --mount=type=cache,id=cargo-$TARGETPLATFORM-$RUNTIME,sharing=locked,target=$CARGO_HOME/git \
8571
--mount=type=cache,id=cargo-$TARGETPLATFORM-$RUNTIME,sharing=locked,target=$CARGO_HOME/registry \
@@ -88,16 +74,20 @@ RUN --mount=type=cache,id=cargo-$TARGETPLATFORM-$RUNTIME,sharing=locked,target=$
8874
"linux/arm64") \
8975
# Build snapshot generator for target \
9076
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 && \
77+
# Generate snapshot (explicitly using qemu-aarch64-static with cross libs) \
78+
QEMU_LD_PREFIX=/usr/aarch64-linux-gnu qemu-aarch64-static /build/target/aarch64-unknown-linux-gnu/release/snapshot && \
9379
# Build runner \
9480
cargo build --release --features=$RUNTIME --target aarch64-unknown-linux-gnu && \
9581
mv /build/target/aarch64-unknown-linux-gnu/release/openworkers-runner /build/output ;; \
9682
"linux/amd64") \
9783
# Build snapshot generator for target \
9884
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 && \
85+
# Generate snapshot (direct execution on x86_64, qemu on other archs) \
86+
if [ "$(uname -m)" = "x86_64" ]; then \
87+
/build/target/x86_64-unknown-linux-gnu/release/snapshot; \
88+
else \
89+
QEMU_LD_PREFIX=/usr/x86_64-linux-gnu qemu-x86_64-static /build/target/x86_64-unknown-linux-gnu/release/snapshot; \
90+
fi && \
10191
# Build runner \
10292
cargo build --release --features=$RUNTIME --target x86_64-unknown-linux-gnu && \
10393
mv /build/target/x86_64-unknown-linux-gnu/release/openworkers-runner /build/output ;; \

0 commit comments

Comments
 (0)