Support runtime executable dependencies. #7971
Labels
A-crate-dependencies
Area: [dependencies] of any kind
C-feature-request
Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
Command-install
S-needs-design
Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.
Z-bindeps
Nightly: binary artifact dependencies
Describe the problem you are trying to solve
Base Problem Statement:
As a contrived example, imagine a commandline rust refactoring tool requires being able to execute
cargo-config
.Variant 1:
Example: Whenever a user installs
cargo install cargo-super-audit-helper
they are guaranteed to be able to runcargo-audit
after that, sincecargo-super-audit-helper
has an "executable dependency" oncargo-audit
.Variant 2:
Describe the solution you'd like
My personal preference is to solve Variant 1 along these lines:
Cargo.toml
section[executable-dependencies]
whose entries are similar to[dependencies]
entries.A
hasB = <v1spec>
in[executable-dependencies]
thencargo install A
behaves the same as runningcargo install --version <v1spec> B && cargo install A
.Note that final
&&
command is intended to be precise when it comes to name/version collisions, so if there's a name/version collision withB = <v1spec>
that will behave exactly the same as if the user executedcargo install --version <v1spec> B
directly (and no attempt to install A is attempted). This might make name/version collisions cumbersome for the user, but my intuition is at the very least it will be easy for all cargo users to understand what's happening and why.I prefer this approach because I believe it's relatively simple for all cargo users to understand.
Notes
My preferred solution this assumes that if an executable from
A
is on the executable search$PATH
then the executables fromB
are also, so that the code inA
can do something likestd::process::Command("B").output()
successfully.A solution to Variant 2 might build on my proposed solution by placing the dependency binary in a private location and somehow expose the path to the code in
A
perhaps an environment variable.Related Tickets: I believe my proposed solution addresses Enable 'cargo install' to install binary-crates according to a spec of dependencies #5120. I don't think it addresses Make commands in dev-dependencies available to run #2267 even though that seems similar. I think the build script approach makes sense for Make commands in dev-dependencies available to run #2267, unless we want to also introduce
[dev-executable-dependencies]
.In all of this discussion of course, I am assuming all dependencies are crates and that executable crates provide 1 or more executables (perhaps transitively). This feature wouldn't facilitate depending on non-cargo binaries as a simplification.
Variant 2 seems pretty similar to just having the dependency provide a public API that the crate consumes as a normal library. It's different for two reasons: First, an executable commandline interface is an API. Not every dependency ensures they provide a library whose interface matches the executable perfectly. Second, the process abstraction matters for many reasons: resource management, concurrency, error handling, I/O, etc...
The text was updated successfully, but these errors were encountered: