From 24cac4e04468f0375bc463eb0819ca08670b0a80 Mon Sep 17 00:00:00 2001 From: james58899 Date: Mon, 3 Jun 2024 10:18:37 +0000 Subject: [PATCH] Build musl The performance of musl is worse than glibc, but static link is suitable for more environments. --- .github/workflows/build.yml | 48 ++++++++++++++++++++++++++++ .github/workflows/docker-publish.yml | 1 + .github/workflows/release.yml | 6 ++++ 3 files changed, 55 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4b31222..b199eb1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,6 +11,10 @@ on: required: false type: boolean default: false + skip-linux-musl: + required: false + type: boolean + default: false skip-windows: required: false type: boolean @@ -58,6 +62,50 @@ jobs: with: name: hath-rust-${{ matrix.target }} path: target/${{ matrix.target }}/release/hath-rust + build-linux-musl: + runs-on: ubuntu-latest + if: inputs.skip-linux-musl != true + strategy: + fail-fast: false + matrix: + target: ["x86_64-unknown-linux-musl", "aarch64-unknown-linux-musl", "armv7-unknown-linux-musleabihf"] + steps: + - uses: actions/checkout@v4 + - name: Install build tools + run: | + wget https://apt.llvm.org/llvm.sh + chmod +x llvm.sh + sudo ./llvm.sh 18 + sudo apt-get install -y crossbuild-essential-arm64 crossbuild-essential-armhf + - uses: actions/cache@v4 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: cargo-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }} + - name: Install toolchain + run: | + rustup update + rustup toolchain install nightly + rustup target add --toolchain nightly ${{ matrix.target }} + - name: Build + env: + CC: clang-18 + CXX: clang-18 + CFLAGS: "-fuse-ld=lld-18" + CXXFLAGS: "-fuse-ld=lld-18" + CARGO_HOST_RUSTFLAGS: "-Clinker=clang-18 -Clink-arg=-fuse-ld=lld-18" + CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_RUSTFLAGS: "-Clinker=clang-18 -Clink-arg=-fuse-ld=lld-18 -Clink-arg=--target=x86_64-unknown-linux-musl" + CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_RUSTFLAGS: "-Clinker=clang-18 -Clink-arg=-fuse-ld=lld-18 -Clink-arg=--target=aarch64-unknown-linux-musl" + CARGO_TARGET_ARMV7_UNKNOWN_LINUX_MUSLEABIHF_RUSTFLAGS: "-Clinker=clang-18 -Clink-arg=-fuse-ld=lld-18 -Clink-arg=--target=armv7-unknown-linux-musleabihf" + run: cargo +nightly -Ztarget-applies-to-host -Zhost-config build --verbose --release --target=${{ matrix.target }} + - uses: actions/upload-artifact@v4 + with: + name: hath-rust-${{ matrix.target }} + path: target/${{ matrix.target }}/release/hath-rust build-windows: runs-on: windows-latest if: inputs.skip-windows != true diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index b16d2c8..e33aa84 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -20,6 +20,7 @@ jobs: with: skip-windows: true skip-macos: true + skip-linux-musl: true Docker: needs: Build runs-on: ubuntu-latest diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ff32323..05fccfd 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -20,8 +20,11 @@ jobs: - name: Rename artifact run: | mv artifacts/hath-rust-x86_64-unknown-linux-gnu/hath-rust hath-rust-x86_64-unknown-linux-gnu + mv artifacts/hath-rust-x86_64-unknown-linux-musl/hath-rust hath-rust-x86_64-unknown-linux-musl mv artifacts/hath-rust-aarch64-unknown-linux-gnu/hath-rust hath-rust-aarch64-unknown-linux-gnu + mv artifacts/hath-rust-aarch64-unknown-linux-musl/hath-rust hath-rust-aarch64-unknown-linux-musl mv artifacts/hath-rust-armv7-unknown-linux-gnueabihf/hath-rust hath-rust-armv7-unknown-linux-gnueabihf + mv artifacts/hath-rust-armv7-unknown-linux-musleabihf/hath-rust hath-rust-armv7-unknown-linux-musleabihf mv artifacts/hath-rust-x86_64-pc-windows-msvc/hath-rust.exe hath-rust-x86_64-pc-windows-msvc.exe mv artifacts/hath-rust-i686-pc-windows-msvc/hath-rust.exe hath-rust-i686-pc-windows-msvc.exe mv artifacts/hath-rust-universal-apple-darwin/hath-rust hath-rust-universal-apple-darwin @@ -32,8 +35,11 @@ jobs: generate_release_notes: true files: | hath-rust-x86_64-unknown-linux-gnu + hath-rust-x86_64-unknown-linux-musl hath-rust-aarch64-unknown-linux-gnu + hath-rust-aarch64-unknown-linux-musl hath-rust-armv7-unknown-linux-gnueabihf + hath-rust-armv7-unknown-linux-musleabihf hath-rust-x86_64-pc-windows-msvc.exe hath-rust-i686-pc-windows-msvc.exe hath-rust-universal-apple-darwin \ No newline at end of file