-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Named custom cargo profiles #2678
Conversation
Co-Authored-By: da-x <[email protected]>
Co-Authored-By: da-x <[email protected]>
Co-Authored-By: da-x <[email protected]>
Co-Authored-By: da-x <[email protected]>
It's very helpful to be able to run test binary under gdb, or the bench binary under a profiler. These have unpredictable paths already, so a different location would be fine, but they should be persisted in an accessible location. |
The RFC doesn't mention cross-compilation. Cargo changes |
Might be orthogonal, but many times i really wished that there's a profile that build the current crate in dev mode but all its dependencies in release mode. |
Yes, a different profile for the workspace and dependencies outside of the workspace would be fantastic. |
I definitely want something iike this. The "Direct The justfile in my project boilerplate already works around the lack of this functionality by using custom The downside is that, due to that and my justfile forcing Another former downside that wasn't specifically due to the lack of custom profiles (rather, it was about (On the plus side, cargo-make's
Why is it so important for the profile to be named I couldn't find a justification for that.
Assuming we take it as a given that we're not going to accept the convenience regression of requiring users to do some setup before they can run |
The main issue is backward compatibility. If the alternative is to abolish the
The alternative would be for |
Yes, that would be the expected behavior. Should update the RFC. |
@crlf0710 @kornelski I think this is achievable with profiles overrides (currently in nightly cargo). Combined with this RFC's changes, it would be even better, because you could have these overrides under a custom profile, retaining the standard functionality with the For example:
|
Ahh, yes. I'd forgotten about that existing mismatch. Hazard of putting together a project template once and then not needing to modify it much, I guess. |
Maybe It's for development only, so it doesn't affect crate users, and the developer will see any deprecation notices. |
So the suggestion as I understand - having a However I am not sure it puts the This may be a good, but I'd feel better with more votes on the matter. Pinging @ehuss @matklad @Manishearth. |
(I'm not really a cargo person, and while I've written a profile RFC before I don't have strong opinions on this. I recall the cargo team having plans about profiles, though) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for putting this together!
Some questions/comments:
- What happens if the user specifies
--release --profile=foo
? - Is
--release
an alias for--profile=release
? - Currently the profile is driven by the command, cargo target (
--test
uses test,--bench
uses bench,--all-targets
uses a mixture, etc.), and the--release
flag. Does Cargo continue to behave that way if no profile is chosen? I'm concerned that is a little confusing, but the alternative (only using one profile) would also be problematic. doc
is currently unused, and I think has some issues that would prevent it from being reintroduced. I would prefer to leave outdoc
in the discussion here and leave it for future consideration.- There should be restrictions on valid profile names. I'm thinking the same as a package name (
validate_package_name
) would be a good start, though maybe it should be even more restrictive? - Can you add a link to the PR description to https://internals.rust-lang.org/t/strawman-pre-rfc-custom-profiles/6412 which had a very similar proposal?
- Does
cargo test --profile=foo
build all crates with thefoo
profile? Currentlycargo test
is a little strange in that dependencies are built with dev/release. I'm thinking this might be a good opportunity to change that, so that test/bench are less special. The drawback is that it takes longer to compile if you change thetest
profile (since it can't share dependencies withdev
), but it may be worthwhile.
|
||
Finished release-lto [optimized + lto] target(s) in 3.83s | ||
|
||
* As before, optimization mode is always printed, with `optimized` if |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with the Finished
line is that multiple profiles may be used during a single command. For example, cargo build --all-targets
can use both dev
and test
. I think this will need more consideration to figure out the best way to present a final summary.
FWIW, I don't mind that it is slightly incorrect now, so I don't think it is critical to fix this. But it should be fixed at some point, so it would be good to hear if anyone has any ideas on how to fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on more feedback from more users, we may leave it out from the RFC or move it to the 'future possibilities' section (makes sense?). Maybe a good solution would come out of trying to implement a better Finished
line while working to implement this RFC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, do think it would be realistic to print a Finished
line per target, with the profiles that used to build it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with deferring the details here. I'm not sure if printing multiple lines would be desirable. Perhaps after it's implemented we could experiment with a few different examples and come up with something people can look at.
* Similarly, `TomlProfiles` will be changed to hold profiles in a `BTreeMap`. | ||
* We would need to compute the actual `build_override` for a profile based on | ||
resolution through the `inherited` key. | ||
* Custom build scripts: For compatibility, the `PROFILE` environment currently |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about this change. Why the output directory and not the profile name? Some build scripts use it for accessing the output directory, but in general they shouldn't be.
Also, build scripts today only expect two values ("release" and "debug") and typically use that to determine how to compile other code. They will have no knowledge of any other profile name (especially within dependencies which are from other projects). I'm not sure we can change this behavior. No matter what is done here, I think it will break some projects.
I'm wondering if it might be best to deprecate "PROFILE"
, and build scripts should use "DEBUG"
and "OPT_LEVEL"
for determining build settings. I don't think they should be writing to the target directory. It could keep some sort of "best guess" to set it to "debug" or "release".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it would be ok, to have it debug
or release
depending on the inherited-from profile being used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so?
Co-Authored-By: da-x <[email protected]>
Co-Authored-By: da-x <[email protected]>
Co-Authored-By: da-x <[email protected]>
Co-Authored-By: da-x <[email protected]>
Co-Authored-By: da-x <[email protected]>
Co-Authored-By: da-x <[email protected]>
@ehuss, thanks for investing the time to review!
I'd suggest the following:
Yes. I think it would be too late to deprecate this functionality.
Agreed.
Yes, let's take the restriction from package names: Name must not be empty, use only alphanumeric characters or
Was not aware of it. Sure.
It's very good that you brought this up. If I understood correctly, only the special test crate is built with the
The existing functionality has the advantage that in |
Co-Authored-By: da-x <[email protected]>
Co-Authored-By: da-x <[email protected]>
Co-Authored-By: da-x <[email protected]>
Co-Authored-By: da-x <[email protected]>
Co-Authored-By: da-x <[email protected]>
I'm not sure. I'll ask the team if there's any opinion on this. |
Spurious b indeed. Thanks. Co-Authored-By: da-x <[email protected]>
Discussed this with the team. I think we all agree that we should remove the special casing for test/bench, and make them behave like a normal profile (that is, they don't treat dependencies differently). If someone really wants to only apply profile settings to the local crate, they can use I'd like to move this forward, as I think we're all 👍 on the basic concept of adding named profiles. @rfcbot fcp merge |
Team member @ehuss has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
Thanks! Regarding this discussion:
It's the main point still standing, i.e whether to have this fallback or keep the RFC as it is. I'm assuming this can be a version 2.0 material? |
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. The RFC will be merged soon. |
Huzzah! This RFC has been merged! Tracking issue: rust-lang/cargo#6988 |
Summary
The proposed change to Cargo is to add the ability to specify user-defined profiles in addition to the four predefined profiles,
dev
,release
,test
, andbench
. It is also desired in this scope to reduce confusion regarding where final outputs reside, and increase the flexbility to specify the user-defined profile attributes.Related links