Rust - ArchWiki

# Rust

Rust is a systems programming language that runs blazingly fast, prevents nearly all segfaults, and guarantees thread and memory safety.

## 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).

### 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`).

1. Install mingw-w64-gcc and wine
2. Add a binfmt definition for windows executables either manually or by installing binfmt-wineAUR.
3. 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.
4. 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"

## Cargo

Cargo, Rust's package manager, is available as cargo-binAUR.

Cargo is a tool that allows Rust projects to declare their various dependencies, and ensure that you'll always get a repeatable build.

### Usage

To create a new project using Cargo:

    $ cargo new hello_world --bin

Note: Cargo uses a file named `Cargo.toml`, a manifest containing all of the metadata that Cargo needs to compile your project.

    Cargo.toml

    [package]
    name = "hello_world"
    version = "0.1.0"
    authors = ["Your Name <you@example.com>"]

## See also

- Official website of the Rust Programming Language
- Wikipedia article
- Examples with small descriptions
- Official starting guide
- Page listing of Rust tutorials
- Libraries(crates) avalaible through Cargo

Category:

- Programming languages