From fdfb55d81fb00a39f08923ca62eb3054c210c62e Mon Sep 17 00:00:00 2001 From: Yuwei Ba Date: Tue, 28 Nov 2023 13:16:21 +1100 Subject: [PATCH] update build config (#196) * musl * some progress * install musl tools * install * static crt * musl and static * ver * f * u * u * f * no musl * f * up * no musl --- .github/workflows/ci.yml | 6 +--- scripts/build.sh | 56 ++++++++++++++++++-------------- scripts/cmake/aarch64-musl.cmake | 3 ++ scripts/cmake/arm-musl.cmake | 3 ++ scripts/cmake/armhf-musl.cmake | 3 ++ scripts/cmake/armv7-musl.cmake | 3 ++ scripts/cmake/armv7hf-musl.cmake | 3 ++ scripts/cmake/x86_64-musl.cmake | 3 ++ 8 files changed, 50 insertions(+), 30 deletions(-) create mode 100644 scripts/cmake/aarch64-musl.cmake create mode 100644 scripts/cmake/arm-musl.cmake create mode 100644 scripts/cmake/armhf-musl.cmake create mode 100644 scripts/cmake/armv7-musl.cmake create mode 100644 scripts/cmake/armv7hf-musl.cmake create mode 100644 scripts/cmake/x86_64-musl.cmake diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 739c5a34b..2f9afec34 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,7 +36,7 @@ jobs: run: cargo test --all --all-features publish: - name: publish ${{ matrix.platforms.target }} on ${{ matrix.platforms.os }} + name: publish ${{ matrix.platforms.target }} on ${{ matrix.platforms.os }} static - ${{ matrix.static }} if: contains(github.ref, 'tags/v') needs: [test] runs-on: ${{ matrix.platforms.os }} @@ -45,13 +45,9 @@ jobs: static: [true, false] platforms: [ {os: ubuntu-22.04, target: x86_64-unknown-linux-gnu}, - {os: ubuntu-22.04, target: x86_64-unknown-linux-musl}, {os: ubuntu-22.04, target: aarch64-unknown-linux-gnu}, - {os: ubuntu-22.04, target: aarch64-unknown-linux-musl}, {os: ubuntu-22.04, target: armv7-unknown-linux-gnueabihf}, - {os: ubuntu-22.04, target: armv7-unknown-linux-musleabihf}, {os: ubuntu-22.04, target: armv7-unknown-linux-gnueabi}, - {os: ubuntu-22.04, target: armv7-unknown-linux-musleabi}, {os: macos-13, target: aarch64-apple-darwin}, {os: macos-13, target: x86_64-apple-darwin}, {os: windows-2022, target: x86_64-pc-windows-msvc}, diff --git a/scripts/build.sh b/scripts/build.sh index a78ab5e17..d543ef3d9 100644 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -15,8 +15,8 @@ esac llvm_version=16 install_llvm() { - if ! command -v -- "clang-$llvm_version" &> /dev/null - then + status=$(command -v -- "clang-$llvm_version" > /dev/null 2>&1; echo $?) + if [ $status -ne 0 ]; then wget https://apt.llvm.org/llvm.sh -O /tmp/llvm.sh chmod +x /tmp/llvm.sh sudo /tmp/llvm.sh $llvm_version @@ -36,6 +36,7 @@ for TARGET in $1; do install_llvm export CC=clang-$llvm_version export CXX=clang++-$llvm_version + export LDFLAGS="-fuse-ld=lld" export CMAKE_TOOLCHAIN_FILE=$ROOT_DIR/scripts/cmake/x86_64-musl.cmake ;; aarch64-unknown-linux-gnu) @@ -45,11 +46,11 @@ for TARGET in $1; do export BINDGEN_EXTRA_CLANG_ARGS="--sysroot=/usr/aarch64-linux-gnu" ;; aarch64-unknown-linux-musl) - sudo apt install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu binutils-aarch64-linux-gnu libc6-dev-arm64-cross + sudo apt install -y libc6-dev-arm64-cross install_llvm export CC=clang-$llvm_version export CXX=clang++-$llvm_version - export LDFLAGS="-fuse-ld=lld" + export LDFLAGS="-fuse-ld=lld --sysroot=/usr/aarch64-linux-gnu" export BINDGEN_EXTRA_CLANG_ARGS="--sysroot=/usr/aarch64-linux-gnu" export CMAKE_TOOLCHAIN_FILE=$ROOT_DIR/scripts/cmake/aarch64-musl.cmake ;; @@ -64,35 +65,35 @@ for TARGET in $1; do export CXX=arm-linux-gnueabihf-g++ ;; arm-unknown-linux-musleabi) - sudo apt install -y gcc-arm-linux-gnueabi g++-arm-linux-gnueabi binutils-arm-linux-gnueabi libc6-dev-armel-cross + sudo apt install -y libc6-dev-armel-cross install_llvm export CC=clang-$llvm_version export CXX=clang++-$llvm_version - export LDFLAGS="-fuse-ld=lld" + export LDFLAGS="-fuse-ld=lld --sysroot=/usr/arm-linux-gnueabi" export CMAKE_TOOLCHAIN_FILE=$ROOT_DIR/scripts/cmake/arm-musl.cmake ;; arm-unknown-linux-musleabihf) - sudo apt install -y gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf binutils-arm-linux-gnueabihf libc6-dev-armhf-cross + sudo apt install -y libc6-dev-armhf-cross install_llvm export CC=clang-$llvm_version export CXX=clang++-$llvm_version - export LDFLAGS="-fuse-ld=lld" + export LDFLAGS="-fuse-ld=lld --sysroot=/usr/arm-linux-gnueabihf" export CMAKE_TOOLCHAIN_FILE=$ROOT_DIR/scripts/cmake/armhf-musl.cmake ;; armv7-unknown-linux-musleabi) - sudo apt install -y gcc-arm-linux-gnueabi g++-arm-linux-gnueabi binutils-arm-linux-gnueabi libc6-dev-armel-cross + sudo apt install -y libc6-dev-armel-cross install_llvm export CC=clang-$llvm_version export CXX=clang++-$llvm_version - export LDFLAGS="-fuse-ld=lld" + export LDFLAGS="-fuse-ld=lld --sysroot=/usr/arm-linux-gnueabi" export CMAKE_TOOLCHAIN_FILE=$ROOT_DIR/scripts/cmake/armv7-musl.cmake ;; armv7-unknown-linux-musleabihf) - sudo apt install -y gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf binutils-arm-linux-gnueabihf libc6-dev-armhf-cross + sudo apt install -y libc6-dev-armhf-cross install_llvm export CC=clang-$llvm_version export CXX=clang++-$llvm_version - export LDFLAGS="-fuse-ld=lld" + export LDFLAGS="-fuse-ld=lld --sysroot=/usr/arm-linux-gnueabihf" export CMAKE_TOOLCHAIN_FILE=$ROOT_DIR/scripts/cmake/armv7hf-musl.cmake ;; i686-unknown-linux-gnu) @@ -144,20 +145,25 @@ for TARGET in $1; do export CXX=riscv64-linux-gnu-g++ ;; esac - if [[ "$TARGET" == *"musl"* ]]; then - if [[ $2 == "true" ]]; then - export RUSTFLAGS="-Clinker=rust-lld -Clink-self-contained=yes -Ctarget-feature=+crt-static" - else - export RUSTFLAGS="-Clinker=rust-lld" - fi - else - if [[ $2 == "true" ]]; then - export RUSTFLAGS="-Clink-self-contained=yes -Ctarget-feature=+crt-static" - fi - fi + + case $TARGET in + *musl*) + if [ "$2" = "true" ]; then + export RUSTFLAGS="-Clinker=rust-lld -Clink-self-contained=yes -Ctarget-feature=+crt-static" + else + export RUSTFLAGS="-Clinker=rust-lld" + fi + ;; + *) + if [ "$2" = "true" ]; then + export RUSTFLAGS="-Ctarget-feature=+crt-static" + fi + ;; + esac + OUTPUT_BIN=./target/artifacts/clash-$TARGET - if [[ "$2" == "true" ]]; then - OUTPUT_BIN=$OUTPUT_BIN-static + if [ "$2" = "true" ]; then + OUTPUT_BIN=$OUTPUT_BIN-static-crt fi cargo build -p clash --target $TARGET --release diff --git a/scripts/cmake/aarch64-musl.cmake b/scripts/cmake/aarch64-musl.cmake new file mode 100644 index 000000000..7f363ed53 --- /dev/null +++ b/scripts/cmake/aarch64-musl.cmake @@ -0,0 +1,3 @@ +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR aarch64) +set(CMAKE_LINKER ld.ldd) \ No newline at end of file diff --git a/scripts/cmake/arm-musl.cmake b/scripts/cmake/arm-musl.cmake new file mode 100644 index 000000000..5d825ca5f --- /dev/null +++ b/scripts/cmake/arm-musl.cmake @@ -0,0 +1,3 @@ +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR arm) +set(CMAKE_LINKER ld.ldd) \ No newline at end of file diff --git a/scripts/cmake/armhf-musl.cmake b/scripts/cmake/armhf-musl.cmake new file mode 100644 index 000000000..c11e52db3 --- /dev/null +++ b/scripts/cmake/armhf-musl.cmake @@ -0,0 +1,3 @@ +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR armhf) +set(CMAKE_LINKER ld.ldd) \ No newline at end of file diff --git a/scripts/cmake/armv7-musl.cmake b/scripts/cmake/armv7-musl.cmake new file mode 100644 index 000000000..08da48447 --- /dev/null +++ b/scripts/cmake/armv7-musl.cmake @@ -0,0 +1,3 @@ +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR armv7) +set(CMAKE_LINKER ld.ldd) \ No newline at end of file diff --git a/scripts/cmake/armv7hf-musl.cmake b/scripts/cmake/armv7hf-musl.cmake new file mode 100644 index 000000000..664af8d59 --- /dev/null +++ b/scripts/cmake/armv7hf-musl.cmake @@ -0,0 +1,3 @@ +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR armv7hf) +set(CMAKE_LINKER ld.ldd) \ No newline at end of file diff --git a/scripts/cmake/x86_64-musl.cmake b/scripts/cmake/x86_64-musl.cmake new file mode 100644 index 000000000..9eee6d80f --- /dev/null +++ b/scripts/cmake/x86_64-musl.cmake @@ -0,0 +1,3 @@ +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR x86_64) +set(CMAKE_LINKER ld.ldd) \ No newline at end of file