← 返回命令列表

Linux command

cargo-rustc 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Compile with extra rustc flags

cargo rustc -- [rustc_flags]

Compile specific binary with flags

cargo rustc --bin [name] -- [flags]

Compile library with flags

cargo rustc --lib -- [-C opt-level=3]

Enable specific codegen option

cargo rustc -- -C [target-cpu=native]

Add link arguments

cargo rustc -- -C [link-arg=-fuse-ld=lld]

说明

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.

参数

--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

FAQ

What is the cargo-rustc command used for?

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.

How do I run a basic cargo-rustc example?

Run `cargo rustc -- [rustc_flags]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does --lib do in cargo-rustc?

Compile library only