Skip to content

Commit

Permalink
Enable github workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
madeye committed Dec 11, 2021
1 parent 76babcb commit b027356
Show file tree
Hide file tree
Showing 5 changed files with 409 additions and 0 deletions.
110 changes: 110 additions & 0 deletions .github/workflows/build-nightly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: Build Nightly Releases
on:
push:
branches: [master]

env:
CARGO_TERM_COLOR: always

jobs:
build-cross:
runs-on: ubuntu-latest
env:
RUST_BACKTRACE: full
strategy:
matrix:
target:
- x86_64-unknown-linux-musl
- aarch64-unknown-linux-musl

steps:
- uses: actions/checkout@v2

- name: Install cross
run: cargo install cross

- name: Build ${{ matrix.target }}
timeout-minutes: 120
run: |
compile_target=${{ matrix.target }}
cd build
./build-release -t ${{ matrix.target }} $compile_features $compile_compress
- name: Upload Artifacts
uses: actions/upload-artifact@v2
with:
name: ${{ matrix.target }}
path: build/release/*

build-unix:
runs-on: ${{ matrix.os }}
env:
RUST_BACKTRACE: full
strategy:
matrix:
os: [macos-latest]
target:
- x86_64-apple-darwin
- aarch64-apple-darwin
steps:
- uses: actions/checkout@v2

- name: Install GNU tar
if: runner.os == 'macOS'
run: |
brew install gnu-tar
# echo "::add-path::/usr/local/opt/gnu-tar/libexec/gnubin"
echo "/usr/local/opt/gnu-tar/libexec/gnubin" >> $GITHUB_PATH
- name: Install Rust stable
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: ${{ matrix.target }}
default: true
override: true

# https://github.com/actions/virtual-environments/issues/2557#issuecomment-769611326
- if: ${{ matrix.target }} == 'aarch64-apple-darwin'
run: |
sudo xcode-select -s /Applications/Xcode_12.4.app &&
sudo rm -Rf /Library/Developer/CommandLineTools/SDKs/*
- name: Build release
shell: bash
run: |
./build/build-host-release -t ${{ matrix.target }}
- name: Upload Artifacts
uses: actions/upload-artifact@v2
with:
name: ${{ matrix.target }}
path: build/release/*

build-windows:
runs-on: windows-latest
env:
RUSTFLAGS: "-Ctarget-feature=+crt-static"
RUST_BACKTRACE: full
steps:
- uses: actions/checkout@v2

- name: Install Rust stable
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
default: true
override: true

- name: Build release
run: |
pwsh ./build/build-host-release.ps1
- name: Upload Artifacts
uses: actions/upload-artifact@v2
with:
name: windows-native
path: build/release/*
21 changes: 21 additions & 0 deletions build/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## Build Standalone Binaries

### Build with `cross`

- Install [`cross`](https://github.com/rust-embedded/cross)

```bash
cargo install cross
```

- Build with cross

```bash
cross build --target x86_64-unknown-linux-musl
```

### Predefined build routines

- `build-release`: Build binaries with `cross` and packages outputs into `release` folder
- `build-host-release`: Build binaries with host's Rust toolchain. *NIX shell script
- `build-host-release.ps1`: Build binaries with host's Rust toolchain. PowerShell script
95 changes: 95 additions & 0 deletions build/build-host-release
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/bin/bash

BUILD_TARGET=""
BUILD_FEATURES=()
while getopts "t:f:" opt; do
case $opt in
t)
BUILD_TARGET=$OPTARG
;;
f)
BUILD_FEATURES+=($OPTARG)
;;
?)
echo "Usage: $(basename $0) [-t <target-triple>] [-f <feature>]"
;;
esac
done

BUILD_FEATURES+=${BUILD_EXTRA_FEATURES}

ROOT_DIR=$( cd $( dirname $0 ) && pwd )
VERSION=$(grep -E '^version' "${ROOT_DIR}/../Cargo.toml" | awk '{print $3}' | sed 's/"//g')
HOST_TRIPLE=$(rustc -Vv | grep 'host:' | awk '{print $2}')

echo "Started build release ${VERSION} for ${HOST_TRIPLE} (target: ${BUILD_TARGET}) with features \"${BUILD_FEATURES}\"..."

if [[ "${BUILD_TARGET}" != "" ]]; then
if [[ "${BUILD_FEATURES}" != "" ]]; then
cargo build --release --features "${BUILD_FEATURES}" --target "${BUILD_TARGET}"
else
cargo build --release --target "${BUILD_TARGET}"
fi
else
if [[ "${BUILD_FEATURES}" != "" ]]; then
cargo build --release --features "${BUILD_FEATURES}"
else
cargo build --release
fi
fi

if [[ "$?" != "0" ]]; then
exit $?;
fi

if [[ "${BUILD_TARGET}" == "" ]]; then
BUILD_TARGET=$HOST_TRIPLE
fi

TARGET_SUFFIX=""
if [[ "${BUILD_TARGET}" == *"-windows-"* ]]; then
TARGET_SUFFIX=".exe"
fi

TARGETS=("qtun-client${TARGET_SUFFIX}" "qtun-server${TARGET_SUFFIX}")

RELEASE_FOLDER="${ROOT_DIR}/release"
RELEASE_PACKAGE_NAME="qtun-v${VERSION}.${BUILD_TARGET}"

mkdir -p "${RELEASE_FOLDER}"

# Into release folder
if [[ "${BUILD_TARGET}" != "" ]]; then
cd "${ROOT_DIR}/../target/${BUILD_TARGET}/release"
else
cd "${ROOT_DIR}/../target/release"
fi

if [[ "${BUILD_TARGET}" == *"-windows-"* ]]; then
# For Windows, use zip

RELEASE_PACKAGE_FILE_NAME="${RELEASE_PACKAGE_NAME}.zip"
RELEASE_PACKAGE_FILE_PATH="${RELEASE_FOLDER}/${RELEASE_PACKAGE_FILE_NAME}"
zip "${RELEASE_PACKAGE_FILE_PATH}" "${TARGETS[@]}"

# Checksum
cd "${RELEASE_FOLDER}"
shasum -a 256 "${RELEASE_PACKAGE_FILE_NAME}" > "${RELEASE_PACKAGE_FILE_NAME}.sha256"
else
# For others, Linux, OS X, uses tar.xz

# For Darwin, .DS_Store and other related files should be ignored
if [[ "$(uname -s)" == "Darwin" ]]; then
export COPYFILE_DISABLE=1
fi

RELEASE_PACKAGE_FILE_NAME="${RELEASE_PACKAGE_NAME}.tar.xz"
RELEASE_PACKAGE_FILE_PATH="${RELEASE_FOLDER}/${RELEASE_PACKAGE_FILE_NAME}"
tar -cJf "${RELEASE_PACKAGE_FILE_PATH}" "${TARGETS[@]}"

# Checksum
cd "${RELEASE_FOLDER}"
shasum -a 256 "${RELEASE_PACKAGE_FILE_NAME}" > "${RELEASE_PACKAGE_FILE_NAME}.sha256"
fi

echo "Finished build release ${RELEASE_PACKAGE_FILE_PATH}"
59 changes: 59 additions & 0 deletions build/build-host-release.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!pwsh
<#
OpenSSL is already installed on windows-latest virtual environment.
If you need OpenSSL, consider install it by:
choco install openssl
#>
param(
[Parameter(HelpMessage = "extra features")]
[Alias('f')]
[string]$Features
)

$ErrorActionPreference = "Stop"

$TargetTriple = (rustc -Vv | Select-String -Pattern "host: (.*)" | ForEach-Object { $_.Matches.Value }).split()[-1]

Write-Host "Started building release for ${TargetTriple} ..."

if ([string]::IsNullOrEmpty($Features)) {
cargo build --release
}
else {
cargo build --release --features "${Features}"
}

if (!$?) {
exit $LASTEXITCODE
}

$Version = (Select-String -Pattern '^version *= *"([^"]*)"$' -Path "${PSScriptRoot}\..\Cargo.toml" | ForEach-Object { $_.Matches.Value }).split()[-1]
$Version = $Version -replace '"'

$PackageReleasePath = "${PSScriptRoot}\release"
$PackageName = "shadowsocks-v${Version}.${TargetTriple}.zip"
$PackagePath = "${PackageReleasePath}\${PackageName}"

Write-Host $Version
Write-Host $PackageReleasePath
Write-Host $PackageName
Write-Host $PackagePath

Push-Location "${PSScriptRoot}\..\target\release"

$ProgressPreference = "SilentlyContinue"
New-Item "${PackageReleasePath}" -ItemType Directory -ErrorAction SilentlyContinue
$CompressParam = @{
LiteralPath = "qtun-client.exe", "qtun-server.exe"
DestinationPath = "${PackagePath}"
}
Compress-Archive @CompressParam

Write-Host "Created release packet ${PackagePath}"

$PackageChecksumPath = "${PackagePath}.sha256"
$PackageHash = (Get-FileHash -Path "${PackagePath}" -Algorithm SHA256).Hash
"${PackageHash} ${PackageName}" | Out-File -FilePath "${PackageChecksumPath}"

Write-Host "Created release packet checksum ${PackageChecksumPath}"
Loading

0 comments on commit b027356

Please sign in to comment.