Skip to content

Commit 03664ac

Browse files
committed
Add musl build
1 parent 3df186b commit 03664ac

File tree

5 files changed

+63
-3
lines changed

5 files changed

+63
-3
lines changed

.github/workflows/native.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,28 @@ jobs:
3232
- name: Build Linux
3333
if: matrix.os == 'ubuntu-22.04'
3434
run: |
35+
sudo apt-get update
3536
chmod 755 *.sh
3637
echo "building linux-x64"
3738
./build-linux-x64.sh
3839
echo "building linux-arm64"
39-
sudo apt-get install gcc-aarch64-linux-gnu
40+
sudo apt-get install -y gcc-aarch64-linux-gnu
4041
./build-linux-arm64.sh
4142
echo "building linux-arm"
42-
sudo apt-get install gcc-arm-linux-gnueabihf
43+
sudo apt-get install -y gcc-arm-linux-gnueabihf
4344
./build-linux-arm.sh
45+
46+
# musl
47+
echo "building linux-musl-x64"
48+
sudo apt-get install -y musl-tools
49+
CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER=musl-gcc ./build-linux-musl-x64.sh
50+
51+
echo "building linux-musl-arm64"
52+
# Use cross (Docker-based) to avoid installing a full aarch64 musl toolchain on the runner.
53+
cargo install cross --locked
54+
cross build --release --target aarch64-unknown-linux-musl
55+
mkdir -p build/linux-musl-arm64/native
56+
cp target/aarch64-unknown-linux-musl/release/libblake3_dotnet.so build/linux-musl-arm64/native
4457
- name: Build macOS
4558
if: matrix.os == 'macos-latest'
4659
run: |

lib/blake3_dotnet/.cargo/config.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ rustflags = ["-Ctarget-feature=+crt-static"]
44
rustflags = ["-Ctarget-feature=+crt-static"]
55
[target.x86_64-unknown-linux-gnu]
66
rustflags = ["-Ctarget-feature=-crt-static"]
7+
[target.x86_64-unknown-linux-musl]
8+
linker = "musl-gcc"
9+
rustflags = ["-Ctarget-feature=-crt-static", "-Clinker=x86_64-linux-musl-gcc"]
710
[target.aarch64-unknown-linux-gnu]
811
linker = "aarch64-linux-gnu-gcc"
12+
[target.aarch64-unknown-linux-musl]
13+
linker = "aarch64-linux-musl-gcc"
14+
rustflags = ["-Ctarget-feature=-crt-static", "-Clinker=aarch64-linux-musl-gcc"]
915
[target.arm-unknown-linux-gnueabihf]
1016
linker = "arm-linux-gnueabihf-gcc"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/sh
2+
set -eu
3+
4+
TARGET="aarch64-unknown-linux-musl"
5+
BUILD="linux-musl-arm64"
6+
7+
rustup target add "$TARGET"
8+
cargo build --release --target "$TARGET"
9+
10+
mkdir -p "build/$BUILD/native"
11+
cp "target/$TARGET/release/libblake3_dotnet.so" "build/$BUILD/native"
12+
13+
# Prefer a target-specific strip if available, otherwise fall back.
14+
if command -v aarch64-linux-musl-strip >/dev/null 2>&1; then
15+
aarch64-linux-musl-strip "build/$BUILD/native"/*.so
16+
elif command -v llvm-strip >/dev/null 2>&1; then
17+
llvm-strip "build/$BUILD/native"/*.so || true
18+
elif command -v strip >/dev/null 2>&1; then
19+
strip "build/$BUILD/native"/*.so || true
20+
fi
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
set -eu
3+
4+
TARGET="x86_64-unknown-linux-musl"
5+
BUILD="linux-musl-x64"
6+
7+
export CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-linux-gnu-gcc
8+
9+
rustup target add "$TARGET"
10+
cargo build --release --target "$TARGET"
11+
12+
mkdir -p "build/$BUILD/native"
13+
cp "target/$TARGET/release/libblake3_dotnet.so" "build/$BUILD/native"
14+
15+
if command -v strip >/dev/null 2>&1; then
16+
strip "build/$BUILD/native"/*.so || true
17+
fi

lib/blake3_dotnet/readme.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@ BLAKE3 Rust libraries compiled to native and exposed as plain shared libraries.
66

77
You need to have [`rustup`](https://rustup.rs/) installed
88

9-
Run one of the `build*` scripts (e.g `build-win-x64.ps1` or `build-linux-x64.sh`).
9+
Run one of the `build*` scripts (e.g `build-win-x64.ps1` or `build-linux-x64.sh`).
10+
11+
Musl targets are supported via:
12+
- `build-linux-musl-x64.sh` (`x86_64-unknown-linux-musl`)
13+
- `build-linux-musl-arm64.sh` (`aarch64-unknown-linux-musl`)

0 commit comments

Comments
 (0)