Skip to content

Commit 9cb1063

Browse files
review: xtask updates on options/parameters around install-version, ci
Includes: - xtask documentation on main readme
1 parent 8441874 commit 9cb1063

File tree

4 files changed

+64
-29
lines changed

4 files changed

+64
-29
lines changed

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

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

9-
# Run cargo check on illumos with feature-specifics like `no-default-features`
10-
# or `feature-powerset`.
9+
# Run the check-features `xtask` on illumos, testing compilation of feature combinations.
1110

1211
set -o errexit
1312
set -o pipefail
@@ -28,13 +27,10 @@ source ./env.sh
2827
banner prerequisites
2928
ptime -m bash ./tools/install_builder_prerequisites.sh -y
3029

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-
3630
#
3731
# Check the feature set with the `cargo xtask check-features` command.
3832
#
39-
banner hack
40-
ptime -m timeout 2h cargo xtask check-features --version "$CARGO_HACK_VERSION" --exclude-features image-trampoline,image-standard
33+
banner hack-check
34+
export CARGO_INCREMENTAL=0
35+
ptime -m timeout 2h cargo xtask check-features --ci --install-version "$CARGO_HACK_VERSION"
36+
RUSTDOCFLAGS="--document-private-items -D warnings" ptime -m cargo doc --workspace --no-deps --no-default-features

.github/workflows/rust.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,13 @@ jobs:
106106
run: cat "$GITHUB_ENV"
107107
- name: Install Pre-Requisites
108108
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
111109
# Uses manifest for install
112110
- uses: taiki-e/install-action@v2
113111
with:
114112
tool: cargo-hack@${{ env.CARGO_HACK_VERSION }}
115113
- name: Run Check on Features (Feature-Powerset, No-Dev-Deps)
116114
timeout-minutes: 120 # 2 hours
117-
run: cargo xtask check-features --no-install --exclude-features image-trampoline,image-standard
115+
run: cargo xtask check-features --ci
118116

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

README.adoc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,24 @@ cargo nextest run
112112

113113
We check that certain system library dependencies are not leaked outside of their intended binaries via `cargo xtask verify-libraries` in CI. If you are adding a new dependency on a illumos/helios library it is recommended that you update xref:.cargo/xtask.toml[] with an allow list of where you expect the dependency to show up. For example some libraries such as `libnvme.so.1` are only available in the global zone and therefore will not be present in any other zone. This check is here to help us catch any leakage before we go to deploy on a rack. You can inspect a compiled binary in the target directory for what it requires by using `elfedit` - for example `elfedit -r -e 'dyn:tag NEEDED' /path/to/omicron/target/debug/sled-agent`.
114114

115+
=== Checking feature flag combinations
116+
117+
To ensure that varying combinations of features compile, run `cargo xtask check-features`, which executes the https://github.com/taiki-e/cargo-hack[`cargo hack`] subcommand under the hood. This `xtask` is run in CI using the `--ci` parameter , which automatically exludes certain `image-*` features that purposefully cause compiler errors if set.
118+
119+
If you don't have `cargo hack` installed locally, run the the `xtask` with the `install-version <VERSION>` option, which will install it into your user's `.cargo` directory:
120+
121+
[source,text]
122+
----
123+
$ cargo xtask check-features --install-version 0.6.28
124+
----
125+
126+
To limit the max number of simultaneous feature flags combined for checking, run the `xtask` with the `--depth <NUM>` flag:
127+
128+
[source,text]
129+
----
130+
$ cargo xtask check-features --depth 2
131+
----
132+
115133
=== Rust packages in Omicron
116134

117135
NOTE: The term "package" is overloaded: most programming languages and operating systems have their own definitions of a package. On top of that, Omicron bundles up components into our own kind of "package" that gets delivered via the install and update systems. These are described in the `package-manifest.toml` file in the root of the repo. In this section, we're just concerned with Rust packages.

dev-tools/xtask/src/check_features.rs

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,52 +6,74 @@
66
77
use anyhow::{bail, Context, Result};
88
use clap::Parser;
9-
use std::process::Command;
9+
use std::{collections::HashSet, process::Command};
1010

1111
/// The default version of `cargo-hack` to install.
1212
/// We use a patch-floating version to avoid breaking the build when a new
1313
/// version is released (locally).
1414
const FLOAT_VERSION: &str = "~0.6.28";
1515

16+
const CI_EXCLUDED_FEATURES: [&str; 2] = ["image-trampoline", "image-standard"];
17+
1618
#[derive(Parser)]
1719
pub struct Args {
20+
/// Run in CI mode, with a default set of features excluded.
21+
#[clap(long, default_value_t = false)]
22+
ci: bool,
1823
/// Features to exclude from the check.
19-
#[clap(long)]
24+
#[clap(long, value_name = "FEATURES")]
2025
exclude_features: Option<Vec<String>>,
2126
/// Depth of the feature powerset to check.
22-
#[clap(long)]
27+
#[clap(long, value_name = "NUM")]
2328
depth: Option<usize>,
2429
/// Error format passed to `cargo hack check`.
2530
#[clap(long, value_name = "FMT")]
2631
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,
3032
/// Version of `cargo-hack` to install.
31-
#[clap(long)]
32-
version: Option<String>,
33+
#[clap(long, value_name = "VERSION")]
34+
install_version: Option<String>,
3335
}
3436

3537
/// Run `cargo hack check`.
3638
pub fn run_cmd(args: Args) -> Result<()> {
37-
if !args.no_install {
38-
install_cargo_hack(args.version).unwrap();
39+
// Install `cargo-hack` if the `install-version` was specified.
40+
if let Some(version) = args.install_version {
41+
install_cargo_hack(Some(version))?;
3942
}
4043

4144
let cargo =
4245
std::env::var("CARGO").unwrap_or_else(|_| String::from("cargo"));
4346
let mut command = Command::new(&cargo);
4447

48+
// Add the `hack check` subcommand.
4549
command.args(&["hack", "check"]);
4650

47-
if let Some(features) = args.exclude_features {
48-
let ex = format!("--exclude-features={}", features.join(","));
49-
command.arg(ex);
51+
// Add the `--exclude-features` flag if we are running in CI mode.
52+
if args.ci {
53+
let ex = if let Some(mut features) = args.exclude_features {
54+
// Extend the list of features to exclude with the CI defaults.
55+
features.extend(
56+
CI_EXCLUDED_FEATURES.into_iter().map(|s| s.to_string()),
57+
);
58+
59+
// Remove duplicates.
60+
let excludes = features.into_iter().collect::<HashSet<_>>();
61+
62+
excludes.into_iter().collect::<Vec<_>>().join(",")
63+
} else {
64+
CI_EXCLUDED_FEATURES.join(",")
65+
};
66+
67+
command.args(["--exclude-features", &ex]);
68+
} else {
69+
// Add "only" the `--exclude-features` flag if it was provided.
70+
if let Some(features) = args.exclude_features {
71+
command.args(["--exclude-features", &features.join(",")]);
72+
}
5073
}
5174

5275
if let Some(depth) = args.depth {
53-
let depth = format!("depth={}", depth);
54-
command.arg(depth);
76+
command.args(&["--depth", &depth.to_string()]);
5577
}
5678

5779
// Pass along the `--message-format` flag if it was provided.
@@ -62,11 +84,12 @@ pub fn run_cmd(args: Args) -> Result<()> {
6284
command
6385
// Make sure we check everything.
6486
.arg("--workspace")
87+
// We want to check the binaries.
6588
.arg("--bins")
6689
// We want to check the feature powerset.
6790
.arg("--feature-powerset")
68-
.arg("--no-dev-deps")
69-
.arg("--exclude-no-default-features");
91+
// We will not check the dev-dependencies, which should covered by tests.
92+
.arg("--no-dev-deps");
7093

7194
eprintln!(
7295
"running: {:?} {}",

0 commit comments

Comments
 (0)