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

can't specify lto in profile #9330

Closed
sehz opened this issue Apr 5, 2021 · 19 comments
Closed

can't specify lto in profile #9330

sehz opened this issue Apr 5, 2021 · 19 comments
Labels
A-lto Area: link-time optimization A-profiles Area: profiles C-bug Category: bug S-needs-team-input Status: Needs input from team on whether/how to proceed.

Comments

@sehz
Copy link

sehz commented Apr 5, 2021

Problem

Cargo doesn't accept lto in profile as below:

[profile.release.package.fluvio-filter-test]
lto = true

Steps
This result in following error message:

$ cargo check
error: failed to parse manifest at `/home/ubuntu/fluvio/Cargo.toml`

Caused by:
  `lto` may not be specified in a `package` profile
$ cargo version
cargo 1.51.0 (43b129a20 2021-03-16)
@sehz sehz added the C-bug Category: bug label Apr 5, 2021
@ehuss
Copy link
Contributor

ehuss commented Apr 5, 2021

Thanks for the report! Can you say more about your use case? LTO only works for the final artifact, so it can't be set per-dependency. Is this maybe an executable in a workspace?

@M1cha
Copy link

M1cha commented May 19, 2021

library crates (like clap-rs) can enable LTO. If the toolchain does not support LTO the build is gonna fail even though the binary crate you're trying to build doesn't have that enabled.

@ehuss ehuss added A-lto Area: link-time optimization A-profiles Area: profiles labels Jun 2, 2021
@petrochenkov
Copy link
Contributor

petrochenkov commented Apr 7, 2022

@ehuss

Is this maybe an executable in a workspace?

Yes, multiple executables, they can easily need different build settings.
In general, crates in the build tree aren't necessarily built together into the same binary.

I encountered the same issue, but with panic instead of lto

`panic` may not be specified in a `package` profile

The worst thing is that there's no reasonable workaround for this (or at least I haven't found one).

@petrochenkov
Copy link
Contributor

10 more people encountered the same issue here - #8264 (comment).

(I consider all of the "may not be specified in a {} profile" errors to be the same issue because in all these cases cargo wrongly assumes that all of the workspace members are always going to be combined into the same binary, which is pretty far from the truth.)

@petrochenkov
Copy link
Contributor

there's no reasonable workaround for this

Looks like it's possible to make a separate profile that inherits from the main one, but overrides panic or lto.
Then the specific package will always be built with that profile.

workspace members are always going to be combined into the same binary

Ugh, looks like different executables may share built dependencies, which is obviously good, but will prevent overriding things like panic.
I guess it's hard for cargo to setup some mini-equivalent of profiles to build dependencies with different panic values separately while keeping everything in a single workspace?

@eldenpark
Copy link

Is this being taken care of?

I'm having the same issue. Of many packages and crates in the workspace, I was hoping some specific crates to be compiled with different settings. Specifying profile in the non-root package caused warnings hence I put those in the workspace which throws out errors.

workspace
  - pkg1
    - lib crate
    - lib crate
    - bin crate
  - pkg2
    - lib crate (needs the compilation-specific settings)
  - other pkgs...

@ctrlcctrlv
Copy link

Same issue here.

@CPerezz
Copy link
Contributor

CPerezz commented Jan 15, 2023

Well, in the Cargo documentation it's already mentioned that panic, lto and rpath are not supported.
See: https://doc.rust-lang.org/cargo/reference/profiles.html#overrides at last line of the section.

What I ignore is if it could be supported or not.

@BartMassey
Copy link
Contributor

This is honestly pretty painful. I am giving up on the workspace for my toy example due to this, but it will arise in larger contexts. Anything that could be done to kludge around it?

@vogtb
Copy link

vogtb commented Mar 21, 2023

I'm experiencing this same issue. Would love a way around this.

@EstebanBorai
Copy link
Contributor

Any news on this?

@weihanglo weihanglo added the S-needs-team-input Status: Needs input from team on whether/how to proceed. label May 17, 2023
@epage
Copy link
Contributor

epage commented Sep 27, 2023

Since its not mentioned, the workaround for this is to define different profiles and build the different binaries with the relevant profiles.

@BartMassey
Copy link
Contributor

@petrochenkov commented that it's not clear that using different profiles is sufficient? I don't think I understand this workaround very well.

@epage
Copy link
Contributor

epage commented Sep 29, 2023

Missed that in the among the different commes but not seeing what the downside to it is.

@BartMassey
Copy link
Contributor

For LTO I don't know that it matters much if some deps are built with and some without: should be just a small performance surprise. For panic=abort it does seem to me that one normally wants it everywhere if they want it anywhere? Or am I misunderstanding how all this works?

@JohnScience
Copy link

Similar issue.

`panic` may not be specified in a `package` profile

@ExaltedVanguard
Copy link

The need to use multiple profiles definitely isn't ideal, since you can't just cargo build --workspace --release and have everything build correctly. I would also like to see overrides work for panic, lto, and rpath.

For those coming from google looking for a resolution, there are 2 workarounds. The first is to define a second profile with the relevant settings:

[profile.release-lto]
inherits = "release"
lto = true

and compile using cargo build --profile release-lto

The second is to add a /.cargo/config.toml to the crate and compile it from outside the workspace root. This works great for wasm.

workspace/
  - crates/
    - crate1/
      - .cargo/
        - config.toml
    - crate2/
    - crate3/
  - cargo.toml

where the contents of config.toml are the same as a standard cargo.toml and will override the workspace cargo.toml.

Note that this will NOT work if you call cargo build from workspace root (workspace>cargo build) but will work as expected (using local settings to override workspace settings) if you call it from the subdirectory (workspace/crates/crate1>cargo build).

This works great for the very common use-case of wasm-pack (which seems to be the use-case for several people in a related thread).
workspace>wasm-pack build crates/crate1 will work just fine, and you can get great size optimizations without affecting other projects in your workspace.

@sehz
Copy link
Author

sehz commented Aug 12, 2024

Profile in workspace works fine now and solves original problem I had. I consider this as resolved.

@sehz sehz closed this as completed Aug 12, 2024
@tgross35
Copy link

I think this may be worth leaving open to track a way to do this using the release profile, without workarounds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lto Area: link-time optimization A-profiles Area: profiles C-bug Category: bug S-needs-team-input Status: Needs input from team on whether/how to proceed.
Projects
None yet
Development

No branches or pull requests