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

cargo init or cargo new Cargo.toml don't respect workspace exclude #13235

Closed
kzhui125 opened this issue Jan 2, 2024 · 10 comments
Closed

cargo init or cargo new Cargo.toml don't respect workspace exclude #13235

kzhui125 opened this issue Jan 2, 2024 · 10 comments
Assignees
Labels
C-bug Category: bug Command-init Command-new S-triage Status: This issue is waiting on initial triage.

Comments

@kzhui125
Copy link

kzhui125 commented Jan 2, 2024

Problem

when I have a workspace, exclude data:

[workspace]
resolver = "2"
members = ["crates/*"]
exclude = ["data"]

then I create a new crate in data folder:

The Cargo.toml will be:

version.workspace = true
edition.workspace = true

instead of

version = "0.1.0"
edition = "2021"

I have to change it manually.

Steps

No response

Possible Solution(s)

No response

Notes

No response

Version

No response

@kzhui125 kzhui125 added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Jan 2, 2024
@Rustin170506
Copy link
Member

Could you please provide your Cargo version?

I can not reproduce this issue. My Cargo version:

cargo -Vv
cargo 1.77.0-nightly (ac6bbb332 2023-12-26)
release: 1.77.0-nightly
commit-hash: ac6bbb33293d8d424c17ecdb42af3aac25fb7295
commit-date: 2023-12-26
host: aarch64-apple-darwin
libgit2: 1.7.1 (sys:0.18.1 vendored)
libcurl: 8.4.0 (sys:0.4.70+curl-8.5.0 system ssl:(SecureTransport) LibreSSL/3.3.6)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: Mac OS 14.2.1 [64-bit]

@kzhui125
Copy link
Author

kzhui125 commented Jan 2, 2024

this is my cargo version:

cargo 1.75.0 (1d8b05cdd 2023-11-20)
release: 1.75.0
commit-hash: 1d8b05cdd1287c64467306cf3ca2c8ac60c11eb0
commit-date: 2023-11-20
host: aarch64-apple-darwin
libgit2: 1.7.1 (sys:0.18.1 vendored)
libcurl: 8.4.0 (sys:0.4.68+curl-8.4.0 system ssl:(SecureTransport) LibreSSL/3.3.6)
ssl: OpenSSL 1.1.1u  30 May 2023
os: Mac OS 14.2.1 [64-bit]

@kzhui125
Copy link
Author

kzhui125 commented Jan 2, 2024

It seems another issue.

cargo init will add members = ["data/a1"] to workspace Cargo.toml, it doesn't respect the exclude setting.

When I remove the members = ["data/a1"], then I have to change the Cargo.toml in data/a1 folder

[workspace]
resolver = "2"
exclude = ["data"]
members = ["data/a1"]

@Rustin170506
Copy link
Member

Oh, I see. I think there are two problems:

  1. When we add a new package to a workspace, it may not always respect the exclude glob. It will only skip adding the new package to the members list if the exclude path exactly matches the path of the new package. For instance, if we set exclude = ["data/test2"], then the new package won't be added to the members list.
  2. Even if you set exclude = ["data/test2"], it will still add version.workspace = true to inherit the package fields from the workspace.

cc: @epage Any thoughts about those behaviors? I am not sure if the first issue is by design.
But I think the second one is a bug.

@kzhui125
Copy link
Author

kzhui125 commented Jan 4, 2024

I have a main cargo workspace which contain data folder.

I will create many crates in data/**.

But when using cargo init or cargo new, I don't want to add those crates to main workspace.

Thanks,

@Rustin170506
Copy link
Member

@rustbot claim

@epage
Copy link
Contributor

epage commented Jan 8, 2024

cargo new should only inherit from a workspace it should be a member of and we should only make it a member if our path isn't already excluded.

Does that clarify things?

@Rustin170506
Copy link
Member

  1. When we add a new package to a workspace, it may not always respect the exclude glob. It will only skip adding the new package to the members list if the exclude path exactly matches the path of the new package. For instance, if we set exclude = ["data/test2"], then the new package won't be added to the members list.

This was a mistake. We don't support glob for exclude path now.

@Rustin170506
Copy link
Member

@kzhui125 Did you try this fix? I think this would help you fix your issue.

If you don't have any more questions. Could you please close this issue?

@kzhui125
Copy link
Author

will try, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug Command-init Command-new S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

No branches or pull requests

3 participants