LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

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

INSTALL

sudo apt install cargo
copy
sudo dnf install cargo
copy
sudo apk add cargo
copy
sudo zypper install cargo
copy
nix profile install nixpkgs#cargo
copy

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)

RESOURCES

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid