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

Add named path bases to cargo (v2) #3529

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

dpaoliello
Copy link

@dpaoliello dpaoliello commented Nov 14, 2023

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)

@ehuss ehuss added the T-cargo Relevant to the Cargo team, which will review and decide on the RFC. label Nov 14, 2023
@runiq
Copy link

runiq commented Nov 16, 2023

Mind fixing the 'Rendered' link in the OP? https://github.com/dpaoliello/rfcs/blob/basepath/text/3529-cargo-path-bases.md :)

@dpaoliello
Copy link
Author

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!

@dpaoliello
Copy link
Author

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

@joshtriplett
Copy link
Member

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 base-paths, rather than base_path, for consistency with other manifest fields which use plurals and dashes.

@rfcbot concern rename-to-base-paths

Second, it should be possible to define this in Cargo.toml, not only in config.toml. config.toml or environment variables can always override, but Cargo.toml should be able to define the default values.

@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 workspace base path that refers to your workspace root.

@rfcbot concern allow-built-in-base-paths-with-shadowing
@rfcbot concern define-built-in-workspace-base-path

@rfcbot
Copy link
Collaborator

rfcbot commented Jun 18, 2024

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.

@rfcbot rfcbot added proposed-final-comment-period Currently awaiting signoff of all team members in order to enter the final comment period. disposition-merge This RFC is in PFCP or FCP with a disposition to merge it. labels Jun 18, 2024
Introduce shared base directories in Cargo configuration files that in turn enable base-relative path dependencies.
@dpaoliello
Copy link
Author

@joshtriplett I've updated the RFC to address these concerns

Also, I especially love the built-in workspace base path - that's super nice!

@joshtriplett
Copy link
Member

@rfcbot resolved rename-to-base-paths

@joshtriplett
Copy link
Member

@rfcbot resolved allow-built-in-base-paths-with-shadowing
@rfcbot resolved define-built-in-workspace-base-path

@joshtriplett
Copy link
Member

@rfcbot resolved base-names-alphanumeric-with-dash-or-underscore

@joshtriplett
Copy link
Member

@rfcbot resolved define-in-manifest-override-in-config

@joshtriplett
Copy link
Member

@dpaoliello Thank you for the updates!

@dpaoliello
Copy link
Author

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 config.toml in a common parent directory that then points to each of the useful subdirectories with your packages? If you are putting the base paths in the manifests, then you'll need to duplicate that list into each of your manifests.

The original concern mentioned "default values". I'm not sure how useful that is versus using the patch feature - if you want to override where Cargo looks for packages, then that's what patch is for.

I'm going to scope it out of this RFC, and it can be proposed later if someone has a strong case for it.

@joshtriplett
Copy link
Member

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.

@dpaoliello
Copy link
Author

@epage I've removed support for defining this in the manifest, can you please resolve the need-for-manifest concern?

@Eh2406
Copy link
Contributor

Eh2406 commented Jul 2, 2024

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.

@dpaoliello
Copy link
Author

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.

@epage
Copy link
Contributor

epage commented Jul 5, 2024

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
Copy link
Contributor

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.

Comment on lines +382 to +384
# Unresolved questions
[unresolved-questions]: #unresolved-questions

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 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.

Comment on lines +6 to +10
# Summary
[summary]: #summary

Introduce shared base directories in Cargo configuration files that in
turn enable base-relative `path` dependencies.
Copy link
Contributor

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?

Comment on lines +108 to +110
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Comment on lines +190 to +192
* `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.
Copy link
Contributor

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.

Copy link
Contributor

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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

@epage
Copy link
Contributor

epage commented Jul 5, 2024

@epage I've removed support for defining this in the manifest, can you please resolve the need-for-manifest concern?

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)

Comment on lines +33 to +34
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Comment on lines +147 to +149
## Specifying Dependencies

### Path Bases
Copy link
Contributor

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 with workspace = 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
Copy link
Contributor

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?

Comment on lines +27 to +28
and consume from some intermediate directory. Cargo has poor support for
mono-repos: the only viable mechanism is `path` dependencies, but these require
Copy link
Contributor

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.

Comment on lines +424 to +426
## Support patches

It may also be useful to be able to use path bases in `patch` and `path` tables.
Copy link
Contributor

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.

Copy link
Contributor

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

@epage
Copy link
Contributor

epage commented Jul 9, 2024

@rfcbot concern comments

@epage
Copy link
Contributor

epage commented Jul 9, 2024

@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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Comment on lines +423 to +426

## Support patches

It may also be useful to be able to use path bases in `patch` and `path` tables.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## 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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disposition-merge This RFC is in PFCP or FCP with a disposition to merge it. proposed-final-comment-period Currently awaiting signoff of all team members in order to enter the final comment period. T-cargo Relevant to the Cargo team, which will review and decide on the RFC.
Projects
Status: FCP blocked
Status: Unreviewed
Development

Successfully merging this pull request may close these issues.

None yet

9 participants