-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathDockerfile.toolchain
More file actions
133 lines (108 loc) · 4.22 KB
/
Dockerfile.toolchain
File metadata and controls
133 lines (108 loc) · 4.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# syntax=docker/dockerfile:1
# https://hub.docker.com/_/ubuntu
FROM docker.io/library/ubuntu:24.04 AS base
ARG QEMU_CPU=
SHELL ["/bin/bash", "-eux", "-o", "pipefail", "-c"]
WORKDIR /
ENV DEBIAN_FRONTEND=noninteractive \
LANG=C.UTF-8 \
TZ=UTC \
TERM=xterm-256color
# Make sure we have basic dev tools for building.
# We only build the gcc musl based toolchain here
# and use these compiled files later in other Docker builds.
# This saves time during the building of the actual libraries
# we want to build since the toolchain doesn't change that much anyway.
#
RUN <<EOF
apt-get update
apt-get install -y \
gcc-14 g++-14 cpp-14 \
make \
cmake \
libtool \
pkg-config \
curl \
patch \
file \
bzip2 \
xz-utils \
unzip \
rsync \
texinfo \
ca-certificates \
--no-install-recommends
# Set GCC14 As default
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-14 90 \
--slave /usr/bin/cc cc /usr/bin/gcc-14 \
--slave /usr/bin/gcc-ar gcc-ar /usr/bin/gcc-ar-14 \
--slave /usr/bin/gcc-nm gcc-nm /usr/bin/gcc-nm-14 \
--slave /usr/bin/gcc-ranlib gcc-ranlib /usr/bin/gcc-ranlib-14
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-14 90 \
--slave /usr/bin/c++ c++ /usr/bin/g++-14
update-alternatives --install /lib/cpp cpp /usr/bin/cpp-14 90 && \
update-alternatives --install /usr/bin/gcov gcov /usr/bin/gcov-14 90 \
--slave /usr/bin/gcov-dump gcov-dump /usr/bin/gcov-dump-14 \
--slave /usr/bin/gcov-tool gcov-tool /usr/bin/gcov-tool-14
# Cleanup apt
apt-get autoremove -y --purge
apt-get clean -y
rm -rf /var/cache/* /var/lib/apt/lists/*
# Default cleanups
find /var/log -type f -delete
# Pre-Create the /musl-cross-make directory
mkdir -pv /musl-cross-make
EOF
WORKDIR /musl-cross-make
FROM base AS build
ARG TARGETARCH
ARG TARGET=x86_64-unknown-linux-musl
COPY config.mak /musl-cross-make/config.mak
# 3635262e4524c991552789af6f36211a335a77b3 == Jul 27, 2025, 3:34 AM GMT+2
ARG MUSL_CROSS_MAKE_HASH=3635262e4524c991552789af6f36211a335a77b3
ARG ARCH_COMMON_CONFIG=""
RUN <<EOF
echo "Downloading musl-cross-make"
# Download musl-cross-make from https://github.com/richfelker/musl-cross-make based upon the provided $MUSL_CROSS_MAKE_HASH
curl -w"%{stderr}URL: %{url_effective}\nTime: %{time_total}\nSize: %{size_download}\n" --retry 5 --retry-all-errors \
-sSL "https://github.com/richfelker/musl-cross-make/archive/${MUSL_CROSS_MAKE_HASH}.tar.gz" | \
tar xzf - --strip-components=1
mkdir -p /usr/local/musl
echo "Building musl toolchain for target ${TARGET}"
# Build the actual toolchain here
# We store the toolchain in /usr/local/musl
make -j"$(nproc)" install > /dev/null
# Fix symlink to libc.so
ln -sfrn "/usr/local/musl/${TARGET}/lib/libc.so" "$(ls -1 /usr/local/musl/${TARGET}/lib/ld-*.so.1)"
# Cleanup
cd /
rm -rf /musl-cross-make /usr/local/musl/share/man
echo "Finished building target ${TARGET}"
EOF
RUN <<EOF
echo "Fix glibc for Busybox"
# Make the newer glibc libraries available in /arch-lib so we can copy them to the busybox container
mkdir -pv /arch-lib
if [ "${TARGETARCH}" = "arm64" ]; then
ln -sfn /usr/lib/aarch64-linux-gnu/{ld-linux-aarch64.so.1,libc.so.6,libm.so.6} /arch-lib/
else
ln -sfn /usr/lib/x86_64-linux-gnu/{ld-linux-x86-64.so.2,libc.so.6,libm.so.6} /arch-lib/
fi
EOF
# https://hub.docker.com/_/busybox
FROM docker.io/busybox:1.37.0-glibc
WORKDIR /
ENV PATH="${PATH}:/usr/local/musl/bin" \
LANG=C.UTF-8 \
TZ=UTC \
TERM=xterm-256color
ARG TARGET
COPY --link --from=build /usr/local/musl /usr/local/musl
# Use newer lib's than currently provided in the busybox container
# aarch64-linux-gnu
COPY --link --from=build /arch-lib/* /lib/
LABEL org.opencontainers.image.authors="BlackDex <black.dex@gmail.com>"
LABEL org.opencontainers.image.documentation="https://github.com/BlackDex/rust-musl/"
LABEL org.opencontainers.image.licenses="Apache License 2.0"
LABEL org.opencontainers.image.url="https://github.com/BlackDex/rust-musl/"
LABEL org.opencontainers.image.description="MUSL Cross Build Toolchain for ${TARGET}"