Skip to content

Commit 10fe5d8

Browse files
authored
add builds for rust compatible musl toolchains (#17)
Adds builds of several musl cross toolchains that are compatible with rustc. The rust musl libc is based on version 1.1.24, which is incompatible with prebuilt versions of these toolchains that are available online. This build is based off of the following two projects: - https://github.com/richfelker/musl-cross-make - https://github.com/rust-cross/rust-musl-cross
1 parent e797fdd commit 10fe5d8

File tree

5 files changed

+140
-0
lines changed

5 files changed

+140
-0
lines changed

.github/workflows/musl.yaml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
name: musl
3+
on:
4+
pull_request:
5+
paths:
6+
- "musl/**"
7+
- .github/workflows/musl.yaml
8+
push:
9+
tags:
10+
- "musl-cross-*"
11+
12+
jobs:
13+
toolchains:
14+
strategy:
15+
matrix:
16+
target: [aarch64-linux-musl, arm-linux-musleabihf, x86_64-linux-musl]
17+
runs-on: ubuntu-22.04
18+
name: ${{ matrix.target }}
19+
steps:
20+
- name: Checkout source
21+
uses: actions/checkout@v2
22+
23+
- name: Build ${{ matrix.target }}
24+
run: make ${{ matrix.target }}
25+
26+
- name: Upload release
27+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
28+
uses: svenstaro/upload-release-action@v1-release
29+
with:
30+
repo_token: ${{ secrets.GITHUB_TOKEN }}
31+
file: "${{ matrix.target }}-cross.tar.gz*"
32+
tag: ${{ github.ref }}
33+
overwrite: true
34+
file_glob: true
35+

Makefile

+12
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ else
2727
NO_TTY_ARG :=
2828
endif
2929

30+
arm-linux-musleabihf:
31+
docker build --tag 'rust-musl-cross' musl
32+
docker run --rm -v $(CURDIR):/mnt/workspace -w /mnt/workspace rust-musl-cross musl/build.sh arm-linux-musleabihf
33+
34+
aarch64-linux-musl:
35+
docker build --tag 'rust-musl-cross' musl
36+
docker run --rm -v $(CURDIR):/mnt/workspace -w /mnt/workspace rust-musl-cross musl/build.sh aarch64-linux-musl
37+
38+
x86_64-linux-musl:
39+
docker build --tag 'rust-musl-cross' musl
40+
docker run --rm -v $(CURDIR):/mnt/workspace -w /mnt/workspace rust-musl-cross musl/build.sh x86_64-linux-musl
41+
3042
base: check-base
3143
$(CURDIR)/base.bash $(NO_TTY_ARG)
3244

musl/Dockerfile

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM debian:buster-slim
2+
3+
ENV DEBIAN_FRONTEND=noninteractive
4+
5+
RUN apt-get update && \
6+
apt-get install -y \
7+
build-essential \
8+
curl \
9+
file \
10+
git \
11+
sudo \
12+
unzip
13+
14+
CMD ["bash"]

musl/build.sh

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
3+
set -ex
4+
5+
if [ $# -ne 1 ]; then
6+
echo "usage: $0 target" 2>&1
7+
exit 1
8+
fi
9+
10+
target=$1
11+
12+
git clone --depth 1 https://github.com/richfelker/musl-cross-make.git /tmp/musl
13+
cp musl/config.mak /tmp/musl
14+
export CFLAGS="-fPIC -g1 $CFLAGS"
15+
export TARGET=$target
16+
make -C /tmp/musl -j4
17+
make -C /tmp/musl install
18+
tar -C /tmp/musl -czf ${target}-cross.tar.gz output/
19+
sha256sum ${target}-cross.tar.gz > ${target}-cross.tar.gz.sha256

musl/config.mak

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# By default, cross compilers are installed to ./output under the top-level
2+
# musl-cross-make directory and can later be moved wherever you want them.
3+
# To install directly to a specific location, set it here. Multiple targets
4+
# can safely be installed in the same location. Some examples:
5+
6+
#OUTPUT = /opt/musl/armhf
7+
8+
# By default, latest supported release versions of musl and the toolchain
9+
# components are used. You can override those here, but the version selected
10+
# must be supported (under hashes/ and patches/) to work. For musl, you
11+
# can use "git-refname" (e.g. git-master) instead of a release. Setting a
12+
# blank version for gmp, mpc, mpfr and isl will suppress download and
13+
# in-tree build of these libraries and instead depend on pre-installed
14+
# libraries when available (isl is optional and not set by default).
15+
# Setting a blank version for linux will suppress installation of kernel
16+
# headers, which are not needed unless compiling programs that use them.
17+
18+
# BINUTILS_VER =
19+
GCC_VER = 11.2.0
20+
21+
# https://github.com/rust-embedded/cross/issues/478
22+
# https://github.com/rust-lang/libc/issues/1848
23+
24+
MUSL_VER = 1.1.24
25+
26+
# GMP_VER =
27+
# MPC_VER =
28+
# MPFR_VER =
29+
# ISL_VER =
30+
# LINUX_VER =
31+
32+
# By default source archives are downloaded with wget. curl is also an option.
33+
34+
# DL_CMD = wget -c -O
35+
DL_CMD = curl -C - -L -o
36+
37+
# Something like the following can be used to produce a static-linked
38+
# toolchain that's deployable to any system with matching arch, using
39+
# an existing musl-targeted cross compiler. This only # works if the
40+
# system you build on can natively (or via binfmt_misc and # qemu) run
41+
# binaries produced by the existing toolchain (in this example, i486).
42+
43+
# COMMON_CONFIG += CC="i486-linux-musl-gcc -static --static" CXX="i486-linux-musl-g++ -static --static"
44+
45+
# Recommended options for smaller build for deploying binaries:
46+
47+
COMMON_CONFIG += CFLAGS="-g0 -Os -w" CXXFLAGS="-g0 -Os -w" LDFLAGS="-s"
48+
49+
# Recommended options for faster/simpler build:
50+
51+
COMMON_CONFIG += --disable-nls
52+
GCC_CONFIG += --enable-languages=c,c++
53+
GCC_CONFIG += --disable-libquadmath --disable-decimal-float
54+
GCC_CONFIG += --disable-multilib
55+
56+
# You can keep the local build path out of your toolchain binaries and
57+
# target libraries with the following, but then gdb needs to be told
58+
# where to look for source files.
59+
60+
COMMON_CONFIG += --with-debug-prefix-map=$(CURDIR)=

0 commit comments

Comments
 (0)