Rust and Cargo on FreeBSD
This is a post of oppourtunity and not one of the regularly scheduled posts in my series on writing a debugger in C and Rust. In the course of working on the nix-rust crate I needed to get a Rust environment setup on FreeBSD and I thought I would document my experience here.
Rust on FreeBSD
Installing Rust itself on FreeBSD is easy. There is a binary package available so installation is as simple as:
# pkg install rust-1.1.0
Updating FreeBSD repository catalogue...
FreeBSD repository is up-to-date.
All repositories are up-to-date.
The following 1 package(s) will be affected (of 0 checked):
New packages to be INSTALLED:
rust: 1.1.0
The process will require 172 MiB more space.
58 MiB to be downloaded.
Proceed with this action? [y/N]: y
Fetching rust-1.1.0.txz: 100% 58 MiB 3.0MB/s 00:20
Checking integrity... done (0 conflicting)
[1/1] Installing rust-1.1.0...
[1/1] Extracting rust-1.1.0: 100%
But, this rust doesn’t come with Cargo.
Cargo for FreeBSD
Building Cargo from source depends on Cargo. There is a bootstrapping process but it depends on the official Rust nightly builds which are only built for Linux, Mac OS X, and Windows. I’ve seen a number of posts on how to build Cargo for FreeBSD but they all seem very involved and potentially out of date.
This reddit post describes a pkg repo for nighly builds of Cargo for FreeBSD. These nighly builds are kindly provided by /u/andoriyu.
Installing the Repo
I had no idea how to install a pkg repo on FreeBSD so I did some Googling which was suprisingly unhelpful. However, the man page was quite useful. PKG.CONF(5) describes how to get things setup. Based on the man page I wrote
/etc/pkg/Cargo.conf:
Cargo: {
url: "pkg+https://s3-us-west-1.amazonaws.com/freebsd-repos/edenbsd",
mirror_type: "srv",
signature_type: "pubkey",
pubkey: "https://s3-us-west-1.amazonaws.com/freebsd-repos/eden-poudriere.pub"
enabled: yes
}
After this I was able to install Cargo:
$ pkg install cargo
Updating Cargo repository catalogue...
Cargo repository is up-to-date.
Updating FreeBSD repository catalogue...
FreeBSD repository is up-to-date.
All repositories are up-to-date.
The following 7 package(s) will be affected (of 0 checked):
New packages to be INSTALLED:
cargo: 0.4.0n_5 [Cargo]
python27: 2.7.10 [Cargo]
openssl: 1.0.2_3 [Cargo]
python2: 2_3 [Cargo]
libssh2: 1.4.3_5,2 [FreeBSD]
curl: 7.43.0_2 [FreeBSD]
c-ares-config: 1.10.0_1 [Cargo]
The process will require 109 MiB more space.
20 MiB to be downloaded.
Proceed with this action? [y/N]: y
Fetching cargo-0.4.0n_5.txz: 100% 5 MiB 1.8MB/s 00:03
Fetching python27-2.7.10.txz: 100% 10 MiB 2.1MB/s 00:05
...
It works!
And the resulting cargo build works:
$ cargo
Rust's package manager
Usage:
cargo <command> [<args>...]
cargo [options]
Options:
-h, --help Display this message
-V, --version Print version info and exit
--list List installed commands
-v, --verbose Use verbose output
-q, --quiet No output printed to stdout
Some common cargo commands are:
build Compile the current project
clean Remove the target directory
doc Build this project's and its dependencies' documentation
new Create a new cargo project
run Build and execute src/main.rs
test Run the tests
bench Run the benchmarks
update Update dependencies listed in Cargo.lock
search Search registry for crates
See 'cargo help <command>' for more information on a specific command.
Thanks /u/andoriyu!