name: Rust
on:
push:
branches: [main]
pull_request:
merge_group:
concurrency:
group: ${{ github.workflow }}-${{ github.ref_protected == 'true' && github.sha || github.ref }}-{{ github.event_name }}
cancel-in-progress: true
jobs:
complete:
if: always()
needs: [generate, fmt, readme, prepare, build, test, fuzz-corpus, publish-dry-run-wasm32, publish-dry-run-wasm32v1, publish-dry-run-x86_64]
runs-on: ubuntu-latest
steps:
- if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
run: exit 1
generate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: true
- run: rustup update
- run: make clean generate
- shell: 'script --return --quiet --command "bash {0}"'
run: git diff --exit-code || (echo "Generated Rust code is out-of-date with the XDR .x files.\nRegenerate and test them by running 'make clean generate build test'." && exit 1)
fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: rustup update
- run: cargo fmt --all --check
readme:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: stellar/actions/rust-cache@main
- run: rustup install nightly
- run: make readme
- run: git add -N . && git diff HEAD --exit-code
prepare:
runs-on: ubuntu-latest
outputs:
feature-args: ${{ steps.gen.outputs.feature-args }}
clippy-matrix: ${{ steps.gen.outputs.clippy-matrix }}
publish-feature-args: ${{ steps.gen.outputs.publish-feature-args }}
steps:
- uses: actions/checkout@v3
- run: rustup update
- uses: stellar/binaries@v55
with:
name: cargo-hack
version: 0.6.35
- id: gen
run: |
CARGO_HACK_ARGS="$(make print-cargo-hack-args)"
feature_args="$(cargo hack test $CARGO_HACK_ARGS --print-command-list | sed 's/^cargo test //' | jq -R . | jq -sc .)"
echo "feature-args=$feature_args" >> "$GITHUB_OUTPUT"
echo "clippy-matrix=$(printf '%s' "$feature_args" | jq -c '
[{target:"wasm32v1-none", flags:"--target wasm32v1-none --no-default-features"}]
+ map({target:"x86_64-unknown-linux-gnu", flags:(. + " --target x86_64-unknown-linux-gnu --all-targets")})
')" >> "$GITHUB_OUTPUT"
echo "publish-feature-args=$(printf '%s' "$feature_args" | jq -c 'map(sub("^--manifest-path Cargo\\.toml ";""))')" >> "$GITHUB_OUTPUT"
build:
needs: prepare
strategy:
fail-fast: false
matrix:
rust: [msrv, latest]
sys: ${{ fromJSON(needs.prepare.outputs.clippy-matrix) }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: stellar/actions/rust-cache@main
- name: Use the minimum supported Rust version
if: matrix.rust == 'msrv'
run: |
msrv="$(cargo metadata --format-version 1 --no-deps | jq -r '.packages | map(.rust_version) | map(values) | min')"
rustup override set $msrv
rustup component add clippy --toolchain $msrv
- name: Error on warnings and clippy checks
if: matrix.rust == 'msrv'
run: echo RUSTFLAGS='-Dwarnings -Dclippy::all -Dclippy::pedantic' >> $GITHUB_ENV
- run: rustup update
- run: rustup target add ${{ matrix.sys.target }}
- run: cargo version
- run: cargo clippy ${{ matrix.sys.flags }}
test:
needs: prepare
strategy:
fail-fast: false
matrix:
rust: [msrv, latest]
feature-args: ${{ fromJSON(needs.prepare.outputs.feature-args) }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: stellar/actions/rust-cache@main
- name: Use the minimum supported Rust version
if: matrix.rust == 'msrv'
run: |
msrv="$(cargo metadata --format-version 1 --no-deps | jq -r '.packages | map(.rust_version) | map(values) | min')"
rustup override set $msrv
- name: Error on warnings and clippy checks
if: matrix.rust == 'msrv'
run: echo RUSTFLAGS='-Dwarnings -Dclippy::all -Dclippy::pedantic' >> $GITHUB_ENV
- name: Reduce test debug info on the msrv to keep linking within memory
if: matrix.rust == 'msrv'
run: echo CARGO_PROFILE_TEST_DEBUG=0 >> $GITHUB_ENV
- run: rustup update
- run: cargo version
- run: cargo test ${{ matrix.feature-args }}
fuzz-corpus:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: stellar/actions/rust-cache@main
- uses: stellar/binaries@v55
with:
name: cargo-fuzz
version: 0.13.1
- run: rustup install nightly
- run: rustup default nightly
- name: Run fuzz corpus
run: make fuzz
- name: Check no diffs exist
run: git add -N . && git diff HEAD --exit-code
publish-dry-run-wasm32:
if: github.event_name == 'push' || startsWith(github.head_ref, 'release/')
uses: stellar/actions/.github/workflows/rust-publish-dry-run-v2.yml@main
with:
runs-on: ubuntu-latest
target: wasm32-unknown-unknown
cargo-hack-feature-options: ''
cargo-hack-package-options: --each-feature --exclude-features cli,rand --manifest-path Cargo.toml
publish-dry-run-wasm32v1:
if: github.event_name == 'push' || startsWith(github.head_ref, 'release/')
uses: stellar/actions/.github/workflows/rust-publish-dry-run-v2.yml@main
with:
runs-on: ubuntu-latest
target: wasm32v1-none
cargo-hack-feature-options: ''
cargo-hack-package-options: --each-feature --exclude-features default,cli,rand,schemars,serde,alloc,arbitrary,base64,hex,serde_json,std,serde_ignored --manifest-path Cargo.toml
publish-dry-run-x86_64:
if: github.event_name == 'push' || startsWith(github.head_ref, 'release/')
needs: prepare
strategy:
fail-fast: false
matrix:
feature-args: ${{ fromJSON(needs.prepare.outputs.publish-feature-args) }}
uses: stellar/actions/.github/workflows/rust-publish-dry-run-v2.yml@main
with:
runs-on: ubuntu-latest
target: x86_64-unknown-linux-gnu
cargo-hack-feature-options: ''
cargo-hack-package-options: ${{ matrix.feature-args }}