Skip to content

Commit e57dbf8

Browse files
chore: i686 is 32-bit, we need 64-bit
1 parent f3dde64 commit e57dbf8

File tree

3 files changed

+55
-45
lines changed

3 files changed

+55
-45
lines changed

Dockerfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Rust toolchain setup
12
FROM --platform=${BUILDPLATFORM} rust:1.87.0@sha256:5e33ae75f40bf25854fa86e33487f47075016d16726355a72171f67362ad6bf7 AS rust-base
23

34
ARG APPLICATION_NAME
@@ -23,7 +24,7 @@ ARG TARGET=aarch64-unknown-linux-musl
2324

2425
FROM rust-${TARGETPLATFORM//\//-} AS rust-cargo-build
2526

26-
# expose (used in ./build.sh)
27+
# expose (used in ./setup.sh and ./build.sh)
2728
ARG BUILDPLATFORM
2829
ARG TARGETPLATFORM
2930
ARG TARGETARCH
@@ -54,6 +55,7 @@ RUN --mount=type=cache,target=/build/${APPLICATION_NAME}/target \
5455
--mount=type=cache,id=cargo-registery,target=/usr/local/cargo/registry/,sharing=locked \
5556
./build.sh build --release --target ${TARGET}
5657

58+
# Rust full build
5759
FROM rust-cargo-build AS rust-build
5860

5961
# expose (used in ./build.sh)
@@ -75,6 +77,7 @@ RUN --mount=type=cache,target=/build/${APPLICATION_NAME}/target \
7577
--mount=type=cache,id=cargo-registery,target=/usr/local/cargo/registry/,sharing=locked \
7678
./build.sh install --path . --target ${TARGET} --root /output
7779

80+
# Container user setup
7881
FROM --platform=${BUILDPLATFORM} alpine:3.21.3@sha256:a8560b36e8b8210634f77d9f7f9efd7ffa463e380b75e2e74aff4511df3ef88c AS passwd-build
7982

8083
# setting `--system` prevents prompting for a password
@@ -84,6 +87,7 @@ RUN addgroup --gid 900 appgroup \
8487
RUN cat /etc/group | grep appuser > /tmp/group_appuser
8588
RUN cat /etc/passwd | grep appuser > /tmp/passwd_appuser
8689

90+
# Final stage, no `BUILDPLATFORM`, this one is run where it is deployed
8791
FROM scratch
8892

8993
ARG APPLICATION_NAME
@@ -98,4 +102,5 @@ WORKDIR /app
98102
COPY --from=rust-build /output/bin/${APPLICATION_NAME} /app/entrypoint
99103

100104
ENV RUST_BACKTRACE=full
105+
101106
ENTRYPOINT ["/app/entrypoint"]

build.sh

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,38 @@
11
#!/usr/bin/env bash
22

33
# sane defaults
4-
compiler="gcc"
5-
# static linking
6-
flags="-Clink-self-contained=yes -Clinker=rust-lld"
7-
8-
# mind the space between the [ and "
9-
if [[ "$BUILDPLATFORM" != "$TARGETPLATFORM" ]]; then
10-
case $TARGET in
11-
x86_64-unknown-linux-musl)
12-
compiler="i686-linux-gnu-gcc"
13-
;;
14-
aarch64-unknown-linux-musl)
15-
compiler="aarch64-linux-gnu-gcc"
16-
;;
17-
*)
18-
echo "INVALID CONFIGURATION"
19-
exit 1
20-
;;
21-
esac
22-
fi
4+
c_compiler="gcc"
5+
cpp_compiler="g++"
6+
7+
rust_flags="-Clink-self-contained=yes -Clinker=rust-lld"
8+
9+
case $TARGET in
10+
x86_64-unknown-linux-*)
11+
c_compiler="x86_64-linux-gnu-gcc-12"
12+
cpp_compiler="x86_64-linux-gnu-g++-12"
13+
;;
14+
aarch64-unknown-linux-*)
15+
c_compiler="aarch64-linux-gnu-gcc"
16+
cpp_compiler="aarch64-linux-gnu-g++"
17+
;;
18+
*)
19+
echo "INVALID CONFIGURATION"
20+
exit 1
21+
;;
22+
esac
2323

2424
# replace - with _ in the Rust target
2525
target_lower=${TARGET//-/_}
26+
27+
target_upper=${target_lower^^}
28+
2629
cc_var=CC_${target_lower}
27-
declare -x "${cc_var}=${compiler}"
30+
declare -x "${cc_var}=${c_compiler}"
31+
32+
cxx_var=CXX_${target_lower}
33+
declare -x "${cxx_var}=${cpp_compiler}"
34+
35+
cargo_target_linker_var=CARGO_TARGET_${target_upper}_LINKER
36+
declare -x "${cargo_target_linker_var}=${c_compiler}"
2837

29-
RUSTFLAGS=$flags cargo $@
38+
RUSTFLAGS=$rust_flags cargo $@

setup-env.sh

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,26 @@
11
#!/usr/bin/env bash
22

33
dpkg_add_arch() {
4-
dpkg --add-architecture $1
4+
# mind the space between the [ and "
5+
if [[ "$BUILDPLATFORM" != "$TARGETPLATFORM" ]]; then
6+
dpkg --add-architecture $1
7+
fi
58
apt-get update
69
apt-get --no-install-recommends install --yes \
7-
gcc-$2-linux-gnu
10+
binutils-$2-linux-gnu \
11+
gcc-$2-linux-gnu \
12+
g++-$2-linux-gnu
813
}
914

10-
# mind the space between the [ and "
11-
if [[ "$BUILDPLATFORM" != "$TARGETPLATFORM" ]]; then
12-
case $TARGET in
13-
x86_64-unknown-linux-musl)
14-
dpkg_add_arch "amd64" "i686"
15-
16-
apt-get --no-install-recommends install --yes \
17-
gcc-12-multilib-i686-linux-gnu
18-
;;
19-
aarch64-unknown-linux-musl)
20-
dpkg_add_arch "arm64" "aarch64"
21-
22-
apt-get --no-install-recommends install --yes \
23-
libc6-dev-arm64-cross
24-
;;
25-
*)
26-
echo "INVALID CONFIGURATION"
27-
exit 1
28-
;;
29-
esac
30-
fi
15+
case $TARGET in
16+
x86_64-unknown-linux-*)
17+
dpkg_add_arch "amd64" "x86-64"
18+
;;
19+
aarch64-unknown-linux-*)
20+
dpkg_add_arch "arm64" "aarch64"
21+
;;
22+
*)
23+
echo "INVALID CONFIGURATION"
24+
exit 1
25+
;;
26+
esac

0 commit comments

Comments
 (0)