Skip to content

Custom runner without specifying target #13381

@WVAviator

Description

@WVAviator

Problem

Custom runners are currently available to be specified for certain targets in .cargo/config, for example:

[target.x86_64-unknown-uefi]
runner = "./scripts/run.sh"

I would like to specify a custom runner script without specifying a target. This will allow me to perform some other setup and initialization in that script before building and executing the binary. This will be especially useful in workspace setups where the runner could be specified in the root workspace without forcing all crates to use a certain target.

I encountered this issue in working with multiple crates in a workspace - the crates run under different targets (for example, a bin crate that runs under a no_std target and has a custom runner script, and a lib crate that runs without a specified target to maintain the std library for tests). I want to be able to execute cargo run in the workspace root, but I cannot specify a custom runner there because custom runners are tied to targets, and it would enforce the same target for all crates in the workspace.

Proposed Solution

Allow the specification of a default-runner in either Cargo.toml as package.default-runner or workspace.default-runner, or in .cargo/config as build.default-runner. Exactly as it currently works with the existing target.runner option, this would specify a command or path to executable that is run whenever cargo run, cargo test, or cargo bench is executed, with the output binary path (or paths for multiple targets) provided as arguments to that command.

Notes

There is an unstable feature per-package-targets that would sort-of solve my problem in a less elegant way, but it's not ideal because I would need to override the workspace target with another specific target (I'd rather leave it unspecified, because I might be developing on different machines). I also tried this feature in my project anyway and could not get it to work (likely due to its instability).

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-needs-infoStatus: Needs more info, such as a reproduction or more background for a feature request.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions