Building Cargo on FreeBSD 10.1-RELEASE
The preferred build tool and package manager for the Rust programming language is Cargo. Unfortunately, as early January 2015 there is no release of Cargo for FreeBSD, and building from source is difficult because the Cargo build process uses Cargo, and needs an initial release to bootstrap. I found a gist that builds Cargo manually, but it only gives a single snapshot, and the result is too old to use for bootstrapping the current version.
The script linked below is my attempt to solve this problem. It does two things: firstly, it manually downloads and builds a snapshot of Rust and Cargo from 12 December 2014, following a slightly updated version of the approach used in the previous gist. Then, it pulls the Cargo source from github, and bootstraps up to the latest version by checking out and building each merge commit in sequence, and using that to bootstrap the next version in turn. When the script is re-run, it continues bootstrapping from the last installed version to the latest commit in github.
- build-cargo-freebsd-v1.sh 2015-01-02
- build-cargo-freebsd-v2.sh 2015-01-03 (updates for latest rust nightly; better error handling)
- build-cargo-freebsd-v3.sh 2015-01-03 (updates for latest rust nightly)
- build-cargo-freebsd-v4.sh 2015-01-06 (fixes for initial bootstrap)
- build-cargo-freebsd-v5.sh 2015-01-07 (add blacklist of revisions that don't build)
- build-cargo-freebsd-v6.sh 2015-01-14 (updates for latest rust nightly)
- build-cargo-freebsd-v7.sh 2015-01-16 (work around broken docopt dependencies)
- build-cargo-freebsd-v8.sh 2015-01-16 (update blacklist; fix mkdir)
- build-cargo-freebsd-v9.sh 2015-04-14 (update for latest Rust/Cargo; clarify licence and copyright)
Note that Cargo depends on Rust nightly builds, and this script will fetch and compile these as needed. Accordingly, the initial bootstrap process is very slow, since it builds multiple versions of the Rust compiler.
Cargo depends on libgit2, but seems to need a version that differs from that available in the in FreeBSD pkg repository. The script installs an appropriate version into the Cargo lib directory; this likely conflicts if you have the libgit2 pkg installed. Fixes are welcome.
Building some versions of libgit2-sys will likely fail due to missing includes. The simplest fix is to edit the downloaded source, adding:
#include <sys/socket.h> #include <netinet/in.h>just before the #include <arpa/inet.h> around line 56 of common.h in the libgit2-sys download (this was in ~/.cargo/registry/src/github.com-1ecc6299db9ec823/libgit2-sys-0.1.9/libgit2/src/common.h in the last version I built).
The Rust makefile requires high precision timestamps, especially if make is allowed to run jobs in parallel on a multicore system. On FreeBSD 10.1-RELEASE, I had to set sysctl vfs.timestamp_precision=2 to ensure consistent builds (man 9 vfs_timestamp). Precision timestamps were made the default in FreeBSD SVN revision 277712, and will presumably be included in 11.0-RELEASE (and will likely also be MFC'd to 10.2-RELEASE).
This script has allowed me to bootstrap Cargo up to version 174d2320e57ec9629bb81a0f7ca83fe2b662ad91 (29 Jan 2015).
The script has only been tested on FreeBSD 10.1-RELEASE, and probably depends on quirks of my environment, but is provided in the hope that it will be useful to others building Cargo on FreeBSD (or other Unix systems).