Launch of a community safe network

@bzee has asked me via PM about the compilation process for ARM+musl, so that he could try doing it himself, then suggested that I could also post the instructions here, so here you go :slight_smile:

What I did was cross-compile for ARM on a x86-64 laptop with Gentoo. The only part that would look different on other distros (or maybe even OSs, like Windows) should be getting the cross-compilation GCC toolchain. The rest should look pretty similar.

The process also works almost unchanged whether you compile for musl or for glibc, although it might be easier to get a cross-compiler for glibc on some distros (it is on Arch).

So…

  1. You need a cross-compilation GCC toolchain for linking. On Gentoo, I could get that with crossdev -t armv7a-hardfloat-linux-musleabi (although I had to modify the build script slightly - if you want details, ping me); I’ve also tried searching for a corresponding Arch package, but there seem to be none for musl; there is one for glibc on AUR, though: AUR (en) - arm-linux-gnueabihf-gcc
    If you want to compile directly on the Pi, you don’t need this step if compiling for glibc (regular gcc will suffice), and you need musl and musl-gcc if compiling for musl.
  2. Add an appropriate target to Rust via rustup : rustup target add armv7-unknown-linux-musleabihf for musl or rustup target add armv7-unknown-linux-gnueabihf for glibc (not needed if compiling on Pi for glibc).
  3. Configure the cross-GCC as the linker for the target. This is done by editing ~/.cargo/config and adding:
    [target.armv7-unknown-linux-musleabihf]
    linker = "armv7a-hardfloat-linux-musleabi-gcc"
    (You would need to change musleabihf to gnueabihf if compiling for glibc, and provide the proper GCC binary name, of course. For musl directly on Pi, the linker would be musl-gcc. For glibc directly on Pi, you can omit this step entirely.)
  4. Clone the safe_vault repo (git clone https://github.com/maidsafe/safe_vault.git; git checkout 0.18.0 or just download the source from here), enter its directory and execute cargo build --release --target=armv7-unknown-linux-musleabihf (or -gnueabihf if compiling for glibc; you can omit --target entirely if compiling for glibc on Pi).
    On my system, there was a crate among the dependencies that wouldn’t compile this way, as it was trying to call the cross-gcc under a wrong name for some reason - I solved that by creating the symlink to the gcc binary with the name it was looking for.

And that’s it. You should have a binary that will work on a Pi after that. When you use a musl target, it’s statically linked by default, a glibc binary is dynamically linked and it’s what caused problems for some people (although worked for me with Arch on the Pi).

I hope it’s useful, or at least allows someone to learn something :wink:

20 Likes