Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 4 commits into from Jul 6, 2020

Conversation

DevinR528
Copy link
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
Member

@jplatte jplatte Jul 6, 2020

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
Member

jplatte commented Jul 6, 2020

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

@DevinR528
Copy link
Member Author

DevinR528 commented Jul 6, 2020

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
Member

jplatte commented Jul 6, 2020

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

ruma-events/Cargo.toml Outdated Show resolved Hide resolved
[features]
default = []
Copy link
Member

@jplatte jplatte Jul 6, 2020

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.

ruma-events/Cargo.toml Outdated Show resolved Hide resolved
@jplatte jplatte merged commit 39b37e4 into ruma:master Jul 6, 2020
3 checks passed
@DevinR528 DevinR528 deleted the gate-criterion branch May 3, 2021
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.

2 participants