====== Rust install from tar.gz ====== * Unpack rust-1.XX.X--unknown-linux-gnu.tar.gz (after checking gpg signature) * Run install.sh --prefix=/usr/local/rust --disable-ldconfig (for minimal install --components=rustc,rust-std-armv7-unknown-linux-gnueabihf,cargo) * Make symlinks in /usr/local/bin (if not done previously - maybe avoid rls as emacs defaults to that instead of rust-analyzer) * Create /etc/ld.so.conf.d/rust.conf contents: /usr/local/rust/lib * Run ldconfig * Unpack rustc-1.XX.X-src.tar.gz (after checking gpg signature) * mkdir -p /usr/local/rust/lib/rustlib/src/rust * cp -dR --preserve=timestamps rustc-1.XX.X-src/library/ /usr/local/rust/lib/rustlib/src/rust/ ====== Script to update after verifying GPG signatures ====== #!/bin/sh # Update to rust release by downloading and verifying GPG keys set -u if [ $# -ne 1 ]; then echo "Usage: $0 " echo "Example: $0 1.67.1" exit 1 fi TMPDIR_BASE=/tmp RUST_VERSION=$1 TARGET="x86_64-unknown-linux-gnu" RUST_REPO="https://static.rust-lang.org/dist" RUST_FILE="rust-${RUST_VERSION}-${TARGET}.tar.xz" RUSTC_FILE="rustc-${RUST_VERSION}-src.tar.xz" ARMV7HF_EXT="armv7-unknown-linux-gnueabihf" MUSL_EXT="x86_64-unknown-linux-musl" WASM_EXT="wasm32-unknown-unknown" WINX64_EXT="x86_64-pc-windows-gnu" #EXTENSIONS="$ARMV7HF_EXT $MUSL_EXT $WASM_EXT $WINX64_EXT" EXTENSIONS="" create_rust_pgp_key_file() { echo | base64 -d > rust.key < ====== Add WASM support ====== Found good info here [[https://rustwasm.github.io/docs/wasm-pack/prerequisites/non-rustup-setups.html|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 ====== * Start Rust 1.63 (MSVC) Shell for 32-bit or 64-bit * Run the following command to setup the MSVC environment 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|https://www.youtube.com/watch?v=rAF8mLI0naQ&t=1355s]] ====== Using C libraries ====== [[https://medium.com/dwelo-r-d/using-c-libraries-in-rust-13961948c72a|Wrapping Unsafe C Libraries in Rust (1/2)]] [[https://medium.com/dwelo-r-d/wrapping-unsafe-c-libraries-in-rust-d75aeb283c65|Wrapping Unsafe C Libraries in Rust (2/2)]] [[https://github.com/fitzgen/bindgen-tutorial-bzip2-sys|Tutorial: Generating bzip2 bindings with bindgen at cargo build time in build.rs]] ====== Rust guides ====== [[http://gradebot.org/doc/ipur/|Introduction to Programming Using Rust]] [[https://rust-unofficial.github.io/patterns/|Rust Design Patterns]] ====== Rust memory ====== [[https://deepu.tech/memory-management-in-rust/|Visualizing memory management in Rust]] ====== Perf and Rust ====== From [[https://rustc-dev-guide.rust-lang.org/profiling/with_perf.html|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. ====== Find unused source files ====== rustc --emit=dep-info src/main.rs 2> /dev/null; for file in $(find src/ -name '*.rs'); do grep -q -E "^${file}:$" main.d || echo "$file"; done; rm main.d ====== User cargo config ====== ~/.cargo/config.toml [registries.crates-io] protocol = "sparse" [target.x86_64-unknown-linux-gnu] # linker = "clang" # rustflags = ["-C", "link-arg=-fuse-ld=/usr/bin/mold"] rustflags = ["-C", "link-arg=-fuse-ld=mold"] [profile.profiling] inherits = "release" debug = true To build release with debug info: ''cargo build --profile profiling''