Skip to content

A way to execute local dependencies #12764

@Expurple

Description

@Expurple

Problem

My project has a dependency (sea-orm), which I use both as a library and as a binary that I need to run (sea-orm-cli). This is a common use case for that dependency. The authors recommend cargo installing the binary globally, but this method has multiple disadvantages, because the binary's version is not tracked by my Cargo.toml and goes out of sync with the library. This becomes especially inconvenient when I need to work on multiple branches or multiple projects that use different versions of that dependency. I want the binary to be local and versioned by my Cargo.toml.

I started a discussion in the sea-orm repo. The authors suggest building my own executable which would act exactly like sea-orm-cli by running its exported function. This workaround solves the initial issue, but it still feels hacky and inconvenient. I would like if cargo supported this natively. From what I understand, currently there's no way to get it to build the upsteam binary.

Proposed Solution

Add an option like --from-crate, so that I can cargo build and cargo run a binary from a local dependency:

cargo run --bin sea-orm-cli --from-crate sea-orm-cli

For the initial implementation, cargo build would be enough. I can run the binary manually.

The name of the option is discussable, it can also be something like --crate, --from-dep, etc.

Notes

Essentially, I want npx, but for cargo.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`S-triageStatus: This issue is waiting on initial triage.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions