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

Feature request: expose the Link Time Optimization profile settings to build scripts #15144

Open
JSorngard opened this issue Feb 4, 2025 · 2 comments
Labels
A-build-scripts Area: build.rs scripts A-profiles Area: profiles C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-needs-team-input Status: Needs input from team on whether/how to proceed.

Comments

@JSorngard
Copy link

JSorngard commented Feb 4, 2025

Problem

It is not possible for build scripts to see whether the profile that is currently used enables LTO, or which level of it.

Proposed Solution

Make the value of the lto profile setting exposed to build scripts as an environment variable, along with the other ones: https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts.

Notes

My reason for wanting this is that I use the no-panic crate to verify that a project of mine can't panic. In order to give some feedback if this test results in false positives I would like to be able to detect in a build script if the current profile enabled fat LTO.
EDIT: This is because no-panic can give false positives if LTO and optimizations are not enabled.

A related issue was recently closed: #11054.

Thanks for your time!

@JSorngard JSorngard added C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-triage Status: This issue is waiting on initial triage. labels Feb 4, 2025
@epage epage added A-profiles Area: profiles A-build-scripts Area: build.rs scripts S-needs-team-input Status: Needs input from team on whether/how to proceed. and removed S-triage Status: This issue is waiting on initial triage. labels Feb 4, 2025
@epage
Copy link
Contributor

epage commented Feb 4, 2025

What do you expect your build script to do with this information?

I'm assuming that generally, code shouldn't care about whether LTO isn't used anymore. This is a couple layers of workarounds

  • Because a better way to enforce no-panic isn't provided, the no-panic crate exists
  • Because of how the no-panic crate is implemented, it can't always see through some function calls and, if I'm understanding correctly, reports them as panicking. To see through these function calls, LTO is needed
  • To check whether failures are false positives, I'm assuming some kind of LTO conditional compilation is needed

As this is the first issue opened after closing #11054, we haven't really setup a precedence for whether we should blanket provide this information or if the cases need enough justification. For the latter, I would question this and suggest we work to resolve one of the other layers of this. We have also had alternative names for profile fields added in the past and so by exposing a profile field, we'd be locking things in to a degree which we'd need to work out the specifics for.

@JSorngard
Copy link
Author

JSorngard commented Feb 4, 2025

Currently I use a workaround to read the profile name from the OUT_DIR variable, and emit a compile warning if the panic check is enabled, but the profile isn't the release-lto custom profile. The point is to tell the user that the errors they are getting are false positives and how those can be avoided.

I understand that some other solution to my proposal here might be preferred though.

I did some edits for clarity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-build-scripts Area: build.rs scripts A-profiles Area: profiles C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-needs-team-input Status: Needs input from team on whether/how to proceed.
Projects
None yet
Development

No branches or pull requests

2 participants