From 7bab662bbf3ac5afe9759575fc581844ba68a0a5 Mon Sep 17 00:00:00 2001
From: Will Sloan <xanarin@848.email>
Date: Fri, 22 Nov 2024 12:34:24 -0500
Subject: [PATCH] Modify README to cross-compile deb packages for ARM in
 Pi-targeted builds

Currently if executed on an x86_64 system, the README's instructions
will generate a `deb` package which contains x86_64 binaries (or
whatever the host architecture is of the machine which compiles the
code). This is contrary to the users' expectation, which is that they
would build a `deb` package which can be installed on a Raspberry Pi.

This commit modifies the README to add the appropriate commands and
setup steps necessary to build `deb` packages for Raspberry Pi systems,
the intended target of this software. The specific commands were taken
from the GitLab CI configuration that builds the `deb` packages in CI.
---
 README.md | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/README.md b/README.md
index 9a6eab9..28251b6 100644
--- a/README.md
+++ b/README.md
@@ -34,6 +34,8 @@ To build the software, you will need to install [Rustup](https://rustup.rs/). Yo
 ```bash
 sudo apt install git protobuf-compiler
 cargo install cargo-deb
+rustup target add aarch64-unknown-linux-gnu # necessary to build for all RPi models 2B and newer
+rustup target add arm-unknown-linux-musleabihf # necessary to build for RPi zero, and RPi 1
 ```
 
 After these are installed, restart your terminal, or open a new one. Then run these commands:
@@ -42,7 +44,16 @@ After these are installed, restart your terminal, or open a new one. Then run th
 git clone https://gitlab.scd31.com/cats/igate
 cd igate
 git pull
-cargo deb
 ```
 
-The resulting deb package will placed in `target/debian/cats-igate_VERSION.deb`. The package can be installed with `sudo dpkg -i target/debian/cats-igate_VERSION.deb`, replacing `VERSION` with whatever version and architecture was built.
+To build for modern Raspberry Pis (everything newer than Model 2B):
+```bash
+cargo deb --target aarch64-unknown-linux-gnu
+```
+
+To build for the Rasberry Pi Zero or Pi 1:
+```bash
+cargo deb --target arm-unknown-linux-musleabihf
+```
+
+The resulting deb package will placed in `target/$TARGET_ARCH/debian/cats-igate_VERSION_arm64.deb`. The package can be installed with `sudo dpkg -i target/$TARGET_ARCH/debian/cats-igate_VERSION.deb`, replacing `TARGET_ARCH` with the architecture specified in `cargo deb`, and `VERSION` with whatever version and architecture was built.
-- 
GitLab