Skip to content

Rust

Rust #3373

Workflow file for this run

name: Rust
on:
push:
branches: [main, release/**]
pull_request:
merge_group:
env:
RUSTFLAGS: -D warnings
defaults:
run:
shell: bash
jobs:
complete:
if: always()
needs: [fmt, check-git-rev-deps, rust-analyzer-compat, build-and-test, docs]
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@e0a440755b184aa50374330fa75cca0f84fcb59a
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
rust-analyzer-compat:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: rustup update
- run: rustup +nightly component add rust-analyzer
- name: Check if rust-analyzer encounters any errors parsing project
run: rustup run nightly rust-analyzer analysis-stats . 2>&1 | (! grep '^\[ERROR')
build-and-test:
strategy:
fail-fast: false
matrix:
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
- run: rustup update
- run: rustup target add ${{ matrix.sys.target }}
- run: rustup target add wasm32-unknown-unknown
- if: matrix.target == 'aarch64-unknown-linux-gnu'
run: sudo apt-get update && sudo apt-get -y install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
- uses: stellar/binaries@v12
with:
name: cargo-hack
version: 0.5.16
- run: cargo-hack hack build --target wasm32-unknown-unknown --profile release
- if: "!matrix.sys.cdylib-cross-compile-workaround"
run: cargo-hack hack --feature-powerset --exclude-features docs build --target ${{ matrix.sys.target }}
- if: "matrix.sys.cdylib-cross-compile-workaround"
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')
run: cargo-hack hack --feature-powerset --ignore-unknown-features --features testutils --exclude-features docs test --target ${{ matrix.sys.target }}
build-fuzz:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: stellar/actions/rust-cache@main
- run: rustup install nightly
- uses: stellar/binaries@v15
with:
name: cargo-fuzz
version: 0.11.2
- run: make build-fuzz
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: stellar/actions/rust-cache@main
- run: rustup install nightly
- run: make doc
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 }}