Skip to content

Commit 9b2980f

Browse files
committed
musl.cc does not allow downloads from GitHub Actions. But adding the tgz files is far too large for a default checkout of yafl. So we add downloading from a GitHub mirror to the CI process and script it so that it can be done by users on their own machines.
1 parent 3e83bfd commit 9b2980f

13 files changed

Lines changed: 256 additions & 95 deletions

.gitattributes

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
11
# Git LFS configuration for large binary files
2+
#
3+
# These files are optional and only needed if you plan to run musl.cc-based
4+
# cross-compilation workflows locally. Most developers can skip them:
5+
#
6+
# GIT_LFS_SKIP_SMUDGE=1 git clone <repo>
7+
# # or
8+
# git clone --no-lfs <repo>
9+
#
10+
# To pull these files later:
11+
# git lfs pull
12+
#
13+
214
# Cross-compiler toolchains (stored with Git LFS)
315
cross-compilers/*.tgz filter=lfs diff=lfs merge=lfs -text

.github/workflows/armv7-musl-linux.yml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,14 @@ jobs:
1616
steps:
1717
- uses: actions/checkout@v4
1818
- name: Install build tools
19-
run: sudo apt-get update && sudo apt-get install -y cmake make
20-
- name: Extract musl.cc cross-compiler
21-
run: |
22-
mkdir -p /opt/cross
23-
cd /opt/cross
24-
tar xzf ${{ github.workspace }}/cross-compilers/arm-linux-musleabihf-cross.tgz
25-
echo "Cross-compiler extracted successfully"
19+
run: sudo apt-get update && sudo apt-get install -y cmake make wget
20+
- name: Download and install musl-cross toolchain
21+
run: ./scripts/download-musl-cross.sh arm-unknown-linux-musleabihf
2622
- name: Configure and Build
2723
run: |
2824
mkdir -p build && cd build
29-
cmake -DTARGET=arm-unknown-linux-gnueabihf \
30-
-DCMAKE_C_COMPILER=/opt/cross/arm-linux-musleabihf-cross/bin/arm-linux-musleabihf-gcc \
25+
cmake -DTARGET=arm-unknown-linux-musleabihf \
26+
-DCMAKE_C_COMPILER=${{ github.workspace }}/cross-compilers/x-tools/arm-unknown-linux-musleabihf/bin/arm-unknown-linux-musleabihf-gcc \
3127
-DCMAKE_C_FLAGS='-static' \
3228
-DCMAKE_SYSTEM_NAME=Linux \
3329
-DCMAKE_SYSTEM_PROCESSOR=arm \

.github/workflows/ppc64le-musl-linux.yml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,14 @@ jobs:
1616
steps:
1717
- uses: actions/checkout@v4
1818
- name: Install build tools
19-
run: sudo apt-get update && sudo apt-get install -y cmake make
20-
- name: Extract musl.cc cross-compiler
21-
run: |
22-
mkdir -p /opt/cross
23-
cd /opt/cross
24-
tar xzf ${{ github.workspace }}/cross-compilers/powerpc64le-linux-musl-cross.tgz
25-
echo "Cross-compiler extracted successfully"
19+
run: sudo apt-get update && sudo apt-get install -y cmake make wget
20+
- name: Download and install musl-cross toolchain
21+
run: ./scripts/download-musl-cross.sh powerpc64le-unknown-linux-musl
2622
- name: Configure and Build
2723
run: |
2824
mkdir -p build && cd build
29-
cmake -DTARGET=powerpc64le-unknown-linux-gnu \
30-
-DCMAKE_C_COMPILER=/opt/cross/powerpc64le-linux-musl-cross/bin/powerpc64le-linux-musl-gcc \
25+
cmake -DTARGET=powerpc64le-unknown-linux-musl \
26+
-DCMAKE_C_COMPILER=${{ github.workspace }}/cross-compilers/x-tools/powerpc64le-unknown-linux-musl/bin/powerpc64le-unknown-linux-musl-gcc \
3127
-DCMAKE_C_FLAGS='-static' \
3228
-DCMAKE_SYSTEM_NAME=Linux \
3329
-DCMAKE_SYSTEM_PROCESSOR=ppc64le \

.github/workflows/riscv64-musl-linux.yml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,14 @@ jobs:
1616
steps:
1717
- uses: actions/checkout@v4
1818
- name: Install build tools
19-
run: sudo apt-get update && sudo apt-get install -y cmake make
20-
- name: Extract musl.cc cross-compiler
21-
run: |
22-
mkdir -p /opt/cross
23-
cd /opt/cross
24-
tar xzf ${{ github.workspace }}/cross-compilers/riscv64-linux-musl-cross.tgz
25-
echo "Cross-compiler extracted successfully"
19+
run: sudo apt-get update && sudo apt-get install -y cmake make wget
20+
- name: Download and install musl-cross toolchain
21+
run: ./scripts/download-musl-cross.sh riscv64-unknown-linux-musl
2622
- name: Configure and Build
2723
run: |
2824
mkdir -p build && cd build
29-
cmake -DTARGET=riscv64-unknown-linux-gnu \
30-
-DCMAKE_C_COMPILER=/opt/cross/riscv64-linux-musl-cross/bin/riscv64-linux-musl-gcc \
25+
cmake -DTARGET=riscv64-unknown-linux-musl \
26+
-DCMAKE_C_COMPILER=${{ github.workspace }}/cross-compilers/x-tools/riscv64-unknown-linux-musl/bin/riscv64-unknown-linux-musl-gcc \
3127
-DCMAKE_C_FLAGS='-static' \
3228
-DCMAKE_SYSTEM_NAME=Linux \
3329
-DCMAKE_SYSTEM_PROCESSOR=riscv64 \

.github/workflows/s390x-musl-linux.yml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,14 @@ jobs:
1616
steps:
1717
- uses: actions/checkout@v4
1818
- name: Install build tools
19-
run: sudo apt-get update && sudo apt-get install -y cmake make
20-
- name: Extract musl.cc cross-compiler
21-
run: |
22-
mkdir -p /opt/cross
23-
cd /opt/cross
24-
tar xzf ${{ github.workspace }}/cross-compilers/s390x-linux-musl-cross.tgz
25-
echo "Cross-compiler extracted successfully"
19+
run: sudo apt-get update && sudo apt-get install -y cmake make wget
20+
- name: Download and install musl-cross toolchain
21+
run: ./scripts/download-musl-cross.sh s390x-ibm-linux-musl
2622
- name: Configure and Build
2723
run: |
2824
mkdir -p build && cd build
29-
cmake -DTARGET=s390x-ibm-linux-gnu \
30-
-DCMAKE_C_COMPILER=/opt/cross/s390x-linux-musl-cross/bin/s390x-linux-musl-gcc \
25+
cmake -DTARGET=s390x-ibm-linux-musl \
26+
-DCMAKE_C_COMPILER=${{ github.workspace }}/cross-compilers/x-tools/s390x-ibm-linux-musl/bin/s390x-ibm-linux-musl-gcc \
3127
-DCMAKE_C_FLAGS='-static' \
3228
-DCMAKE_SYSTEM_NAME=Linux \
3329
-DCMAKE_SYSTEM_PROCESSOR=s390x \

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,7 @@ coverage.info
5555
__pycache__/
5656
*.pyc
5757

58+
# Downloaded musl-cross toolchains (generated by scripts/download-musl-cross.sh)
59+
/cross-compilers/x-tools/
60+
5861
.claude

CMakeLists.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,32 @@ else()
143143
endif()
144144

145145
message(STATUS "Loading configuration for triple: ${TRIPLE}")
146+
147+
# Check if this is a musl target that requires cross-compiler binaries
148+
string(REGEX MATCH "musl" IS_MUSL_TARGET "${TRIPLE}")
149+
150+
if(IS_MUSL_TARGET)
151+
# For musl targets, check if cross-compiler is available in the repo
152+
set(MUSL_X_TOOLS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cross-compilers/x-tools")
153+
set(MUSL_TOOLCHAIN_DIR "${MUSL_X_TOOLS_DIR}/${TRIPLE}")
154+
155+
if(NOT EXISTS "${MUSL_TOOLCHAIN_DIR}")
156+
message(FATAL_ERROR
157+
"Musl cross-compiler toolchain not found: ${MUSL_TOOLCHAIN_DIR}\n"
158+
"\n"
159+
"To enable musl-based cross-compilation, download and install the toolchain:\n"
160+
" ./scripts/download-musl-cross.sh\n"
161+
"\n"
162+
"This will download pre-built toolchains from:\n"
163+
" https://github.com/cross-tools/musl-cross/releases\n"
164+
"\n"
165+
"If you don't need musl cross-compilation, you can build without it:\n"
166+
" cmake -DTARGET=<native-triple> ..\n"
167+
)
168+
endif()
169+
message(STATUS "Using musl cross-compiler from: ${MUSL_TOOLCHAIN_DIR}")
170+
endif()
171+
146172
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/toolchains/${TRIPLE}.cmake")
147173
include(toolchains/${TRIPLE}.cmake)
148174
else()

cross-compilers/README.md

Lines changed: 48 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,71 @@
11
# Cross-Compiler Toolchains
22

3-
This directory contains pre-built cross-compiler toolchains from [musl.cc](https://musl.cc/).
3+
This directory contains downloaded musl-cross pre-built toolchains for cross-compilation support.
44

5-
## Files
5+
## Installation
66

7-
These files are stored with Git LFS (Large File Storage) and are downloaded via GitHub Actions CI/CD:
7+
The musl cross-compiler binaries are downloaded on-demand and stored in the `x-tools/` subdirectory.
88

9-
- `arm-linux-musleabihf-cross.tgz` - ARM 32-bit (ARMv7) EABI Hard Float
10-
- `riscv64-linux-musl-cross.tgz` - RISC-V 64-bit
11-
- `s390x-linux-musl-cross.tgz` - IBM System z (s390x)
12-
- `powerpc64le-linux-musl-cross.tgz` - PowerPC 64-bit Little Endian
9+
To install the musl-cross toolchains locally:
1310

14-
## Downloading Toolchains Locally
11+
```bash
12+
./scripts/download-musl-cross.sh
13+
```
1514

16-
To download these toolchains to your local machine:
15+
This will download all four supported architectures from the [cross-tools/musl-cross](https://github.com/cross-tools/musl-cross) GitHub releases.
1716

18-
1. **Install Git LFS** (if not already installed):
19-
```bash
20-
# macOS
21-
brew install git-lfs
17+
To download a specific architecture only:
2218

23-
# Ubuntu/Debian
24-
sudo apt-get install git-lfs
19+
```bash
20+
./scripts/download-musl-cross.sh arm-unknown-linux-musleabihf
21+
./scripts/download-musl-cross.sh riscv64-unknown-linux-musl
22+
./scripts/download-musl-cross.sh s390x-ibm-linux-musl
23+
./scripts/download-musl-cross.sh powerpc64le-unknown-linux-musl
24+
```
2525

26-
# Other systems: https://git-lfs.com/
27-
```
26+
## Building with Musl
2827

29-
2. **Initialize Git LFS in this repository** (one-time setup):
30-
```bash
31-
git lfs install
32-
```
28+
Once installed, you can build for musl targets:
3329

34-
3. **Run the download script**:
35-
```bash
36-
./scripts/download-musl-cc.sh
37-
```
30+
```bash
31+
mkdir build && cd build
32+
cmake -DTARGET=arm-unknown-linux-musleabihf ..
33+
cmake --build .
34+
```
3835

39-
This script will:
40-
- Create this directory if it doesn't exist
41-
- Download all four cross-compiler toolchains
42-
- Retry up to 3 times if downloads fail
43-
- Store them for Git LFS tracking
36+
## Supported Architectures
4437

45-
4. **Commit and push to GitHub**:
46-
```bash
47-
git add cross-compilers/ .gitattributes
48-
git commit -m "Add musl.cc cross-compiler toolchains"
49-
git push
50-
```
38+
- **arm-unknown-linux-musleabihf** - ARM 32-bit (ARMv7) EABI Hard Float
39+
- **riscv64-unknown-linux-musl** - RISC-V 64-bit
40+
- **s390x-ibm-linux-musl** - IBM System z (s390x)
41+
- **powerpc64le-unknown-linux-musl** - PowerPC 64-bit Little Endian
5142

52-
## Git LFS Tracking
43+
## Directory Structure
5344

54-
These files are tracked with Git LFS, which means:
45+
```
46+
cross-compilers/
47+
├── README.md (this file)
48+
├── .gitkeep
49+
└── x-tools/
50+
├── arm-unknown-linux-musleabihf/
51+
├── riscv64-unknown-linux-musl/
52+
├── s390x-ibm-linux-musl/
53+
└── powerpc64le-unknown-linux-musl/
54+
```
5555

56-
- Git stores pointers to the actual files instead of the full archives
57-
- The repository size remains small
58-
- When you clone or pull, Git LFS downloads only the files you need
59-
- Bandwidth usage is optimized for large binary files
56+
The `x-tools/` directory is generated by the download script and is not checked into Git.
6057

61-
To verify Git LFS is working correctly, check the `.gitattributes` file to see which patterns are tracked.
58+
## Optional
6259

63-
## Why These Toolchains?
60+
These toolchains are **optional**. If you don't need musl cross-compilation, you can build for your native platform without downloading them:
6461

65-
The musl.cc project provides pre-built, statically-linked cross-compiler toolchains. They're:
66-
- Ready to use without system dependencies
67-
- Statically compiled (portable across Linux distributions)
68-
- Designed for cross-compilation to various architectures
69-
- Updated regularly with latest compiler versions
70-
71-
## Updates
72-
73-
To update these toolchains to newer versions in the future:
74-
75-
1. Run the download script again: `./scripts/download-musl-cc.sh`
76-
2. Git will detect changes if new versions are available
77-
3. Commit and push the updated files
62+
```bash
63+
mkdir build && cd build
64+
cmake .. # Auto-detects your native platform
65+
cmake --build .
66+
```
7867

7968
## References
8069

81-
- [musl.cc](https://musl.cc/) - Pre-built musl libc cross-compiler toolchains
82-
- [Git LFS Documentation](https://git-lfs.com/)
70+
- [cross-tools/musl-cross](https://github.com/cross-tools/musl-cross) - Pre-built musl libc cross-compiler toolchains
71+
- [musl libc](https://musl.libc.org) - Standard C library for Linux

scripts/download-musl-cross.sh

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/bin/bash
2+
#
3+
# Download and install musl-cross pre-built toolchains
4+
#
5+
# This script downloads pre-built cross-compiler toolchains from the
6+
# cross-tools/musl-cross GitHub releases and installs them to the
7+
# cross-compilers/x-tools/ directory for use with CMake builds.
8+
#
9+
# Usage: ./scripts/download-musl-cross.sh [optional: specific architecture]
10+
# ./scripts/download-musl-cross.sh # Download all
11+
# ./scripts/download-musl-cross.sh arm-unknown-linux-musleabihf # Download one
12+
#
13+
14+
set -e
15+
16+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
17+
REPO_ROOT="$(dirname "$SCRIPT_DIR")"
18+
X_TOOLS_DIR="$REPO_ROOT/cross-compilers/x-tools"
19+
20+
# musl-cross release version
21+
RELEASE="20250929"
22+
23+
# Array of architectures we need
24+
declare -a ARCHITECTURES=(
25+
"arm-unknown-linux-musleabihf"
26+
"riscv64-unknown-linux-musl"
27+
"s390x-ibm-linux-musl"
28+
"powerpc64le-unknown-linux-musl"
29+
)
30+
31+
# Colors for output
32+
GREEN='\033[0;32m'
33+
BLUE='\033[0;34m'
34+
RED='\033[0;31m'
35+
NC='\033[0m' # No Color
36+
37+
echo -e "${BLUE}Downloading musl-cross toolchains${NC}"
38+
echo "Release: ${RELEASE}"
39+
echo "Destination: $X_TOOLS_DIR"
40+
echo ""
41+
42+
# Create x-tools directory if it doesn't exist
43+
mkdir -p "$X_TOOLS_DIR"
44+
45+
# If specific architecture requested, override the array
46+
if [ $# -gt 0 ]; then
47+
ARCHITECTURES=("$1")
48+
echo "Downloading only: $1"
49+
echo ""
50+
fi
51+
52+
# Download each toolchain
53+
for arch in "${ARCHITECTURES[@]}"; do
54+
filename="${arch}.tar.xz"
55+
filepath="$X_TOOLS_DIR/$filename"
56+
extract_dir="$X_TOOLS_DIR/$arch"
57+
url="https://github.com/cross-tools/musl-cross/releases/download/${RELEASE}/${filename}"
58+
59+
# Skip if already exists
60+
if [ -d "$extract_dir" ]; then
61+
echo -e "${GREEN}${NC} $arch already installed, skipping"
62+
continue
63+
fi
64+
65+
echo -e "${BLUE}Downloading${NC} $filename..."
66+
67+
# Download with retries
68+
for attempt in 1 2 3; do
69+
if wget -O "$filepath" "$url"; then
70+
echo -e "${BLUE}Extracting${NC} $filename..."
71+
tar xf "$filepath" -C "$X_TOOLS_DIR"
72+
rm "$filepath"
73+
echo -e "${GREEN}${NC} Installed: $arch"
74+
break
75+
else
76+
if [ $attempt -lt 3 ]; then
77+
echo " Attempt $attempt failed, retrying in 10 seconds..."
78+
sleep 10
79+
else
80+
echo -e "${RED}${NC} Failed to download $filename after 3 attempts"
81+
rm -f "$filepath"
82+
exit 1
83+
fi
84+
fi
85+
done
86+
done
87+
88+
echo ""
89+
echo -e "${GREEN}All musl-cross toolchains ready!${NC}"
90+
echo ""
91+
echo "You can now build with musl targets:"
92+
echo " cmake -DTARGET=arm-unknown-linux-musleabihf .."
93+
echo " cmake -DTARGET=riscv64-unknown-linux-musl .."
94+
echo " cmake -DTARGET=s390x-ibm-linux-musl .."
95+
echo " cmake -DTARGET=powerpc64le-unknown-linux-musl .."
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# CMake toolchain configuration for arm-unknown-linux-musleabihf
2+
# Uses musl-cross pre-built toolchain from /opt/x-tools
3+
# Compiler path must be specified: -DCMAKE_C_COMPILER=/opt/x-tools/arm-unknown-linux-musleabihf/bin/arm-unknown-linux-musleabihf-gcc
4+
# Copyright Kyle Hayes (2026)
5+
# Distributed under the Boost Software License, Version 1.0.
6+
# See LICENSE file for details
7+
8+
set(ASM_FILES
9+
src/asm/arm/make_arm_aapcs_elf_gas.S
10+
src/asm/arm/jump_arm_aapcs_elf_gas.S
11+
)
12+
enable_language(ASM)
13+
add_compile_options(-Wall -Wextra -Werror -g -O2 -static)

0 commit comments

Comments
 (0)