Skip to content

Commit 0b5ffbb

Browse files
xtask + version pinning
1 parent 7a61342 commit 0b5ffbb

File tree

4 files changed

+154
-9
lines changed

4 files changed

+154
-9
lines changed

.github/buildomat/jobs/check-features.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
#: rust_toolchain = true
77
#: output_rules = []
88

9-
# Run cargo check on illumos with feature-specifics like `no-default-features`.
9+
# Run cargo check on illumos with feature-specifics like `no-default-features`
10+
# or `feature-powerset`.
1011

1112
set -o errexit
1213
set -o pipefail
@@ -15,6 +16,10 @@ set -o xtrace
1516
cargo --version
1617
rustc --version
1718

19+
# NOTE: This version should be in sync with the recommended version in
20+
# ./dev-tools/xtask/src/check-features.rs.
21+
CARGO_HACK_VERSION='0.6.28'
22+
1823
#
1924
# Set up our PATH for use with this workspace.
2025
#
@@ -29,8 +34,7 @@ ptime -m cargo check --workspace --bins --tests --no-default-features
2934
RUSTDOCFLAGS="--document-private-items -D warnings" ptime -m cargo doc --workspace --no-deps --no-default-features
3035

3136
#
32-
# `cargo-hack` check feature-powerset
37+
# Check the feature set with the `cargo xtask check-features` command.
3338
#
3439
banner hack
35-
cargo install cargo-hack --locked
36-
ptime -m timeout 2h cargo hack check --workspace --feature-powerset --no-dev-deps --exclude-features image-trampoline,image-standard
40+
ptime -m timeout 2h cargo xtask check-features --version "$CARGO_HACK_VERSION" --exclude-features image-trampoline,image-standard

.github/workflows/rust.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ jobs:
8686
runs-on: ubuntu-22.04
8787
env:
8888
CARGO_INCREMENTAL: 0
89+
CARGO_HACK_VERSION: 0.6.28
8990
steps:
9091
# This repo is unstable and unnecessary: https://github.com/microsoft/linux-package-repositories/issues/34
9192
- name: Disable packages.microsoft.com repo
@@ -105,13 +106,15 @@ jobs:
105106
run: cat "$GITHUB_ENV"
106107
- name: Install Pre-Requisites
107108
run: ./tools/install_builder_prerequisites.sh -y
108-
- name: Run Cargo Check (No Default Features)
109+
- name: Run `cargo check` for no-default-features
109110
run: cargo check --workspace --bins --tests --no-default-features
110-
- name: Install cargo-hack
111-
uses: taiki-e/install-action@cargo-hack
112-
- name: Run Cargo Hack Check (Feature-Powerset, No-Dev-Deps)
111+
# Uses manifest for install
112+
- uses: taiki-e/install-action@v2
113+
with:
114+
tool: cargo-hack@${{ env.CARGO_HACK_VERSION }}
115+
- name: Run Check on Features (Feature-Powerset, No-Dev-Deps)
113116
timeout-minutes: 120 # 2 hours
114-
run: cargo hack check --workspace --feature-powerset --no-dev-deps --exclude-features image-trampoline,image-standard
117+
run: cargo xtask check-features --no-install --exclude-features image-trampoline,image-standard
115118

116119
# This is just a test build of docs. Publicly available docs are built via
117120
# the separate "rustdocs" repo.

dev-tools/xtask/src/check_features.rs

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
5+
//! Subcommand: cargo xtask check-features
6+
7+
use anyhow::{bail, Context, Result};
8+
use clap::Parser;
9+
use std::process::Command;
10+
11+
/// The default version of `cargo-hack` to install.
12+
/// We use a patch-floating version to avoid breaking the build when a new
13+
/// version is released (locally).
14+
const FLOAT_VERSION: &str = "~0.6.28";
15+
16+
#[derive(Parser)]
17+
pub struct Args {
18+
/// Features to exclude from the check.
19+
#[clap(long)]
20+
exclude_features: Option<Vec<String>>,
21+
/// Depth of the feature powerset to check.
22+
#[clap(long)]
23+
depth: Option<usize>,
24+
/// Error format passed to `cargo hack check`.
25+
#[clap(long, value_name = "FMT")]
26+
message_format: Option<String>,
27+
/// Do not install `cargo-hack` before running the check.
28+
#[clap(long, default_value_t = false)]
29+
no_install: bool,
30+
/// Version of `cargo-hack` to install.
31+
#[clap(long)]
32+
version: Option<String>,
33+
}
34+
35+
/// Run `cargo hack check`.
36+
pub fn run_cmd(args: Args) -> Result<()> {
37+
if !args.no_install {
38+
install_cargo_hack(args.version).unwrap();
39+
}
40+
41+
let cargo =
42+
std::env::var("CARGO").unwrap_or_else(|_| String::from("cargo"));
43+
let mut command = Command::new(&cargo);
44+
45+
command.args(&["hack", "check"]);
46+
47+
if let Some(features) = args.exclude_features {
48+
let ex = format!("--exclude-features={}", features.join(","));
49+
command.arg(ex);
50+
}
51+
52+
if let Some(depth) = args.depth {
53+
let depth = format!("depth={}", depth);
54+
command.arg(depth);
55+
}
56+
57+
// Pass along the `--message-format` flag if it was provided.
58+
if let Some(fmt) = args.message_format {
59+
command.args(["--message-format", &fmt]);
60+
}
61+
62+
command
63+
// Make sure we check everything.
64+
.arg("--workspace")
65+
.arg("--bins")
66+
// We want to check the feature powerset.
67+
.arg("--feature-powerset")
68+
.arg("--no-dev-deps")
69+
.arg("--exclude-no-default-features");
70+
71+
eprintln!(
72+
"running: {:?} {}",
73+
&cargo,
74+
command
75+
.get_args()
76+
.map(|arg| format!("{:?}", arg.to_str().unwrap()))
77+
.collect::<Vec<_>>()
78+
.join(" ")
79+
);
80+
81+
let exit_status = command
82+
.spawn()
83+
.context("failed to spawn child process")?
84+
.wait()
85+
.context("failed to wait for child process")?;
86+
87+
if !exit_status.success() {
88+
bail!("check-features failed: {}", exit_status);
89+
}
90+
91+
Ok(())
92+
}
93+
94+
/// Install `cargo-hack` at the specified version or the default version.
95+
fn install_cargo_hack(version: Option<String>) -> Result<()> {
96+
let cargo =
97+
std::env::var("CARGO").unwrap_or_else(|_| String::from("cargo"));
98+
99+
let mut command = Command::new(&cargo);
100+
101+
if let Some(version) = version {
102+
command.args(&["install", "cargo-hack", "--version", &version]);
103+
} else {
104+
command.args(&[
105+
"install",
106+
"cargo-hack",
107+
"--locked",
108+
"--version",
109+
FLOAT_VERSION,
110+
]);
111+
}
112+
113+
eprintln!(
114+
"running: {:?} {}",
115+
&cargo,
116+
command
117+
.get_args()
118+
.map(|arg| format!("{:?}", arg.to_str().unwrap()))
119+
.collect::<Vec<_>>()
120+
.join(" ")
121+
);
122+
123+
let exit_status = command
124+
.spawn()
125+
.expect("failed to spawn child process")
126+
.wait()
127+
.expect("failed to wait for child process");
128+
129+
if !exit_status.success() {
130+
bail!("cargo-hack install failed: {}", exit_status);
131+
}
132+
133+
Ok(())
134+
}

dev-tools/xtask/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use anyhow::{Context, Result};
1010
use cargo_metadata::Metadata;
1111
use clap::{Parser, Subcommand};
1212

13+
mod check_features;
1314
mod check_workspace_deps;
1415
mod clippy;
1516
mod download;
@@ -38,6 +39,8 @@ enum Cmds {
3839
/// Run Argon2 hash with specific parameters (quick performance check)
3940
Argon2(external::External),
4041

42+
/// Check that all features are flagged correctly
43+
CheckFeatures(check_features::Args),
4144
/// Check that dependencies are not duplicated in any packages in the
4245
/// workspace
4346
CheckWorkspaceDeps,
@@ -86,6 +89,7 @@ async fn main() -> Result<()> {
8689
external.cargo_args(["--release"]).exec_example("argon2")
8790
}
8891
Cmds::Clippy(args) => clippy::run_cmd(args),
92+
Cmds::CheckFeatures(args) => check_features::run_cmd(args),
8993
Cmds::CheckWorkspaceDeps => check_workspace_deps::run_cmd(),
9094
Cmds::Download(args) => download::run_cmd(args).await,
9195
#[cfg(target_os = "illumos")]

0 commit comments

Comments
 (0)