Table of Contents

Rust install from tar.gz

Add WASM support

Found good info here Non-rustup setups

$ wget https://static.rust-lang.org/dist/rust-std-1.66.0-wasm32-unknown-unknown.tar.xz
$ wget https://static.rust-lang.org/dist/rust-std-1.66.0-wasm32-unknown-unknown.tar.xz.asc
$ gpg --verify rust-std-1.66.0-wasm32-unknown-unknown.tar.xz.asc
 
$ tar xvaf rust-std-1.66.0-wasm32-unknown-unknown.tar.xz

$ rustc --print sysroot
/usr/local/rust

# cd rust-std-1.66.0-wasm32-unknown-unknown/
# cp --preserve=timestamps -R rust-std-wasm32-unknown-unknown/lib/rustlib/wasm32-unknown-unknown/ /usr/local/rust/lib/rustlib/

Compiling Rust code with MSVC

32-bit

"C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvars32.bat"

64-bit

"C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvars64.bat"

Cross compiling for ARMv7

Make sure to have the necessary external libraries available if needed. Example with librrd (and its dependencies)

# Needs librrd-dev:armhf for the last linking step

#Desired=Unknown/Install/Remove/Purge/Hold
#| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
#|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
#||/ Name             Version      Architecture Description
#+++-================-============-============-=========================================================
#ii  librrd-dev:armhf 1.7.2-3+b7   armhf        time-series data storage and display system (development)

Then to compile for armv7-unknown-linux-gnueabihf

cargo build -r --target armv7-unknown-linux-gnueabihf --config target.armv7-unknown-linux-gnueabihf.linker=\"arm-linux-gnueabihf-gcc\"

Rust error handling

Use #[non_exhaustive] for error enums to avoid API breaks when just adding a new type of error.

https://www.youtube.com/watch?v=rAF8mLI0naQ&t=1355s

Using C libraries

Wrapping Unsafe C Libraries in Rust (1/2)

Wrapping Unsafe C Libraries in Rust (2/2)

Tutorial: Generating bzip2 bindings with bindgen at cargo build time in build.rs

Rust guides

Introduction to Programming Using Rust

Rust Design Patterns

Rust memory

Visualizing memory management in Rust

Perf and Rust

From Guide to Rustc Development The basic perf command is this:

perf record -F99 --call-graph dwarf XXX

The -F99 tells perf to sample at 99 Hz, which avoids generating too much data for longer runs (why 99 Hz you ask? It is often chosen because it is unlikely to be in lockstep with other periodic activity). The –call-graph dwarf tells perf to get call-graph information from debuginfo, which is accurate. The XXX is the command you want to profile. So, for example, you might do: