diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 69e696e..053eaa2 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -1,22 +1,204 @@ -name: Rust +# adapted from https://github.com/thomcc/arcstr/blob/main/.github/workflows/ci.yml + +name: CI on: push: - branches: [ main ] + branches: + - main pull_request: - branches: [ main ] env: - CARGO_TERM_COLOR: always + RUST_BACKTRACE: 1 jobs: - build: - - runs-on: ubuntu-latest + test: + name: Test Rust - ${{ matrix.build }} + runs-on: ${{ matrix.os }} + env: + CARGO: cargo + TARGET: "" + strategy: + fail-fast: false + matrix: + build: + - macos + - linux + - linux32 + - win64-msvc + - win64-gnu + - win32-msvc + - win32-gnu + - msrv + - beta + - nightly + - arm32 + - arm64 + - mips32 + - mips64 + include: + - build: linux + os: ubuntu-latest + rust: stable + - build: macos + os: macos-latest + rust: stable + - build: win64-msvc + os: windows-2019 + rust: stable + - build: win64-gnu + os: windows-2019 + rust: stable-x86_64-gnu + - build: win32-msvc + os: windows-2019 + rust: stable-i686-msvc + - build: win32-gnu + os: windows-2019 + rust: stable-i686-gnu + - build: beta + os: ubuntu-latest + rust: beta + - build: nightly + os: ubuntu-latest + rust: nightly + - build: linux32 + os: ubuntu-latest + rust: stable + target: i686-unknown-linux-gnu + - build: arm32 + os: ubuntu-latest + rust: stable + target: armv7-linux-androideabi + - build: arm64 + os: ubuntu-latest + rust: stable + target: aarch64-linux-android + # Mips is big endian. + - build: mips32 + os: ubuntu-latest + rust: stable + target: mips-unknown-linux-gnu + - build: mips64 + os: ubuntu-latest + rust: stable + target: mips64-unknown-linux-gnuabi64 steps: - - uses: actions/checkout@v3 - - name: Build - run: cargo check --verbose - - name: Run tests - run: cargo test --verbose + - uses: actions/checkout@v2 + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.rust }} + profile: minimal + override: true + + - name: Setup cross if needed + if: matrix.target != '' + run: | + cargo install cross + echo "CARGO=cross" >> $GITHUB_ENV + echo "TARGET=--target ${{ matrix.target }}" >> $GITHUB_ENV + + - name: Show command used for Cargo + run: | + echo "cargo command is: ${{ env.CARGO }}" + echo "target flag is: ${{ env.TARGET }}" + + - name: Test + run: ${{ env.CARGO }} test --verbose ${{ env.TARGET }} + + miri: + name: Miri + runs-on: ubuntu-latest + env: + RUSTFLAGS: "-Zrandomize-layout" + MIRIFLAGS: "-Zmiri-symbolic-alignment-check -Zmiri-check-number-validity -Zmiri-tag-raw-pointers" + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 1 + - uses: hecrj/setup-rust-action@v1 + with: + rust-version: nightly + components: miri + - name: Run tests + run: cargo miri test + + cargo-clippy: + name: Lint + runs-on: ubuntu-latest + env: + RUSTFLAGS: -Dwarnings + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 1 + - uses: hecrj/setup-rust-action@v1 + with: + rust-version: stable + - name: Run cargo clippy (default features) + run: cargo clippy --all-targets --verbose -- -D clippy::all + + # Ensure patch is formatted. + fmt: + name: Format + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 1 + - uses: hecrj/setup-rust-action@v1 + with: + rust-version: stable + components: rustfmt + - name: Check formatting + run: cargo fmt --all -- --check + + # Check doc reference links are all valid. + doc: + name: Doc check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 1 + - uses: hecrj/setup-rust-action@v1 + with: + rust-version: nightly + - name: Check docs + # Note: needs cargo rustdoc, not cargo doc. + run: cargo rustdoc --all-features -- -D warnings + + sanitizers: + name: Test sanitizer ${{ matrix.sanitizer }} + runs-on: ubuntu-latest + env: + RUST_BACKTRACE: 0 + # only used by asan, but we set it for all of them cuz its easy + ASAN_OPTIONS: detect_stack_use_after_return=1 + + strategy: + fail-fast: false + matrix: + sanitizer: [address, memory] + include: + - sanitizer: memory + extra_rustflags: "-Zsanitizer-memory-track-origins" + steps: + - uses: actions/checkout@v2 + with: + fetch-depth: 1 + - uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly + override: true + components: rust-src + + - name: Test with sanitizer + env: + RUSTFLAGS: -Zsanitizer=${{ matrix.sanitizer }} ${{ matrix.extra_rustflags }} + RUSTDOCFLAGS: -Zsanitizer=${{ matrix.sanitizer }} ${{ matrix.extra_rustflags }} + run: | + echo "note: RUSTFLAGS='$RUSTFLAGS'" + cargo -Zbuild-std test --target=x86_64-unknown-linux-gnu diff --git a/src/lib.rs b/src/lib.rs index d5830f8..b3c0a63 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -325,6 +325,7 @@ mod tests { } #[test] + #[allow(clippy::redundant_clone)] fn clone() { let mut unit = (); let stuffed_ptr1: StuffedPtr<(), PanicsInDrop> = StuffedPtr::new_ptr(&mut unit); diff --git a/src/strategies.rs b/src/strategies.rs index 52f9f08..b54d7bd 100644 --- a/src/strategies.rs +++ b/src/strategies.rs @@ -15,9 +15,7 @@ unsafe impl StuffingStrategy for () { 0 } - unsafe fn extract_extra(_data: usize) -> Self::Extra { - () - } + unsafe fn extract_extra(_data: usize) -> Self::Extra {} } #[cfg(test)] @@ -35,6 +33,7 @@ pub(crate) mod test_strategies { data == usize::MAX } + #[allow(clippy::forget_copy)] fn stuff_extra(inner: Self::Extra) -> usize { std::mem::forget(inner); usize::MAX