Skip to content

Commit b027356

Browse files
committed
Enable github workflows
1 parent 76babcb commit b027356

File tree

5 files changed

+409
-0
lines changed

5 files changed

+409
-0
lines changed

.github/workflows/build-nightly.yml

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
name: Build Nightly Releases
2+
on:
3+
push:
4+
branches: [master]
5+
6+
env:
7+
CARGO_TERM_COLOR: always
8+
9+
jobs:
10+
build-cross:
11+
runs-on: ubuntu-latest
12+
env:
13+
RUST_BACKTRACE: full
14+
strategy:
15+
matrix:
16+
target:
17+
- x86_64-unknown-linux-musl
18+
- aarch64-unknown-linux-musl
19+
20+
steps:
21+
- uses: actions/checkout@v2
22+
23+
- name: Install cross
24+
run: cargo install cross
25+
26+
- name: Build ${{ matrix.target }}
27+
timeout-minutes: 120
28+
run: |
29+
compile_target=${{ matrix.target }}
30+
31+
cd build
32+
./build-release -t ${{ matrix.target }} $compile_features $compile_compress
33+
34+
- name: Upload Artifacts
35+
uses: actions/upload-artifact@v2
36+
with:
37+
name: ${{ matrix.target }}
38+
path: build/release/*
39+
40+
build-unix:
41+
runs-on: ${{ matrix.os }}
42+
env:
43+
RUST_BACKTRACE: full
44+
strategy:
45+
matrix:
46+
os: [macos-latest]
47+
target:
48+
- x86_64-apple-darwin
49+
- aarch64-apple-darwin
50+
steps:
51+
- uses: actions/checkout@v2
52+
53+
- name: Install GNU tar
54+
if: runner.os == 'macOS'
55+
run: |
56+
brew install gnu-tar
57+
# echo "::add-path::/usr/local/opt/gnu-tar/libexec/gnubin"
58+
echo "/usr/local/opt/gnu-tar/libexec/gnubin" >> $GITHUB_PATH
59+
60+
- name: Install Rust stable
61+
uses: actions-rs/toolchain@v1
62+
with:
63+
profile: minimal
64+
toolchain: stable
65+
target: ${{ matrix.target }}
66+
default: true
67+
override: true
68+
69+
# https://github.com/actions/virtual-environments/issues/2557#issuecomment-769611326
70+
- if: ${{ matrix.target }} == 'aarch64-apple-darwin'
71+
run: |
72+
sudo xcode-select -s /Applications/Xcode_12.4.app &&
73+
sudo rm -Rf /Library/Developer/CommandLineTools/SDKs/*
74+
75+
- name: Build release
76+
shell: bash
77+
run: |
78+
./build/build-host-release -t ${{ matrix.target }}
79+
80+
- name: Upload Artifacts
81+
uses: actions/upload-artifact@v2
82+
with:
83+
name: ${{ matrix.target }}
84+
path: build/release/*
85+
86+
build-windows:
87+
runs-on: windows-latest
88+
env:
89+
RUSTFLAGS: "-Ctarget-feature=+crt-static"
90+
RUST_BACKTRACE: full
91+
steps:
92+
- uses: actions/checkout@v2
93+
94+
- name: Install Rust stable
95+
uses: actions-rs/toolchain@v1
96+
with:
97+
profile: minimal
98+
toolchain: stable
99+
default: true
100+
override: true
101+
102+
- name: Build release
103+
run: |
104+
pwsh ./build/build-host-release.ps1
105+
106+
- name: Upload Artifacts
107+
uses: actions/upload-artifact@v2
108+
with:
109+
name: windows-native
110+
path: build/release/*

build/README.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## Build Standalone Binaries
2+
3+
### Build with `cross`
4+
5+
- Install [`cross`](https://github.com/rust-embedded/cross)
6+
7+
```bash
8+
cargo install cross
9+
```
10+
11+
- Build with cross
12+
13+
```bash
14+
cross build --target x86_64-unknown-linux-musl
15+
```
16+
17+
### Predefined build routines
18+
19+
- `build-release`: Build binaries with `cross` and packages outputs into `release` folder
20+
- `build-host-release`: Build binaries with host's Rust toolchain. *NIX shell script
21+
- `build-host-release.ps1`: Build binaries with host's Rust toolchain. PowerShell script

build/build-host-release

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/bin/bash
2+
3+
BUILD_TARGET=""
4+
BUILD_FEATURES=()
5+
while getopts "t:f:" opt; do
6+
case $opt in
7+
t)
8+
BUILD_TARGET=$OPTARG
9+
;;
10+
f)
11+
BUILD_FEATURES+=($OPTARG)
12+
;;
13+
?)
14+
echo "Usage: $(basename $0) [-t <target-triple>] [-f <feature>]"
15+
;;
16+
esac
17+
done
18+
19+
BUILD_FEATURES+=${BUILD_EXTRA_FEATURES}
20+
21+
ROOT_DIR=$( cd $( dirname $0 ) && pwd )
22+
VERSION=$(grep -E '^version' "${ROOT_DIR}/../Cargo.toml" | awk '{print $3}' | sed 's/"//g')
23+
HOST_TRIPLE=$(rustc -Vv | grep 'host:' | awk '{print $2}')
24+
25+
echo "Started build release ${VERSION} for ${HOST_TRIPLE} (target: ${BUILD_TARGET}) with features \"${BUILD_FEATURES}\"..."
26+
27+
if [[ "${BUILD_TARGET}" != "" ]]; then
28+
if [[ "${BUILD_FEATURES}" != "" ]]; then
29+
cargo build --release --features "${BUILD_FEATURES}" --target "${BUILD_TARGET}"
30+
else
31+
cargo build --release --target "${BUILD_TARGET}"
32+
fi
33+
else
34+
if [[ "${BUILD_FEATURES}" != "" ]]; then
35+
cargo build --release --features "${BUILD_FEATURES}"
36+
else
37+
cargo build --release
38+
fi
39+
fi
40+
41+
if [[ "$?" != "0" ]]; then
42+
exit $?;
43+
fi
44+
45+
if [[ "${BUILD_TARGET}" == "" ]]; then
46+
BUILD_TARGET=$HOST_TRIPLE
47+
fi
48+
49+
TARGET_SUFFIX=""
50+
if [[ "${BUILD_TARGET}" == *"-windows-"* ]]; then
51+
TARGET_SUFFIX=".exe"
52+
fi
53+
54+
TARGETS=("qtun-client${TARGET_SUFFIX}" "qtun-server${TARGET_SUFFIX}")
55+
56+
RELEASE_FOLDER="${ROOT_DIR}/release"
57+
RELEASE_PACKAGE_NAME="qtun-v${VERSION}.${BUILD_TARGET}"
58+
59+
mkdir -p "${RELEASE_FOLDER}"
60+
61+
# Into release folder
62+
if [[ "${BUILD_TARGET}" != "" ]]; then
63+
cd "${ROOT_DIR}/../target/${BUILD_TARGET}/release"
64+
else
65+
cd "${ROOT_DIR}/../target/release"
66+
fi
67+
68+
if [[ "${BUILD_TARGET}" == *"-windows-"* ]]; then
69+
# For Windows, use zip
70+
71+
RELEASE_PACKAGE_FILE_NAME="${RELEASE_PACKAGE_NAME}.zip"
72+
RELEASE_PACKAGE_FILE_PATH="${RELEASE_FOLDER}/${RELEASE_PACKAGE_FILE_NAME}"
73+
zip "${RELEASE_PACKAGE_FILE_PATH}" "${TARGETS[@]}"
74+
75+
# Checksum
76+
cd "${RELEASE_FOLDER}"
77+
shasum -a 256 "${RELEASE_PACKAGE_FILE_NAME}" > "${RELEASE_PACKAGE_FILE_NAME}.sha256"
78+
else
79+
# For others, Linux, OS X, uses tar.xz
80+
81+
# For Darwin, .DS_Store and other related files should be ignored
82+
if [[ "$(uname -s)" == "Darwin" ]]; then
83+
export COPYFILE_DISABLE=1
84+
fi
85+
86+
RELEASE_PACKAGE_FILE_NAME="${RELEASE_PACKAGE_NAME}.tar.xz"
87+
RELEASE_PACKAGE_FILE_PATH="${RELEASE_FOLDER}/${RELEASE_PACKAGE_FILE_NAME}"
88+
tar -cJf "${RELEASE_PACKAGE_FILE_PATH}" "${TARGETS[@]}"
89+
90+
# Checksum
91+
cd "${RELEASE_FOLDER}"
92+
shasum -a 256 "${RELEASE_PACKAGE_FILE_NAME}" > "${RELEASE_PACKAGE_FILE_NAME}.sha256"
93+
fi
94+
95+
echo "Finished build release ${RELEASE_PACKAGE_FILE_PATH}"

build/build-host-release.ps1

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!pwsh
2+
<#
3+
OpenSSL is already installed on windows-latest virtual environment.
4+
If you need OpenSSL, consider install it by:
5+
6+
choco install openssl
7+
#>
8+
param(
9+
[Parameter(HelpMessage = "extra features")]
10+
[Alias('f')]
11+
[string]$Features
12+
)
13+
14+
$ErrorActionPreference = "Stop"
15+
16+
$TargetTriple = (rustc -Vv | Select-String -Pattern "host: (.*)" | ForEach-Object { $_.Matches.Value }).split()[-1]
17+
18+
Write-Host "Started building release for ${TargetTriple} ..."
19+
20+
if ([string]::IsNullOrEmpty($Features)) {
21+
cargo build --release
22+
}
23+
else {
24+
cargo build --release --features "${Features}"
25+
}
26+
27+
if (!$?) {
28+
exit $LASTEXITCODE
29+
}
30+
31+
$Version = (Select-String -Pattern '^version *= *"([^"]*)"$' -Path "${PSScriptRoot}\..\Cargo.toml" | ForEach-Object { $_.Matches.Value }).split()[-1]
32+
$Version = $Version -replace '"'
33+
34+
$PackageReleasePath = "${PSScriptRoot}\release"
35+
$PackageName = "shadowsocks-v${Version}.${TargetTriple}.zip"
36+
$PackagePath = "${PackageReleasePath}\${PackageName}"
37+
38+
Write-Host $Version
39+
Write-Host $PackageReleasePath
40+
Write-Host $PackageName
41+
Write-Host $PackagePath
42+
43+
Push-Location "${PSScriptRoot}\..\target\release"
44+
45+
$ProgressPreference = "SilentlyContinue"
46+
New-Item "${PackageReleasePath}" -ItemType Directory -ErrorAction SilentlyContinue
47+
$CompressParam = @{
48+
LiteralPath = "qtun-client.exe", "qtun-server.exe"
49+
DestinationPath = "${PackagePath}"
50+
}
51+
Compress-Archive @CompressParam
52+
53+
Write-Host "Created release packet ${PackagePath}"
54+
55+
$PackageChecksumPath = "${PackagePath}.sha256"
56+
$PackageHash = (Get-FileHash -Path "${PackagePath}" -Algorithm SHA256).Hash
57+
"${PackageHash} ${PackageName}" | Out-File -FilePath "${PackageChecksumPath}"
58+
59+
Write-Host "Created release packet checksum ${PackageChecksumPath}"

0 commit comments

Comments
 (0)