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

Duplicate rustflags should be de-duplicated #13774

Open
StealthyKamereon opened this issue Apr 18, 2024 · 4 comments
Open

Duplicate rustflags should be de-duplicated #13774

StealthyKamereon opened this issue Apr 18, 2024 · 4 comments
Labels
A-rustflags Area: rustflags C-bug Category: bug E-hard Experience: Hard S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

Comments

@StealthyKamereon
Copy link

Problem

I have a crate with a .cargo/config.toml to enable tracing unstable features:

[build]
rustflags = ["--cfg", "tracing_unstable"]

However I use this crate as part of a workspace. So I also put the previous config.toml in my workspace .cargo/config.toml.

Now everytime I save, rust-analyzer build every crate if I did a cargo check in the crate directory.
I found that it's because the rustflags are not merged properly:

INFO cargo::core::compiler::fingerprint:     dirty: RustflagsChanged { old: ["--cfg", "tracing_unstable"], new: ["--cfg", "tracing_unstable", "--cfg", "tracing_unstable"] }

Steps

  1. Create a workspace and put the following content in .cargo/config.toml:
[build]
rustflags = ["--cfg", "tracing_unstable"]
  1. Create a crate foo and put the following content in foo/.cargo/config.toml:
[build]
rustflags = ["--cfg", "tracing_unstable"]
  1. Now cargo check in the workspace and in the foo crate are rebuilding every crate instead of using previously built ones.

Possible Solution(s)

When appending rustflags, check for possible duplicates to avoid multiple same values counting as different ones.

Notes

No response

Version

cargo 1.78.0-nightly (ccc84ccec 2024-02-07)
release: 1.78.0-nightly
commit-hash: ccc84ccec4b7340eb916aefda1cb3e2fe17d8e7b
commit-date: 2024-02-07
host: x86_64-pc-windows-msvc
libgit2: 1.7.2 (sys:0.18.2 vendored)
libcurl: 8.6.0-DEV (sys:0.4.71+curl-8.6.0 vendored ssl:Schannel)
os: Windows 10.0.22621 (Windows 11 Professional) [64-bit]
@StealthyKamereon StealthyKamereon added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Apr 18, 2024
@StealthyKamereon
Copy link
Author

Possibly shares subjects with #5376 but is not exactly the same problem.

@epage
Copy link
Contributor

epage commented Apr 18, 2024

However I use this crate as part of a workspace. So I also put the previous config.toml in my workspace .cargo/config.toml.

So it sounds like you have

workspace/
  Cargo.toml
  .cargo/config.toml
  crateA/
    .cargo/config.toml
    Cargo.toml

Is that right?

is there a reason you do both configs, rather than just the workspace config?

As for de-duplicating, to do that would require us to have knowledge of rustc's CLI

  • To detect related names for arguments (short and long forms, aliases)
  • To know when -abc is -a -b -c or -a bc
  • To properly handle multiple values for an argument

Most CLIs are not written in a way to be able to reuse the same definition for parsing as de-duplicating, so we'd have to fork their CLI and keep it in sync.

@epage epage added the A-rustflags Area: rustflags label Apr 18, 2024
@StealthyKamereon
Copy link
Author

So it sounds like you have

workspace/
  Cargo.toml
  .cargo/config.toml
  crateA/
    .cargo/config.toml
    Cargo.toml

Exactly.

is there a reason you do both configs, rather than just the workspace config?

The crateA is versionned in its own git and I would like users to keep being able to just pull and run instead of having to mess with cargo config.

As for de-duplicating, to do that would require us to have knowledge of rustc's CLI

I understand that what I'm asking is far from trivial ☹️ But at the same time it's super weird to see cargo rebuild all the crate because having multiple times the same flag (or even just not in the same order) is considered different.

@weihanglo weihanglo added E-hard Experience: Hard S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted. and removed S-triage Status: This issue is waiting on initial triage. labels Apr 19, 2024
@soloturn
Copy link

soloturn commented Apr 27, 2024

why are you using workspace and not CARGO_TARGE_DIR @StealthyKamereon ? i understand one reason may be that you do not get the binaries easy enough - there is an unstable flag since 5 years: #6790.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustflags Area: rustflags C-bug Category: bug E-hard Experience: Hard S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.
Projects
None yet
Development

No branches or pull requests

4 participants