Rust
Rust is a systems programming language that runs blazingly fast, prevents nearly all segfaults, and guarantees thread and memory safety.
Contents
Installation
To install the latest stable version of Rust, install the rust package.
If you would like to build the stable or Beta from source, visit Rust Downloads. You may also obtain rust-nightly-binAUR via the AUR for the latest development snapshot (provides Cargo).
An alternative is to use multirustAUR, a tool that allows to install and manage multiple rust installations (stable, beta, nightly), and easily switch between them.
Test your installation
Check that Rust is installed correctly by building a simple program, as follows:
~/hello.rs
fn main() { println!("Hello, World!"); }
You can compile it with rustc
, then run it:
$ rustc hello.rs && ./hello
Hello, World!
Cross Compiling
Windows
In this section, $ARCH
is the target architecture (either x86_64
or i686
).
- Install mingw-w64-gcc and wine
- Add a binfmt definition for windows executables either manually or by installing binfmt-wineAUR.
- Install a copy of rust's standard library for windows in your rustlib directory (
/usr/local/lib/rustlib
if you're using rust-nightly-binAUR and/usr/lib/rustlib
if you're using the official rust package). The easiest way to do this is to download the rust installer for windows for your target architecture, install it under wine (wine start my-rust-installer.msi
) and copy$INSTALL_DIR/bin/rustlib/$ARCH-pc-windows-gnu
into your rustlib directory. - Finally, tell cargo where to find the MinGW-w64 gcc/ar by adding the following to your
~/.cargo/config
:
~/.cargo/config
[target.$ARCH-pc-windows-gnu] linker = "/usr/bin/$ARCH-w64-mingw32-gcc" ar = "/usr/$ARCH-w64-mingw32/bin/ar"
Finally, you can cross compile for windows by passing the --target $ARCH-pc-windows-gnu
to cargo:
$ # Build $ cargo build --release --target "$ARCH-pc-windows-gnu" $ # Run unit tests under wine $ cargo test --target "$ARCH-pc-windows-gnu"
unofficial packages
The unofficial repo archlinuxcn has rust-nightly and Rust std library for i686, ARM, ARMv7, Windows 32 and 64 so you can just install the one you want then enjoy cross compiling. However, you have to find an ARM toolchain by yourself. For Windows 32bit targets, you'll need to get a libgcc_s_dw2-1.dll to build and run.
Cargo
Cargo, Rust's package manager, can be installed as cargo. The nightly version is available in the AUR as cargo-binAUR. If you use multirustAUR, it already includes cargo.
Cargo is a tool that allows Rust projects to declare their various dependencies, and ensure that you'll always get a repeatable build. You're encouraged to read the official guide.
Usage
To create a new project using Cargo:
$ cargo new hello_world --bin
This creates a directory with a default Cargo.toml
file, set to build an executable (because we included --bin
, otherwise it would build a library).