Package-specific sub-commands #13359
Labels
C-feature-request
Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
S-triage
Status: This issue is waiting on initial triage.
Disclaimer
See the "Notes" section below for more information.
Problem
Sub-commands are, of course, a powerful feature for extending cargo; and the strategy of looking for sub-commands via the developer's path1 makes for an ergonomic and simple architecture.
Yet sub-commands cannot be specified in a package-specific manner and are instead system-wide which means that developers cannot easily specify a specific version of a sub-command.
Proposed Solution
Proposed addition: CLI
We propose the following CLI argument:
Proposed addition:
Cargo.toml
:[sub-commands]
We also propose the introduction of the following to
Cargo.toml
, which the above CLI command relies upon:Each
sub-command
listed takes the same form of a dependency; for examplecargo-cmd-xyz = { path = ... },
cargo-cmd = { git = ... }`.Proposed addition:
Cargo.toml
:[sub-commands]
:profile
andtarget
Enables
cargo install --profile=... --target=...
semantics (see https://doc.rust-lang.org/cargo/commands/cargo-install.html).Proposed addition:
Cargo.toml
: Additionalcrate-type
Whereas the above proposed additions are for users of a cargo sub-command, this addition is for cargo sub-command developers:
It is an error to specify the
"cargo-bin"
type ifname
is not suffixed by"cargo-"
.Proposed Build Semantics
When a user runs
cargo build
, allsub-commands
are built. Resulting build products are stored intarget/debug/sub-commands/
. For example:... results in the following build products:
Proposed Build Semantics: Existing System Installs
If a sub-command is installed at the system-level
Proposed Invocation Semantics
Simply,
/.../target/debug/sub-commands/
and/.../target/release/sub-commands/
are added to the pathcargo
uses at runtime.Notes
Although many of the details would be the same, this design should almost certainly be refactored to enable Package-specific Binaries more generally (which would include sub-commands). The main differences would be:
[sub-commands]
to[installs]
crate-type = ["cargo-bin"]
would be droppedUpon reflection, most other semantics would remain similar.
Footnotes
i.e.
cargo <the-cmd>
searches forcargo-the-cmd
on the developer's path ↩The text was updated successfully, but these errors were encountered: