rustup是用于安装开发工具链(包括rust语言编译器、各种重要组件和交叉工具)的程序。
看看它自己的help输出!
> rustup --help
rustup 1.24.3 (ce5817a94 2021-05-31)
The Rust toolchain installer
USAGE:
rustup.exe [FLAGS] [+toolchain] <SUBCOMMAND>
FLAGS:
-v, --verbose Enable verbose output
-q, --quiet Disable progress output
-h, --help Prints help information
-V, --version Prints version information
ARGS:
<+toolchain> release channel (e.g. +stable) or custom toolchain to set override
SUBCOMMANDS:
show Show the active and installed toolchains or profiles
update Update Rust toolchains and rustup
check Check for updates to Rust toolchains and rustup
default Set the default toolchain
toolchain Modify or query the installed toolchains
target Modify a toolchain's supported targets
component Modify a toolchain's installed components
override Modify directory toolchain overrides
run Run a command with an environment configured for a given toolchain
which Display which binary will be run for a given command
doc Open the documentation for the current toolchain
self Modify the rustup installation
set Alter rustup settings
completions Generate tab-completion scripts for your shell
help Prints this message or the help of the given subcommand(s)
DISCUSSION:
Rustup installs The Rust Programming Language from the official
release channels, enabling you to easily switch between stable,
beta, and nightly compilers and keep them updated. It makes
cross-compiling simpler with binary builds of the standard library
for common platforms.
If you are new to Rust consider running `rustup doc --book` to
learn Rust.
可以看出,rustup就是rust开发工具链的安装器!
查看已安装的工具链
> rustup show
Default host: x86_64-pc-windows-msvc
rustup home: C:\Users\tfa20\.rustup
installed toolchains (注意:Toolchain的名字可以是stable,nightly或者1.8.0等)
--------------------
stable-x86_64-pc-windows-msvc (default)
nightly-2021-04-24-x86_64-pc-windows-msvc
installed targets for active toolchain
--------------------------------------
thumbv6m-none-eabi
thumbv7em-none-eabihf
x86_64-pc-windows-msvc
active toolchain
----------------
stable-x86_64-pc-windows-msvc (default)
rustc 1.56.1 (59eed8a2a 2021-11-01)
target、component是toolchain下的一个子项目(子分支)或其中一部分! toolchain是rust语言编译器、component是rust编译相关的重要工具,这两者都是您的电脑上运行的软件,而target是您的目标机器(比如MCU)上的软件的编译器(即交叉编译工具)。
比如添加target时的说明,可选地可以指定一个toolchain:
> rustup target add --help
rustup.exe-target-add
Add a target to a Rust toolchain
USAGE:
rustup.exe target add [OPTIONS] <target>...
FLAGS:
-h, --help Prints help information
OPTIONS:
--toolchain <toolchain> Toolchain name, such as 'stable', 'nightly', or '1.8.0'. For more information see `rustup help toolchain`
ARGS:
<target>... List of targets to install; "all" installs all available targets
比如,对于STM32F3Discovery,使用的是thumbv7em-none-eabihf目标。在我们进行交叉编译之前,我们还必须下载这个目标的预编译的标准库(实际上是精简版)。就是运行下面的指令:
rustup target add thumbv7em-none-eabihf
您只需要运行一次即可,当您update toolchain的时候rustup会更新安装最新的标准库(rust-std组件)。 rust-std组件安装好之后,您就可以开开心心地使用Cargo进行交叉编译了。
> rustup component list
cargo-x86_64-pc-windows-msvc (installed)
clippy-x86_64-pc-windows-msvc (installed)
llvm-tools-preview-x86_64-pc-windows-msvc (installed)
rls-x86_64-pc-windows-msvc (installed)
rust-analysis-x86_64-pc-windows-msvc (installed)
rust-docs-x86_64-pc-windows-msvc (installed)
rust-src (installed)
rust-std-aarch64-apple-darwin
...
rust-std-sparcv9-sun-solaris
rust-std-thumbv6m-none-eabi (installed) 这个是精简版的、适用于thumbv6m的标准库!!
rust-std-thumbv7em-none-eabi
rust-std-thumbv7em-none-eabihf (installed)
rust-std-thumbv7m-none-eabi
...
rust-std-x86_64-pc-windows-gnu
rust-std-x86_64-pc-windows-msvc (installed)
...
rust-std-x86_64-unknown-redox
rustc-x86_64-pc-windows-msvc (installed)
rustc-dev-aarch64-apple-darwin
...
rustc-docs-x86_64-unknown-linux-gnu
rustfmt-x86_64-pc-windows-msvc (installed)