From 824bf03287a3e3c1e76df3cb62d56c87168ac39e Mon Sep 17 00:00:00 2001 From: Alexandre Mutel Date: Wed, 24 Dec 2025 19:35:05 +0100 Subject: [PATCH] Add musl build --- .github/workflows/native.yml | 12 +++++++++--- lib/blake3_dotnet/.cargo/config.toml | 6 ++++++ lib/blake3_dotnet/build-linux-musl-arm64.sh | 20 ++++++++++++++++++++ lib/blake3_dotnet/build-linux-musl-x64.sh | 15 +++++++++++++++ lib/blake3_dotnet/readme.md | 6 +++++- 5 files changed, 55 insertions(+), 4 deletions(-) create mode 100755 lib/blake3_dotnet/build-linux-musl-arm64.sh create mode 100755 lib/blake3_dotnet/build-linux-musl-x64.sh diff --git a/.github/workflows/native.yml b/.github/workflows/native.yml index 151a05a..9581316 100644 --- a/.github/workflows/native.yml +++ b/.github/workflows/native.yml @@ -32,21 +32,27 @@ jobs: - name: Build Linux if: matrix.os == 'ubuntu-22.04' run: | + sudo apt-get update chmod 755 *.sh echo "building linux-x64" ./build-linux-x64.sh echo "building linux-arm64" - sudo apt-get install gcc-aarch64-linux-gnu + sudo apt-get install -y gcc-aarch64-linux-gnu ./build-linux-arm64.sh echo "building linux-arm" - sudo apt-get install gcc-arm-linux-gnueabihf + sudo apt-get install -y gcc-arm-linux-gnueabihf ./build-linux-arm.sh - - name: Build macOS + - name: Build macOS and musl Linux if: matrix.os == 'macos-latest' run: | chmod 755 *.sh ./build-osx-x64.sh ./build-osx-arm64.sh + brew tap messense/macos-cross-toolchains + brew install aarch64-unknown-linux-musl + brew install x86_64-unknown-linux-musl + ./build-linux-musl-x64.sh + ./build-linux-musl-arm64.sh - name: Build Windows if: matrix.os == 'windows-latest' run: | diff --git a/lib/blake3_dotnet/.cargo/config.toml b/lib/blake3_dotnet/.cargo/config.toml index c0dbe9c..9162b06 100644 --- a/lib/blake3_dotnet/.cargo/config.toml +++ b/lib/blake3_dotnet/.cargo/config.toml @@ -4,7 +4,13 @@ rustflags = ["-Ctarget-feature=+crt-static"] rustflags = ["-Ctarget-feature=+crt-static"] [target.x86_64-unknown-linux-gnu] rustflags = ["-Ctarget-feature=-crt-static"] +[target.x86_64-unknown-linux-musl] +linker = "musl-gcc" +rustflags = ["-Ctarget-feature=-crt-static", "-Clinker=x86_64-linux-musl-gcc"] [target.aarch64-unknown-linux-gnu] linker = "aarch64-linux-gnu-gcc" +[target.aarch64-unknown-linux-musl] +linker = "aarch64-linux-musl-gcc" +rustflags = ["-Ctarget-feature=-crt-static", "-Clinker=aarch64-linux-musl-gcc"] [target.arm-unknown-linux-gnueabihf] linker = "arm-linux-gnueabihf-gcc" diff --git a/lib/blake3_dotnet/build-linux-musl-arm64.sh b/lib/blake3_dotnet/build-linux-musl-arm64.sh new file mode 100755 index 0000000..bea8c32 --- /dev/null +++ b/lib/blake3_dotnet/build-linux-musl-arm64.sh @@ -0,0 +1,20 @@ +#!/bin/sh +set -eu + +TARGET="aarch64-unknown-linux-musl" +BUILD="linux-musl-arm64" + +rustup target add "$TARGET" +cargo build --release --target "$TARGET" + +mkdir -p "build/$BUILD/native" +cp "target/$TARGET/release/libblake3_dotnet.so" "build/$BUILD/native" + +# Prefer a target-specific strip if available, otherwise fall back. +if command -v aarch64-linux-musl-strip >/dev/null 2>&1; then + aarch64-linux-musl-strip "build/$BUILD/native"/*.so +elif command -v llvm-strip >/dev/null 2>&1; then + llvm-strip "build/$BUILD/native"/*.so || true +elif command -v strip >/dev/null 2>&1; then + strip "build/$BUILD/native"/*.so || true +fi diff --git a/lib/blake3_dotnet/build-linux-musl-x64.sh b/lib/blake3_dotnet/build-linux-musl-x64.sh new file mode 100755 index 0000000..a1f5b45 --- /dev/null +++ b/lib/blake3_dotnet/build-linux-musl-x64.sh @@ -0,0 +1,15 @@ +#!/bin/sh +set -eu + +TARGET="x86_64-unknown-linux-musl" +BUILD="linux-musl-x64" + +rustup target add "$TARGET" +cargo build --release --target "$TARGET" + +mkdir -p "build/$BUILD/native" +cp "target/$TARGET/release/libblake3_dotnet.so" "build/$BUILD/native" + +if command -v strip >/dev/null 2>&1; then + strip "build/$BUILD/native"/*.so || true +fi diff --git a/lib/blake3_dotnet/readme.md b/lib/blake3_dotnet/readme.md index e0fb7a7..84eae57 100644 --- a/lib/blake3_dotnet/readme.md +++ b/lib/blake3_dotnet/readme.md @@ -6,4 +6,8 @@ BLAKE3 Rust libraries compiled to native and exposed as plain shared libraries. You need to have [`rustup`](https://rustup.rs/) installed -Run one of the `build*` scripts (e.g `build-win-x64.ps1` or `build-linux-x64.sh`). \ No newline at end of file +Run one of the `build*` scripts (e.g `build-win-x64.ps1` or `build-linux-x64.sh`). + +Musl targets are supported via: +- `build-linux-musl-x64.sh` (`x86_64-unknown-linux-musl`) +- `build-linux-musl-arm64.sh` (`aarch64-unknown-linux-musl`) \ No newline at end of file