Skip to content

Support profile overrides for -Z build-std #15811

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

maurer
Copy link

@maurer maurer commented Aug 6, 2025

Pass both the main package graph and the build-std package graph to the verifier so that e.g. [profile.dev.package.core] is not rejected and ignored if core is being built.

What does this PR try to resolve?

Currently, [profile.dev.package.my_std_crate_here] will not be respected when -Z build-std=my_std_crate_here is passed, because profile overrides are verified on a package graph that does not include the build-std package graph.

This is important to support because many users of -Z build-std are targeting embedded environments where image space may be at a premium. This means that while they may be able to support a more relaxed dev build for their own code, they'd like to build standard libraries with optimizations and fewer assertions to shrink things down.

The default behavior without -Z build-std is to use prebuilt stdlibs, so you will get an optimized stdlib and a dev-profile version of your project. This configurability allows developers to opt back in to a similar configuration with -Z build-std by setting profile flags for core/compiler_builtins/alloc/std as appropriate.

How to test and review this PR?

cargo test should test it - I've added a new test which ensures both that:

  • No warning is emitted when a stdlib is specified in a profile clause and -Z build-std is used
  • The adjustment to the profile affects the requested crate
  • The adjustment to the profile does not affect another crate in the graph

@rustbot
Copy link
Collaborator

rustbot commented Aug 6, 2025

r? @weihanglo

rustbot has assigned @weihanglo.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-profiles Area: profiles S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 6, 2025
Pass both the main package graph and the build-std package graph to the
verifier so that e.g. `[profile.dev.package.core]` is not rejected and
ignored if `core` is being built.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to #15772 (comment) and #15670 (comment), build-std's design is in flux. We might want to hold off on making design changes at this momemnt. Also, we generally prefer to have a design discussed and approved before proceeding to implementation.

See also rust-lang/wg-cargo-std-aware#2 for the relevant build-std profile overrides.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not believe a design was required because I was not adding any new features, just fixing a bug (that when an override is set for core, and core is being built, we don't use the override).

Those overrides don't allow you to set core to be built with debug-assertions disabled while building the rest of the world with debug-assertions enabled, so they don't address the issue. Should I file a bug instead? This is preventing me from enabling BTI and PAC for a firmware project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-profiles Area: profiles S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants