cargo: can't specify lto in profile on specific packages

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)

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 12
  • Comments: 20 (11 by maintainers)

Most upvoted comments

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

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

@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).

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

Same issue here.

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...

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?