Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 46 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ jobs:
rust:
name: Rust Workspace
runs-on: ubuntu-latest
env:
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: "0"
RUSTC_WRAPPER: sccache
SCCACHE_GHA_ENABLED: "true"
defaults:
run:
working-directory: rust_hft
Expand All @@ -29,11 +34,27 @@ jobs:
with:
components: rustfmt, clippy

- name: Install Linux linker
run: sudo apt-get update && sudo apt-get install -y clang mold

- name: Setup sccache
uses: mozilla-actions/sccache-action@v0.0.10

- name: Record cache dimensions
id: cache-info
shell: bash
run: |
echo "rust=$(rustc -Vv | awk '/^release:/ {print $2}')" >> "$GITHUB_OUTPUT"
echo "sccache=$(${SCCACHE_PATH:-sccache} --version | awk '{print $2}')" >> "$GITHUB_OUTPUT"

- name: Cache Rust
uses: Swatinem/rust-cache@v2
with:
workspaces: |
rust_hft
key: rust_hft-ci-rust-${{ steps.cache-info.outputs.rust }}-sccache-${{ steps.cache-info.outputs.sccache }}-${{ hashFiles('rust_hft/Cargo.lock') }}
cache-all-crates: true
save-if: ${{ github.event_name != 'pull_request' }}

- name: Format check (non-blocking)
run: cargo fmt --all -- --check
Expand All @@ -47,30 +68,36 @@ jobs:
-W clippy::suspicious
continue-on-error: true

- name: Build (release)
run: cargo build --workspace --release
- name: Build
run: cargo build --workspace --locked

- name: Package binaries (if present)
if: github.event_name == 'push'
run: |
mkdir -p dist
for bin in hft-live hft-paper hft-all-in-one hft-replay; do
if [ -f target/release/$bin ]; then
cp target/release/$bin dist/
if [ -f target/debug/$bin ]; then
cp target/debug/$bin dist/
fi
done
ls -la dist || true

- name: Upload artifacts
if: success()
if: success() && github.event_name == 'push'
uses: actions/upload-artifact@v4
with:
name: rust-binaries-${{ github.sha }}
name: rust-dev-binaries-${{ github.sha }}
path: rust_hft/dist/*
if-no-files-found: ignore

rust_extra_standalone:
name: Rust Standalone (test_bitget_standalone)
runs-on: ubuntu-latest
env:
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: "0"
RUSTC_WRAPPER: sccache
SCCACHE_GHA_ENABLED: "true"
defaults:
run:
working-directory: test_bitget_standalone
Expand All @@ -81,11 +108,24 @@ jobs:
- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@stable

- name: Setup sccache
uses: mozilla-actions/sccache-action@v0.0.10

- name: Record cache dimensions
id: cache-info
shell: bash
run: |
echo "rust=$(rustc -Vv | awk '/^release:/ {print $2}')" >> "$GITHUB_OUTPUT"
echo "sccache=$(${SCCACHE_PATH:-sccache} --version | awk '{print $2}')" >> "$GITHUB_OUTPUT"

- name: Cache Rust (standalone)
uses: Swatinem/rust-cache@v2
with:
workspaces: |
test_bitget_standalone
key: bitget-standalone-rust-${{ steps.cache-info.outputs.rust }}-sccache-${{ steps.cache-info.outputs.sccache }}-${{ hashFiles('test_bitget_standalone/Cargo.lock', 'test_bitget_standalone/Cargo.toml') }}
cache-all-crates: true
save-if: ${{ github.event_name != 'pull_request' }}

- name: Build (release)
run: cargo build --release
Expand Down
119 changes: 107 additions & 12 deletions .github/workflows/release-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
tags:
- 'v*'
workflow_dispatch:

permissions:
contents: write
Expand All @@ -12,50 +13,144 @@ concurrency:
group: release-${{ github.ref }}
cancel-in-progress: false

env:
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: "0"
RUSTC_WRAPPER: sccache
SCCACHE_GHA_ENABLED: "true"
TZ: UTC
LC_ALL: C
LANG: C
RELEASE_PACKAGES: hft-live hft-paper hft-all-in-one hft-replay hft-backtest hft-collector

jobs:
build:
name: Build binaries (linux x86_64)
runs-on: ubuntu-latest
name: Build ${{ matrix.name }}
runs-on: ${{ matrix.os }}
defaults:
run:
working-directory: rust_hft
strategy:
fail-fast: false
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
name: linux-x86_64
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
name: linux-x86_64-musl
- target: x86_64-apple-darwin
os: macos-15-intel
name: macos-x86_64
- target: aarch64-apple-darwin
os: macos-15
name: macos-aarch64

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}

- name: Install Linux linker
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install -y clang mold musl-tools

- name: Setup sccache
uses: mozilla-actions/sccache-action@v0.0.10

- name: Configure target linker
if: matrix.target == 'x86_64-unknown-linux-musl'
run: echo "CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER=musl-gcc" >> "$GITHUB_ENV"

- name: Record cache dimensions
id: cache-info
shell: bash
run: |
echo "rust=$(rustc -Vv | awk '/^release:/ {print $2}')" >> "$GITHUB_OUTPUT"
echo "sccache=$(${SCCACHE_PATH:-sccache} --version | awk '{print $2}')" >> "$GITHUB_OUTPUT"

- name: Cache Rust
uses: Swatinem/rust-cache@v2
with:
workspaces: |
rust_hft
key: release-${{ matrix.target }}-rust-${{ steps.cache-info.outputs.rust }}-sccache-${{ steps.cache-info.outputs.sccache }}-${{ hashFiles('rust_hft/Cargo.lock') }}
cache-all-crates: true

- name: Set reproducible build metadata
run: echo "SOURCE_DATE_EPOCH=$(git log -1 --format=%ct)" >> "$GITHUB_ENV"

- name: Build apps
shell: bash
run: |
cargo build --release -p hft-live -p hft-paper -p hft-all-in-one -p hft-replay
set -euo pipefail
for package in ${RELEASE_PACKAGES}; do
cargo build --release --locked --target "${{ matrix.target }}" -p "${package}"
done

- name: Package artifacts
shell: bash
run: |
set -euo pipefail
mkdir -p dist
for bin in hft-live hft-paper hft-all-in-one hft-replay; do
if [ -f target/release/$bin ]; then
cp target/release/$bin dist/
(cd dist && tar -czf ${bin}-linux-x86_64.tar.gz $bin && rm -f $bin)
fi
package_dir="rust-hft-${{ matrix.name }}"
mkdir -p "${package_dir}/bin" "${package_dir}/docs"

for package in ${RELEASE_PACKAGES}; do
cp "target/${{ matrix.target }}/release/${package}" "${package_dir}/bin/${package}"
done
ls -la dist

cp docs/README.md "${package_dir}/README.md"
cp docs/guides/RUST_BUILD_RELEASE.md "${package_dir}/docs/RUST_BUILD_RELEASE.md"

{
echo "Rust HFT Trading System"
echo "Version: ${GITHUB_REF_NAME}"
echo "Commit: ${GITHUB_SHA}"
echo "Target: ${{ matrix.target }}"
echo "Source-Date-Epoch: ${SOURCE_DATE_EPOCH}"
echo "Packages: ${RELEASE_PACKAGES}"
} > "${package_dir}/VERSION.txt"

tar -czf "dist/${package_dir}.tar.gz" "${package_dir}"
shasum -a 256 "dist/${package_dir}.tar.gz" > "dist/${package_dir}.tar.gz.sha256"

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: rust-binaries-${{ github.ref_name }}
path: rust_hft/dist/*.tar.gz
name: rust-hft-${{ matrix.name }}
path: |
rust_hft/dist/*.tar.gz
rust_hft/dist/*.sha256
retention-days: 14

- name: sccache stats
if: always()
run: ${SCCACHE_PATH:-sccache} --show-stats

github-release:
name: Publish GitHub Release
needs: [build]
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')

steps:
- name: Download release artifacts
uses: actions/download-artifact@v4
with:
path: dist
merge-multiple: true

- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
files: rust_hft/dist/*.tar.gz
files: |
dist/*.tar.gz
dist/*.sha256
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pip-delete-this-directory.txt
**/*.rs.bk
*.pdb
Cargo.lock
!/rust_hft/Cargo.lock

# IDE files
.vscode/
Expand Down Expand Up @@ -126,3 +127,4 @@ AWSCLIV2.pkg
# Compiled binaries in root
/hft-collector-linux*
/hft-collector-darwin*
.omx/
15 changes: 4 additions & 11 deletions rust_hft/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,10 @@
[build]
# 開發時並行度 (根據 CPU 核數調整)
jobs = 8
# Rust 編譯快取;本地需先安裝 sccache
rustc-wrapper = "sccache"

# 針對不同平台的快速 linker
# Linux 使用 clang 驅動 mold,避免直接調用 ld 時找不到 mold。
[target.x86_64-unknown-linux-gnu]
linker = "clang"
rustflags = ["-C", "link-arg=-fuse-ld=mold"]

[target.x86_64-apple-darwin]
rustflags = ["-C", "link-arg=-fuse-ld=lld"]

# 環境變數
[env]
# sccache 快取編譯結果 (安裝: cargo install sccache)
RUSTC_WRAPPER = "sccache"
# 增量編譯
CARGO_INCREMENTAL = "1"
45 changes: 45 additions & 0 deletions rust_hft/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ on:
pull_request:
branches: [ main, master ]

env:
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: "0"
RUSTC_WRAPPER: sccache
SCCACHE_GHA_ENABLED: "true"

jobs:
build-test:
runs-on: ${{ matrix.os }}
Expand All @@ -26,10 +32,26 @@ jobs:
toolchain: ${{ matrix.toolchain }}
components: clippy, rustfmt

- name: Install Linux linker
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install -y clang mold

- name: Setup sccache
uses: mozilla-actions/sccache-action@v0.0.10

- name: Record cache dimensions
id: cache-info
shell: bash
run: |
echo "rust=$(rustc -Vv | awk '/^release:/ {print $2}')" >> "$GITHUB_OUTPUT"
echo "sccache=$(${SCCACHE_PATH:-sccache} --version | awk '{print $2}')" >> "$GITHUB_OUTPUT"

- name: Cache cargo
uses: Swatinem/rust-cache@v2
with:
key: ci-${{ matrix.os }}-${{ matrix.toolchain }}-${{ matrix.features }}-rust-${{ steps.cache-info.outputs.rust }}-sccache-${{ steps.cache-info.outputs.sccache }}-${{ hashFiles('Cargo.lock') }}
cache-all-crates: true
save-if: ${{ github.event_name != 'pull_request' }}

- name: Format (check)
run: cargo fmt --all -- --check
Expand All @@ -43,6 +65,10 @@ jobs:
- name: Test (runtime single-threaded)
run: cargo test -p hft-runtime -- --test-threads=1

- name: sccache stats
if: always()
run: ${SCCACHE_PATH:-sccache} --show-stats

smoke-quotes-only:
runs-on: ubuntu-latest
steps:
Expand All @@ -53,10 +79,25 @@ jobs:
with:
toolchain: stable

- name: Install Linux linker
run: sudo apt-get update && sudo apt-get install -y clang mold

- name: Setup sccache
uses: mozilla-actions/sccache-action@v0.0.10

- name: Record cache dimensions
id: cache-info
shell: bash
run: |
echo "rust=$(rustc -Vv | awk '/^release:/ {print $2}')" >> "$GITHUB_OUTPUT"
echo "sccache=$(${SCCACHE_PATH:-sccache} --version | awk '{print $2}')" >> "$GITHUB_OUTPUT"

- name: Cache cargo
uses: Swatinem/rust-cache@v2
with:
key: smoke-quotes-only-stable-rust-${{ steps.cache-info.outputs.rust }}-sccache-${{ steps.cache-info.outputs.sccache }}-${{ hashFiles('Cargo.lock') }}
cache-all-crates: true
save-if: ${{ github.event_name != 'pull_request' }}

- name: Build live app (binance)
run: cargo build -p hft-live --features "binance"
Expand All @@ -65,3 +106,7 @@ jobs:
env:
RUST_LOG: info
run: cargo run -p hft-live --features "binance" -- --config config/dev/binance_quotes_only.yaml --exit-after-ms 15000

- name: sccache stats
if: always()
run: ${SCCACHE_PATH:-sccache} --show-stats
Loading
Loading