-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add named path bases to cargo (v2) #3529
base: master
Are you sure you want to change the base?
Conversation
Mind fixing the 'Rendered' link in the OP? https://github.com/dpaoliello/rfcs/blob/basepath/text/3529-cargo-path-bases.md :) |
Oops, my bad, thanks! |
Creating a thread on Rust internals to discuss alternative solutions for this issue: https://internals.rust-lang.org/t/integration-with-mono-repos-via-intermediate-directories/20160 |
We discussed this in today's @rust-lang/cargo meeting. We were generally in favor, but wanted to see a few changes made. @rfcbot merge First, this should be @rfcbot concern rename-to-base-paths Second, it should be possible to define this in @rfcbot concern define-in-manifest-override-in-config Third, we should restrict the possible names for bases, to reserve space for extension in the future. We felt that base names should be restricted to the same naming as package names: "The name must use only alphanumeric characters or - or _, and cannot be empty." @rfcbot concern base-names-alphanumeric-with-dash-or-underscore Finally, this should define a mechanism for Cargo to provide built-in base paths. User-defined base paths should shadow built-in base paths, so that we can add more in the future without creating conflicts. And we should provide a built-in @rfcbot concern allow-built-in-base-paths-with-shadowing |
Team member @joshtriplett has proposed to merge this. The next step is review by the rest of the tagged team members: Concerns:
Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
Introduce shared base directories in Cargo configuration files that in turn enable base-relative path dependencies.
@joshtriplett I've updated the RFC to address these concerns Also, I especially love the built-in |
@rfcbot resolved rename-to-base-paths |
@rfcbot resolved base-names-alphanumeric-with-dash-or-underscore |
@rfcbot resolved define-in-manifest-override-in-config |
@dpaoliello Thank you for the updates! |
The more that I think about having base paths in the manifest, the less that I like it. If you are using it for convenience, then this suggests that you have a bunch of packages locally which you'd like to reference from each other. In which case, why not drop a The original concern mentioned "default values". I'm not sure how useful that is versus using the I'm going to scope it out of this RFC, and it can be proposed later if someone has a strong case for it. |
I continue to think there's value in placing this in the manifest. We regularly find ourselves wishing that things in the config also existed in the manifest. However, I'm not going to treat that as a blocking concern. We can add it to the large pile of things that only exist in config and not yet in the manifest. Hopefully we shrink that pile over time. |
@epage I've removed support for defining this in the manifest, can you please resolve the |
I had missed an important piece of the conversation. Specifically that @joshtriplett's use case is not hypothetical. The second paragraph here is his actual use case. He has two different workspaces and regularly needs to construct path dependencies from one to the other. (I would like to apologize again, and publicly, for the rude thing I said when calling for a non-hypothetical user.) This leads me to being comfortable merging a version of this RFC that does allow setting it in the Cargo.toml. That being said, adding that functionality later is always a possibility. So if the decision of the team is to accept an RFC that only discusses config, I would not object. Leaving Cargo.toml for later is a two way door. |
I agree that this is a valid use case for this feature, but it does not require path bases in the manifest - they could be specified in the configuration instead. It might be more convenient to have them in the manifest, but given all of the complexity surrounding how to handle workspace vs member manifests I'd rather defer that for now. |
If we feel the config use case is important on its own, an important reason for splitting out manifest support is we don't block on the extra questions that introduces (workspace vs package, implicit vs explicit inheritance, etc) |
mechanism is simple to understand and to use, and still covers a wide | ||
variety of use-cases. | ||
|
||
## Support for declaring path bases in the manifest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move this to Future Possibilities and call out the open questions on workspace vs package, implicit vs explicit inheritance, etc.
# Unresolved questions | ||
[unresolved-questions]: #unresolved-questions | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Unresolved questions | |
[unresolved-questions]: #unresolved-questions | |
# Unresolved questions | |
[unresolved-questions]: #unresolved-questions | |
- What exact names we should use for the table (`path-bases`) and field names (`base`) | |
I feel uncomfortable with the names but don't think we need to block approval of the RFC on it.
# Summary | ||
[summary]: #summary | ||
|
||
Introduce shared base directories in Cargo configuration files that in | ||
turn enable base-relative `path` dependencies. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a config/manifest summary here for easy reference on what the proposal is?
Cargo can also provide built-in base paths, for example `workspace` to point to | ||
the root directory of the workspace. This allows workspace members to reference | ||
each other without first needing to `../` their way back to the workspace root. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cargo can also provide built-in base paths, for example `workspace` to point to | |
the root directory of the workspace. This allows workspace members to reference | |
each other without first needing to `../` their way back to the workspace root. | |
Cargo will also provide built-in base paths, for example `workspace` to point to | |
the root directory of the workspace. This allows workspace members to reference | |
each other without first needing to `../` their way back to the workspace root. | |
The current wording makes it sound like a future possibility
* `workspace` - If a project is [a workspace or workspace member](https://doc.rust-lang.org/cargo/reference/workspaces.html) | ||
then this path base is defined as the parent directory of the root Cargo.toml of | ||
the workspace. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about a package
base that is the default value for base
?
While this won't necessarily be a value users specify explicitly, I think it can help in modeling this to talk about how this feature works generally and not just in this specific case.
I am fine with this being an Unresolved Question that is left for stabilization.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, if including config, maybe current-dir
would be a better name
path base is prepended to the `path` value to produce the actual location where | ||
Cargo will look for the dependency. | ||
|
||
For example, if the Cargo.toml contains: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example, if the Cargo.toml contains: | |
For example, if the `Cargo.toml` contains: | |
them in a `[path-bases]` table. | ||
|
||
* `workspace` - If a project is [a workspace or workspace member](https://doc.rust-lang.org/cargo/reference/workspaces.html) | ||
then this path base is defined as the parent directory of the root Cargo.toml of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then this path base is defined as the parent directory of the root Cargo.toml of | |
then this path base is defined as the parent directory of the root `Cargo.toml` of | |
There is a little more nuance I want to dig into. Will need to get back to this later (soon, I'm back from vacation) |
This RFC proposes a mechanism to specify path bases in `config.toml` or | ||
`Cargo.toml` files which can be used to prepend `path` dependencies. This allows |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This RFC proposes a mechanism to specify path bases in `config.toml` or | |
`Cargo.toml` files which can be used to prepend `path` dependencies. This allows | |
This RFC proposes a mechanism to specify path bases in `config.toml` which can be used to prepend `path` dependencies. This allows | |
As Cargo.toml
is deferred out
## Specifying Dependencies | ||
|
||
### Path Bases |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this is adding a new field to the detailed dependency table, we need to specify how it interacts with workspace inheritance
- Can it be specified in
workspace.dependencies
? Yes - Can it be specified in
dependencies
withworkspace = true
? No - How does specifying both of the above interact? N/A
the path must exist on any other host where you want to use the same | ||
`Cargo.toml` to build your project. | ||
|
||
# Reference-level explanation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should cargo add
be updated to handle this? If so, what would that look like?
and consume from some intermediate directory. Cargo has poor support for | ||
mono-repos: the only viable mechanism is `path` dependencies, but these require |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would assume the biggest issue for monorepos is scaling the builds. If you use a registry, features like rust-lang/cargo#5931 could help. We have no plans in site for any kind of monorepo caching scheme. This makes me wonder how viable Cargo is more generally for monorepos which makes me wonder how important this feature is.
## Support patches | ||
|
||
It may also be useful to be able to use path bases in `patch` and `path` tables. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With how intertwined dependencies and patches are in Cargo, this should probably be called out in the main section of the RFC that patches are not intended to be supported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We talked about this in today's Cargo meeting and lean towards going ahead and supporting patches now.
- In theory, we'll get support for nearly free. We'll need to test various corner cases and maybe something will be uncovered that needs development
- Otherwise, we'd have to add explicit error checks and tests for the various corner cases to ensure the error check happens
@rfcbot concern comments |
@rfcbot resolved need-for-manifest |
the name of a path base from the `[path-bases]` table in either the | ||
[configuration](https://doc.rust-lang.org/cargo/reference/config.html#path-bases) | ||
or one of the [built-in path bases](#built-in-path-bases). The value of that | ||
path base is prepended to the `path` value to produce the actual location where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
path base is prepended to the `path` value to produce the actual location where | |
path base is prepended to the `path` value (along with a path separator if necessary) to produce the actual location where | |
(This ensures a base of xyz
and a path of abc
produces xyz/abc
rather than xyzabc
.)
Like with other path dependencies, keep in mind that both the base _and_ | ||
the path must exist on any other host where you want to use the same | ||
`Cargo.toml` to build your project. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also use `base` along with `path` when specifying a `[patch]`. Specifying a `path` and `base` on a `[patch]` is equivalent to specifying just a `path` containing the full path including the prepended base. | |
|
||
## Support patches | ||
|
||
It may also be useful to be able to use path bases in `patch` and `path` tables. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
## Support patches | |
It may also be useful to be able to use path bases in `patch` and `path` tables. |
(Along with the suggestion above adding it.)
Introduce shared base directories in Cargo configuration files that in turn enable base-relative path dependencies.
Rendered
Draft Implementation PR: rust-lang/cargo#12974
This is a resurrection of @jonhoo's RFC (#3074). Many thanks and kudos to him for the idea, original RFC text and original implementation.
FCP proposed: checkboxes at #3529 (comment)