User Tools

Site Tools


general:rust

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
general:rust [2022/04/27 08:10] sunkangeneral:rust [2023/02/21 11:05] (current) sunkan
Line 1: Line 1:
 +====== Rust install from tar.gz ======
 +  * Unpack rust-1.XX.X-<arch>-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/
 +
 +====== Add WASM support ======
 +Found good info here [[https://rustwasm.github.io/docs/wasm-pack/prerequisites/non-rustup-setups.html|Non-rustup setups]]
 +
 +<code>
 +$ 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/
 +</code>
 +
 +====== 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
 +<code>
 +"C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvars32.bat"
 +</code>
 +
 +64-bit
 +<code>
 +"C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvars64.bat"
 +</code>
 +
 +====== Cross compiling for ARMv7 ======
 +Make sure to have the necessary external libraries available if needed.
 +Example with librrd (and its dependencies)
 +
 +<code>
 +# 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)
 +</code>
 +
 +Then to compile for armv7-unknown-linux-gnueabihf
 +<code>
 +cargo build -r --target armv7-unknown-linux-gnueabihf --config target.armv7-unknown-linux-gnueabihf.linker=\"arm-linux-gnueabihf-gcc\"
 +</code>
 +
 ====== Rust error handling ====== ====== Rust error handling ======
 Use #[non_exhaustive] for error enums to avoid API breaks when just adding a new type of error. Use #[non_exhaustive] for error enums to avoid API breaks when just adding a new type of error.
Line 13: Line 75:
 ====== Rust guides ====== ====== Rust guides ======
 [[http://gradebot.org/doc/ipur/|Introduction to Programming Using Rust]] [[http://gradebot.org/doc/ipur/|Introduction to Programming Using Rust]]
 +
 +[[https://rust-unofficial.github.io/patterns/|Rust Design Patterns]]
  
 ====== Rust memory ====== ====== Rust memory ======
 [[https://deepu.tech/memory-management-in-rust/|Visualizing memory management in Rust]] [[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:
 +
 +<code>
 +perf record -F99 --call-graph dwarf XXX
 +</code>
 +
 +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:
 +
general/rust.1651047020.txt.gz · Last modified: 2022/04/27 08:10 by sunkan

Donate Powered by PHP Valid HTML5 Valid CSS Run on Debian Driven by DokuWiki