Bootstrapping Rust for a new architecture

Install build dependencies (as root)

# apt install debhelper dpkg-dev python:native \
  llvm-4.0-dev:native llvm-4.0-tools:native libllvm4.0 \
  autotools-dev cmake gperf zlib1g-dev liblzma-dev \
  binutils git procps antlr4 bison flex gdb default-jdk-headless

Building the Debian package with pre-compiled binaries

Pre-compiled Rust binaries can be downloaded from:

Download pre-compiled rust and cargo binaries

$ wget

In case the download fails because of missing certificates, install the CA certificates and retry:

# apt install ca-certificates

Unpack and install Rust into a local directory

$ tar xf rust-1.20.0-powerpc64-unknown-linux-gnu.tar.gz

$ cd rust-1.20.0-ppc64-unknown-linux-gnu

$ ./ --destdir=/home/${USER}/rust
install: creating uninstall script at /home/$USER/rust/usr/local/lib/rustlib/
install: installing component 'rustc'
install: installing component 'cargo'
install: installing component 'rust-analysis-ppc64-unknown-linux-gnu'
install: installing component 'rust-docs'
install: installing component 'rust-std-ppc64-unknown-linux-gnu'
install: WARNING: failed to run ldconfig. this may happen when not installing as root. run with --verbose to see the error

    Rust is ready to roll.

$ cd ~

Download source of Rust Debian package

$ mkdir debian
$ cd debian
$ dget -u
$ cd rustc-1.21.0+dfsg1

Modify debian/ to point to the correct paths for rustc and cargo

glaubitz@ikarus:/tmp/rustc-1.23.0+dfsg1$ diff -u debian/ debian/
--- debian/  2018-01-13 17:50:19.000000000 +0100
+++ debian/       2018-02-27 16:22:43.079889382 +0100
@@ -4,8 +4,8 @@
 locked-deps = false
 verbose = 2
-rustc = "RUST_DESTDIR/usr/bin/rustc"
-cargo = "RUST_DESTDIR/usr/bin/cargo"
+rustc = "/home/$USER/rust/usr/local/bin/rustc"
+cargo = "/home/$USER/rust/usr/local/bin/cargo"
 host = ["DEB_HOST_RUST_TYPE"]

Build rustc package (as normal user)

$ DEB_BUILD_PROFILES="nocheck" DEB_BUILD_OPTIONS="nocheck" dpkg-buildpackage -B -d

Building rustc and cargo without pre-compiled binaries

Cross-compiling cargo

glaubitz@z6:~> cat .cargo/config 
linker = "powerpc-linux-gnu-gcc"

# apt build-dep cargo
# apt install gcc-powerpc-linux-gnu g++-powerpc-linux-gnu
# dpkg --add-architecture powerpc # Note: For ports architectures, you need to add to your sources.list
# apt update
# apt install libcurl4-gnutls-dev:powerpc libssh2-1-dev:powerpc libgit2-dev:powerpc libhttp-parser-dev:powerpc libssl-dev:powerpc zlib1g-dev:powerpc

$ apt-get source cargo
$ cd cargo-0.25.0

$ DEB_BUILD_PROFILES="nocheck" DEB_BUILD_OPTIONS="nocheck" dpkg-buildpackage -B -d --host-arch=powerpc