From 6be4a4a48de731f069b5629b9d4a47f4df3a12e8 Mon Sep 17 00:00:00 2001 From: Guilherme Silva <626206+guihkx@users.noreply.github.com> Date: Sun, 13 Nov 2022 15:48:40 -0300 Subject: [PATCH] CI improvements + Android and FreeBSD targets (#177) * Bump minimum Rust version to 1.60 As required by the `time` crate (`notify-rust` > `mac-notification-sys` > `time`). * Simplify CI Changes: - Bump `actions/checkout` to v3, fixing a bunch of warnings. - Replace unmaintained `actions-rs/cargo` by `dtolnay/rust-toolchain`. - Run Rustfmt only once. - Add support for cached dependencies (via `Swatinem/rust-cache`). * Add Android target Use the awesome `cross` tool for cross-compiling! * Add FreeBSD target --- .github/workflows/check-and-lint.yaml | 120 +++++++++++++++----------- Cross.toml | 4 + README.md | 2 +- 3 files changed, 73 insertions(+), 53 deletions(-) create mode 100644 Cross.toml diff --git a/.github/workflows/check-and-lint.yaml b/.github/workflows/check-and-lint.yaml index dd48dfb8..c12c0cd8 100644 --- a/.github/workflows/check-and-lint.yaml +++ b/.github/workflows/check-and-lint.yaml @@ -4,67 +4,83 @@ on: branches: - main +name: CI -name: Check and Lint +env: + RUST_VER: '1.60.0' + CROSS_VER: '0.2.4' + CARGO_NET_RETRY: 3 jobs: - check: - name: Check - strategy: - matrix: - platform: [ ubuntu-latest, macos-latest, windows-latest ] - runs-on: ${{ matrix.platform }} - steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - uses: actions-rs/cargo@v1 - with: - command: check - args: --color always - fmt: name: Rustfmt - strategy: - matrix: - platform: [ ubuntu-latest, macos-latest, windows-latest ] - runs-on: ${{ matrix.platform }} + runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - - run: rustup component add rustfmt - - uses: actions-rs/cargo@v1 - with: - command: fmt - args: --all -- --check --color always + - name: Checkout code + uses: actions/checkout@v3 - clippy: - name: Clippy + - name: Setup Rust + uses: dtolnay/rust-toolchain@master + with: + toolchain: '${{ env.RUST_VER }}' + targets: ${{ matrix.target }} + components: clippy, rustfmt + + - name: Run cargo fmt + run: | + cargo fmt --all -- --check + + main: + needs: fmt + name: ${{ matrix.target_name }} (check, clippy) + runs-on: ${{ matrix.os }} strategy: + fail-fast: false matrix: - platform: [ ubuntu-latest, macos-latest, windows-latest ] - runs-on: ${{ matrix.platform }} + include: + - target: x86_64-linux-android + target_name: Android + use_cross: true + os: ubuntu-20.04 + + - target: x86_64-unknown-freebsd + target_name: FreeBSD + use_cross: true + os: ubuntu-20.04 + + - target: x86_64-unknown-linux-gnu + target_name: Linux + os: ubuntu-20.04 + + - target: x86_64-apple-darwin + target_name: macOS + os: macos-11 + + - target: x86_64-pc-windows-msvc + target_name: Windows + os: windows-2019 steps: - - uses: actions/checkout@v2 - - uses: actions-rs/toolchain@v1 + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup Rust + uses: dtolnay/rust-toolchain@master with: - toolchain: stable - components: clippy - override: true - - uses: actions-rs/cargo@v1.0.1 + toolchain: '${{ env.RUST_VER }}' + targets: ${{ matrix.target }} + components: clippy, rustfmt + + - name: Setup Rust Cache + uses: Swatinem/rust-cache@v2 with: - command: clippy - args: --color always --all-targets --locked -- -D warnings - name: Clippy Output - - uses: actions-rs/cargo@v1.0.1 - with: - command: clippy - args: --color always --all-targets --locked --all-features -- -D warnings - name: Clippy (All features) Output + prefix-key: ${{ matrix.target }} + + - name: Setup cross + if: matrix.use_cross == true + run: curl -fL --retry 3 https://github.com/cross-rs/cross/releases/download/v${{ env.CROSS_VER }}/cross-x86_64-unknown-linux-musl.tar.gz | tar vxz -C /usr/local/bin + + - name: Run cargo check + run: ${{ matrix.use_cross == true && 'cross' || 'cargo' }} check --locked --target ${{ matrix.target }} + + - name: Run cargo clippy + run: ${{ matrix.use_cross == true && 'cross' || 'cargo' }} clippy --locked --target ${{ matrix.target }} --all-features -- -D warnings diff --git a/Cross.toml b/Cross.toml new file mode 100644 index 00000000..33be5cdd --- /dev/null +++ b/Cross.toml @@ -0,0 +1,4 @@ +# Workaround for: https://github.com/cross-rs/cross/issues/1100 +# TODO: Remove this file altogether once a new version of cross (after v0.2.4) is released. +[target.x86_64-unknown-freebsd.env] +passthrough = ["AR_x86_64_unknown_freebsd=x86_64-unknown-freebsd12-ar"] diff --git a/README.md b/README.md index aa5bedf1..db8f5cfe 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ To remedy this, **Topgrade** detects which tools you use and runs the appropriat Other systems users can either use `cargo install` or the compiled binaries from the release page. The compiled binaries contain a self-upgrading feature. -Topgrade requires Rust 1.51 or above. +Topgrade requires Rust 1.60 or above. ## Usage