2024-01-28 15:56:42 +08:00
name : Rust
on :
push :
branches : [ "develop" , "main" ]
pull_request :
2024-02-03 01:43:33 +08:00
branches : [ "develop" , "main" ]
2024-01-28 15:56:42 +08:00
env :
CARGO_TERM_COLOR : always
2024-01-31 08:24:29 +08:00
defaults :
run :
# necessary for windows
shell : bash
2024-01-28 15:56:42 +08:00
jobs :
build :
2024-01-31 08:24:29 +08:00
strategy :
fail-fast : false
matrix :
include :
2024-02-06 16:19:42 +08:00
- TARGET : aarch64-unknown-linux-musl
2024-01-31 08:24:29 +08:00
OS : ubuntu-latest
2024-04-14 23:29:34 +08:00
GUI_TARGET : aarch64-unknown-linux-gnu
2024-02-06 16:19:42 +08:00
- TARGET : x86_64-unknown-linux-musl
2024-01-31 08:24:29 +08:00
OS : ubuntu-latest
2024-04-14 23:29:34 +08:00
GUI_TARGET : x86_64-unknown-linux-gnu
2024-05-03 07:55:00 +08:00
- TARGET : mips-unknown-linux-musl
OS : ubuntu-latest
GUI_TARGET :
- TARGET : mipsel-unknown-linux-musl
OS : ubuntu-latest
GUI_TARGET :
2024-02-06 16:19:42 +08:00
- TARGET : x86_64-apple-darwin
2024-01-31 08:24:29 +08:00
OS : macos-latest
2024-04-14 23:29:34 +08:00
GUI_TARGET : x86_64-apple-darwin
2024-02-06 16:19:42 +08:00
- TARGET : aarch64-apple-darwin
2024-01-31 08:24:29 +08:00
OS : macos-latest
2024-04-14 23:29:34 +08:00
GUI_TARGET : aarch64-apple-darwin
2024-02-06 16:19:42 +08:00
- TARGET : x86_64-pc-windows-msvc
2024-01-31 08:24:29 +08:00
OS : windows-latest
2024-04-14 23:29:34 +08:00
GUI_TARGET : x86_64-pc-windows-msvc
2024-01-31 08:24:29 +08:00
runs-on : ${{ matrix.OS }}
env :
2024-02-06 16:19:42 +08:00
NAME : easytier
2024-01-31 08:24:29 +08:00
TARGET : ${{ matrix.TARGET }}
OS : ${{ matrix.OS }}
2024-04-14 23:29:34 +08:00
GUI_TARGET : ${{ matrix.GUI_TARGET }}
2024-01-31 08:24:29 +08:00
steps :
- uses : actions/checkout@v3
- name : Setup protoc
uses : arduino/setup-protoc@v2
with :
# GitHub repo token to use to avoid rate limiter
repo-token : ${{ secrets.GITHUB_TOKEN }}
2024-04-14 23:29:34 +08:00
- uses : actions/setup-node@v4
with :
node-version : 21
cache : 'yarn'
cache-dependency-path : easytier-gui/yarn.lock
- name : Install Yarn
run : npm install -g yarn
2024-01-31 08:24:29 +08:00
- name : Cargo cache
uses : actions/cache@v4.0.0
with :
path : |
2024-02-03 01:43:33 +08:00
~/.cargo
2024-01-31 08:24:29 +08:00
./target
2024-04-14 23:29:34 +08:00
key : ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
2024-01-31 08:24:29 +08:00
- name : Install rust target
run : |
2024-02-06 16:19:42 +08:00
# dependencies are only needed on ubuntu as that's the only place where
# we make cross-compilation
if [[ $OS =~ ^ubuntu.*$ ]]; then
sudo apt-get update && sudo apt-get install -qq crossbuild-essential-arm64 crossbuild-essential-armhf musl-tools
2024-04-14 23:29:34 +08:00
# for easytier-gui
sudo apt install libwebkit2gtk-4.0-dev \
build-essential \
curl \
wget \
file \
libssl-dev \
libgtk-3-dev \
libayatana-appindicator3-dev \
librsvg2-dev
2024-02-06 16:19:42 +08:00
# curl -s musl.cc | grep mipsel
case $TARGET in
mipsel-unknown-linux-musl)
2024-05-03 07:55:00 +08:00
MUSL_URI=mipsel-linux-muslsf
2024-02-06 16:19:42 +08:00
;;
aarch64-unknown-linux-musl)
2024-05-03 07:55:00 +08:00
MUSL_URI=aarch64-linux-musl
2024-02-06 16:19:42 +08:00
;;
armv7-unknown-linux-musleabihf)
2024-05-03 07:55:00 +08:00
MUSL_URI=armv7l-linux-musleabihf
2024-02-06 16:19:42 +08:00
;;
arm-unknown-linux-musleabihf)
2024-05-03 07:55:00 +08:00
MUSL_URI=arm-linux-musleabihf
2024-02-06 16:19:42 +08:00
;;
mips-unknown-linux-musl)
2024-05-03 07:55:00 +08:00
MUSL_URI=mips-linux-muslsf
2024-02-06 16:19:42 +08:00
;;
esac
if [ -n "$MUSL_URI" ]; then
mkdir -p ./musl_gcc
2024-05-03 07:55:00 +08:00
wget -c https://musl.cc/${MUSL_URI}-cross.tgz -P ./musl_gcc/
tar zxf ./musl_gcc/${MUSL_URI}-cross.tgz -C ./musl_gcc/
sudo ln -s $(pwd)/musl_gcc/${MUSL_URI}-cross/bin/*gcc /usr/bin/
2024-02-06 16:19:42 +08:00
fi
fi
2024-03-21 23:33:19 +08:00
# see https://github.com/rust-lang/rustup/issues/3709
rustup set auto-self-update disable
2024-01-31 08:24:29 +08:00
rustup install 1.75
rustup default 1.75
2024-05-03 07:55:00 +08:00
# mips/mipsel cannot add target from rustup, need compile by ourselves
if [[ $OS =~ ^ubuntu.*$ && $TARGET =~ ^mips.*$ ]]; then
cd "$PWD/musl_gcc/${MUSL_URI}-cross/lib/gcc/${MUSL_URI}/11.2.1" || exit 255
cp libgcc_eh.a libunwind.a
rustup toolchain install nightly-x86_64-unknown-linux-gnu
rustup component add rust-src --toolchain nightly-x86_64-unknown-linux-gnu
cd -
else
rustup target add $TARGET
rustup target add $GUI_TARGET
fi
2024-01-31 08:24:29 +08:00
- name : Run build
2024-05-03 07:55:00 +08:00
run : |
if [[ $OS =~ ^ubuntu.*$ && $TARGET =~ ^mips.*$ ]]; then
cargo +nightly build -r --verbose --target $TARGET -Z build-std --no-default-features --features mips
else
cargo build --release --verbose --target $TARGET
fi
2024-04-14 23:29:34 +08:00
- name : Install for aarch64 gui cross compile
run : |
# see https://tauri.app/v1/guides/building/linux/
if [[ $TARGET == "aarch64-unknown-linux-musl" ]]; then
echo "deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ jammy main restricted" | sudo tee /etc/apt/sources.list
echo "deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ jammy-updates main restricted" | sudo tee -a /etc/apt/sources.list
echo "deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ jammy universe" | sudo tee -a /etc/apt/sources.list
echo "deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ jammy-updates universe" | sudo tee -a /etc/apt/sources.list
echo "deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ jammy multiverse" | sudo tee -a /etc/apt/sources.list
echo "deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ jammy-updates multiverse" | sudo tee -a /etc/apt/sources.list
echo "deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse" | sudo tee -a /etc/apt/sources.list
echo "deb [arch=amd64] http://security.ubuntu.com/ubuntu/ jammy-security main restricted" | sudo tee -a /etc/apt/sources.list
echo "deb [arch=amd64] http://security.ubuntu.com/ubuntu/ jammy-security universe" | sudo tee -a /etc/apt/sources.list
echo "deb [arch=amd64] http://security.ubuntu.com/ubuntu/ jammy-security multiverse" | sudo tee -a /etc/apt/sources.list
echo "deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy main restricted" | sudo tee -a /etc/apt/sources.list
echo "deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy-updates main restricted" | sudo tee -a /etc/apt/sources.list
echo "deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy universe" | sudo tee -a /etc/apt/sources.list
echo "deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy-updates universe" | sudo tee -a /etc/apt/sources.list
echo "deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy multiverse" | sudo tee -a /etc/apt/sources.list
echo "deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy-updates multiverse" | sudo tee -a /etc/apt/sources.list
echo "deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy-backports main restricted universe multiverse" | sudo tee -a /etc/apt/sources.list
echo "deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy-security main restricted" | sudo tee -a /etc/apt/sources.list
echo "deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy-security universe" | sudo tee -a /etc/apt/sources.list
echo "deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy-security multiverse" | sudo tee -a /etc/apt/sources.list
sudo dpkg --add-architecture arm64
sudo apt-get update && sudo apt-get upgrade -y
sudo apt install libwebkit2gtk-4.0-dev:arm64
sudo apt install libssl-dev:arm64
echo "PKG_CONFIG_SYSROOT_DIR=/usr/aarch64-linux-gnu/" >> "$GITHUB_ENV"
fi
- name : Run build GUI
run : |
2024-05-03 07:55:00 +08:00
if [ ! -n "$GUI_TARGET" ]; then
exit 0
fi
2024-04-14 23:29:34 +08:00
cd easytier-gui
yarn install
if [[ $OS =~ ^ubuntu.*$ && ! $GUI_TARGET =~ ^x86_64.*$ ]]; then
# only build deb for non-x86_64 linux
yarn tauri build -- --target $GUI_TARGET --verbose --bundles deb
else
yarn tauri build -- --target $GUI_TARGET --verbose
fi
2024-01-31 08:24:29 +08:00
- name : Compress
run : |
2024-01-31 10:53:11 +08:00
mkdir -p ./artifacts/objects/
2024-01-31 08:24:29 +08:00
# windows is the only OS using a different convention for executable file name
if [[ $OS =~ ^windows.*$ ]]; then
SUFFIX=.exe
2024-04-04 10:33:53 +08:00
cp easytier/third_party/Packet.dll ./artifacts/objects/
cp easytier/third_party/wintun.dll ./artifacts/objects/
2024-01-31 08:24:29 +08:00
fi
if [[ $GITHUB_REF_TYPE =~ ^tag$ ]]; then
TAG=$GITHUB_REF_NAME
else
TAG=$GITHUB_SHA
fi
2024-01-31 10:53:11 +08:00
mv ./target/$TARGET/release/easytier-core"$SUFFIX" ./artifacts/objects/
mv ./target/$TARGET/release/easytier-cli"$SUFFIX" ./artifacts/objects/
2024-04-14 23:29:34 +08:00
# copy gui bundle, gui is built without specific target
if [[ $OS =~ ^windows.*$ ]]; then
mv ./target/$GUI_TARGET/release/bundle/nsis/*.exe ./artifacts/objects/
elif [[ $OS =~ ^macos.*$ ]]; then
mv ./target/$GUI_TARGET/release/bundle/dmg/*.dmg ./artifacts/objects/
2024-05-03 07:55:00 +08:00
elif [[ $OS =~ ^ubuntu.*$ && ! $TARGET =~ ^mips.*$ ]]; then
2024-04-14 23:29:34 +08:00
mv ./target/$GUI_TARGET/release/bundle/deb/*.deb ./artifacts/objects/
if [[ $GUI_TARGET =~ ^x86_64.*$ ]]; then
# currently only x86 appimage is supported
mv ./target/$GUI_TARGET/release/bundle/appimage/*.AppImage ./artifacts/objects/
fi
fi
2024-02-03 01:43:33 +08:00
tar -cvf ./artifacts/$NAME-$TARGET-$TAG.tar -C ./artifacts/objects/ .
2024-01-31 10:53:11 +08:00
rm -rf ./artifacts/objects/
2024-01-31 08:24:29 +08:00
- name : Archive artifact
uses : actions/upload-artifact@v4
with :
name : easytier-${{ matrix.OS }}-${{ matrix.TARGET }}
path : |
2024-01-31 10:53:11 +08:00
./artifacts/*
2024-02-03 01:43:33 +08:00
- name : Upload OSS
uses : Menci/upload-to-oss@main
with :
access-key-id : ${{ secrets.ALIYUN_OSS_ACCESS_ID }}
access-key-secret : ${{ secrets.ALIYUN_OSS_ACCESS_KEY }}
endpoint : ${{ secrets.ALIYUN_OSS_ENDPOINT }}
bucket : ${{ secrets.ALIYUN_OSS_BUCKET }}
local-path : ./artifacts/
remote-path : /easytier-releases/${{ github.sha }}/
no-delete-remote-files : true
retry : 5
2024-01-31 08:24:29 +08:00
test :
2024-01-28 15:56:42 +08:00
runs-on : ubuntu-latest
steps :
- uses : actions/checkout@v3
- name : Setup protoc
uses : arduino/setup-protoc@v2
with :
# GitHub repo token to use to avoid rate limiter
repo-token : ${{ secrets.GITHUB_TOKEN }}
- name : Setup tools for test
run : sudo apt install bridge-utils
- name : Setup system for test
run : |
sudo sysctl net.bridge.bridge-nf-call-iptables=0
sudo sysctl net.bridge.bridge-nf-call-ip6tables=0
2024-04-27 23:10:28 +08:00
sudo sysctl net.ipv6.conf.lo.disable_ipv6=0
sudo ip addr add 2001:db8::2/64 dev lo
2024-01-31 08:24:29 +08:00
- name : Cargo cache
uses : actions/cache@v4.0.0
with :
path : |
2024-02-03 01:43:33 +08:00
~/.cargo
2024-01-31 08:24:29 +08:00
./target
2024-04-14 23:29:34 +08:00
key : ${{ runner.os }}-cargo-test-${{ hashFiles('**/Cargo.lock') }}
2024-01-28 15:56:42 +08:00
- name : Run tests
2024-04-14 23:29:34 +08:00
run : |
sudo -E env "PATH=$PATH" cargo test --verbose
sudo chown -R $USER:$USER ./target
sudo chown -R $USER:$USER ~/.cargo