From 27c2bb9f0a1479dbe7a26c69d0fad21f02a3d1f0 Mon Sep 17 00:00:00 2001
From: Stephen D <stephen@scd31.com>
Date: Thu, 22 Feb 2024 21:52:24 +0000
Subject: [PATCH] .deb builds for Raspberry Pis

---
 .cargo/config  |  8 ++++++++
 .gitlab-ci.yml | 26 +++++++++++++++++++++++++-
 README.md      | 47 ++++++++++++++++++++++++++++-------------------
 3 files changed, 61 insertions(+), 20 deletions(-)
 create mode 100644 .cargo/config

diff --git a/.cargo/config b/.cargo/config
new file mode 100644
index 0000000..9bb0719
--- /dev/null
+++ b/.cargo/config
@@ -0,0 +1,8 @@
+[target.arm-unknown-linux-gnueabihf]
+linker = "arm-linux-gnueabihf-gcc"
+
+[target.arm-unknown-linux-musleabihf]
+linker = "arm-linux-gnueabihf-gcc"
+
+[target.aarch64-unknown-linux-gnu]
+linker = "aarch64-linux-gnu-gcc"
\ No newline at end of file
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 2dc91ec..29565b0 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,14 +1,38 @@
 image: "rust:latest"
 
+stages:
+  - test
+  - build
+
 before_script:
   - apt-get update
-  - apt-get install -y protobuf-compiler
+  - apt-get install -y protobuf-compiler gcc-arm-linux-gnueabihf gcc-aarch64-linux-gnu
   - rustup component add rustfmt
   - rustup component add clippy
   - cargo install cargo-deb
+  - rustup target add arm-unknown-linux-musleabihf
+  - rustup target add aarch64-unknown-linux-gnu
 
 test:
+  stage: test
   script:
     - cargo fmt -- --check
     - cargo clippy --all-targets --all-features -- -D warnings
     - cargo test
+
+# pi zero, and pi one
+build_pi_old:
+  stage: build
+  script:
+    - cargo deb --target arm-unknown-linux-musleabihf
+  artifacts:
+    paths: 
+      - target/arm-unknown-linux-musleabihf/debian/*.deb
+
+build_pi_modern:
+  stage: build
+  script:
+    - cargo deb --target aarch64-unknown-linux-gnu
+  artifacts:
+    paths:
+      - target/aarch64-unknown-linux-gnu/debian/*.deb
diff --git a/README.md b/README.md
index 5621d34..2975090 100644
--- a/README.md
+++ b/README.md
@@ -2,29 +2,15 @@
 
 Reference CATS/FELINET I-gate/digipeater for the Raspberry Pi. Requires an I-Gate board: https://gitlab.scd31.com/cats/pi-hardware
 
-## Building
+## Installing (Prebuilt Packages)
 
-To build the software, you will need to install [Rustup](https://rustup.rs/). You'll also need to install some dependencies:
-
-```bash
-sudo apt install git protobuf-compiler
-```
-
-After these are installed, restart your terminal, or open a new one. Then run these commands:
-
-```bash
-git clone https://gitlab.scd31.com/cats/igate
-cd igate
-git pull
-cargo install cargo-deb
-cargo deb
-```
+Download the .deb file for your Pi:
 
-The resulting deb package will placed in `target/debian/cats-igate_VERSION.deb`
+[Pi Zero/1](https://gitlab.scd31.com/cats/igate/builds/artifacts/master/browse/target/arm-unknown-linux-musleabihf/debian?job=build_pi_old))
 
-## Installing
+[Pi 2/3/4/5](https://gitlab.scd31.com/cats/igate/builds/artifacts/master/browse/target/aarch64-unknown-linux-gnu/debian/?job=build_pi_modern)
 
-Once built, the package can be installed with `sudo dpkg -i target/debian/cats-igate_VERSION.deb`, replacing `VERSION` with whatever version and architecture was built.
+Once downloaded, the package can be installed with `sudo dpkg -i FILENAME.deb`, where `FILENAME.deb` is the file you downloaded.
 
 ## Configuring
 
@@ -37,3 +23,26 @@ The configuration for the I-gate lives in `/etc/cats_igate/config.toml`. Make su
 For debugging, a single command line option exists. Running `cats-igate -x <freq>` in a terminal will send out constant test packets (properly identified, of course) which is useful for diagnostics. Please don't run this on the main CATS frequency or it will utilize 100% of the channel! Also, make sure whichever frequency you choose is unused.
 
 The I-gate ships with a service file, which allows it to run autonomously. To start the service, run `sudo systemctl start cats-igate`. To have the service automatically start at bootup, run `sudo systemctl enable cats-igate`.
+
+
+## Building From Source
+
+You probably don't need to do this unless you're planning to change the code, or if you're having problems with the prebuilt binaries.
+
+To build the software, you will need to install [Rustup](https://rustup.rs/). You'll also need to install some dependencies:
+
+```bash
+sudo apt install git protobuf-compiler
+cargo install cargo-deb
+```
+
+After these are installed, restart your terminal, or open a new one. Then run these commands:
+
+```bash
+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.
-- 
GitLab