Skip to content

Commit d93e363

Browse files
authored
Merge pull request #155 from clux/merge-dockerfiles
Merge docker images with extra build-arg
2 parents 80f4e22 + 8c3fe21 commit d93e363

File tree

6 files changed

+33
-121
lines changed

6 files changed

+33
-121
lines changed

.github/workflows/nightly.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ jobs:
2626
platform: [linux/amd64, linux/arm64]
2727
include:
2828
- platform: linux/amd64
29-
dockerfile: Dockerfile.x86_64
29+
dockerfile: Dockerfile
3030
arch: amd64
31+
aarch: x86_64
3132
target_dir: x86_64-unknown-linux-musl
3233
- platform: linux/arm64
33-
dockerfile: Dockerfile.arm64
34+
dockerfile: Dockerfile
3435
arch: arm64
36+
aarch: aarch64
3537
target_dir: aarch64-unknown-linux-musl
3638
steps:
3739
- uses: actions/checkout@v4
@@ -73,6 +75,7 @@ jobs:
7375
tags: rustmusl-temp
7476
build-args: |
7577
CHANNEL=nightly
78+
AARCH=${{ matrix.aarch }}
7679
7780
- name: Run tests
7881
shell: bash

.github/workflows/stable.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ jobs:
2626
platform: [linux/amd64, linux/arm64]
2727
include:
2828
- platform: linux/amd64
29-
dockerfile: Dockerfile.x86_64
29+
dockerfile: Dockerfile
3030
arch: amd64
31+
aarch: x86_64
3132
target_dir: x86_64-unknown-linux-musl
3233
- platform: linux/arm64
33-
dockerfile: Dockerfile.arm64
34+
dockerfile: Dockerfile
3435
arch: arm64
36+
aarch: aarch64
3537
target_dir: aarch64-unknown-linux-musl
3638
steps:
3739
- uses: actions/checkout@v4
@@ -85,6 +87,7 @@ jobs:
8587
tags: rustmusl-temp
8688
build-args: |
8789
CHANNEL=stable
90+
AARCH=${{ matrix.aarch }}
8891
if: ${{ steps.stablecheck.outputs.BUILD }}
8992

9093
- name: Run tests

Dockerfile.arm64 renamed to Dockerfile

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# syntax=docker/dockerfile:1
22
FROM ubuntu:noble
33
LABEL maintainer="Eirik Albrigtsen <sszynrae@gmail.com>"
4+
LABEL org.opencontainers.image.create="$(date --utc --iso-8601=seconds)"
5+
LABEL org.opencontainers.image.documentation="https://github.com/clux/muslrust"
6+
LABEL org.opencontainers.image.licenses="MIT"
7+
LABEL org.opencontainers.image.url="https://github.com/clux/muslrust"
8+
LABEL org.opencontainers.image.description="Docker environment for building musl based static rust binaries"
49

510
# Required packages:
611
# - musl-dev, musl-tools - the musl toolchain
@@ -30,17 +35,19 @@ RUN apt-get update && apt-get install -y \
3035
--no-install-recommends && \
3136
rm -rf /var/lib/apt/lists/*
3237

38+
# Common arg for arch used in urls and triples
39+
ARG AARCH
3340
# Install rust using rustup
3441
ARG CHANNEL
3542
ENV RUSTUP_VER="1.27.1" \
36-
RUST_ARCH="aarch64-unknown-linux-gnu" \
43+
RUST_ARCH="${AARCH}-unknown-linux-gnu" \
3744
CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse
3845

3946
RUN curl "https://static.rust-lang.org/rustup/archive/${RUSTUP_VER}/${RUST_ARCH}/rustup-init" -o rustup-init && \
4047
chmod +x rustup-init && \
4148
./rustup-init -y --default-toolchain ${CHANNEL} --profile minimal --no-modify-path && \
4249
rm rustup-init && \
43-
~/.cargo/bin/rustup target add aarch64-unknown-linux-musl
50+
~/.cargo/bin/rustup target add ${AARCH}-unknown-linux-musl
4451

4552
# Allow non-root access to cargo
4653
RUN chmod a+X /root
@@ -49,7 +56,7 @@ RUN chmod a+X /root
4956
# This helps continuing manually if anything breaks.
5057
ENV ZLIB_VER="1.3.1" \
5158
SQLITE_VER="3490100" \
52-
PROTOBUF_VER="29.2" \
59+
PROTOBUF_VER="31.0" \
5360
SCCACHE_VER="0.9.1" \
5461
CC=musl-gcc \
5562
PREFIX=/musl \
@@ -59,18 +66,18 @@ ENV ZLIB_VER="1.3.1" \
5966

6067
# Install a more recent release of protoc (protobuf-compiler in jammy is 4 years old and misses some features)
6168
RUN cd /tmp && \
62-
curl -sSL https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOBUF_VER}/protoc-${PROTOBUF_VER}-linux-aarch_64.zip -o protoc.zip && \
69+
curl -sSL https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOBUF_VER}/protoc-${PROTOBUF_VER}-linux-$([ "$AARCH" = "aarch64" ] && echo "aarch_64" || echo "$AARCH").zip -o protoc.zip && \
6370
unzip protoc.zip && \
6471
cp bin/protoc /usr/bin/protoc && \
6572
rm -rf *
6673

6774
# Install prebuilt sccache based on platform
68-
RUN curl -sSL https://github.com/mozilla/sccache/releases/download/v${SCCACHE_VER}/sccache-v${SCCACHE_VER}-aarch64-unknown-linux-musl.tar.gz | tar xz && \
75+
RUN curl -sSL https://github.com/mozilla/sccache/releases/download/v${SCCACHE_VER}/sccache-v${SCCACHE_VER}-${AARCH}-unknown-linux-musl.tar.gz | tar xz && \
6976
mv sccache-v${SCCACHE_VER}-*-unknown-linux-musl/sccache /usr/local/bin/ && \
7077
chmod +x /usr/local/bin/sccache && \
7178
rm -rf sccache-v${SCCACHE_VER}-*-unknown-linux-musl
7279

73-
# Build zlib (used in pq)
80+
# Build zlib
7481
RUN curl -sSL https://zlib.net/zlib-$ZLIB_VER.tar.gz | tar xz && \
7582
cd zlib-$ZLIB_VER && \
7683
CC="musl-gcc -fPIC -pie" LDFLAGS="-L$PREFIX/lib" CFLAGS="-I$PREFIX/include" ./configure --static --prefix=$PREFIX && \
@@ -88,13 +95,16 @@ RUN curl -sSL https://www.sqlite.org/2025/sqlite-autoconf-$SQLITE_VER.tar.gz | t
8895

8996
ENV PATH=/root/.cargo/bin:$PREFIX/bin:$PATH \
9097
RUSTUP_HOME=/root/.rustup \
91-
CARGO_BUILD_TARGET=aarch64-unknown-linux-musl \
98+
CARGO_BUILD_TARGET=${AARCH}-unknown-linux-musl \
9299
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_RUSTFLAGS="-Clink-self-contained=yes -Clinker=rust-lld -Ctarget-feature=+crt-static" \
93100
PKG_CONFIG_ALLOW_CROSS=true \
94101
PKG_CONFIG_ALL_STATIC=true \
95102
PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig \
103+
PG_CONFIG_X86_64_UNKNOWN_LINUX_GNU=/usr/bin/pg_config \
96104
PG_CONFIG_AARCH64_UNKNOWN_LINUX_GNU=/usr/bin/pg_config \
105+
# Rust libz-sys support
97106
LIBZ_SYS_STATIC=1 \
107+
ZLIB_STATIC=1 \
98108
DEBIAN_FRONTEND=noninteractive \
99109
TZ=Etc/UTC
100110

Dockerfile.x86_64

Lines changed: 0 additions & 101 deletions
This file was deleted.

justfile

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
default:
44
@just --list --unsorted --color=always
55

6-
_build channel ar platform ext:
7-
docker build --build-arg CHANNEL="{{channel}}" --build-arg AR="{{ar}}" --platform="{{platform}}" -t rustmusl-temp . -f Dockerfile.{{ext}}
6+
_build channel platform aarch:
7+
docker build --build-arg CHANNEL="{{channel}}" --build-arg AARCH="{{aarch}}" --platform="{{platform}}" -t rustmusl-temp . -f Dockerfile --debug
88
# Build the stable x86 container
9-
build-stable-amd: (_build "stable" "amd64" "linux/amd64" "x86_64")
9+
build-stable-amd: (_build "stable" "linux/amd64" "x86_64")
1010
# Build the nightly x86 container
11-
build-nightly-amd: (_build "nightly" "amd64" "linux/amd64" "x86_64")
11+
build-nightly-amd: (_build "nightly" "linux/amd64" "x86_64")
1212
# Build the stable arm container
13-
build-stable-arm: (_build "stable" "arm64" "linux/arm64" "arm64")
13+
build-stable-arm: (_build "stable" "linux/arm64" "aarch64")
1414
# Build the nightly arm container
15-
build-nightly-arm: (_build "nightly" "arm64" "linux/arm64" "arm64")
15+
build-nightly-arm: (_build "nightly" "linux/arm64" "aarch64")
1616

1717
# Shell into the built container
1818
run:
@@ -36,13 +36,11 @@ _t_linux_x86_64 crate:
3636
#!/bin/bash
3737
export PLATFORM="linux/amd64"
3838
export TARGET_DIR="x86_64-unknown-linux-musl"
39-
export AR="amd64"
4039
./test.sh {{crate}}
4140
_t_macos_aarch64 crate:
4241
#!/bin/bash
4342
export PLATFORM="linux/arm64"
4443
export TARGET_DIR="aarch64-unknown-linux-musl"
45-
export AR="arm64"
4644
./test.sh {{crate}}
4745

4846
# Test all crates against built container locally

test.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ docker_build() {
1111
-v "$PWD/test/${crate}:/volume" \
1212
-v cargo-cache:/root/.cargo/registry \
1313
-e RUST_BACKTRACE=1 \
14-
-e AR=ar \
1514
--platform "${PLATFORM}" \
1615
rustmusl-temp \
1716
cargo build

0 commit comments

Comments
 (0)