LinuxCommandLibrary

cargo-rustc

Compile a package with extra rustc flags

TLDR

Compile with extra rustc flags

$ cargo rustc -- [rustc_flags]
copy
Compile specific binary with flags
$ cargo rustc --bin [name] -- [flags]
copy
Compile library with flags
$ cargo rustc --lib -- [-C opt-level=3]
copy
Enable specific codegen option
$ cargo rustc -- -C [target-cpu=native]
copy
Add link arguments
$ cargo rustc -- -C [link-arg=-fuse-ld=lld]
copy

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)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community