Skip to content

Commit

Permalink
update build config (#196)
Browse files Browse the repository at this point in the history
* musl

* some progress

* install musl tools

* install

* static crt

* musl and static

* ver

* f

* u

* u

* f

* no musl

* f

* up

* no musl
  • Loading branch information
ibigbug authored Nov 28, 2023
1 parent 40366d7 commit fdfb55d
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 30 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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},
Expand Down
56 changes: 31 additions & 25 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
;;
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions scripts/cmake/aarch64-musl.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
set(CMAKE_LINKER ld.ldd)
3 changes: 3 additions & 0 deletions scripts/cmake/arm-musl.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_LINKER ld.ldd)
3 changes: 3 additions & 0 deletions scripts/cmake/armhf-musl.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR armhf)
set(CMAKE_LINKER ld.ldd)
3 changes: 3 additions & 0 deletions scripts/cmake/armv7-musl.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR armv7)
set(CMAKE_LINKER ld.ldd)
3 changes: 3 additions & 0 deletions scripts/cmake/armv7hf-musl.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR armv7hf)
set(CMAKE_LINKER ld.ldd)
3 changes: 3 additions & 0 deletions scripts/cmake/x86_64-musl.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR x86_64)
set(CMAKE_LINKER ld.ldd)

0 comments on commit fdfb55d

Please sign in to comment.