Skip to content

Workspace "profile ignored" warning discounts the possibility of publishing binary crates which use profile settings #8264

Open
@daboross

Description

@daboross

Problem

When a profile section is provided in the Cargo.toml for a crate in a workspace that isn't the workspace root, the following warning is generated:

warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
package:   /home/daboross/workspace/subcrate/Cargo.toml
workspace: /home/daboross/workspace/Cargo.toml

However, if subcrate is a binary crate published to crates.io, then the profile section will be used when someone cargo installs that crate. Moving the profile section to the workspace root would remove the settings when cargo installing the crate downloaded from crates.io.

Steps

  1. Create a workspace & subcrate:
cargo new workspace && cd workspace && cargo new subcrate
  1. Add workspace config:
echo "subcrate = { path = 'subcrate' }" >> Cargo.toml
echo "[workspace]" >> Cargo.toml

or copy whole Cargo.toml:

[package]
name = "workspace"
version = "0.1.0"
authors = ["David Ross <[email protected]>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
subcrate = { path = 'subcrate' }
[workspace]
  1. Add profile to subcrate:
echo "[profile.release]" >> subcrate/Cargo.toml
echo "opt-level = 3" >> subcrate/Cargo.toml

Or copy whole Cargo.toml:

[package]
name = "subcrate"
version = "0.1.0"
authors = ["David Ross <[email protected]>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
[profile.release]
opt-level = 3
  1. Build crates:
$ cargo build
warning: profiles for the non root package will be ignored, specify profiles at the workspace root:
package:   /home/daboross/workspace/subcrate/Cargo.toml
workspace: /home/daboross/workspace/Cargo.toml
   Compiling workspace v0.1.0 (/home/daboross/workspace)
    Finished dev [unoptimized + debuginfo] target(s) in 0.36s

Possible Solution(s)

Add a way to ignore this warning, and output a suggestion for that when outputting the error? Could be something like

[cargo-warnings]
ignored-profile = "ignore"

And when the error occurs, something like:

note: this profile will be used when publishing binary crates. To ignore warning, add the following to /home/dabross/workspace/subcrate/Cargo.toml:
  [cargo-warnings]
  ignored-profile = "ignore"

Another option could be to provide an option to copy configuration from workspace root when publishing the crate?

Notes

Output of cargo version: cargo 1.45.0-nightly (258c89644 2020-04-30)

I found this bug from this post on the users.rust-lang.org forum. The user in question decided to simply not have a workspace to avoid this error, but I don't think that's a good solution in general.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions