Skip to content

Option for cargo run to run the binary in a specified working directory #15789

@taladar

Description

@taladar

Problem

I am currently working on a little project developing a runner for various linters and such things in git hooks. While testing I want to run the program in various git repositories but I noticed that cargo run does not seem to offer a way to set a working directory for the binary it creates.

This means I would have to build and then run the binary directly for every code change and test cycle.

I am sure I am not the only one developing a binary that requires a specific working directory during development test runs so I would like to request a parameter to set the working directory to a user-specified directory for the run portion (after the Cargo.toml and build portions,... have been done as usual in the current directory).

Alternatively, if this is not general enough, it might be useful if the user can specify a wrapper program that can then set working directory, user and all kinds of other inherited process parameters (most likely a shell script for simple cases like the working directory).

Proposed Solution

Add an option --working-directory (possibly with a different name to distinguish it from changing cargo's working directory?) that sets the working directory for the binary after the build.

Notes

No response

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`Command-runS-triageStatus: This issue is waiting on initial triage.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions