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

Tracking Issue for path-bases #14355

Open
10 tasks
dpaoliello opened this issue Aug 5, 2024 · 5 comments
Open
10 tasks

Tracking Issue for path-bases #14355

dpaoliello opened this issue Aug 5, 2024 · 5 comments
Labels
A-manifest Area: Cargo.toml issues C-tracking-issue Category: A tracking issue for something unstable.

Comments

@dpaoliello
Copy link
Contributor

dpaoliello commented Aug 5, 2024

Summary

RFC: #3529
Original issue: #9855
Documentation: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#path-bases
Implementation:

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

Changes from RFC

Unresolved Issues

  • How should each layer (config, eventually manifest) layer? Section-wide, per-field? We should have tests to confirm the approach we have
  • Can we switch our existing "make dep paths absolute" to build on top of this? (Implement path-bases (RFC 3529) 1/n: path dep and patch support #14360)
  • What exact names we should use for the table (path-bases) and field names (base)?
  • What other built-in base paths could be useful?
    • package or current-dir for the directory of the current project?
    • home or user_home for the user's home directory?
    • sysroot for the current rustc sysroot?
  • Do we actually want to support the [patch] table? Adding support for [patch] in config files greatly complicates the implementation
  • Should base = "workspace" work with implicit workspaces?

Future Extensions

  • Add support for declaring path bases in the manifest
  • Path bases relative to other path bases
  • Path dependency with just a base
  • Git dependencies

About tracking issues

Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.

@dpaoliello dpaoliello added the C-tracking-issue Category: A tracking issue for something unstable. label Aug 5, 2024
@epage epage added the A-manifest Area: Cargo.toml issues label Aug 5, 2024
bors added a commit that referenced this issue Aug 14, 2024
Implement base paths (RFC 3529) 1/n: path dep and patch support

RFC: rust-lang/rfcs#3529
Tracking Issue: #14355

This PR add support in path dependencies and `patch` table and the `workspace` built-in path base.
dpaoliello added a commit to dpaoliello/cargo that referenced this issue Aug 19, 2024
RFC: rust-lang/rfcs#3529
Tracking Issue: rust-lang#14355

This PR adds the `--base` option to `cargo add` to allow adding a path dependency with a path base.
dpaoliello added a commit to dpaoliello/cargo that referenced this issue Aug 19, 2024
RFC: rust-lang/rfcs#3529
Tracking Issue: rust-lang#14355

This PR adds the `--base` option to `cargo add` to allow adding a path dependency with a path base.
dpaoliello added a commit to dpaoliello/cargo that referenced this issue Aug 20, 2024
RFC: rust-lang/rfcs#3529
Tracking Issue: rust-lang#14355

This PR adds the `--base` option to `cargo add` to allow adding a path dependency with a path base.
dpaoliello added a commit to dpaoliello/cargo that referenced this issue Aug 27, 2024
RFC: rust-lang/rfcs#3529
Tracking Issue: rust-lang#14355

This PR adds the `--base` option to `cargo add` to allow adding a path dependency with a path base.
dpaoliello added a commit to dpaoliello/cargo that referenced this issue Sep 5, 2024
RFC: rust-lang/rfcs#3529
Tracking Issue: rust-lang#14355

This PR adds the `--base` option to `cargo add` to allow adding a path dependency with a path base.
dpaoliello added a commit to dpaoliello/cargo that referenced this issue Sep 6, 2024
RFC: rust-lang/rfcs#3529
Tracking Issue: rust-lang#14355

This PR adds the `--base` option to `cargo add` to allow adding a path dependency with a path base.
bors added a commit that referenced this issue Sep 6, 2024
Implement path-bases (RFC 3529) 2/n: `cargo [add|remove|update]` support

RFC: rust-lang/rfcs#3529
Tracking Issue: #14355

This PR adds the `--base` option to `cargo add` to allow adding a path dependency with a path base.
dingxiangfei2009 pushed a commit to dingxiangfei2009/cargo that referenced this issue Sep 17, 2024
RFC: rust-lang/rfcs#3529
Tracking Issue: rust-lang#14355

This PR adds the `--base` option to `cargo add` to allow adding a path dependency with a path base.
@Sajjon
Copy link

Sajjon commented Jan 4, 2025

@dpaoliello this makes it possible to shorten the chars needed when specifying paths in workspaces, which is a great feature.

But even better a feature would be to be able to declare paths like constants, once and reuse them everywhere. Has this been pitched / discussed? I understand this is a tracking issue for path-bases specifically, so sorry to hijack this issue, but what I propose is related to the problem which this tries to solve: better ergonomics for my-crate = { path = "../my-crate" } config.

Imagine many crates (30+) in a single workspace, where I would like to group some crates together on filesystem by use of folders. We note that this is ofc opaque to cargo, but filesystem grouping is still good for IDE exploration and git.

Project root:

crates/
    core/
        utils/
            Cargo.toml
            src/
                lib.rs
        error/
            Cargo.toml
            src/
                lib.rs
    clients/
        http/
            Cargo.toml
            src/
                lib.rs
        database
            Cargo.toml
            src/
                lib.rs
    really_huge_structure/
        logic/
            foo/
                Cargo.toml
                src/
                    lib.rs
            bar/
                Cargo.toml
                src/
                    lib.rs
        models/
            foo/
                Cargo.toml
                src/
                    lib.rs
            bar/
                Cargo.toml
                src/
                    lib.rs
Cargo.toml
README.md

many many crates omitted, very simplified!

I now have to specify the path foo-logic = { path = "../crates/really_huge_structure/logic/foo" } many times whenever it is references in the 30 other crates. path-bases could give me a variable for crates/really_huge_structure, right?

But even better would be:

Declaration in Cargo.toml in root (the workspace toml)

PATH_FOO_LOGIC = "../crates/really_huge_structure/logic/foo"

Usage

In some workspace crates toml
foo-logic = { path = "$PATH_FOO_LOGIC }

Or can a path-base be a full path? If so I guess this feature gives me what I want? And/or can a path-base reference another path base?

@dpaoliello
Copy link
Contributor Author

Or can a path-base be a full path? If so I guess this feature gives me what I want? And/or can a path-base reference another path base?

Path base can be either relative or absolute. Note that relative paths are relative to the declaring config.toml, which makes it convenient for scenarios like yours where there is a common parent directory.

In .cargo/config.toml:

[path-bases]
core = "../crates/core"
clients = "../crates/clients"
logic = "../crates/really_huge_structure/logic"
models = "../crates/really_huge_structure/models"

Which makes the cargo.toml quite nice:

foo-logic = { path = "foo", base = "logic" }

That all said, I think a workspace may be better suited for your scenario than relying on path base.

@Sajjon
Copy link

Sajjon commented Jan 6, 2025

@dpaoliello cool! Im using workspaces, but I don't think I can use workspace = true for one of my crates in my workspace, can I? 🤨

@dpaoliello
Copy link
Contributor Author

@dpaoliello cool! Im using workspaces, but I don't think I can use workspace = true for one of my crates in my workspace, can I? 🤨

Yep, it's a bit verbose since you have to repeat everything, but you can list each of the workspace members as a path dependency in the workspace and then inherit those in the member manifests.

[workspace]
members = [
    "crates/really_huge_structure/logic/foo",
    ...
]

[workspace.dependencies]
foo-logic = { path = "crates/really_huge_structure/logic/foo" }

@Sajjon
Copy link

Sajjon commented Jan 6, 2025

Thank you! That is fantastic! I thought to try it first, but then I deemed it as silly, but it is way better than repeating a "core" crate many many times with path also being different (for nested crates at different directory "depths").

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-manifest Area: Cargo.toml issues C-tracking-issue Category: A tracking issue for something unstable.
Projects
Status: In Progress
Development

No branches or pull requests

3 participants