cargo-rustc
Compile a package with extra rustc flags
TLDR
Compile with extra rustc flags
SYNOPSIS
cargo rustc [options] [-- args]
DESCRIPTION
cargo rustc compiles the current package and passes extra options directly to the Rust compiler. Unlike `RUSTFLAGS`, which applies flags to all crates in the build, arguments after `--` are passed only to the final compiler invocation for the specified target, not to its dependencies.
This command is useful for enabling specific codegen options, changing optimization levels, emitting intermediate representations like LLVM IR or assembly, or passing custom linker arguments for a single crate without affecting the rest of the dependency graph.
PARAMETERS
--lib
Compile library only--bin name
Compile specified binary--bins
Compile all binaries--example name
Compile specified example--test name
Compile specified test--bench name
Compile specified benchmark-r, --release
Use release profile--profile name
Use specified profile-p, --package spec
Package to compile--target triple
Target platform-j, --jobs n
Parallel jobs--features features
Enable features--all-features
Enable all features
RUSTC OPTIONS
Common rustc flags:
- -C opt-level=N: Optimization level
- -C target-cpu=NAME: Target CPU
- -C link-arg=ARG: Linker argument
- --emit=TYPE: Output type (asm, llvm-ir, obj)
ENVIRONMENT
RUSTFLAGS
Pass flags to all rustc invocations
CAVEATS
Only one target can be compiled when passing extra arguments. Use filters (--lib, --bin) to select target.
SEE ALSO
cargo(1), rustc(1), cargo-build(1)
