-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Make package.name
optional
#12689
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
Comments
I'm not sure we'd be able to reduce documentation much here, as the logic to take the filename would not be suiting for |
Oops, forgot to specify the parent directory. While that technically is still a difference, the general concept is the same which makes it easier to teach. |
We talked about this in today's @rust-lang/cargo meeting. People seemed somewhat amenable to this, though we want to discuss it again with @epage present. There were also a few caveats:
|
I'm on board with that. Especially when a package is in the root of a repo, one can accidentally change the name of the package and we probably want it pinned.
I would be interested in better understanding the concern here.
Should these restrictions apply equally to cargo scripts when we add support for them being workspace members, depending on them (most likely as artifact dependencies), or publishing them? Granted, we don't have to make that decision yet but we'd need to track it to remember for when we do stabilize support for those situations (which wouldn't be considered until after the MVP is stabilized). |
We discussed this in today's @rust-lang/cargo meeting. @Eh2406 had a good suggestion for simplifying this further: we could just say that if a crate doesn't have a name, it can't be a dependency. |
To expand on that and to answer my earlier question on the problems with git dependencies, the issue is when the package is in the root of the repo. In that situation, the name is not under version control and is subject to how the work-dir was checked out. So the problem with publishing a package to a registry equally applies to git and path dependencies. So like Josh said, our publish solution of "don't allow it" could be extended to dependencies. If we don't allow the name-less packages to be discovered in the first place, adding it later would introduce a slight incompatibility because name that might have been unambiguous might become ambiguous. We could consider that the users problem that they created that situation. Or we could allow the package to be discovered by its implicit name but then error on use, bypassing that problem. That error could happen in the Source or in a Lint pass. If we were to implement git dependency support, it would be trivial as our git discovery code uses our regular manifest loading code and there is no extra work needed to support optional names. If we wanted to make it error when in the root of a repo, that would likely need to be done after manifest loading because the manifest loading code doesn't have knowledge of the git repo root. |
Problem
The primary motivation for this is to close the gap between
Cargo.toml
and the cargo script experiment (#12207).For
Cargo.toml
,package.name
is requiredFor "cargo script",
package.name
is defaulted to a slug of the file stem.Proposed Solution
Like with #9829, making this field optional would reduce the specialized documentation around "cargo script". The default for
Cargo.toml
would be a slug of the parent directory.Notes
I think there are some other concrete cases that could potentially benefit from this, like rust-lang/rfcs#3452 though I overall see this rarely being relied upon.
The text was updated successfully, but these errors were encountered: