Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross Compilation: add a sv2-rpi.sh script to generate tarball distributions for Raspberry Pi OS #684

Closed
wants to merge 15 commits into from
Closed
99 changes: 99 additions & 0 deletions .github/workflows/sv2-rpi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Check Raspberry Pi Cross Compilation

on:
push:
branches:
- main
- dev
pull_request:
branches:
- main
- dev
pull_request_review:
types: [submitted]
branches: [bot/versioning]

jobs:
cross_compile_64:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.75.0
override: true

- name: Install cargo-cross
run: cargo install cross

- name: Cross Compile 64-bit
run: |
bash sv2-rpi.sh jd_client 64
bash sv2-rpi.sh jd_server 64
bash sv2-rpi.sh mining_proxy_sv2 64
bash sv2-rpi.sh pool_sv2 64
bash sv2-rpi.sh translator_sv2 64

- name: Check artifacts
run: |
arch="aarch64-unknown-linux-gnu"
bin_dir="target/$arch/release"
tar_dir="tar"
artifacts=("jd_client" "jd_server" "mining_proxy_sv2" "pool_sv2" "translator_sv2")

for file in "${artifacts[@]}"; do
bin_path="$bin_dir/$file"
if [ ! -e "$bin_path" ]; then
echo "Binary file $bin_path does not exist."
exit 1
fi
tar_path="$tar_dir/$file-$arch.tar.gz"
if [ ! -e "$tar_path" ]; then
echo "File $tar_path does not exist."
exit 1
fi
done

cross_compile_32:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.75.0
override: true

- name: Install cargo-cross
run: cargo install cross

- name: Cross Compile 32-bit
run: |
bash sv2-rpi.sh jd_client 32
bash sv2-rpi.sh jd_server 32
bash sv2-rpi.sh mining_proxy_sv2 32
bash sv2-rpi.sh pool_sv2 32
bash sv2-rpi.sh translator_sv2 32

- name: Check artifacts
run: |
arch="arm-unknown-linux-gnueabi"
bin_dir="target/$arch/release"
tar_dir="tar"
artifacts=("jd_client" "jd_server" "mining_proxy_sv2" "pool_sv2" "translator_sv2")

for file in "${artifacts[@]}"; do
bin_path="$bin_dir/$file"
if [ ! -e "$bin_path" ]; then
echo "Binary file $bin_path does not exist."
exit 1
fi
tar_path="$tar_dir/$file-$arch.tar.gz"
if [ ! -e "$tar_path" ]; then
echo "File $tar_path does not exist."
exit 1
fi
done
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ lcov.info
*.py
**/conf/**
cobertura.xml
pkg
tar
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ the Bitcoin network.
- [Building/Updating sv2-ffi](#buildingupdating-sv2-ffi)
- [4.02 Test](#402-test)
- [4.03 Run](#403-run)
- [4.04 Raspberry Pi OS](#404-raspberry-pi-os)
- [5. Branches](#5-branches)
- [6. Logging](#6-logging)
- [7. proxy-config.toml file](#7-proxy-configtoml-file)
Expand Down Expand Up @@ -514,6 +515,42 @@ binary - for example from the table below to run the interop-cpp test you'd run
| template-provider-test | examples/template-provider-test | Deprecated |
| test-pool | roles/v2/test-utils/pool | Used in the sv2-proxy example as the sv2 pool |

### 4.04 Raspberry Pi OS

`sv2-rpi.sh` automates generation of a tarball distribution for Raspberry Pi OS.
As a prerequisite, you need [`cargo cross`](https://crates.io/crates/cross):
```
$ cargo install cross
```

It also requires that at least one of these dependencies is available:
- [`docker`](https://www.docker.com/)
- [`podman`](https://podman.io/)

Here is how to use the script:
```shell
Usage:
$ ./sv2-rpi.sh <role> <bits>

Available options for <role> are:
jd_client
jd_server
mining_proxy_sv2
pool_sv2
translator_sv2

Available options for <bits> are:
32
64

For example:
$ ./sv2-rpi.sh jd_server 64
```

After the package generation, you are ready to `scp` the tarball to the RPi:
```shell
$ scp tar/jd_server-aarch64-unknown-linux-gnu.tar.gz <rpiuser>@<your.rpi.ip.addr>:/home/<rpiuser>
```

## 5. Branches

Expand Down
5 changes: 3 additions & 2 deletions roles/translator/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ enum ArgsResult {
}

impl Args {
const DEFAULT_CONFIG_PATH: &'static str = "proxy-config.toml";
const HELP_MSG: &'static str = "Usage: -h/--help, -c/--config <path|default proxy-config.toml>";
const DEFAULT_CONFIG_PATH: &'static str = "translator-config.toml";
const HELP_MSG: &'static str =
"Usage: -h/--help, -c/--config <path|default translator-config.toml>";

pub fn from_args() -> Result<Self, String> {
let cli_args = std::env::args();
Expand Down
145 changes: 145 additions & 0 deletions sv2-rpi.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
#!/bin/bash

# This program utilizes cargo-cross to automate the generation of a tarball package distribution of
# SRI releases targeting the Rasperry Pi OS (32 and 64 bits).

print_help() {
echo "StratumV2 Reference Implementation (SRI) distribution for Raspberry Pi OS (32 and 64 bits)"
echo ""
echo "Usage:"
echo "$ ./sv2-rpi.sh <role> <bits>"
echo ""
echo "Available options for <role> are:"
echo "jd_client"
echo "jd_server"
echo "mining_device"
echo "mining_proxy_sv2"
echo "pool_sv2"
echo "translator_v2"
echo ""
echo "Available options for <bits> are:"
echo "32"
echo "64"
echo ""
echo "For example:"
echo "$ ./sv2-rpi.sh jd_server 64"
}

build(){
cross build -p $PKG --target $TARGET --release
}

clean_pkg(){
rm -rf pkg
}

clean_tar(){
rm -rf tar/$TARBALL
}

pkg(){
clean_pkg
mkdir -p pkg/$PKG
mkdir -p pkg/$PKG/bin
mkdir -p pkg/$PKG/etc/sri
mkdir -p tar
}

tarball(){
TARBALL=$PKG-$TARGET.tar.gz
clean_tar
pushd pkg
tar -cvf ../tar/$TARBALL .
popd
echo "tar/$TARBALL created with success."
}

jd_client(){
build
pkg

install target/$TARGET/release/jd_client pkg/$PKG/bin
install roles/jd-client/config-examples/jdc-config-hosted-example.toml pkg/$PKG/etc/sri
install roles/jd-client/config-examples/jdc-config-local-example.toml pkg/$PKG/etc/sri

echo "finished bootstrapping package $PKG... creating tarball now..."
tarball
}

jd_server(){
build
pkg

install target/$TARGET/release/jd_server pkg/$PKG/bin
install roles/jd-server/config-examples/jds-config-hosted-example.toml pkg/$PKG/etc/sri
install roles/jd-server/config-examples/jds-config-local-example.toml pkg/$PKG/etc/sri

echo "finished bootstrapping package $PKG... creating tarball now..."
tarball
}

mining_proxy_sv2(){
build
pkg

install target/$TARGET/release/mining_proxy_sv2 pkg/$PKG/bin

echo "finished bootstrapping package $PKG... creating tarball now..."
tarball
}

pool_sv2(){
build
pkg

install target/$TARGET/release/pool_sv2 pkg/$PKG/bin
install roles/pool/config-examples/pool-config-hosted-tp-example.toml pkg/$PKG/etc/sri
install roles/pool/config-examples/pool-config-local-tp-example.toml pkg/$PKG/etc/sri

echo "finished bootstrapping package $PKG... creating tarball now..."
tarball
}

translator_sv2(){
build
pkg

install target/$TARGET/release/translator_sv2 pkg/$PKG/bin
install roles/translator/config-examples/translator-config-local-jdc-example.toml pkg/$PKG/etc/sri
install roles/translator/config-examples/translator-config-local-pool-example.toml pkg/$PKG/etc/sri

echo "finished bootstrapping package $PKG... creating tarball now..."
tarball
}

CMD=$1
BITS=$2

case $CMD in
"" | "h" | "-h" | "help" | "--help")
print_help
exit 0
;;
*)
;;
esac

case $BITS in
64*) ARCH=aarch64;TARGET=$ARCH-unknown-linux-gnu;;
32*) ARCH=arm;TARGET=$ARCH-unknown-linux-gnueabi;;
*) echo "Error: must choose 32 or 64"; exit 1
;;
esac

case $CMD in
*)
shift
PKG=$CMD
${PKG} $@
if [ $? = 127 ]; then
echo "Error: '$PKG' is not a known SRI package." >&2
echo "Run './sv2-rpi.sh --help' for a list of known subcommands." >&2
exit 1
fi
;;
esac
Loading