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

Cargo metadata: Expose available build profiles #11228

Open
jschwe opened this issue Oct 13, 2022 · 3 comments
Open

Cargo metadata: Expose available build profiles #11228

jschwe opened this issue Oct 13, 2022 · 3 comments
Labels
A-profiles Area: profiles C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-metadata S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request.

Comments

@jschwe
Copy link
Contributor

jschwe commented Oct 13, 2022

Problem

Currently cargo metadata does not expose which custom build profiles are available.
For corrosion which integrates cargo into CMake it would be nice to expose a list of available build profiles for users to choose from (e.g. in a graphical interface for configuring CMake cache variables).

Proposed Solution

Add an additional field to the package section which contains an array of available profile names (dev, release, test, bench plus any custom profiles).

Notes

No response

@jschwe jschwe added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Oct 13, 2022
@jyn514
Copy link
Member

jyn514 commented Feb 2, 2023

This would be helpful for holmgr/cargo-sweep#76.

@weihanglo weihanglo added S-needs-team-input Status: Needs input from team on whether/how to proceed. S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request. and removed S-needs-team-input Status: Needs input from team on whether/how to proceed. labels Jul 9, 2023
@calavera
Copy link
Contributor

calavera commented Jul 9, 2023

I was looking to extract profile information from cargo metadata, when I noticed that the information in not serialized, and I bumped into this issue.

I maintain a Cargo plugin called Cargo Lambda to help people build and deploy Rust projects on AWS Lambda. By default, Cargo Lambda adds some release optimizations, via RUSTFLAGS, when projects are built, like -C strip="symbols. Small binaries are important to deploy on AWS Lambda because they help reduce cold starts. Debug symbols are also not useful on AWS Lambda because you cannot attach a debugger to your production environment. This way, people don't need to add optimizations to every project themselves.

I was about to add other optimizations, and I wanted to check if the user has already set those options in their [profile.release] section. This check is important because I don't want to override values set by users. For example, I want to set -C lto="thin" by default, but if a user has set [profile.release] lto="fat", I don't want to override the option. My idea was to check the profile information from cargo metadata and apply optimizations as needed. Without exposing the profiles data, I have to parse Cargo.toml files myself.

I can update the code and open a PR to expose the profile data if this issue is accepted. I've contributed to the project in the past, so I'm familiar with the codebase.

@ehuss
Copy link
Contributor

ehuss commented Jul 9, 2023

Unrelated to this issue, I would advise against using -C flags to override cargo's behavior. There are some rules that cargo uses that can be disrupted or broken if you try to override them manually. If you want to control a profile setting, I would suggest to use environment variables (or maybe --config), like CARGO_PROFILE_RELEASE_LTO=thin or CARGO_PROFILE_RELEASE_STRIP=symbols.
(That won't help with your use case to not override the user's setting, since config takes precedence.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-profiles Area: profiles C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-metadata S-needs-info Status: Needs more info, such as a reproduction or more background for a feature request.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants