-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
[profile.*] not affecting doctests #4251
Comments
Another use case: no_std crates. I have a doctest with
What I would like is to use
Currently I use |
This link #3166 (comment) add some context why it might not be that easy. In my case, though, doctest is |
Set an option for running doctests so that they can be run without the "`eh_personality` language item not found" popping up. See also: rust-lang/cargo#4251
By using custom profile, we can have a profile for doctest or whatever, so we probably don't need an extra built-in profile. This solves the first half of the issue. The other half is that there is a discrepancy between rustc and rustdoc handling (see #6570 (comment)) options, we track it with #6570. For panic behaviour in test/doctest driven by libtest, please follow the progress of Going to close this now. If you found this is a fault, please comment, and we'll consider re-open. |
If a custom profile is used it wouldn't be used by |
This issue was created before custom profiles got stabilized, so I assumed you didn't know the feature at that time. Now it looks like even with the ability to customize profiles, a built-in one for doc/doctest is still the thing you are looking for, right? I'd like to know more about your opinion on having a built-in versus customizing your own. Could you share more from your side? Thank you! |
Basically my goal is to get 1: I guess having a separate built-in profile may be nicer architecture but not sure if it's worth the hassle. |
Sorry, I don't really get it. What do you want to achieve with Assumed you meant I'd suggest using the combos of config
Unfortunately, Cargo doesn't allow an alias to shadow built-in commands. Instead, people need to run On the other hand, as aforementioned, rustdoc doesn't handle all compiler settings in the same way as rustc, so we may need to fix that before adding any built-in profile for rustdoc. Otherwise people will get confused by those flags not working the same. |
Sorry, yes, I meant
it shouldn't by default, only when overridden by
Indeed. |
From my perspective, I would much prefer building doctests with the same profile as unit tests (i.e. #[cfg(test)]
compile_error!("cfg(test)");
#[cfg(not(test))]
compile_error!("cfg(not(test))"); Running
How can
(By the way, True, the above situation rarely happens in real life—I believe this would come up only when compiler settings (like Footnotes
|
Thank @andylizi for pointing out one concern I have. Currently, profile selection is on a command-basis. All rustc invocations of a Cargo command invocation should receive the same set of flags (theoretically, see #6570). If we decide to differentiate doctests from unit tests, it would probably complicate Cargo internals, and also confuses users as they now need to remember the special case of doctest since it will be a feature. Personally I lean toward not doing so. @andylizi said:
From my understanding, Cargo compiles doctests and unittests under the same profiles when executing If you run |
Agree with not making it a separate profile, |
Ah I see. I had thought it was profile-related because The problem I encountered was a long time ago and I've forgot the exact details (maybe something to do with |
There seems to be no way to set profile for doctests. I need it in my two crates - without
opt_level = 3
it fails to compile (this is on purpose of course).I'd suggest to use one of
profile.test
,profile.doc
or create a new one calledprofile.doctest
.Steps for reproducing:
no_compile
from doctestcargo doc
Expected result: cargo compiles optimized version (without call to non-existing function)
What happened: cargo ignored any profile options and attempted to build doctest without optimization.
The text was updated successfully, but these errors were encountered: