Cross compiling Lemmy API backend
Cross compiling Lemmy API backend
Since this instance is running on a cross compiled Lemmy API backend I decided to write some basic steps I had to take to get everything working so here is some info on what I did in case this is useful to anyone else.
Basic instructions for installing Lemmy from scratch are available on join-lemmy. To cross compile Lemmy API backend is relatively easy to do with Cross, but will require some minor changes to the instructions, I will use armv7 on Raspberry Pi 2B rev 1.1 as example.
To get all required dependencies in the build environment used by cross it is needed to create a Cross.toml
file to tell cross to install dependencies, Cross.toml I used is below
[target.armv7-unknown-linux-gnueabihf]
pre-build = [
"export DEBIAN_FRONTEND=noninteractive",
"dpkg --add-architecture $CROSS_DEB_ARCH",
"apt-get update && apt-get install --assume-yes libssl-dev:$CROSS_DEB_ARCH pkg-config libpq-dev:$CROSS_DEB_ARCH"
]
Add the above to the repository root alongside Cargo.toml
Then the backend can be compiled using command cross build --target armv7-unknown-linux-gnueabihf --release --features embed-pictrs
And that is all that is needed for cross compiling the backend, cross really does wonders and for me cut build time from multiple hours to couple minutes then just copying the binary over to the target system and starting the service should be enough.
In case the compile errors or version mismatches you you can also try to use vendored OpenSSL by following recipe on Cross wiki.
I had to try some variations on the Cross.toml file, original recipe on Cross wiki does not have the "export DEBIAN_FRONTEND=noninteractive",
line but I found it to be required since without it the podman/docker build would fail by hanging at tzdata installation when tzdata wants to know system timezone. For OpenSSL I also tried to add image = "ghcr.io/cross-rs/armv7-unknown-linux-gnueabihf:0.2.4"
since it seemed to work with less changes to recipe but that base image has too old OpenSSL for my use. Also notice that pkg-config
is installed for host platform, not for target since it is only used by compile while other two are dependencies for the binary.
Also worth noting that if you want to enable pict-rs and your target platform is not supported by pre-compiled Imagemagick you will have to compile Imagemagick for the target system, instructions over at Imagemagick website. I have not yet looked at cross compiling Imagemagick since it doesn't update that often. If you are compiling on a system with low RAM you will want to make sure you have enough swap space, for Raspberry Pi instructions which I followed are available here, I increased swap space to 2 GiB since I have only 1 GiB of RAM
I will probably write a follow up on what I had to do to compile UI and what Lighttpd configuration I use. Looking for any guidance if anyone knows how to cross compile the UI since it does take a while or of less importance but might be interesting if someone knows how to cross compile Imagemagick.