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

Allow profile to be used in cfgs #3803

Closed
torkleyy opened this issue Mar 7, 2017 · 7 comments
Closed

Allow profile to be used in cfgs #3803

torkleyy opened this issue Mar 7, 2017 · 7 comments

Comments

@torkleyy
Copy link
Contributor

torkleyy commented Mar 7, 2017

It would be nice to have something like

#[cfg(profile = "bench")]
pub use InternalStruct;

That is helpful if you want to benchmark something internal of the library without exporting it globally.

@aturon
Copy link
Member

aturon commented Mar 11, 2017

@alexcrichton See any downsides to exposing the profile this way? This seems like a good "mentored PR" situation.

@alexcrichton
Copy link
Member

Unfortunately there's not actually a great way to implement this. Libraries are compiled in either dev or release, they're never compiled with a "bench" option to get linked against. This is due to Cargo's caching strategy where it caches builds of a library between cargo build --release and cargo bench.

@torkleyy is it possible to use a separate crate for this, or use support in benches/*.rs to implement this?

@torkleyy
Copy link
Contributor Author

@torkleyy is it possible to use a separate crate for this, or use support in benches/*.rs to implement this?

I am already using benches and I don't see how another crate would solve that. I guess the only way would be to integrate the benchmark into the module and do conditional compilation based on stable / unstable.

@aturon
Copy link
Member

aturon commented Mar 13, 2017

I'm going to go ahead and close out the issue as written, since as @alexcrichton points out, we're specifically avoiding a separate compilation step for libraries when benchmarking, and it doesn't seem like that's something we'd want to change.

@aturon aturon closed this as completed Mar 13, 2017
@sam0x17
Copy link

sam0x17 commented Oct 28, 2022

Is there any workaround for this in 2022?

@torkleyy
Copy link
Contributor Author

torkleyy commented Nov 7, 2022

Only using an "unstable" feature flag and enable it when you're benchmarking, afaik.

@Pzixel
Copy link

Pzixel commented Nov 1, 2023

I've created a topic on irlo: https://internals.rust-lang.org/t/ability-to-detect-profiles/19794

In a nutshell I think that this question was closed preemptively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants