Skip to content

Commit d542d03

Browse files
brucegjszwedko
authored andcommitted
chore(ci): Run check-component-features in parallel (#12950)
This speeds up the `check-component-features` check by running each feature in a separate job in a separate build tree. This is possible because cargo doesn't overwrite output files after they are created. To take advantage of this, we first do a check on the full build and then create a temporary build tree for each feature composed of hard links to the individual files created during that check. This speeds up the subsequent builds and allows them to run in parallel as they no longer clobber each other's outputs.
1 parent 5c4a12c commit d542d03

File tree

7 files changed

+83
-7
lines changed

7 files changed

+83
-7
lines changed

.github/workflows/test.yml

-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,6 @@ jobs:
275275
- run: sudo -E bash scripts/environment/bootstrap-ubuntu-20.04.sh
276276
- run: bash scripts/environment/prepare.sh
277277
- run: echo "::add-matcher::.github/matchers/rust.json"
278-
- run: cargo install cargo-hack
279278
- run: make check-component-features
280279

281280
check-msrv:

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ check-all: check-scripts
424424

425425
.PHONY: check-component-features
426426
check-component-features: ## Check that all component features are setup properly
427-
${MAYBE_ENVIRONMENT_EXEC} cargo hack check --workspace --keep-going --each-feature --exclude-features "sources-utils-http sources-utils-http-encoding sources-utils-http-prelude sources-utils-http-query sources-utils-tcp-keepalive sources-utils-tcp-socket sources-utils-tls sources-utils-udp sources-utils-unix sinks-utils-udp" --all-targets
427+
${MAYBE_ENVIRONMENT_EXEC} ./scripts/check-component-features
428428

429429
.PHONY: check-clippy
430430
check-clippy: ## Check code with Clippy

scripts/check-component-features

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
set -o errexit
3+
set -o nounset
4+
set -o pipefail
5+
6+
# Extract all feature names from Cargo.toml
7+
features=$(
8+
sed -e '
9+
1,/^\[features\]$/d;
10+
/^\[/,$d;
11+
/=/!d;
12+
s/ *=.*$//;
13+
14+
# Skip over certain features
15+
/-utils-/d;
16+
/^default$/d;
17+
/^all-integration-tests$/d;
18+
' < Cargo.toml | sort
19+
)
20+
21+
# Prime the pump to build most of the artifacts
22+
cargo check --workspace --all-targets --no-default-features
23+
cargo check --workspace --all-targets --no-default-features --features default
24+
cargo check --workspace --all-targets --no-default-features --features all-integration-tests
25+
26+
# The feature builds already run in parallel below, don't overload
27+
export CARGO_BUILD_JOBS=1
28+
29+
exec parallel --verbose --retries 2 scripts/check-one-feature {} ::: $features

scripts/check-one-feature

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env bash
2+
set -o errexit
3+
set -o nounset
4+
set -o pipefail
5+
6+
if [ $# -lt 1 ]
7+
then
8+
echo "usage: $0 FEATURE [OPTIONS]"
9+
exit 1
10+
fi
11+
12+
feature=$1
13+
shift
14+
15+
if [ ! -d target ]
16+
then
17+
echo $0: 'Run `cargo check` first to prime the `target` directory.'
18+
exit 1
19+
fi
20+
21+
target=$PWD/target-feature-$feature
22+
log=$target/.logfile
23+
trap 'rm --force --recursive $target' EXIT
24+
25+
cp --archive --link target $target
26+
rm --force $target/debug/.cargo-lock
27+
28+
echo "===== Feature: $feature ====="
29+
if cargo check --workspace --all-targets \
30+
--no-default-features \
31+
--features $feature \
32+
--target-dir $target \
33+
"$@" >$log 2>&1
34+
then
35+
# If the run was successful, just output the `Finished` line
36+
# to prevent cluttering the logs.
37+
exit=0
38+
fgrep --word-regexp Finished $log
39+
else
40+
exit=$?
41+
cat $log
42+
fi
43+
44+
exit $exit
45+
46+
# It would be nice to relink newer files back into `target` so
47+
# subsequent runs can pick them up, but that ends up confusing `cargo`
48+
# later in the process.

src/sources/util/http/auth.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ impl TryFrom<Option<&HttpSourceAuthConfig>> for HttpSourceAuth {
4242

4343
#[derive(Debug, Clone)]
4444
pub struct HttpSourceAuth {
45-
#[allow(unused)] // triggered by cargo-hack
45+
#[allow(unused)] // triggered by check-component-features
4646
pub(self) token: Option<String>,
4747
}
4848

4949
impl HttpSourceAuth {
50-
#[allow(unused)] // triggered by cargo-hack
50+
#[allow(unused)] // triggered by check-component-features
5151
pub fn is_valid(&self, header: &Option<String>) -> Result<(), ErrorMessage> {
5252
use warp::http::StatusCode;
5353

src/sources/util/http/error.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ pub struct ErrorMessage {
1515
feature = "sources-datadog_agent"
1616
))]
1717
impl ErrorMessage {
18-
#[allow(unused)] // triggered by cargo-hack
18+
#[allow(unused)] // triggered by check-component-features
1919
pub fn new(code: http::StatusCode, message: String) -> Self {
2020
ErrorMessage {
2121
code: code.as_u16(),
2222
message,
2323
}
2424
}
2525

26-
#[allow(unused)] // triggered by cargo-hack
26+
#[allow(unused)] // triggered by check-component-features
2727
pub fn status_code(&self) -> http::StatusCode {
2828
http::StatusCode::from_u16(self.code).unwrap_or(http::StatusCode::INTERNAL_SERVER_ERROR)
2929
}

src/sources/vector/v1.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const fn default_shutdown_timeout_secs() -> u64 {
3939
impl VectorConfig {
4040
#[cfg(test)]
4141
#[allow(unused)] // this test function is not always used in test, breaking
42-
// our cargo-hack run
42+
// our check-component-features run
4343
pub fn set_tls(&mut self, config: Option<TlsEnableableConfig>) {
4444
self.tls = config;
4545
}

0 commit comments

Comments
 (0)