diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2709919135..13dbc37efb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -109,8 +109,8 @@ jobs: # # ...to: # - # toolchain: $ {{ cargo run -p cargos -- --version matrix.toolchain }} # hypothetical syntax - ZC_TOOLCHAIN="$(cargo run -p cargos -- --version ${{ matrix.toolchain }})" + # toolchain: $ {{ ./cargos.sh --version matrix.toolchain }} # hypothetical syntax + ZC_TOOLCHAIN="$(./cargos.sh --version ${{ matrix.toolchain }})" echo "Found that the '${{ matrix.toolchain }}' toolchain is $ZC_TOOLCHAIN" | tee -a $GITHUB_STEP_SUMMARY echo "ZC_TOOLCHAIN=$ZC_TOOLCHAIN" >> $GITHUB_ENV @@ -125,12 +125,12 @@ jobs: fi # On our MSRV, `cargo` does not know about the `rust-version` field. As a - # result, in `cargo.sh`, if we use our MSRV toolchain in order to run `cargo + # result, in `cargos.sh`, if we use our MSRV toolchain in order to run `cargo # metadata`, we will not be able to extract the `rust-version` field. Thus, - # in `cargo.sh`, we explicitly do `cargo +stable metadata`. This requires a + # in `cargos.sh`, we explicitly do `cargo +stable metadata`. This requires a # (more recent) stable toolchain to be installed. As of this writing, this # toolchain is not used for anything else. - - name: Install stable Rust for use in 'cargo.sh' + - name: Install stable Rust for use in 'cargos.sh' uses: dtolnay/rust-toolchain@00b49be78f40fba4e87296b2ead62868750bdd83 # stable with: toolchain: stable @@ -158,10 +158,10 @@ jobs: key: "${{ matrix.target }}" - name: Check tests - run: cargo run -p cargos -- +${{ matrix.toolchain }} check --tests --package ${{ matrix.crate }} --target ${{ matrix.target }} ${{ matrix.features }} --verbose + run: ./cargos.sh +${{ matrix.toolchain }} check --tests --package ${{ matrix.crate }} --target ${{ matrix.target }} ${{ matrix.features }} --verbose - name: Build - run: cargo run -p cargos -- +${{ matrix.toolchain }} build --package ${{ matrix.crate }} --target ${{ matrix.target }} ${{ matrix.features }} --verbose + run: ./cargos.sh +${{ matrix.toolchain }} build --package ${{ matrix.crate }} --target ${{ matrix.target }} ${{ matrix.features }} --verbose # When building tests for the i686 target, we need certain libraries which # are not installed by default; `gcc-multilib` includes these libraries. @@ -180,7 +180,7 @@ jobs: - name: Run tests run: | - cargo run -p cargos -- +${{ matrix.toolchain }} test \ + ./cargos.sh +${{ matrix.toolchain }} test \ --package ${{ matrix.crate }} \ --target ${{ matrix.target }} \ ${{ matrix.features }} \ @@ -206,7 +206,7 @@ jobs: # # TODO(#560), TODO(#187): Once we migrate to the ui-test crate, we # likely won't have to special-case the UI tests like this. - RUSTFLAGS="$RUSTFLAGS -Wwarnings" cargo run -p cargos -- +${{ matrix.toolchain }} test \ + RUSTFLAGS="$RUSTFLAGS -Wwarnings" ./cargos.sh +${{ matrix.toolchain }} test \ --package ${{ matrix.crate }} \ --target ${{ matrix.target }} \ ${{ matrix.features }} \ @@ -242,7 +242,7 @@ jobs: # Run under both the stacked borrows model (default) and under the tree # borrows model to ensure we're compliant with both. for EXTRA_FLAGS in "" "-Zmiri-tree-borrows"; do - MIRIFLAGS="$MIRIFLAGS $EXTRA_FLAGS" cargo run -p cargos -- +${{ matrix.toolchain }} \ + MIRIFLAGS="$MIRIFLAGS $EXTRA_FLAGS" ./cargos.sh +${{ matrix.toolchain }} \ miri test \ --package ${{ matrix.crate }} \ --target ${{ matrix.target }} \ @@ -256,7 +256,7 @@ jobs: if: matrix.toolchain == 'nightly' && matrix.target != 'riscv64gc-unknown-linux-gnu' && matrix.target != 'wasm32-wasi' - name: Clippy check - run: cargo run -p cargos -- +${{ matrix.toolchain }} clippy --package ${{ matrix.crate }} --target ${{ matrix.target }} ${{ matrix.features }} --tests --verbose + run: ./cargos.sh +${{ matrix.toolchain }} clippy --package ${{ matrix.crate }} --target ${{ matrix.target }} ${{ matrix.features }} --tests --verbose # Clippy improves the accuracy of lints over time, and fixes bugs. Only # running Clippy on nightly allows us to avoid having to write code which # is compatible with older versions of Clippy, which sometimes requires @@ -275,7 +275,7 @@ jobs: METADATA_DOCS_RS_RUSTDOC_ARGS="$(cargo metadata --format-version 1 | \ jq -r ".packages[] | select(.name == \"zerocopy\").metadata.docs.rs.\"rustdoc-args\".[]" | tr '\n' ' ')" export RUSTDOCFLAGS="${{ matrix.toolchain == 'nightly' && '-Z unstable-options --document-hidden-items' || '' }} $RUSTDOCFLAGS $METADATA_DOCS_RS_RUSTDOC_ARGS" - cargo run -p cargos -- +${{ matrix.toolchain }} doc --document-private-items --package ${{ matrix.crate }} ${{ matrix.features }} + ./cargos.sh +${{ matrix.toolchain }} doc --document-private-items --package ${{ matrix.crate }} ${{ matrix.features }} # Check semver compatibility with the most recently-published version on # crates.io. We do this in the matrix rather than in its own job so that it diff --git a/Cargo.toml b/Cargo.toml index f8887940b9..2e31cc2793 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,15 +11,6 @@ # avoids issues like: # https://github.com/dtolnay/trybuild/issues/207#issuecomment-131227.594 [workspace] -members = [ - "zerocopy-derive", - "tools/cargos", - "tools/generate-readme", -] -default-members = [ - ".", - "zerocopy-derive", -] [package] edition = "2018" diff --git a/INTERNAL.md b/INTERNAL.md index f7bb46abe1..8a005fb109 100644 --- a/INTERNAL.md +++ b/INTERNAL.md @@ -29,7 +29,7 @@ Updating the versions pinned in CI may cause the UI tests to break. In order to fix UI tests after a version update, run: ``` -$ TRYBUILD=overwrite cargo run -p cargos -- +all test +$ TRYBUILD=overwrite ./cargos.sh +all test ``` ## Crate versions diff --git a/cargos.bat b/cargos.bat new file mode 100644 index 0000000000..bc678203d1 --- /dev/null +++ b/cargos.bat @@ -0,0 +1,10 @@ +@rem Copyright 2024 The Fuchsia Authors + +@rem Licensed under a BSD-style license , Apache License, Version 2.0 +@rem , or the MIT +@rem license , at your option. +@rem This file may not be copied, modified, or distributed except according to +@rem those terms. + +@rem Thin wrapper around the `cargos` binary in `tools/cargos` +@cargo -q run --manifest-path tools/Cargo.toml -p cargos -- %* diff --git a/cargos.sh b/cargos.sh new file mode 100755 index 0000000000..3c4a679eec --- /dev/null +++ b/cargos.sh @@ -0,0 +1,10 @@ +# Copyright 2024 The Fuchsia Authors +# +# Licensed under a BSD-style license , Apache License, Version 2.0 +# , or the MIT +# license , at your option. +# This file may not be copied, modified, or distributed except according to +# those terms. + +# Thin wrapper around the `cargos` binary in `tools/cargos` +cargo -q run --manifest-path tools/Cargo.toml -p cargos -- $@ diff --git a/ci/check_readme.sh b/ci/check_readme.sh index b3c2399daf..8bb614acca 100755 --- a/ci/check_readme.sh +++ b/ci/check_readme.sh @@ -6,5 +6,5 @@ set -eo pipefail # suppress all errors from it. cargo install cargo-readme --version 3.2.0 -q -diff <(cargo run -p generate-readme) README.md +diff <(cargo -q run --manifest-path tools/Cargo.toml -p generate-readme) README.md exit $? diff --git a/src/lib.rs b/src/lib.rs index 67b55e2852..73b33745be 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,7 +10,7 @@ // After updating the following doc comment, make sure to run the following // command to update `README.md` based on its contents: // -// cargo run -p generate-readme > README.md +// cargo -q run --manifest-path tools/Cargo.toml -p generate-readme > README.md //! *Need more out of zerocopy? //! Submit a [customer request issue][customer-request-issue]!* diff --git a/tools/Cargo.toml b/tools/Cargo.toml new file mode 100644 index 0000000000..e0d6de0de5 --- /dev/null +++ b/tools/Cargo.toml @@ -0,0 +1,25 @@ +# Copyright 2018 The Fuchsia Authors +# +# Licensed under a BSD-style license , Apache License, Version 2.0 +# , or the MIT +# license , at your option. +# This file may not be copied, modified, or distributed except according to +# those terms. + +[workspace] +members = [ + "cargos", + "generate-readme", +] +resolver = "2" + +[workspace.package] +edition = "2021" +version = "0.0.0" +authors = ["Joshua Liebow-Feeser "] +license = "BSD-2-Clause OR Apache-2.0 OR MIT" +publish = false + +[workspace.dependencies] +regex = "1" +serde_json = "1" diff --git a/tools/cargos/Cargo.toml b/tools/cargos/Cargo.toml index 8bd4cc648b..e7e7351dfa 100644 --- a/tools/cargos/Cargo.toml +++ b/tools/cargos/Cargo.toml @@ -7,11 +7,12 @@ # those terms. [package] -edition = "2021" +edition.workspace = true name = "cargos" -version = "0.0.0" -license = "BSD-2-Clause OR Apache-2.0 OR MIT" -publish = false +version.workspace = true +authors.workspace = true +license.workspace = true +publish.workspace = true [dependencies] -serde_json = "1" +serde_json.workspace = true diff --git a/tools/cargos/src/main.rs b/tools/cargos/src/main.rs index 8e2ced588f..82d04e33a1 100644 --- a/tools/cargos/src/main.rs +++ b/tools/cargos/src/main.rs @@ -151,7 +151,7 @@ fn install_toolchain_or_exit(versions: &Versions, name: &str) -> Result<(), Erro loop { let mut input = [0]; - io::stdin().read(&mut input).unwrap(); + io::stdin().read_exact(&mut input).unwrap(); match input[0] as char { 'y' | 'Y' => break, 'n' | 'N' => process::exit(1), @@ -204,7 +204,7 @@ fn delegate_cargo() -> Result<(), Error> { } Some(arg) => { if let Some(name) = arg.strip_prefix('+') { - let version = versions.get(&name)?; + let version = versions.get(name)?; if !is_toolchain_installed(&versions, name)? { install_toolchain_or_exit(&versions, name)?; diff --git a/tools/generate-readme/Cargo.toml b/tools/generate-readme/Cargo.toml index db6f3e6b80..10dc0d18f3 100644 --- a/tools/generate-readme/Cargo.toml +++ b/tools/generate-readme/Cargo.toml @@ -7,11 +7,12 @@ # those terms. [package] -edition = "2021" +edition.workspace = true name = "generate-readme" -version = "0.0.0" -license = "BSD-2-Clause OR Apache-2.0 OR MIT" -publish = false +version.workspace = true +authors.workspace = true +license.workspace = true +publish.workspace = true [dependencies] -regex = "1" +regex.workspace = true diff --git a/tools/generate-readme/src/main.rs b/tools/generate-readme/src/main.rs index 150813c3b7..8945caea7b 100644 --- a/tools/generate-readme/src/main.rs +++ b/tools/generate-readme/src/main.rs @@ -10,7 +10,7 @@ use std::process::Command; use regex::{Captures, Regex}; -const COPYRIGHT_HEADER: &'static str = "\ +const COPYRIGHT_HEADER: &str = "\ \ "; -const DISCLAIMER_FOOTER: &'static str = "\ +const DISCLAIMER_FOOTER: &str = "\ ## Disclaimer Disclaimer: Zerocopy is not an officially supported Google product.\