Skip to content

Rust

Rust #4458

Workflow file for this run

name: Rust
on:
push:
branches: [main, release/**]
pull_request:
merge_group:
concurrency:
group: ${{ github.workflow }}-${{ github.ref_protected == 'true' && github.sha || github.ref }}-{{ github.event_name }}
cancel-in-progress: true
defaults:
run:
shell: bash
jobs:
complete:
if: always()
needs: [fmt, check-git-rev-deps, semver-checks, build-and-test, docs, readme]
runs-on: ubuntu-latest
steps:
- if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
run: exit 1
fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: rustup update
- run: cargo fmt --all --check
cargo-deny:
runs-on: ubuntu-latest
strategy:
matrix:
checks:
- advisories
- bans licenses sources
# Prevent sudden announcement of a new advisory from failing ci:
continue-on-error: ${{ matrix.checks == 'advisories' }}
steps:
- uses: actions/checkout@v3
- uses: EmbarkStudios/cargo-deny-action@b01e7a8cfb1f496c52d77361e84c1840d8246393
with:
command: check ${{ matrix.checks }}
check-git-rev-deps:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: stellar/actions/rust-check-git-rev-deps@main
semver-checks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: rustup update
- uses: stellar/binaries@v30
with:
name: cargo-semver-checks
version: 0.35.0
- run: cargo semver-checks
build-and-test:
strategy:
fail-fast: false
matrix:
rust: [msrv, latest]
sys:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
- os: ubuntu-latest
target: aarch64-unknown-linux-gnu
# Fix #1011 by avoiding the use of crate-type = ["cdylib"] in native
# builds that cross-compile. It causes linker errors. The root cause
# is rust-lang/cargo#4133. This workaround uses rustc to build for a
# specific crate-type, lib, such that the Cargo.toml crate-type is
# ignored.
cdylib-cross-compile-workaround: true
# - os: macos-latest
# target: x86_64-apple-darwin
# - os: macos-latest
# target: aarch64-apple-darwin
- os: windows-latest
target: x86_64-pc-windows-msvc
runs-on: ${{ matrix.sys.os }}
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
# Only error on warnings and checks for the msrv, because new versions of
# Rust will frequently add new warnings and checks.
if: matrix.rust == 'msrv'
run: echo RUSTFLAGS='-Dwarnings' >> $GITHUB_ENV
- run: rustup update
- run: cargo version
- run: rustup target add ${{ matrix.sys.target }}
- run: rustup target add wasm32-unknown-unknown
- uses: stellar/binaries@v18
with:
name: cargo-hack
version: 0.5.28
- if: startsWith(matrix.sys.target, 'x86_64')
name: Clear test snapshots for checking no diffs exists after test run
run: rm -fr **/test_snapshots
- name: Build for wasm
run: cargo-hack hack build --target wasm32-unknown-unknown --profile release
- name: Wasm Size
run: |
cd target/wasm32-unknown-unknown/release/ && \
for i in *.wasm ; do \
ls -l "$i"; \
done
- if: "!matrix.sys.cdylib-cross-compile-workaround"
name: Build for native
run: cargo-hack hack --feature-powerset --exclude-features docs build --target ${{ matrix.sys.target }}
- if: "matrix.sys.cdylib-cross-compile-workaround"
name: Build for native
run: cargo-hack hack --feature-powerset --exclude-features docs rustc --workspace --exclude soroban-sdk-macros --crate-type lib --target ${{ matrix.sys.target }}
- if: startsWith(matrix.sys.target, 'x86_64')
name: Run tests
run: cargo-hack hack --feature-powerset --ignore-unknown-features --features testutils --exclude-features docs test --target ${{ matrix.sys.target }}
- if: startsWith(matrix.sys.target, 'x86_64')
name: Check no diffs exist
run: git add -N . && git diff HEAD --exit-code
build-fuzz:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: stellar/actions/rust-cache@main
# TODO: Unpin nightly version after https://github.com/rust-lang/rust/issues/131643 is fixed.
- run: rustup install nightly-2024-10-10
- uses: stellar/binaries@v15
with:
name: cargo-fuzz
version: 0.11.2
- run: make build-fuzz
- name: Check no diffs exist
run: git add -N . && git diff HEAD --exit-code
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: stellar/actions/rust-cache@main
# TODO: Unpin nightly version after https://github.com/rust-lang/rust/issues/131643 is fixed.
- run: rustup install nightly-2024-10-10
- run: make doc
- name: Check no diffs exist
run: git add -N . && git diff HEAD --exit-code
readme:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: stellar/actions/rust-cache@main
# TODO: Unpin nightly version after https://github.com/rust-lang/rust/issues/131643 is fixed.
- run: rustup install nightly-2024-10-10
- run: make readme
- run: git add -N . && git diff HEAD --exit-code
publish-dry-run:
if: github.event_name == 'push' || startsWith(github.head_ref, 'release/')
strategy:
matrix:
sys:
- os: ubuntu-latest
target: wasm32-unknown-unknown
cargo-hack-feature-options: ''
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
cargo-hack-feature-options: '--feature-powerset --exclude-features docs'
uses: stellar/actions/.github/workflows/rust-publish-dry-run.yml@main
with:
runs-on: ${{ matrix.sys.os }}
target: ${{ matrix.sys.target }}
cargo-hack-feature-options: ${{ matrix.sys.cargo-hack-feature-options }}