Skip to content

Commit

Permalink
feat!: change way MSRV is handled, use cargo-msrv-prep
Browse files Browse the repository at this point in the history
  • Loading branch information
clechasseur committed Mar 2, 2024
1 parent dfe3642 commit 3a5217f
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 51 deletions.
16 changes: 0 additions & 16 deletions .github/workflows/audit-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,3 @@ jobs:
uses: clechasseur/rustsec-audit-check@b5ade62a8d38826bb50ca4b8b9bc2a8a97f0d44d
with:
token: ${{ secrets.GITHUB_TOKEN }}

- name: Check if we need to audit MSRV manifest
id: check_msrv_manifest
uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6
with:
files: "Cargo.toml.msrv"

- name: Install MSRV manifest
if: ${{ steps.check_msrv_manifest.outputs.files_exists == 'true' }}
run: cp Cargo.toml.msrv Cargo.toml

- name: Run security audit for MSRV manifest
if: ${{ steps.check_msrv_manifest.outputs.files_exists == 'true' }}
uses: clechasseur/rustsec-audit-check@b5ade62a8d38826bb50ca4b8b9bc2a8a97f0d44d
with:
token: ${{ secrets.GITHUB_TOKEN }}
13 changes: 8 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ jobs:
- name: Rust Cache
uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84
with:
prefix-key: v4-rust
key: all-features-${{ matrix.all-features }}-msrv-cargo-files-${{ hashFiles('**/Cargo.*.msrv') }}
prefix-key: v5-rust
key: all-features-${{ matrix.all-features }}-msrv-pins-files-${{ hashFiles('**/msrv-pins.toml') }}

- name: Install just, cargo-hack and cargo-minimal-versions
- name: Install required tools
uses: taiki-e/install-action@b7add58e53e52e624966da65007ce24524f3dcf3
with:
tool: just,cargo-hack,cargo-minimal-versions
tool: just,cargo-hack,cargo-minimal-versions,cargo-msrv-prep

- name: Run checks using cargo-minimal-versions
run: just all_features=${{ matrix.all-features }} check-minimal
Expand Down Expand Up @@ -140,6 +140,9 @@ jobs:
run: just all_features=${{ matrix.all-features }} test

tarpaulin:
# Note: there seems to be an issue in `cargo-tarpaulin` when using Rust 1.75.0 or later - it reports some missing line coverage.
# I've entered an issue: https://github.com/xd009642/tarpaulin/issues/1438
# In the meantime, let's pin the Rust version used for code coverage to 1.74.1 until we know what's happening.
name: Code coverage
runs-on: ubuntu-latest
steps:
Expand All @@ -149,7 +152,7 @@ jobs:
- name: Install Rust
uses: actions-rust-lang/setup-rust-toolchain@b113a30d27a8e59c969077c0a0168cc13dab5ffc
with:
toolchain: stable
toolchain: 1.74.1
cache: false

- name: Rust Cache
Expand Down
68 changes: 68 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Release

on:
# TODO re-enable once project is set up properly if you have bins to publish, otherwise remove the workflow
#release:
# types: [created]
workflow_dispatch:

jobs:
build-release-files:
name: Build release files for ${{ matrix.arch }}-${{ matrix.platform }} with Rust ${{ matrix.toolchain }}
if: github.repository_owner == 'clechasseur' # Don't build on forks # TODO replace with your GitHub username
strategy:
matrix:
toolchain: [ stable ]
arch: [ aarch64, x86_64 ]
platform: [ unknown-linux-gnu, unknown-linux-musl, unknown-freebsd, apple-darwin, pc-windows-msvc ]
include:
- os: ubuntu-latest
- platform: apple-darwin
os: macos-latest
- platform: pc-windows-msvc
os: windows-latest
- crt-static: false
- link-self-contained: false
- platform: pc-windows-msvc
crt-static: true
- platform: unknown-linux-musl
crt-static: true
link-self-contained: true
exclude:
- arch: aarch64
platform: unknown-freebsd
runs-on: ${{ matrix.os }}
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11

- name: Install Rust toolchain ${{ matrix.toolchain }}
uses: actions-rust-lang/setup-rust-toolchain@b113a30d27a8e59c969077c0a0168cc13dab5ffc
with:
toolchain: ${{ matrix.toolchain }}
cache: false

- name: Setup cross-compilation tools
uses: taiki-e/setup-cross-toolchain-action@c31d54d08f2ab1b6c35447b32b3f0dcb829a5b4f
with:
target: ${{ matrix.arch }}-${{ matrix.platform }}

- name: Set flag to link crt-static
run: echo "RUSTFLAGS=${RUSTFLAGS} -C target-feature=+crt-static" >> ${GITHUB_ENV}
if: ${{ matrix.crt-static }}

- name: Set flag to link self-contained
run: echo "RUSTFLAGS=${RUSTFLAGS} -C link-self-contained=yes" >> ${GITHUB_ENV}
if: ${{ matrix.link-self-contained }}

- name: Build binaries and upload to GitHub release
uses: taiki-e/upload-rust-binary-action@aefa20ac5893ee9a660dd3e995c9dc9a715e93f0
with:
bin: YOUR-BINS-HERE # TODO replace this with a comma-separated list of bins to publish
token: ${{ secrets.GITHUB_TOKEN }}
archive: $bin-$target-$tag # TODO if you have mulitiple bins, replace $bin here
target: ${{ matrix.arch }}-${{ matrix.platform }}
include: LICENSE,README.md
leading-dir: true
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ target*/
**/*.rs.bk

# Files that exist while we run `cargo minimal-versions`/`cargo msrv`
Cargo.toml.bak*
Cargo.lock.bak*
*.msrv-prep*.bak

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb
Expand Down
80 changes: 52 additions & 28 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,68 +18,92 @@ all_targets_flag := if all_targets == "true" { "--all-targets" } else { "" }
message_format := ""
message_format_flag := if message_format != "" { "--message-format " + message_format } else { "" }

[private]
default:
@just --list

# Run clippy and rustfmt on workspace files
tidy: clippy fmt

# Run clippy on workspace files
clippy:
{{cargo}} clippy --workspace {{all_targets_flag}} {{all_features_flag}} -- -D warnings

# Run rustfmt on workspace files
fmt:
cargo +nightly fmt --all

# Run `cargo check` on workspace
check *extra_args:
{{cargo}} check --workspace {{all_targets_flag}} {{all_features_flag}} {{message_format_flag}} {{extra_args}}

# Run `cargo build` on workspace
build *extra_args:
{{cargo}} build --workspace {{all_targets_flag}} {{all_features_flag}} {{message_format_flag}} {{extra_args}}

# Run `cargo test` on workspace
test *extra_args:
{{cargo}} test --workspace {{all_features_flag}} {{message_format_flag}} {{extra_args}}

# Run `cargo update` to update dependencies in Cargo.lock
update *extra_args:
{{cargo}} update {{extra_args}}

tarpaulin *extra_args:
{{cargo}} tarpaulin --target-dir target-tarpaulin {{extra_args}}
{{ if env('CI', '') == '' { `open tarpaulin-report.html` } else { ` ` } }}
# Run `cargo tarpaulin` to produce code coverage
@tarpaulin *extra_args:
# Note: there seems to be an issue in `cargo-tarpaulin` when using Rust 1.75.0 or later - it reports some missing line coverage.
# I've entered an issue: https://github.com/xd009642/tarpaulin/issues/1438
# In the meantime, let's pin the Rust version used for code coverage to 1.74.1 until we know what's happening.
@cargo +1.74.1 tarpaulin --target-dir target-tarpaulin {{extra_args}}
{{ if env('CI', '') == '' { `just _open-tarpaulin` } else { ` ` } }}

doc $RUSTDOCFLAGS="-D warnings":
{{cargo}} doc {{ if env('CI', '') != '' { '--no-deps' } else { '--open' } }} --workspace {{all_features_flag}} {{message_format_flag}}
[unix]
@_open-tarpaulin:
open tarpaulin-report.html

doc-coverage $RUSTDOCFLAGS="-Z unstable-options --show-coverage":
cargo +nightly doc --no-deps --workspace {{all_features_flag}} {{message_format_flag}}
[windows]
@_open-tarpaulin:
./tarpaulin-report.html

backup-manifest manifest_bak="Cargo.toml.bak" lockfile_bak="Cargo.lock.bak":
{{ if path_exists(manifest_bak) == "true" { "rm " + manifest_bak } else { "" } }}
{{ if path_exists(lockfile_bak) == "true" { "rm " + lockfile_bak } else { "" } }}
{{ if path_exists("Cargo.toml") == "true" { "mv Cargo.toml " + manifest_bak } else { "" } }}
{{ if path_exists("Cargo.lock") == "true" { "mv Cargo.lock " + lockfile_bak } else { "" } }}
# Generate documentation with rustdoc
doc: _doc

restore-manifest manifest_bak="Cargo.toml.bak" lockfile_bak="Cargo.lock.bak":
{{ if path_exists("Cargo.toml") == "true" { "rm Cargo.toml" } else { "" } }}
{{ if path_exists("Cargo.lock") == "true" { "rm Cargo.lock" } else { "" } }}
{{ if path_exists(manifest_bak) == "true" { "mv " + manifest_bak + " Cargo.toml" } else { "" } }}
{{ if path_exists(lockfile_bak) == "true" { "mv " + lockfile_bak + " Cargo.lock" } else { "" } }}
_doc $RUSTDOCFLAGS="-D warnings":
{{cargo}} doc {{ if env('CI', '') != '' { '--no-deps' } else { '--open' } }} --workspace {{all_features_flag}} {{message_format_flag}}

apply-msrv:
cp Cargo.toml.msrv Cargo.toml
# Check doc coverage with Nightly rustdoc
doc-coverage: _doc-coverage

save-msrv:
cp Cargo.toml Cargo.toml.msrv
_doc-coverage $RUSTDOCFLAGS="-Z unstable-options --show-coverage":
cargo +nightly doc --no-deps --workspace {{all_features_flag}} {{message_format_flag}}

[private]
minimize:
cargo hack --remove-dev-deps --workspace
{{cargo}} hack --remove-dev-deps --workspace
cargo +nightly update -Z minimal-versions

check-minimal-only:
# Run `cargo minimal-versions check` on workspace
check-minimal: prep _check-minimal-only unprep

_check-minimal-only:
{{cargo}} minimal-versions check --workspace --lib --bins {{all_features_flag}} {{message_format_flag}}

check-minimal: backup-manifest apply-msrv check-minimal-only restore-manifest
# Run `cargo msrv` with `cargo minimal-versions check`
msrv-minimal: (prep "--manifest-backup-suffix .msrv-prep.outer.bak") && (unprep "--manifest-backup-suffix .msrv-prep.outer.bak")
{{cargo}} msrv -- just _check-minimal-only

# Run `cargo msrv` with `cargo check`
msrv *extra_args:
{{cargo}} msrv -- just check {{extra_args}}

# Perform `cargo publish` dry-run
test-package *extra_args:
{{cargo}} publish --dry-run {{extra_args}}

msrv: (backup-manifest "Cargo.toml.bak.msrv" "Cargo.lock.bak.msrv") apply-msrv && (restore-manifest "Cargo.toml.bak.msrv" "Cargo.lock.bak.msrv")
cargo msrv -- just check-minimal
# Run `cargo msrv-prep` on workspace
prep *extra_args:
{{cargo}} msrv-prep --workspace {{extra_args}}

test-package:
{{cargo}} publish --dry-run
# Run `cargo msrv-unprep` on workspace
unprep *extra_args:
{{cargo}} msrv-unprep --workspace {{extra_args}}

0 comments on commit 3a5217f

Please sign in to comment.