This page has been machine-translated from the original page.
Table of Contents
Environment
This time, I’ll build an environment with the following setup so I can enjoy competitive programming in Rust.
- Windows 10
- WSL Ubuntu 20.04
Setting Up the Rust Environment
Installing Rust
According to the official documentation, WSL users can easily install Rust with the following command.
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shDuring the installation, you will be asked something like the following. I selected “Proceed with installation.”
1) Proceed with installation (default)
2) Customize installation
3) Cancel installationOnce the installation is complete, all tools are placed in ~/.cargo/bin, so add this directory to PATH.
export PATH=$PATH:$HOME/.cargo/bin
echo 'export PATH=$PATH:$HOME/.cargo/bin' >> ~/.bashrcAfter adding it to PATH, use the following commands to confirm that the toolchain has been installed.
rustup --version
rustc --version
cargo --versionHello, World
For now, let’s create a Hello, World project.
cargo new hello_worldAt this point, the following project directory is created.
$ tree hello_world/
hello_world/
├── Cargo.toml
└── src
└── main.rs
1 directory, 2 filesNext, compile main.rs.
cd hello_world
cargo run # or cargo buildThen, the target directory is created, and the structure looks like this.
$ tree hello_world/
hello_world/
├── Cargo.lock
├── Cargo.toml
├── src
│ └── main.rs
└── target
├── CACHEDIR.TAG
└── debug
├── build
├── deps
│ ├── hello_world-dcff91f54b10472a
│ └── hello_world-dcff91f54b10472a.d
├── examples
├── hello_world
├── hello_world.d
└── incremental
└── hello_world-2x2zxxntihjma
├── s-g16k84pkgw-1kx1yoj-1r8cowopde7m7
│ ├── 18w4g3z43hvkcb89.o
│ ├── 2195c5i0j9yy401g.o
│ ├── 2d4qpr6fn1o2oy47.o
│ ├── 3n8l6lb07r0z64tp.o
│ ├── 4ltafe1k1v50rxij.o
│ ├── dep-graph.bin
│ ├── g7uy5q5v1tqa9ua.o
│ ├── osa6u353jylok1z.o
│ ├── query-cache.bin
│ ├── work-products.bin
│ └── wzcdn60lipjlwrg.o
└── s-g16k84pkgw-1kx1yoj.lock
9 directories, 20 filesThe hello_world file directly under this debug directory is the compiled ELF binary itself.
Summary
I originally wanted to continue from here and configure VSCode so that Rust debugging would work, but unfortunately I still could not find any VSCode extension that supported Rust debugging.
I’ll add an update if there are any developments.