liana/doc/BUILD.md
Antoine Poinsot 860a1ea074
guix: use Rust 1.70 for release builds
We are being pulled over in two different directions when it comes to
our reproducible builds. On the one hand we need to target reasonably
old glibc versions in order to be compatible with older systems. On the
other hand the immaturity of the Rust ecosystem makes us require
bleeding edge versions of the compiler. With Guix to get the newer
versions of the compiler we need to also bump the glibc version.

This was not a sustainable situation. I was planning for a long time to
cleanup our reproducible builds. To create a proper Guix package for
both the daemon and the GUI using the build system they provide. I had
envisioned this way i could rewrite the inputs of the Guix package to
use an older glibc, while being able to bump the Guix time-machine. It
would even have allowed us to perform Windows builds inside Guix! And
who knows i could even have attempted to perform Apple ones too.

Unfortunately it turned out to be more complicated than that. I couldn't
manage to get my package to compile using an older glibc. Some details
about some of my failed attempts can be found there:
https://lists.gnu.org/archive/html/help-guix/2024-04/msg00056.html.

Instead of wasting more time on this, backport the newer Rust
declarations from up-to-date Guix to Guix-of-our-time-machine.
2024-04-18 17:05:20 +02:00

4.2 KiB

Building Liana

We use Cargo, the ubiquitous Rust package manager. Cargo takes care of downloading and compiling the project's dependencies, as well as compiling the project itself. Dependencies are specified in a Cargo.toml file at the root of this repository. They are pinned in a Cargo.lock file at the same place.

We take security very seriously, and toolchain is a big part of that. We are moderately conservative with dependencies and aim to target reasonable compiler versions that have had time to mature (ie that had the chance to be reviewed and distributed by third parties, as well as tested by the community). See CONTRIBUTING.md for the currently minimum Rust version supported by lianad.

To build the GUI too, you'll unfortunately need a more recent Rust version. The minimum version supported by the GUI at the moment is 1.70. You will most likely have to manually download it or use rustup to install more recent compilers.

Getting Cargo

Through your system package manager

Most package managers distribute a version of Cargo able to build this project. For instance on Debian-based systems (as root):

apt update && apt install cargo

By manually downloading the latest stable version

The "other installation methods" page of the Rust website contains a list of archives for different architectures, along with signatures made with the "Rust signing key":

pub   rsa4096/0x85AB96E6FA1BE5FE 2013-09-26 [SC]
      Key fingerprint = 108F 6620 5EAE B0AA A8DD  5E1C 85AB 96E6 FA1B E5FE
uid                   [ unknown] Rust Language (Tag and Release Signing Key) <rust-key@rust-lang.org>
sub   rsa4096/0x8E9AA3F7AB3F5826 2013-09-26 [E]
sub   rsa4096/0x5CB4A9347B3B09DC 2014-12-15 [S]

You can therefore pull the key from either the above or from a keyserver:

$ gpg --keyserver hkps://keys.openpgp.org --receive 108F66205EAEB0AAA8DD5E1C85AB96E6FA1BE5FE

And then you can download the archive corresponding to your system and CPU architecture, verify the signature and use the cargo binary from this archive to build Liana. Here is an example for amd64:

$ curl -O https://static.rust-lang.org/dist/rust-1.70.0-x86_64-unknown-linux-gnu.tar.gz
$ curl -O https://static.rust-lang.org/dist/rust-1.70.0-x86_64-unknown-linux-gnu.tar.gz.asc
$ gpg --verify rust-1.70.0-x86_64-unknown-linux-gnu.tar.gz.asc
$ tar -xzf rust-1.70.0-x86_64-unknown-linux-gnu.tar.gz
$ ./rust-1.70.0-x86_64-unknown-linux-gnu/cargo/bin/cargo build --release

Through rustup

rustup is a software for installing the Rust toolchain.

Some package managers distribute a version of rustup. Failing that, you can always follow the "official" installation method of rustup (that is, a curl-sh pipe).

Building the project

Once you've got Cargo, building the project is a simple cargo invocation away.

To only build the daemon, run it from the root of the repository:

$ cargo build --release

The lianad and liana-cli binaries will be in the target/ directory at the root of the repository:

$ ls target/release/
build  deps  examples  incremental  liana-cli  liana-cli.d  lianad  lianad.d  libliana.d  libliana.rlib

To build the whole wallet including the GUI, you'll need to install its build and runtime dependencies first. Then run the same command as above within the gui/ folder present at the root of the repository:

$ cd gui/
$ cargo build --release

The liana-gui binary will be in the target/ folder:

$ ls target/release/
build  deps  examples  incremental  liana-gui  liana-gui.d  libliana_gui.d  libliana_gui.rlib

Whether your are building the whole wallet or only the daemon, make sure not to forget the --release command line option. You would otherwise build without optimizations.