rust-lang / rust-lang/cargo

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

Open
#8,264 14 comments 39 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-profiles C-bug Command-publish S-triage
Dominant language
Rust
Stars
15.5k
Forks
3k
Avg merge
23h 30m
Merged PRs (30d)
51

Description

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 <daboross@daboross.net>"]
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 <daboross@daboross.net>"]
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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the workspace and subcrate Cargo.toml files described in the reproduction, then run the listed cargo build command and compare it with publishing or installing the binary crate. Determine how the warning should account for profiles used by published binary crates, and define the expected warning or configuration behavior before changing it.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.