- Learning some Rust
- Complete all 25 x 2 puzzles the days released
- Leverage as few possible crates
- WSL2 Ubuntu 20.04
- VS Code + Remote extension
- Rustup install
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh - Rust extension
- CodeLLDB extension for debugging
- Update
rust-client.rustupPathpathin workspace settings.json to point to your wsl install path (/home/<user>/.cargo/bin/rustup)
-
Create the our daily create:
cargo new aoc-2021-day-# cd aoc-2021-day-# code .
-
Press
F5then say yes to the Cargo.toml workspace configuration -
Add standard IO redirection for an
input.txtfile:# before "args": [], "stdio": ["input.txt"],
-
Create an
input.txtfile, and paste in the example or puzzle input -
Update
src/main.rswith the template:use std::io::{self, BufRead}; use std::time::{Instant}; fn main() { let start = Instant::now(); let stdin = io::stdin(); let lines: Vec<String> = stdin.lock().lines().flatten().collect(); println!("Part 1\r\n{}", "-".repeat(10)); // todo println!("Part 2\r\n{}", "-".repeat(10)); // todo let duration = start.elapsed(); println!("Total execution time: {:?}", duration); }
-
Get to solving
Somewhat difficult to find, but CodeLLDB allows for standard IO redirection using the stdio in the launch.json.
- stdin only:
"stdio": ["input.txt"] - stdout and stderr:
"stdio": [null, "out.txt", "err.txt"]
Due to customer kernel within WSL2, you have to compile from the accessible kernel source.
sudo apt install build-essential flex bison libssl-dev libelf-devgit clone --depth=1 https://github.com/microsoft/WSL2-Linux-Kernel.gitcd WSL2-Linux-Kernel/tools/perfmakecp perf /usr/bin/perf- Copy the stackcollapse-perf.pl script to
/usr/local/bin/stackcollapse-perf.pl chmod 775 /usr/local/bin/stackcollapse-perf.pl- Copy the rust-unmangle sed script to
/usr/local/bin/rust-unmangle - Copy the flamegraph.pl script to
/usr/local/bin/flamegraph.pl chmod 755 /usr/local/bin/flamegraph.pl