rust-lang / rust-lang/cargo

Allow config-relative paths in command aliases

Open
#15,083 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-aliases C-feature-request S-needs-design
Dominant language
Rust
Stars
15.5k
Forks
3k
Avg merge
23h 30m
Merged PRs (30d)
51

Description

Problem

When using nested-workspaces it's not possible to use the normal xtask pattern as the xtask package does not exist in the inner workspace. It would be useful if in the alias we can explicitly specify that it uses this workspace's manifest even if the current-directory is within another one.

Proposed Solution

One idea I had was something similar to how [env] lets you specify relative = true, if that were supported for components of the alias then it could be something like:

[alias]
xtask = [
  "run",
  "--manifest-path",
  { path = "Cargo.toml", relative = true },
  "--package=xtask",
  "--bin=xtask",
  "--"
]
Notes

This is sort of related to https://github.com/rust-lang/cargo/issues/9123, but that cli flag doesn't work for this usecase for two reasons:

  1. It will still be using the inner-workspace to detect what the "root" is, not the outer one that defines the .cargo/config.toml.
  2. It will change the current-working-directory for the command being run, the xtask still wants to be able to resolve its own arguments relative to where it's being run from, we just want to change the path used to find the binary to run.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing Cargo command-alias configuration and the existing [env] handling for relative = true; the issue does not name specific files or tests. Check how aliases resolve paths in nested workspaces, and consider the work done when a config-relative alias can locate the outer workspace's manifest without changing the command's working directory.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.