Skip to content

Commit 14479bc

Browse files
Add a gh-action and buildomat jobs to cargo check on no-default-features and feature-powerset
Includes: - xtask wrapper around cargo-hack and options
1 parent 808b1a1 commit 14479bc

File tree

6 files changed

+215
-2
lines changed

6 files changed

+215
-2
lines changed

.cargo/config.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# CI scripts:
99
# - .github/buildomat/build-and-test.sh
1010
# - .github/buildomat/jobs/clippy.sh
11+
# - .github/buildomat/jobs/check-features.sh
1112
# - .github/workflows/rust.yml
1213
#
1314
[build]
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
#:
3+
#: name = "check-features (helios)"
4+
#: variety = "basic"
5+
#: target = "helios-2.0"
6+
#: rust_toolchain = true
7+
#: output_rules = []
8+
9+
# Run cargo check on illumos with feature-specifics like `no-default-features`
10+
# or `feature-powerset`.
11+
12+
set -o errexit
13+
set -o pipefail
14+
set -o xtrace
15+
16+
cargo --version
17+
rustc --version
18+
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+
23+
#
24+
# Set up our PATH for use with this workspace.
25+
#
26+
source ./env.sh
27+
28+
banner prerequisites
29+
ptime -m bash ./tools/install_builder_prerequisites.sh -y
30+
31+
banner check
32+
export CARGO_INCREMENTAL=0
33+
ptime -m cargo check --workspace --bins --tests --no-default-features
34+
RUSTDOCFLAGS="--document-private-items -D warnings" ptime -m cargo doc --workspace --no-deps --no-default-features
35+
36+
#
37+
# Check the feature set with the `cargo xtask check-features` command.
38+
#
39+
banner hack
40+
ptime -m timeout 2h cargo xtask check-features --version "$CARGO_HACK_VERSION" --exclude-features image-trampoline,image-standard

.github/buildomat/jobs/clippy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# (that we want to check) is conditionally-compiled on illumos only.
1111
#
1212
# Note that `cargo clippy` includes `cargo check, so this ends up checking all
13-
# of our code.
13+
# of our (default) code.
1414

1515
set -o errexit
1616
set -o pipefail

.github/workflows/rust.yml

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
run: cargo run --bin omicron-package -- -t default check
5454

5555
# Note that `cargo clippy` includes `cargo check, so this ends up checking all
56-
# of our code.
56+
# of our (default) code.
5757
clippy-lint:
5858
runs-on: ubuntu-22.04
5959
env:
@@ -82,6 +82,40 @@ jobs:
8282
- name: Run Clippy Lints
8383
run: cargo xtask clippy
8484

85+
check-features:
86+
runs-on: ubuntu-22.04
87+
env:
88+
CARGO_INCREMENTAL: 0
89+
CARGO_HACK_VERSION: 0.6.28
90+
steps:
91+
# This repo is unstable and unnecessary: https://github.com/microsoft/linux-package-repositories/issues/34
92+
- name: Disable packages.microsoft.com repo
93+
run: sudo rm -f /etc/apt/sources.list.d/microsoft-prod.list
94+
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
95+
with:
96+
ref: ${{ github.event.pull_request.head.sha }} # see omicron#4461
97+
- uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3
98+
if: ${{ github.ref != 'refs/heads/main' }}
99+
- name: Report cargo version
100+
run: cargo --version
101+
- name: Update PATH
102+
run: source "./env.sh"; echo "PATH=$PATH" >> "$GITHUB_ENV"
103+
- name: Print PATH
104+
run: echo $PATH
105+
- name: Print GITHUB_ENV
106+
run: cat "$GITHUB_ENV"
107+
- name: Install Pre-Requisites
108+
run: ./tools/install_builder_prerequisites.sh -y
109+
- name: Run `cargo check` for no-default-features
110+
run: cargo check --workspace --bins --tests --no-default-features
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)
116+
timeout-minutes: 120 # 2 hours
117+
run: cargo xtask check-features --no-install --exclude-features image-trampoline,image-standard
118+
85119
# This is just a test build of docs. Publicly available docs are built via
86120
# the separate "rustdocs" repo.
87121
build-docs:

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)