Skip to content

Commit

Permalink
Update Toolchain building and use musl v1.2.5
Browse files Browse the repository at this point in the history
- Updated toolchain building
- Only build musl v1.2.5 toolchains
- Update GitHub Workflow Actions
  • Loading branch information
BlackDex committed Mar 15, 2024
1 parent 6e8ffe6 commit 926ff5c
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 159 deletions.
9 changes: 5 additions & 4 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Directories
**/target
mak
test
.vscode
**/target/
mak/
test/
.vscode/
.github/

# git
.git**
Expand Down
43 changes: 9 additions & 34 deletions .github/workflows/toolchain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ on:
- ".github/workflows/toolchain.yml"
- "Dockerfile.toolchain"
- "config.mak"
- "config32.mak"
- "shared.mak"
branches:
- main

Expand All @@ -27,51 +25,29 @@ jobs:
HAVE_QUAY_LOGIN: ${{ secrets.QUAY_USERNAME != '' && secrets.QUAY_TOKEN != '' }}
if: ${{ github.repository == 'BlackDex/rust-musl' }}
strategy:
# max-parallel: 2 # Use this when using `act`, since this could use a lot of memory
# max-parallel: 1 # Use this when using `act`, since this could use a lot of memory
matrix:
# ARCH_COMMON_CONFIG are based upon the `"COMMON_CONFIG +=` additions extracted
# from the MUSL Dockerfiles here: https://github.com/rust-embedded/cross/tree/master/docker
env:
- IMAGE_TAG: x86_64-musl
TARGET: x86_64-unknown-linux-musl
MUSL_CROSS_MAKE_CONFIG: config.mak
- IMAGE_TAG: aarch64-musl
TARGET: aarch64-unknown-linux-musl
- IMAGE_TAG: armv7-musleabihf
TARGET: armv7-unknown-linux-musleabihf
MUSL_CROSS_MAKE_CONFIG: config32.mak
ARCH_COMMON_CONFIG: "--with-arch=armv7-a --with-float=hard --with-mode=thumb --with-fpu=vfp"
- IMAGE_TAG: armv7-musleabihf-musl-v1.2
TARGET: armv7-unknown-linux-musleabihf
MUSL_CROSS_MAKE_CONFIG: config.mak
ARCH_COMMON_CONFIG: "--with-arch=armv7-a --with-float=hard --with-mode=thumb --with-fpu=vfp"
- IMAGE_TAG: aarch64-musl
TARGET: aarch64-unknown-linux-musl
MUSL_CROSS_MAKE_CONFIG: config.mak
- IMAGE_TAG: arm-musleabi
TARGET: arm-unknown-linux-musleabi
MUSL_CROSS_MAKE_CONFIG: config32.mak
ARCH_COMMON_CONFIG: "--with-arch=armv6 --with-float=soft --with-mode=arm"
- IMAGE_TAG: arm-musleabi-musl-v1.2
TARGET: arm-unknown-linux-musleabi
MUSL_CROSS_MAKE_CONFIG: config.mak
ARCH_COMMON_CONFIG: "--with-arch=armv6 --with-float=soft --with-mode=arm"
# 2023-04-22: Stop building armv6-hf images, the do not seem to be used at all.
# - IMAGE_TAG: arm-musleabihf
# TARGET: arm-unknown-linux-musleabihf
# MUSL_CROSS_MAKE_CONFIG: config32.mak
# ARCH_COMMON_CONFIG: "--with-arch=armv6 --with-float=hard --with-mode=arm --with-fpu=vfp"
# 2023-04-22: Stop building armv5te images, the do not seem to be used at all.
# - IMAGE_TAG: armv5te-musleabi
# TARGET: armv5te-unknown-linux-musleabi
# MUSL_CROSS_MAKE_CONFIG: config32.mak
# ARCH_COMMON_CONFIG: "--with-arch=armv5te --with-float=soft --with-mode=arm"
steps:
- name: Checkout Repo
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

# This action is messing with the host caching when using `act`
- name: Setup Docker Buildx (setup-buildx-action)
if: ${{ !env.ACT }}
uses: docker/setup-buildx-action@4c0219f9ac95b02789c1075625400b2acbff50b1 # v2.9.1
uses: docker/setup-buildx-action@0d103c3126aa41d772a8362f6aa67afac040f80c # v3.1.0
with:
driver-opts: |
network=host
Expand All @@ -91,7 +67,7 @@ jobs:
- name: Login to DockerHub
if: ${{ env.HAVE_DOCKERHUB_LOGIN == 'true' }}
uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2.2.0
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3.1.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
Expand All @@ -105,7 +81,7 @@ jobs:
- name: Login to ghcr.io
if: ${{ env.HAVE_GHCR_LOGIN == 'true' }}
uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2.2.0
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3.1.0
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
Expand All @@ -120,7 +96,7 @@ jobs:
- name: Login to quay.io
if: ${{ env.HAVE_QUAY_LOGIN == 'true' }}
uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2.2.0
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3.1.0
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
Expand All @@ -134,13 +110,12 @@ jobs:
| tee -a "${GITHUB_ENV}"
- name: Docker Build
uses: docker/build-push-action@2eb1c1961a95fc15694676618e422e8ba1d63825 # v4.1.1
uses: docker/build-push-action@af5a7ed5ba88268d5278f7203fb52cd833f66d6e # v5.2.0
with:
context: .
file: ./Dockerfile.toolchain
build-args: |
TARGET=${{ matrix.env.TARGET }}
ARCH_COMMON_CONFIG=${{ matrix.env.ARCH_COMMON_CONFIG }}
MUSL_CROSS_MAKE_CONFIG=${{ matrix.env.MUSL_CROSS_MAKE_CONFIG }}
tags: ${{ env.tags }}
push: ${{ !env.ACT }}
40 changes: 23 additions & 17 deletions Dockerfile.toolchain
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# syntax=docker/dockerfile:1
FROM docker.io/library/ubuntu:22.04
FROM docker.io/library/ubuntu:22.04 as build

SHELL ["/bin/bash", "-o", "pipefail", "-c"]

WORKDIR /tmp
WORKDIR /

ENV DEBIAN_FRONTEND=noninteractive \
LANG=C.UTF-8 \
Expand Down Expand Up @@ -39,37 +39,43 @@ RUN apt-get update && \
apt-get clean -y && \
rm -rf /var/cache/* /var/lib/apt/lists/* && \
# Default cleanups
find /var/log -type f -delete
find /var/log -type f -delete && \
# Pre-Create the /musl-cross-make directory
mkdir -pv /musl-cross-make

ARG TARGET=x86_64-unknown-linux-musl
ARG MUSL_CROSS_MAKE_HASH=fe915821b652a7fa37b34a596f47d8e20bc72338
ARG MUSL_CROSS_MAKE_CONFIG=config.mak
ARG MUSL_CROSS_MAKE_HASH=e149c31c48b4f4a4c9349ddf7bc0027b90245afc
ARG ARCH_COMMON_CONFIG=""

COPY shared.mak /tmp/shared.mak
COPY $MUSL_CROSS_MAKE_CONFIG /tmp/config.mak
COPY config.mak /musl-cross-make/config.mak
# hadolint ignore=DL3003
RUN 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 3 \
-sSL "https://codeload.github.com/richfelker/musl-cross-make/tar.gz/${MUSL_CROSS_MAKE_HASH}" | tar xz && \
mv musl-cross-make-* musl-cross-make && \
# Combine the Shared and Arch specific config files into one config.mak file.
cat /tmp/shared.mak /tmp/config.mak >> /tmp/musl-cross-make/config.mak && \
-sSL "https://github.com/richfelker/musl-cross-make/archive/${MUSL_CROSS_MAKE_HASH}.tar.gz" | \
tar xzf - --strip-components=1 -C /musl-cross-make/ && \
mkdir -p /usr/local/musl && \
#
echo "Building musl toolchain for target ${TARGET}" && \
cd /tmp/musl-cross-make && \
cd /musl-cross-make && \
# Build the actual toolchain here
# We store the toolchain in /usr/local/musl/${TARGET}
make install "-j$(nproc)" \
OUTPUT="/usr/local/musl/${TARGET}" > /dev/null && \
cd /tmp && \
rm -rf /tmp/musl-cross-make && \
# We store the toolchain in /usr/local/musl
make install "-j$(nproc)" > /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 && \
echo "Finished building target ${TARGET}"


FROM docker.io/busybox:1.36.1-glibc

WORKDIR /

COPY --from=build /usr/local/musl /usr/local/musl
ENV PATH="${PATH}:/usr/local/musl/bin"

LABEL maintainer="BlackDex <[email protected]>"
LABEL org.opencontainers.image.create="$(date --utc --iso-8601=seconds)"
LABEL org.opencontainers.image.documentation="https://github.com/BlackDex/rust-musl/"
Expand Down
6 changes: 0 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ info:
@echo
.PHONY: info

# Render Dockerfile.gnu-base and Dockerfile.musl-base via the jinja2 Dockerfile.j2 template
# render:
# ./render_template Dockerfile.j2 '{"base": "gnu"}' > "Dockerfile.gnu-base"
# ./render_template Dockerfile.j2 '{"base": "musl"}' > "Dockerfile.musl-base"
# .PHONY: render

# Include main building make definitions
include mak/build.mak

Expand Down
29 changes: 27 additions & 2 deletions config.mak
Original file line number Diff line number Diff line change
@@ -1,2 +1,27 @@
# 64Bit config.mak
MUSL_VER = 1.2.3
BINUTILS_VER = 2.33.1
GCC_VER = 11.2.0
GMP_VER = 6.1.2
ISL_VER = 0.21
LINUX_VER = 5.8.5
MPC_VER = 1.1.0
MPFR_VER = 4.0.2
MUSL_VER = 1.2.5
#
DL_CMD = curl -w"%{stderr}URL: %{url_effective}\\nTime: %{time_total}\\nSize: %{size_download}\\n" --retry 3 -sSfL -C - -o
#
FLAG = -g0 -O2 -fno-align-functions -fno-align-jumps -fno-align-loops -fno-align-labels -Wno-error
COMMON_CONFIG += CFLAGS="${FLAG}" CXXFLAGS="${FLAG}" LDFLAGS="-s"
#
COMMON_CONFIG += --disable-nls
COMMON_CONFIG += --with-debug-prefix-map=$(CURDIR)=
#
COMMON_CONFIG += ${ARCH_COMMON_CONFIG}
#
GCC_CONFIG += --enable-languages=c,c++
GCC_CONFIG += --disable-multilib
GCC_CONFIG += --enable-default-pie --enable-static-pie
GCC_CONFIG += --enable-initfini-array
#
BINUTILS_CONFIG += --disable-multilib
#
OUTPUT = /usr/local/musl
2 changes: 0 additions & 2 deletions config32.mak

This file was deleted.

8 changes: 4 additions & 4 deletions mak/build.mak
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ include mak/toolchain.mak
# MUSL Images Makefile
include mak/musl.mak

build: build-musl
build-push: build-push-musl
build: musl
build-push: push-musl
.PHONY: build build-push

build-all: build-toolchains build-musl
build-push-all: build-push-toolchains build-push-musl
build-all: toolchains musl
build-push-all: push-toolchains push-musl
.PHONY: build-all build-push-all
56 changes: 27 additions & 29 deletions mak/musl.mak
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
# Define specific target variables
build-musl-x86_64: TARGET=x86_64-unknown-linux-musl
build-musl-x86_64: OPENSSL_ARCH="linux-x86_64 enable-ec_nistp_64_gcc_128"
build-musl-x86_64: TAG=x86_64-musl

build-musl-aarch64: TARGET=aarch64-unknown-linux-musl
build-musl-aarch64: OPENSSL_ARCH=linux-aarch64
build-musl-aarch64: TAG=aarch64-musl
# Default use localhost:5000, useful with a local registry for example
# If you want to get the source from somewhere else use `make TOOLCHAIN_REGISTRY=ghcr.io musl-x86_64` for example
TOOLCHAIN_REGISTRY ?= localhost:5000

build-musl-armv7: TARGET=armv7-unknown-linux-musleabihf
build-musl-armv7: OPENSSL_ARCH=linux-armv4
build-musl-armv7: TAG=armv7-musleabihf
# Define specific target variables
musl-x86_64: TARGET=x86_64-unknown-linux-musl
musl-x86_64: OPENSSL_ARCH="linux-x86_64 enable-ec_nistp_64_gcc_128"
musl-x86_64: TAG=x86_64-musl

build-musl-arm: TARGET=arm-unknown-linux-musleabi
build-musl-arm: OPENSSL_ARCH=linux-armv4
build-musl-arm: TAG=arm-musleabi
musl-aarch64: TARGET=aarch64-unknown-linux-musl
musl-aarch64: OPENSSL_ARCH=linux-aarch64
musl-aarch64: ARCH_CPPFLAGS="-mno-outline-atomics"
musl-aarch64: TAG=aarch64-musl

build-musl-armhf: TARGET=arm-unknown-linux-musleabihf
build-musl-armhf: OPENSSL_ARCH=linux-armv4
build-musl-armhf: TAG=arm-musleabihf
musl-armv7: TARGET=armv7-unknown-linux-musleabihf
musl-armv7: OPENSSL_ARCH=linux-armv4
musl-armv7: TAG=armv7-musleabihf

build-musl-armv5te: TARGET=armv5te-unknown-linux-musleabi
build-musl-armv5te: OPENSSL_ARCH=linux-armv4
build-musl-armv5te: TAG=armv5te-musleabi
musl-arm: TARGET=arm-unknown-linux-musleabi
musl-arm: OPENSSL_ARCH=linux-armv4
musl-arm: TAG=arm-musleabi

# Pull the latest musl-base to be used as cache if possible
# Build the musl-base image using the previous image as cache
# For the musl image we use multi-stage docker images.
# So first we build the musl-base part, and after that we will build the the main image.
build-musl-x86_64 build-musl-aarch64 build-musl-armv7 build-musl-arm build-musl-armhf build-musl-armv5te:
docker buildx build \
musl-x86_64 musl-aarch64 musl-armv7 musl-arm:
docker build \
--progress=plain \
--build-arg TOOLCHAIN_REGISTRY=${TOOLCHAIN_REGISTRY} \
--build-arg TARGET=$(TARGET) \
--build-arg IMAGE_TAG=$(TAG) \
--build-arg OPENSSL_ARCH=$(OPENSSL_ARCH) \
--build-arg ARCH_CPPFLAGS=${ARCH_CPPFLAGS} \
--build-arg RUST_CHANNEL=$(RUST_CHANNEL) \
-t localhost:5000/blackdex/rust-musl:$(TAG)$(TAG_POSTFIX) \
-t localhost:5000/blackdex/rust-musl:$(TAG)$(TAG_POSTFIX)$(TAG_DATE) \
Expand All @@ -45,15 +44,14 @@ build-musl-x86_64 build-musl-aarch64 build-musl-armv7 build-musl-arm build-musl-
fi

# Target to build all cross toolchains supported
build-musl: build-musl-x86_64 build-musl-aarch64 build-musl-armv7 build-musl-arm build-musl-armhf build-musl-armv5te

.PHONY: build-musl build-musl-x86_64 build-musl-aarch64 build-musl-armv7 build-musl-arm build-musl-armhf build-musl-armv5te
musl: musl-x86_64 musl-aarch64 musl-armv7 musl-arm
.PHONY: musl musl-x86_64 musl-aarch64 musl-armv7 musl-arm

# Build and push all musl targets
build-push-musl:
$(MAKE) PUSH=true build-musl
.PHONY: build-push-musl
push-musl:
$(MAKE) PUSH=true musl
.PHONY: push-musl

# Build and push a specific targets
build-push-musl-%:
push-musl-%:
$(MAKE) PUSH=true "$(subst push-,,$@)"
Loading

0 comments on commit 926ff5c

Please sign in to comment.