Files
leaf/.github/workflows/ci.yml
T
ericandClaude Opus 5.5 488ff345f3 feat(plugins): download the plugins a config names by url
A plugin outbound can now give a url instead of a path. With the new
plugin-fetch feature, a start downloads what the cache is missing into
<cache>/<sha256>/<file> before any outbound is built, and points the
outbounds at it; a reload, and testing an outbound, resolve from the cache
only and refuse what they would have to download.

- https only, redirects included, and only together with a sha256 pin.
- Downloads go to a temporary file, are hashed as they arrive, and are
  renamed into place only once the digest matches, under the url's own
  name, with the platform's library suffix added when it has no
  extension, which is what Windows needs to load it. A download past the
  declared size, or past 64 MiB without one, is stopped.
- The cache directory comes from FetchOptions or PLUGIN_CACHE_DIR, with
  no default: whether a directory is safe to load code from is the
  embedding app's call.
- prefetch() reports QUEUED/CACHED for every plugin before any download,
  then STARTED, PROGRESS (at most every 100 ms) and exactly one DONE or
  FAILED each, on the calling thread; the callback can cancel. A download
  that has not finished gets a PROGRESS heartbeat at least once a second,
  before STARTED too, so that one stuck connecting or in the handshake
  can be cancelled as well as one stuck mid-body.

conf gains a [Plugin] section that declares each plugin once (path, url,
sha256, size) and a `plugin` proxy protocol that refers to it by name,
with args= or args-b64= for arguments that contain commas. Proxy
parameters are now split at the first `=` only, which used to drop any
value that contained one.

leaf-ffi gains leaf_prefetch_plugins, so that an app can download the
plugins as soon as it has the config, and show progress, and the start
that follows finds everything in the cache. Events arrive as a
LeafFetchEvent whose first field is its size, on the calling thread and
never after the call returns. Adds ERR_PLUGIN_FETCH, ERR_CANCELLED and
ERR_UNSUPPORTED, and the plugin and plugin-fetch features. It is tested
by unit tests rather than end to end: the library is a Rust dylib, which
does not link in a Windows debug build (LNK1189).

Twenty-three fetch/ e2e cases download from a per-case https server
whose routes can announce a wrong length, omit it, fail, redirect, or
hold a body at a gate until the case opens it. Every case checks its
events against one statement of the progress contract, and every
failure, cancel and timeout case checks that the cache is left empty.
One checks that testing an outbound reads the cache, including a file
put there by hand, and never downloads.

The READMEs describe plugins in conf files and downloading them, and
plugin-test and CI run the new unit tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 22:26:22 +08:00

412 lines
13 KiB
YAML

name: ci
on:
push:
pull_request:
# For the Windows lane below, which is not part of the automatic run.
workflow_dispatch:
jobs:
test:
strategy:
matrix:
os:
- macos-latest
- ubuntu-latest
# - windows-latest
runs-on: ${{ matrix.os }}
steps:
- name: checkout
uses: actions/checkout@v4
with:
submodules: true
- name: install rust toolchain
uses: hecrj/setup-rust-action@v1
with:
rust-version: stable
- name: test leaf
run: cargo test -p leaf
plugin-e2e:
strategy:
fail-fast: false
matrix:
os:
- macos-latest
- ubuntu-latest
runs-on: ${{ matrix.os }}
env:
# CI runners are several times slower than a developer machine, and the
# per-case deadlines are tuned for the latter.
LEAF_E2E_TIMEOUT_SCALE: 4
# The loads run here, at a quarter of their concurrency and duration.
# Enough to put many connections through the host at once, which is where
# the defects a single connection cannot reach live; not enough to turn a
# pull request into a ten-minute wait.
LEAF_E2E_STRESS_SCALE: 0.25
steps:
- name: checkout
uses: actions/checkout@v4
with:
submodules: true
- name: install rust toolchain
uses: hecrj/setup-rust-action@v1
with:
rust-version: stable
- name: install go toolchain
uses: actions/setup-go@v5
with:
go-version: stable
# The C compiler comes with the runner; Zig does not. Both are required
# rather than optional, because `--strict` treats a missing one as a
# failure and a plugin nobody builds is a plugin nobody tests.
- name: install zig toolchain
uses: mlugg/setup-zig@v2
with:
version: 0.16.0
# `--strict` fails the job if a case is skipped, so a missing toolchain
# cannot turn into a green run that tested nothing.
- name: plugin end-to-end tests
run: cargo test -p leaf-e2e --test e2e -- --strict --no-tag soak
# What an end-to-end run cannot reach: the host's own tests for the
# loader and the stream and datagram wrappers, and each plugin's tests --
# a descriptor that lies about its size, a handshake arriving a byte at a
# time, every way a peer can refuse.
- name: plugin and host unit tests
run: make plugin-test
# Nothing else builds the CLI with plugin support, so nothing else would
# notice if it stopped compiling. A check rather than an artifact: the
# released Linux binaries are statically linked against musl, which has
# no dynamic loader to call, so shipping them with this feature on would
# promise something they cannot do.
- name: cli builds with plugin support
run: cargo check -p leaf-cli --features leaf/plugin
- name: upload failure artifacts
if: failure()
uses: actions/upload-artifact@v4
with:
name: e2e-artifacts-${{ matrix.os }}
path: target/debug/e2e-artifacts/
if-no-files-found: ignore
# The hostile lane deliberately loads plugins that lie to the host about how
# much they consumed, produced and can be asked for. The host's answer to
# that is bounds checks and clamps, which is exactly the kind of code a
# sanitizer is for. Go is left out: cgo under ASan is its own project.
plugin-e2e-asan:
runs-on: ubuntu-latest
env:
LEAF_E2E_TIMEOUT_SCALE: 8
# Instrumented and slower still, so the loads run smaller here. The
# hostile lane includes the two loads that drive a misbehaving plugin
# across connections that keep being created and destroyed, which is
# where a context released too early becomes a use-after-free.
LEAF_E2E_STRESS_SCALE: 0.25
# `--export-dynamic` is not optional here. rustc links the sanitizer
# runtime statically into the executable and, unlike clang's driver,
# passes nothing to export it, so the `__asan_*` symbols end up in the
# binary but not in its dynamic symbol table. A plugin is a `dlopen`ed
# shared object built with the same instrumentation and no runtime of its
# own: without this it fails to load with `undefined symbol:
# __asan_option_detect_stack_use_after_return`, and every case in the
# lane fails for a reason that sounds like the plugin's fault.
RUSTFLAGS: -Zsanitizer=address -C link-arg=-Wl,--export-dynamic
# Memory errors are the point here. Leaks are not: a proxy holds plenty
# of process-lifetime state on purpose, and a plugin host keeps libraries
# mapped for as long as it runs.
ASAN_OPTIONS: detect_leaks=0
steps:
- name: checkout
uses: actions/checkout@v4
with:
submodules: true
- name: install rust nightly
uses: hecrj/setup-rust-action@v1
with:
rust-version: nightly
# An explicit --target keeps build scripts and proc macros out of the
# instrumented build. The harness notices the nested layout that produces
# and builds its plugins the same way.
- name: hostile plugins under address sanitizer
run: |
cargo test -p leaf-e2e --test e2e \
--target x86_64-unknown-linux-gnu \
-- --strict --tag hostile
- name: upload failure artifacts
if: failure()
uses: actions/upload-artifact@v4
with:
name: e2e-artifacts-asan
path: target/x86_64-unknown-linux-gnu/debug/e2e-artifacts/
if-no-files-found: ignore
# Windows is not in the automatic run, but it is not unknown either: the
# suite has been through it green on `aarch64-pc-windows-msvc`. What has not
# been tried is this runner -- `windows-latest` is x86-64, and the toolchain
# notes in leaf-e2e/README.md are written from the ARM64 run, where the C and
# cgo compilers are not the ones cargo's own dependencies want. Start it by
# hand from the Actions tab -- "Run workflow" on this file -- and move it into
# the matrix above once it is green here too.
#
# The two black-box cases that interrupt a running leaf are not registered on
# Windows; everything else in the suite is.
plugin-e2e-windows:
if: github.event_name == 'workflow_dispatch'
runs-on: windows-latest
env:
LEAF_E2E_TIMEOUT_SCALE: 4
LEAF_E2E_STRESS_SCALE: 0.25
steps:
- name: checkout
uses: actions/checkout@v4
with:
submodules: true
- name: install rust toolchain
uses: hecrj/setup-rust-action@v1
with:
rust-version: stable
- name: install go toolchain
uses: actions/setup-go@v5
with:
go-version: stable
- name: install zig toolchain
uses: mlugg/setup-zig@v2
with:
version: 0.16.0
# The runner ships MSYS2 but does not put its GCC on PATH. The C plugin
# is built with GCC-style flags and cgo needs a C compiler, so both want
# this one. Adjust the path if the runner image moves it.
- name: put mingw-w64 gcc on PATH
run: echo "C:\msys64\mingw64\bin" >> $env:GITHUB_PATH
- name: show the toolchains
run: |
gcc --version
go version
zig version
- name: plugin end-to-end tests
run: cargo test -p leaf-e2e --test e2e -- --strict --no-tag soak
- name: plugin and host unit tests
run: |
cargo test -p leaf --features plugin --lib
cargo test -p leaf --features plugin-fetch --lib
cargo test -p leaf-ffi --lib --features plugin-fetch
cargo test -p leaf-plugin-abi
cargo test -p tls-cabi-rs -p shadowsocks-cabi-rs
- name: cli builds with plugin support
run: cargo check -p leaf-cli --features leaf/plugin
- name: upload failure artifacts
if: failure()
uses: actions/upload-artifact@v4
with:
name: e2e-artifacts-windows
path: target/debug/e2e-artifacts/
if-no-files-found: ignore
build-cli-cross:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
target:
- x86_64-unknown-linux-musl
- i686-unknown-linux-musl
- aarch64-unknown-linux-musl
- arm-unknown-linux-musleabi
- armv7-unknown-linux-musleabihf
- x86_64-pc-windows-gnu
steps:
- name: checkout
uses: actions/checkout@v4
with:
submodules: true
- name: install rust toolchain
uses: hecrj/setup-rust-action@v1
with:
rust-version: stable
- name: install deps
run: |
sudo apt update && sudo apt install llvm-dev libclang-dev clang libssl-dev pkg-config protobuf-compiler make -y
- name: install cross
run: |
cargo install cross
- name: build
run: |
export CFG_COMMIT_HASH=`git log --pretty=format:'%h' -n 1`
export CFG_COMMIT_DATE=`git log --format="%ci" -n 1`
cross build --release --target ${{ matrix.target }}
- name: rename and compress artifacts
if: ${{ matrix.target == 'x86_64-pc-windows-gnu' }}
run: |
mv target/${{ matrix.target }}/release/leaf.exe leaf-${{ matrix.target }}.exe
- name: rename and compress artifacts
if: ${{ matrix.target != 'x86_64-pc-windows-gnu' }}
run: |
mv target/${{ matrix.target }}/release/leaf leaf-${{ matrix.target }}
- name: upload assets
if: ${{ matrix.target == 'x86_64-pc-windows-gnu' }}
uses: actions/upload-artifact@v4
with:
name: leaf-${{ matrix.target }}.exe
path: leaf-${{ matrix.target }}.exe
- name: upload assets
if: ${{ matrix.target != 'x86_64-pc-windows-gnu' }}
uses: actions/upload-artifact@v4
with:
name: leaf-${{ matrix.target }}
path: leaf-${{ matrix.target }}
build-cli-macos:
runs-on: [macos-latest]
strategy:
fail-fast: false
matrix:
target:
- aarch64-apple-darwin
- x86_64-apple-darwin
steps:
- name: checkout
uses: actions/checkout@v4
with:
submodules: true
- name: show last commit
run: |
git show --summary
- name: install rust toolchain
uses: hecrj/setup-rust-action@v1
with:
rust-version: stable
- name: install llvm
if: ${{ matrix.os == 'macos-latest' }}
run: |
brew install llvm protobuf
- name: install target
run: |
rustup target add ${{ matrix.target }}
- name: build
run: |
export CFG_COMMIT_HASH=`git log --pretty=format:'%h' -n 1`
export CFG_COMMIT_DATE=`git log --format="%ci" -n 1`
cargo build --release --target ${{ matrix.target }} -p leaf-cli
- name: rename and compress artifacts
run: |
mv target/${{ matrix.target }}/release/leaf leaf-${{ matrix.target }}
- name: upload assets
uses: actions/upload-artifact@v4
with:
name: leaf-${{ matrix.target }}
path: leaf-${{ matrix.target }}
build-lib-apple:
runs-on: macos-latest
steps:
- name: checkout
uses: actions/checkout@v4
with:
submodules: true
- name: install rust
uses: hecrj/setup-rust-action@v1
with:
rust-version: stable
- name: install toolchain
run: |
cargo install cbindgen
brew install llvm unzip protobuf
- name: build
run: |
./scripts/build_apple_xcframework.sh
- name: zip artifacts
run: |
mv target/apple/release/leaf.xcframework .
zip -r leaf.xcframework.zip leaf.xcframework
- name: upload assets
uses: actions/upload-artifact@v4
with:
name: leaf.xcframework.zip
path: leaf.xcframework.zip
build-lib-android:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
with:
submodules: true
- name: install rust
uses: hecrj/setup-rust-action@v1
with:
rust-version: stable
- name: install toolchain
run: |
cargo install cbindgen
apt update && apt install -y make llvm-dev libclang-dev clang pkg-config unzip curl default-jdk build-essential
export ANDROID_HOME=/tmp/Android/sdk
export NDK_HOME=/tmp/Android/sdk/ndk/25.2.9519653
export PATH=$ANDROID_HOME/cmdline-tools/bin:$PATH
cd /tmp/
curl -OL https://dl.google.com/android/repository/commandlinetools-linux-6858069_latest.zip
unzip commandlinetools-linux-6858069_latest.zip
mkdir -p $ANDROID_HOME
mv cmdline-tools $ANDROID_HOME
yes | sdkmanager --sdk_root=$ANDROID_HOME --licenses
sdkmanager --sdk_root=$ANDROID_HOME "ndk;25.2.9519653" "platforms;android-21"
- name: build
run: |
export ANDROID_HOME=/tmp/Android/sdk
export NDK_HOME=/tmp/Android/sdk/ndk/25.2.9519653
./scripts/build_android.sh
- name: zip artifacts
run: |
mv target/leaf-android-libs .
zip -r leaf-android-libs.zip leaf-android-libs
- name: upload assets
uses: actions/upload-artifact@v4
with:
name: leaf-android-libs.zip
path: leaf-android-libs.zip