Skip to content

Commit

Permalink
add builds for rust compatible musl toolchains (#17)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jungleraptor authored Apr 26, 2023
1 parent e797fdd commit 10fe5d8
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/musl.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
name: musl
on:
pull_request:
paths:
- "musl/**"
- .github/workflows/musl.yaml
push:
tags:
- "musl-cross-*"

jobs:
toolchains:
strategy:
matrix:
target: [aarch64-linux-musl, arm-linux-musleabihf, x86_64-linux-musl]
runs-on: ubuntu-22.04
name: ${{ matrix.target }}
steps:
- name: Checkout source
uses: actions/checkout@v2

- name: Build ${{ matrix.target }}
run: make ${{ matrix.target }}

- name: Upload release
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
uses: svenstaro/upload-release-action@v1-release
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: "${{ matrix.target }}-cross.tar.gz*"
tag: ${{ github.ref }}
overwrite: true
file_glob: true

12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ else
NO_TTY_ARG :=
endif

arm-linux-musleabihf:
docker build --tag 'rust-musl-cross' musl
docker run --rm -v $(CURDIR):/mnt/workspace -w /mnt/workspace rust-musl-cross musl/build.sh arm-linux-musleabihf

aarch64-linux-musl:
docker build --tag 'rust-musl-cross' musl
docker run --rm -v $(CURDIR):/mnt/workspace -w /mnt/workspace rust-musl-cross musl/build.sh aarch64-linux-musl

x86_64-linux-musl:
docker build --tag 'rust-musl-cross' musl
docker run --rm -v $(CURDIR):/mnt/workspace -w /mnt/workspace rust-musl-cross musl/build.sh x86_64-linux-musl

base: check-base
$(CURDIR)/base.bash $(NO_TTY_ARG)

Expand Down
14 changes: 14 additions & 0 deletions musl/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM debian:buster-slim

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && \
apt-get install -y \
build-essential \
curl \
file \
git \
sudo \
unzip

CMD ["bash"]
19 changes: 19 additions & 0 deletions musl/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash

set -ex

if [ $# -ne 1 ]; then
echo "usage: $0 target" 2>&1
exit 1
fi

target=$1

git clone --depth 1 https://github.com/richfelker/musl-cross-make.git /tmp/musl
cp musl/config.mak /tmp/musl
export CFLAGS="-fPIC -g1 $CFLAGS"
export TARGET=$target
make -C /tmp/musl -j4
make -C /tmp/musl install
tar -C /tmp/musl -czf ${target}-cross.tar.gz output/
sha256sum ${target}-cross.tar.gz > ${target}-cross.tar.gz.sha256
60 changes: 60 additions & 0 deletions musl/config.mak
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# By default, cross compilers are installed to ./output under the top-level
# musl-cross-make directory and can later be moved wherever you want them.
# To install directly to a specific location, set it here. Multiple targets
# can safely be installed in the same location. Some examples:

#OUTPUT = /opt/musl/armhf

# By default, latest supported release versions of musl and the toolchain
# components are used. You can override those here, but the version selected
# must be supported (under hashes/ and patches/) to work. For musl, you
# can use "git-refname" (e.g. git-master) instead of a release. Setting a
# blank version for gmp, mpc, mpfr and isl will suppress download and
# in-tree build of these libraries and instead depend on pre-installed
# libraries when available (isl is optional and not set by default).
# Setting a blank version for linux will suppress installation of kernel
# headers, which are not needed unless compiling programs that use them.

# BINUTILS_VER =
GCC_VER = 11.2.0

# https://github.com/rust-embedded/cross/issues/478
# https://github.com/rust-lang/libc/issues/1848

MUSL_VER = 1.1.24

# GMP_VER =
# MPC_VER =
# MPFR_VER =
# ISL_VER =
# LINUX_VER =

# By default source archives are downloaded with wget. curl is also an option.

# DL_CMD = wget -c -O
DL_CMD = curl -C - -L -o

# Something like the following can be used to produce a static-linked
# toolchain that's deployable to any system with matching arch, using
# an existing musl-targeted cross compiler. This only # works if the
# system you build on can natively (or via binfmt_misc and # qemu) run
# binaries produced by the existing toolchain (in this example, i486).

# COMMON_CONFIG += CC="i486-linux-musl-gcc -static --static" CXX="i486-linux-musl-g++ -static --static"

# Recommended options for smaller build for deploying binaries:

COMMON_CONFIG += CFLAGS="-g0 -Os -w" CXXFLAGS="-g0 -Os -w" LDFLAGS="-s"

# Recommended options for faster/simpler build:

COMMON_CONFIG += --disable-nls
GCC_CONFIG += --enable-languages=c,c++
GCC_CONFIG += --disable-libquadmath --disable-decimal-float
GCC_CONFIG += --disable-multilib

# You can keep the local build path out of your toolchain binaries and
# target libraries with the following, but then gdb needs to be told
# where to look for source files.

COMMON_CONFIG += --with-debug-prefix-map=$(CURDIR)=

0 comments on commit 10fe5d8

Please sign in to comment.