This repository gathers Rust code examples coming from various websites and books. It also includes several build scripts (batch files, Make scripts) for experimenting with Rust on a Windows machine. |
Ada, Akka, C++, COBOL, Dart, Deno, Docker, Erlang, Flix, Golang, GraalVM, Haskell, Kafka, Kotlin, LLVM, Modula-2, Node.js, Scala 3, Spark, Spring, TruffleSqueak, WiX Toolset and Zig are other topics we are continuously monitoring.
This project depends on the following external software for the Microsoft Windows platform:
Optionally one may also install the following software:
☛ Installation policy
When possible we install software from a Zip archive rather than via a Windows installer. In our case we definedC:\opt\
as the installation directory for optional software tools (similar to the/opt/
directory on Unix).
For instance our development environment looks as follows (October 2024) 3:
C:\opt\ConEmu\ ( 26 MB) C:\opt\Git\ (367 MB) C:\opt\msys64\ (3.4 GB) C:\opt\VSCode\ (341 MB) %USERPROFILE%\.cargo\ (100 MB) %USERPROFILE%\.rustup\ (593 MB, installed toolchains and configuration options)
🔎 Git for Windows provides a BASH emulation used to run
git
from the command line (as well as over 250 Unix commands likeawk
,diff
,file
,grep
,more
,mv
,rmdir
,sed
andwc
).
Directory structure ▴
This project is organized as follows:
bin\ docs\ examples\{README.md, diceroller, rust-ui-druid} mastering-rust\{README.md, Chapter01, etc.} possiblerust-examples\{README.md, InnerFunctions, TraitObjects, etc.} rust-by-example\{README.md, 01_Display, etc.} CONTRIBUTIONS.md README.md RESOURCES.md SETUP.md setenv.bat
where
- directory
bin\
contains utility scripts. - directory
docs\
contains Rust related papers/articles. - directory
examples\
contains Rust code examples (seeREADME.md
). - directory
mastering-rust\
contains Rust code examples (seeREADME.md
). - directory
rust-by-example\
contains Rust code examples (seeREADME.md
). - file
CONTRIBUTIONS.md
gathers reported issues and pull requests to the Rust project. - file
README.md
is the Markdown document for this page. - file
RESOURCES.md
is the Markdown document presenting external resources. - file
SETUP.md
gives some Rust setup details. - file
setenv.bat
is the batch script for setting up our environment.
We also define a virtual drive – e.g. drive R:
– in our working environment in order to reduce/hide the real path of our project directory (see article "Windows command prompt limitation" from Microsoft Support).
🔎 We use the Windows external command
subst
to create virtual drives; for instance:> subst R: %USERPROFILE%\workspace\rust-examples
In the next section we give a brief description of the batch files present in this project.
Batch commands ▴
We distinguish different sets of batch commands:
-
setenv.bat
- This batch command makes the external tools such ascargo.exe
,rustc.exe
directly available from the command prompt.> setenv help Usage: setenv { <option> | <subcommand> } Options: -bash start Git bash shell instead of Windows command prompt -debug print commands executed by this script -verbose print progress messages Subcommands: help print this help message
-
rust-by-example\*\build.bat
- Finally each example can be built/run using thebuild
command.☛ While using
cargo
is the recommanded way to build/run Rust projects we also provide the batch commandbuild.bat
in order to exercise the usage of therustc.exe
command.
Usage examples ▴
We execute command setenv.bat
once to setup our development environment; it makes external tools such as cargo.exe
, git.exe
and sh.exe
directly available from the command prompt.
> setenv Tool versions: cargo 1.82.0, rustc 1.82.0, rustfmt 1.7.0-stable, rustup 1.27.1, pelook v1.73, make 4.4.1, git 2.47.0, diff 3.10, bash 5.2.37(1) > where cargo git sh %USERPROFILE%\.cargo\bin\cargo.exe C:\opt\Git\bin\git.exe C:\opt\Git\mingw64\bin\git.exe C:\opt\Git\bin\sh.exe C:\opt\Git\usr\bin\sh.exe C:\opt\msys64\usr\bin\sh.exe
Command setenv.bat
with option -verbose
displays additional information:
- the tool paths (which may not contain the version suffix, i.e.
C:\opt\Git\bin\git.exe
in some installations), - the environment variables defined locally within this session,
- and the path associations (i.e.
F:\
in this case, but other drive names may be displayed as path associations are globally defined).
> setenv -verbose Tool versions: cargo 1.82.0, rustc 1.82.0, rustfmt 1.7.0-stable, rustup 1.27.1, pelook v1.73, make 4.4.1, git 2.47.0, diff 3.10, bash 5.2.37(1) Tool paths: %USERPROFILE%\.cargo\bin\cargo.exe %USERPROFILE%\.cargo\bin\rustc.exe %USERPROFILE%\.cargo\bin\rustfmt.exe %USERPROFILE%\.cargo\bin\rustup.exe R:\bin\pelook.exe C:\opt\Git\bin\git.exe C:\opt\Git\mingw64\bin\git.exe C:\opt\Git\usr\bin\diff.exe C:\opt\Git\bin\bash.exe Environment variables: "CARGO_HOME=%USERPROFILE%\.cargo" "GIT_HOME=C:\opt\Git" "MSYS_HOME=C:\opt\msys64" "RUSTUP_HOME=%USERPROFILE%\.rustup" Path associations: R:\: => %USERPROFILE%\workspace-perso\rust-examples
Footnotes ▴
[1] GNU Front-End for Rust ↩
-
> c:\opt\msys64\usr\bin\pacman.exe -Sy mingw-w64-clang-x86_64-rust :: Synchronizing package databases... clangarm64 is up to date mingw32 is up to date mingw64 is up to date ucrt64 is up to date clang32 is up to date clang64 is up to date msys is up to date resolving dependencies... looking for conflicting packages... Packages (1) mingw-w64-clang-x86_64-rust-1.80.0-1 Total Download Size: 88.01 MiB Total Installed Size: 406.29 MiB Net Upgrade Size: -21.21 MiB :: Proceed with installation? [Y/n] y [...] > where /r c:\opt\msys64 rustc c:\opt\msys64\clang64\bin\rustc.exe > c:\opt\msys64\clang64\bin\\rustc.exe --version rustc 1.80.0 (051478957 2024-07-21) (Rev1, Built by MSYS2 project)
[2] LLVM Backend ↩
-
rustc.exe
uses LLVM for code generation (see section Code Generation in the online Rustc Development Guide). -
> %USERPROFILE%\.cargo\bin\rustc --version --verbose | findstr /b "rustc LLVM" rustc 1.80.0 (051478957 2024-07-21) LLVM version: 18.1.7
-
Rustc Version LLVM Version 1.78.0 - 1.80.0 18.1.7 1.75.0 - 1.77.2 17.0.6 1.73.0 - 1.74.0 17.0.2 1.71.0 - 1.72.0 16.0.5 1.70.0 16.0.0 1.68.1 15.0.6 1.66.1 15.0.2 1.66.0 15.0.0 1.64.0 14.0.6 1.62.0 - 1.63.0 14.0.5 1.60.0 - 1.61.0 14.0.0 1.56.0 - 1.59.0 13.0.0 1.55.0 12.0.1 1.52.0 - 1.54.0 12.0.0 1.47.0 - 1.51.0 11.0.0
[3] Downloads ↩
- In our case we downloaded the following installation files (see section 1):
-
ConEmuPack.230724.7z ( 5 MB) msys2-x86_64-20240727.exe ( 86 MB) PortableGit-2.47.0-64-bit.7z.exe ( 46 MB) rust-init.exe ( 8 MB) VSCode-win32-x64-1.94.2.zip (131 MB)
-
Once the
rustup.exe
tool is installed, we can update our installation by simply runningrustup.exe update
.