Skip to content

ruma-events: Feature gate criterion to avoid compilation in CI#111

Merged
jplatte merged 4 commits intoruma:masterfrom
DevinR528:gate-criterion
Jul 6, 2020
Merged

ruma-events: Feature gate criterion to avoid compilation in CI#111
jplatte merged 4 commits intoruma:masterfrom
DevinR528:gate-criterion

Conversation

@DevinR528
Copy link
Copy Markdown
Member

@DevinR528 DevinR528 commented Jul 5, 2020

edit(jplatte): fixes #106

// This makes the compiler only spit out the `compile_error!` when
// `cargo bench` is run without the `criterion_bench` feature.
#[cfg(not(feature = "criterion_bench"))]
fn main() {}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To have one #[cfg] less, we could move the compile_error! into the alternative main. We could also move all of the actual criterion stuff into a separate #[cfg]ed module, though I'm not sure that's worth it (this would require moving benches/event_deserialize.rs to benches/event_deserialize/main.rs)

@jplatte
Copy link
Copy Markdown
Member

jplatte commented Jul 6, 2020

Looks good, my only concern is the IDE thing you noted in #106.

@DevinR528
Copy link
Copy Markdown
Member Author

This works and doesn't mess up the IDE

#[cfg(not(feature = "criterion_bench"))]
fn main() {
    // To run the benchmarks the "criterion_bench" feature must be enabled.
    // `cargo bench --features criterion_bench --bench <name of the bench>`
    panic!("Enable the criterion_bench feature to run benchmarks");
}

gives

     Running /home/devinr/aprog/rust/__forks__/ruma/target/release/deps/event_deserialize-8bef32f29737f793
thread 'main' panicked at 'Enable the criterion_bench feature to run benchmarks', ruma-events/benches/event_deserialize.rs:124:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: bench failed

A compile_warning! would be nice here it's nightly only rust-lang/rust#54140

@jplatte
Copy link
Copy Markdown
Member

jplatte commented Jul 6, 2020

Yeah, let's just panic! if the feature flag is missing :)

Comment thread ruma-events/Cargo.toml Outdated
Comment thread ruma-events/Cargo.toml Outdated
Comment on lines +35 to +36
[features]
default = []
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm relatively certain this is unnecessary.

Comment thread ruma-events/Cargo.toml Outdated
@jplatte jplatte merged commit 39b37e4 into ruma:master Jul 6, 2020
@DevinR528 DevinR528 deleted the gate-criterion branch May 3, 2021 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Don't build criterion in CI

2 participants