Skip to content

Commit c06d535

Browse files
authored
chore: avoid giant feature powersets using cargo-hack (#1984)
## Motivation The `tracing`' crate's feature powerset is kind of unmanageably huge due to the large number of `max_level_XXX` and `release_max_level_XXX` feature flags. This is why we currently _don't_ run a `cargo-hack` feature powerset check for it on CI. However, I forgot about that when I added feature powerset checks to the `bin/publish` script, so publishing a `tracing` release results in a combinatorial explosion that takes a *very* long time to complete. ## Solution It turns out that `cargo-hack` actually has flags for controlling what features are included in the powerset (`--include-features` and `--exclude-features`). This branch modifies `bin/publish` to use those flags when checking the `tracing` and `tracing-subscriber` crate. Additionally, I've modified the CI `cargo-hack` job to use the same flags, so that it can now check `tracing` and `tracing-subscriber`. This allows us to remove the manual feature check jobs for those crates from CI. Signed-off-by: Eliza Weisman <[email protected]>
1 parent 016e5b8 commit c06d535

File tree

2 files changed

+59
-53
lines changed

2 files changed

+59
-53
lines changed

.github/workflows/check_features.yml

Lines changed: 27 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,8 @@ jobs:
4545
- tracing-serde
4646
- tracing-tower
4747
- tracing-opentelemetry
48-
# tracing and tracing-subscriber have too many features to be checked by
49-
# cargo-hack --feature-powerset, combinatorics there is exploding.
50-
#- tracing
51-
#- tracing-subscriber
48+
- tracing
49+
- tracing-subscriber
5250
steps:
5351
- uses: actions/checkout@main
5452
- uses: actions-rs/toolchain@v1
@@ -61,53 +59,31 @@ jobs:
6159
curl -LsSf https://github.com/taiki-e/cargo-hack/releases/latest/download/cargo-hack-x86_64-unknown-linux-gnu.tar.gz | tar xzf - -C ~/.cargo/bin
6260
- name: cargo hack check
6361
working-directory: ${{ matrix.subcrate }}
64-
run: cargo hack check --feature-powerset --no-dev-deps
65-
66-
cargo-check-tracing:
67-
runs-on: ubuntu-latest
68-
strategy:
69-
matrix:
70-
featureset:
71-
- ""
72-
- log-always
73-
- std log-always
74-
- std
75-
fail-fast: false
76-
steps:
77-
- uses: actions/checkout@main
78-
- uses: actions-rs/toolchain@v1
79-
with:
80-
toolchain: stable
81-
profile: minimal
82-
override: true
83-
- name: cargo check
84-
working-directory: tracing
85-
run: cargo check --no-default-features --features "${{ matrix.featureset }}"
86-
87-
cargo-check-subscriber:
88-
runs-on: ubuntu-latest
89-
strategy:
90-
matrix:
91-
featureset:
92-
- ""
93-
- fmt
94-
- fmt ansi
95-
- fmt json
96-
- fmt json ansi
97-
- fmt registry
98-
- fmt env-filter
99-
- registry
100-
- env-filter
101-
steps:
102-
- uses: actions/checkout@main
103-
- uses: actions-rs/toolchain@v1
104-
with:
105-
toolchain: stable
106-
profile: minimal
107-
override: true
108-
- name: cargo check
109-
working-directory: tracing-subscriber
110-
run: cargo check --no-default-features --features "${{ matrix.featureset }}"
62+
# tracing and tracing-subscriber have too many features to be checked by
63+
# cargo-hack --feature-powerset with all features in the powerset, so
64+
# exclude some
65+
run: |
66+
CARGO_HACK=(cargo hack check --feature-powerset --no-dev-deps)
67+
case "${{ matrix.subcrate }}" in
68+
tracing)
69+
EXCLUDE_FEATURES=(
70+
max_level_off max_level_error max_level_warn max_level_info
71+
max_level_debug max_level_trace release_max_level_off
72+
release_max_level_error release_max_level_warn
73+
release_max_level_info release_max_level_debug
74+
release_max_level_trace
75+
)
76+
${CARGO_HACK[@]} --exclude-features "${EXCLUDE_FEATURES[*]}"
77+
;;
78+
tracing-subscriber)
79+
INCLUDE_FEATURES=(fmt ansi json registry env-filter)
80+
${CARGO_HACK[@]} --include-features "${INCLUDE_FEATURES[*]}"
81+
;;
82+
*)
83+
${CARGO_HACK[@]}
84+
;;
85+
esac
86+
shell: bash
11187

11288
features-stable:
11389
# Feature flag tests that run on stable Rust.

bin/publish

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,41 @@ verify() {
3838

3939
status "Checking" "if $CRATE builds across feature combinations"
4040

41-
if ! cargo hack check $VERBOSE --feature-powerset --no-dev-deps; then
41+
CARGO_HACK=(cargo hack check $VERBOSE --feature-powerset --no-dev-deps)
42+
case "$CRATE" in
43+
tracing-subscriber)
44+
# for tracing-subscriber, don't test a complete powerset because
45+
# there are lots of feature flags
46+
INCLUDE_FEATURES=(fmt ansi json registry env-filter)
47+
${CARGO_HACK[@]} --include-features "${INCLUDE_FEATURES[*]}"
48+
CARGO_HACK_STATUS="$?"
49+
;;
50+
tracing)
51+
# checking the full feature powerset for `tracing` will take
52+
# *forever* because of the `max_level_XXX` and
53+
# `release_max_level_XXX` features
54+
EXCLUDE_FEATURES=(
55+
max_level_off max_level_error max_level_warn max_level_info
56+
max_level_debug max_level_trace release_max_level_off
57+
release_max_level_error release_max_level_warn
58+
release_max_level_info release_max_level_debug
59+
release_max_level_trace
60+
)
61+
${CARGO_HACK[@]} --exclude-features "${EXCLUDE_FEATURES[*]}"
62+
CARGO_HACK_STATUS="$?"
63+
;;
64+
*)
65+
${CARGO_HACK[@]}
66+
CARGO_HACK_STATUS="$?"
67+
;;
68+
esac
69+
70+
if "$CARGO_HACK_STATUS" ; then
4271
err "$CRATE did not build with all feature combinations!"
4372
exit 1
4473
fi
4574

75+
4676
if git tag -l | grep -Fxq "$TAG" ; then
4777
err "git tag \`$TAG\` already exists"
4878
exit 1
@@ -68,7 +98,7 @@ do
6898
case "$1" in
6999
-v|--verbose)
70100
VERBOSE="--verbose"
71-
set +x
101+
set -x
72102
shift
73103
;;
74104
-d|--dry-run)

0 commit comments

Comments
 (0)