Getting started rust development
The sample is: rustup doc
in local
Environment setup
- Setup in *nix and macos
1curl --proto '=https' --tlsv1.3 -sSf https://sh.rustup.rs | sh
2rustup component add rust-src rust-analyzer rust-analysis
3# update the rust binary
4rustup update
5# uninstall the rust and rustup self
6rustup self uninstall
7
8rustc -V
9cargo -V
- Setup the
rustup
environment in windows use Mingw64-Ucrt64- Install the
Msys2
environment Msys2 - Open the
Ucrt64
console in windows and enable the Ucrt staging Enable staging - Install the
rustup
usepacman -Ss mingw-w64-ucrt-x86_64-rustup
- Install the
- Select and install the compile tools and environment
- for the gnu tools
rustup toolchain install stable-x86_64-pc-windows-gnu
- for the native windows
rustup toolchain install stable-x86_64-pc-windows-msvc
- for the gnu tools
- Set the default toolchain
rustup default stable-x86_64-pc-windows-gnu
Debug in VSCode ide use mingw-w64-ucrt environment
- Installation the extension
rust-analyzer
andCodeLLDB
- CodeLLDB (vadimcn.vscode-lldb) – on macOS/Linux this include the Mingw64 or Ucrt64 environment
- Microsoft C++ (ms-vscode.cpptools) – on Windows
- Create or change the
Cargo
config file inC:\Users\you\.cargo\config.toml
1[target.x86_64-pc-windows-gnu]
2linker = "D:\\msys64\\ucrt64\\bin\\gcc.exe"
3ar = "D:\\msys64\\ucrt64\\bin\\ar.exe"
- If the
rust-analyzer
can’t launch thelldb.dll
, may be can disalbe theCodeLLDB
extesion and redebug the rust program theCodeLLDB
extension can’t not working if use UCRT64 environment in windows
Basic commands
1rustc --version
2cargo --version
3
4# crate the cargo project
5cargo new exercise
6cd exercise
7cargo run
8
9# to fast check
10cargo check
11# build
12cargo build --release
13# to debug
14cargo run
15# to debug build
16cargo build
17# to fromat the code
18rustfmt ./src/main.rs
Launch the Comprehensive-rust
in local use the mdbook
This is the Rust course used by the Android team at Google. It provides you the material to quickly teach Rust.
1# clone the repo to local
2git clone https://github.com/google/comprehensive-rust/
3cd comprehensive-rust
4
5# install tehse tools
6cargo install mdbook
7cargo install --locked mdbook-svgbob
8cargo install --locked mdbook-i18n-helpers
9cargo install --locked i18n-report
10cargo install --locked mdbook-linkcheck
11cargo install --locked --path mdbook-exerciser
12cargo install --locked --path mdbook-course
13
14mdbook test
15mdbook serve
Launch the rustlings
rustlings.cool
Small exercises to get you used to reading and writing Rust code!
1# install the rustlings
2cargo install rustlings
3# initialization and enter the directory
4rustlings init
5cd rustlings/
6rustlings
7
8# open the exercises in vscode
9cd rustlings/
10code .
Setup the 100-exercises-to-learn-rust
in local
- Clone the repo
git clone https://github.com/mainmatter/100-exercises-to-learn-rust.git
- Checkout
1cd 100-exercises-to-learn-rust
2git checkout -b my-solutions
- Installation the Workshop runntime
1cargo install --locked workshop-runner
2# enter the exercises folder
3cd exercises
4# open the project in vs code
5code ./01_intro/00_welcome
6# debug and complete the src/lib.rs
7# launch the workshop runtime
8wr
Excellent library and frameworks
References
- setup the rustup env in windows Mingw64 or Ucrt64 environment
- rust installation on windows
- rustlings
- comprehensive-rust
- Yet Another Rust Resource
- Rust Atomics and Locks
- Rust by Example
- pingora
- Create book from markdown files. Like Gitbook but implemented in Rust
- full-stack-rust-a-complete-tutorial-with-examples
- rust course
- rusty book
- Educational blog posts for Rust beginners