Skip to content

Commit

Permalink
Move tools into separate workspace
Browse files Browse the repository at this point in the history
Also adds shell and batch wrapper scripts
  • Loading branch information
djkoloski committed Feb 20, 2024
1 parent 01be3aa commit 36c92d0
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 38 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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 }} \
Expand All @@ -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 }} \
Expand Down Expand Up @@ -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 }} \
Expand All @@ -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
Expand All @@ -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
Expand Down
9 changes: 0 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion INTERNAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions cargos.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@rem Copyright 2024 The Fuchsia Authors

@rem Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
@rem <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
@rem license <LICENSE-MIT or https://opensource.org/licenses/MIT>, 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 -- %*
10 changes: 10 additions & 0 deletions cargos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright 2024 The Fuchsia Authors
#
# Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
# <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
# license <LICENSE-MIT or https://opensource.org/licenses/MIT>, 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 -- $@
2 changes: 1 addition & 1 deletion ci/check_readme.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 $?
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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

//! *<span style="font-size: 100%; color:grey;">Need more out of zerocopy?
//! Submit a [customer request issue][customer-request-issue]!</span>*
Expand Down
25 changes: 25 additions & 0 deletions tools/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2018 The Fuchsia Authors
#
# Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
# <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
# license <LICENSE-MIT or https://opensource.org/licenses/MIT>, 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 <[email protected]>"]
license = "BSD-2-Clause OR Apache-2.0 OR MIT"
publish = false

[workspace.dependencies]
regex = "1"
serde_json = "1"
11 changes: 6 additions & 5 deletions tools/cargos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions tools/cargos/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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)?;
Expand Down
11 changes: 6 additions & 5 deletions tools/generate-readme/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions tools/generate-readme/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::process::Command;

use regex::{Captures, Regex};

const COPYRIGHT_HEADER: &'static str = "\
const COPYRIGHT_HEADER: &str = "\
<!-- Copyright 2024 The Fuchsia Authors
Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
Expand All @@ -24,7 +24,7 @@ made in the doc comment on `src/lib.rs` or in `tools/generate-readme`.
-->\
";

const DISCLAIMER_FOOTER: &'static str = "\
const DISCLAIMER_FOOTER: &str = "\
## Disclaimer
Disclaimer: Zerocopy is not an officially supported Google product.\
Expand Down

0 comments on commit 36c92d0

Please sign in to comment.