LinuxCommandLibrary

cargo-run

Build and execute a local package binary

TLDR

Build and run project

$ cargo run
copy
Run with release optimizations
$ cargo run --release
copy
Run specific binary
$ cargo run --bin [binary_name]
copy
Run example
$ cargo run --example [example_name]
copy
Pass arguments to binary
$ cargo run -- [arg1] [arg2]
copy
Run with features enabled
$ cargo run --features [feature1,feature2]
copy
Run specific package
$ cargo run -p [package]
copy

SYNOPSIS

cargo run [options] [-- args]

DESCRIPTION

cargo run builds and executes a binary target of the current package. It automatically recompiles the project when source files have changed, then runs the resulting executable. Any arguments placed after `--` are forwarded directly to the binary rather than being interpreted by Cargo.
If the package contains multiple binary targets, a specific one must be selected with `--bin` or `--example`, or a default can be configured via the `default-run` field in Cargo.toml. The binary's working directory is set to the current shell directory.

PARAMETERS

--bin name

Run specified binary
--example name
Run specified example
-r, --release
Run with release profile optimizations
--profile name
Build with specific profile
-p, --package spec
Run from specified package
--target triple
Run for target platform
-j, --jobs n
Parallel build jobs
--features features
Enable specified features
--all-features
Enable all features
--no-default-features
Disable default features
-v, --verbose
Verbose output

WORKING DIRECTORY

Sets binary working directory to current directory (same as shell execution).

DEFAULT BINARY

Set default-run in Cargo.toml [package] section to choose default binary.

CAVEATS

Errors if multiple binaries exist without --bin flag. Use default-run manifest key to set default.

SEE ALSO

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community