rustc、Cargo、Rustup 常被一起提到,但它们是三个东西。这台机器碰巧只用 Homebrew 装了 rustc 和 cargo、没有 rustup,正好可以把前两者的边界量清楚:rustc 带着什么、cargo 到底怎么调用 rustc、缺了 rustup 会少什么。rustup 本身没有装,所以关于它的部分我只写「没有」的证据。
$ command -v rustc; command -v cargo; command -v rustup || echo "rustup: 本机没有"
/opt/homebrew/bin/rustc
/opt/homebrew/bin/cargo
rustup: 本机没有
$ rustc --version
rustc 1.98.1 (48a229cea 2026-09-01) (Homebrew)
$ cargo --version
cargo 1.98.1 (797e8a9bc 2026-08-05) (Homebrew)
$ rustc --version --verbose
rustc 1.98.1 (48a229cea 2026-09-01) (Homebrew)
binary: rustc
commit-hash: 48a229ceaefd4985c50990b14116b6d856af0985
commit-date: 2026-09-01
host: aarch64-apple-darwin
release: 1.98.1
LLVM version: 22.1.8 $ rustc --print sysroot → /opt/homebrew/Cellar/rust/1.98.1
sysroot 顶层: ['.bottle', '.brew', 'COPYRIGHT', 'INSTALL_RECEIPT.json', 'LICENSE-APACHE', 'LICENSE-MIT', 'README.md', 'bin', 'etc', 'lib', 'libexec', 'license-metadata.json', 'sbom.spdx.json', 'share']
lib/rustlib 下: ['aarch64-apple-darwin', 'components', 'etc', 'rust-installer-version', 'src']
已安装标准库的目标平台: ['aarch64-apple-darwin', 'etc'] (只有宿主平台)
标准库文件: {'.dylib': '1,326,976 字节', '.rlib': '3,260,096 字节', '.rmeta': '8,361,025 字节'}
$ rustc --print target-list → rustc 认识 330 个目标三元组(但只有 2 个装了标准库)标准库是随编译器分发的预编译库(rlib),不是每次编译重新编译的。
$ cargo build -v
Compiling verbose v0.1.0 (<实验目录>/proj/verbose)
Running rustc 的参数(省略了 --check-cfg):
rustc --crate-name verbose --edition=2024 src/main.rs --error-format=json
--json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type bin --emit=dep-info,link
-C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked -C metadata=10e6bdd0d2a08525 -C
extra-filename=-5115401704f9e5a2 --out-dir <实验目录>/target/debug/deps -C
incremental=<实验目录>/target/debug/incremental -L dependency=<实验目录>/target/debug/deps
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.21s这些参数的含义会在后面的文章里陆续展开,比如Cargo Profile(debuginfo、opt-level)与增量编译(-C incremental)。
$ rustc --edition=2024 src/main.rs -o verbose_direct (0.09 s,退出码 0)
运行: Hello, world! | 文件大小 434752 字节;cargo debug 产物 438120 字节
$ RUSTC=/nonexistent/rustc cargo build →
error: could not execute process `/nonexistent/rustc -vV` (never executed)
Caused by:
No such file or directory (os error 2)
$ rustc +nightly src/main.rs("+toolchain" 是 rustup 的代理才认识的写法):
error: multiple input filenames provided (first two filenames are `+nightly` and `<实验目录>/proj/verbose/src/main.rs`) [退出码 1]rustup 的作用(多版本工具链、+nightly、交叉编译目标的安装)我没有在本机验证,因为没有装它。