Skip to content

Commit

Permalink
ci(fix): further cross build improvements, with updated build doc (#6359
Browse files Browse the repository at this point in the history
)

Description
Further fix the optional build requirement in the console_wallet, so
that ```hidapi``` is not nessesary
Remove OSX brew package installs that produce warnings - left comments,
if anybody uses the workflows as build recipes
Extend, test and fix cross builds for Linux from OSX and possibly
Windows
Update build documentation to include some docker focus options, that
could help build arm64 (Raspberry Pi) binaries on faster machines

Motivation and Context
Remove warnings
Fix build ffi, binary and docker builds

How Has This Been Tested?
Built locally:
 OSX arm64 to Linux arm64 and Linux x86_64
 OSX x86_64 to Linux x86_64 and arm64
Built binaries, libffis and docker images in local fork

<!-- Checklist -->
<!-- 1. Is the title of your PR in the form that would make nice release
notes? The title, excluding the conventional commit
tag, will be included exactly as is in the CHANGELOG, so please think
about it carefully. -->


Breaking Changes
Need to use current cross-rs from git for cross-compiling support on
binaries and ffi libraries.
```cargo install cross --git https://github.com/cross-rs/cross```

- [ ] None
- [ ] Requires data directory on base node to be deleted
- [ ] Requires hard fork
- [X] Other - Please specify

<!-- Does this include a breaking change? If so, include this line as a footer -->
<!-- BREAKING CHANGE: Description what the user should do, e.g. delete a database, resync the chain -->

---------

Co-authored-by: Hansie Odendaal <[email protected]>
  • Loading branch information
leet4tari and hansieodendaal authored May 30, 2024
1 parent 01f93ab commit 561ac67
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 28 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/build_binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ jobs:
- name: Install macOS dependencies
if: startsWith(runner.os,'macOS')
run: |
# openssl and cmake already installed
brew install zip coreutils automake autoconf protobuf
# openssl, cmake and autoconf already installed
brew install zip coreutils automake protobuf
rustup target add ${{ matrix.builds.target }}
- name: Install Windows dependencies
Expand Down Expand Up @@ -283,7 +283,8 @@ jobs:
if: ${{ matrix.builds.cross }}
shell: bash
run: |
cargo install cross
#cargo install cross
cargo install cross --git https://github.com/cross-rs/cross
echo "CARGO=cross" >> $GITHUB_ENV
- name: Install and setup cargo-auditable
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/build_libffis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ jobs:
if: ${{ matrix.builds.cross }}
shell: bash
run: |
cargo install cross
#cargo install cross
cargo install cross --git https://github.com/cross-rs/cross
echo "CARGO=cross" >> $GITHUB_ENV
- name: Install rust target/toolchain for native/local cross-compile builds
Expand Down
18 changes: 14 additions & 4 deletions Cross.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ passthrough = [
"BUILD_TARGET",
"CARGO_BUILD_TARGET",
"TARGET_CFLAGS",
"CC_aarch64_unknown_linux_gnu",
"PKG_CONFIG_SYSROOT_DIR",
"PKG_CONFIG_ALLOW_CROSS",
"RUSTFLAGS",
"RUST_BACKTRACE",
"RUST_DEBUG",
Expand Down Expand Up @@ -52,13 +55,20 @@ passthrough = [
"CFLAGS=-DMDB_USE_ROBUST=0",
]

# Currently needs cross-rs from git ```cargo install cross --git https://github.com/cross-rs/cross```
[target.aarch64-unknown-linux-gnu]
image = "ubuntu:18.04"
# Need to use native aarch64 on Apple silicon
#image.name = "ubuntu:18.04"
#image.toolchain = ["linux/arm64=aarch64-unknown-linux-gnu"]
image.name = "ubuntu:18.04"
# targetting is needed for apple silicon
image.toolchain = ["linux/arm64=aarch64-unknown-linux-gnu", "linux/amd64=x86_64-unknown-linux-gnu"]
pre-build = "./scripts/cross_compile_ubuntu_18-pre-build.sh"

[target.aarch64-unknown-linux-gnu.env]
passthrough = [
"CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc",
"PKG_CONFIG_SYSROOT_DIR=/usr/lib/aarch64-linux-gnu/",
"PKG_CONFIG_ALLOW_CROSS=true",
]

[target.x86_64-unknown-linux-gnu]
image = "ubuntu:18.04"
pre-build = "./scripts/cross_compile_ubuntu_18-pre-build.sh"
4 changes: 2 additions & 2 deletions applications/minotari_console_wallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "BSD-3-Clause"
[dependencies]
minotari_app_grpc = { path = "../minotari_app_grpc" }
minotari_app_utilities = { path = "../minotari_app_utilities" }
minotari_ledger_wallet_comms = { path = "../../applications/minotari_ledger_wallet/comms", version = "1.0.0-pre.13" }
minotari_ledger_wallet_comms = { path = "../../applications/minotari_ledger_wallet/comms", version = "1.0.0-pre.13", optional = true }
tari_common = { path = "../../common" }
tari_common_types = { path = "../../base_layer/common_types" }
tari_comms = { path = "../../comms/core" }
Expand Down Expand Up @@ -89,7 +89,7 @@ tari_features = { path = "../../common/tari_features", version = "1.0.0-pre.13"
[features]
default = ["libtor"]
grpc = []
ledger = ["ledger-transport-hid", ]
ledger = ["ledger-transport-hid", "minotari_ledger_wallet_comms"]
libtor = ["tari_libtor"]

[package.metadata.cargo-machete]
Expand Down
1 change: 1 addition & 0 deletions applications/minotari_console_wallet/src/init/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use std::{fs, io, path::PathBuf, str::FromStr, sync::Arc, time::Instant};
use ledger_transport_hid::{hidapi::HidApi, TransportNativeHID};
use log::*;
use minotari_app_utilities::{consts, identity_management::setup_node_identity};
#[cfg(feature = "ledger")]
use minotari_ledger_wallet_comms::{
error::LedgerDeviceError,
ledger_wallet::{get_transport, Instruction},
Expand Down
67 changes: 54 additions & 13 deletions buildtools/build-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,76 @@ Build options:
- Virtualised
- Emulated

# Building Linux x86_64 & ARM64
# Building for Linux x86_64 & ARM64

Using Vagrant and VirtualBox has a baseline for building needs, including tools, libs and testing

Linux ARM64 can be built using Vagrant and VirtualBox or Docker and cross

# Prep Ubuntu for development
# Using Docker as a temporary guest for targeting Linux build options
```bash
docker run -it --rm \
ubuntu:18.04 bash
```

# Testing on OSX (x86_64/arm64) with docker targeting Linux build
Setup a temp folder and tari folder, provide ssh access, with network ports exposed
```bash
docker run -it --rm \
-v /run/host-services/ssh-auth.sock:/run/host-services/ssh-auth.sock \
-e SSH_AUTH_SOCK=/run/host-services/ssh-auth.sock \
-v ${PWD}/../temp/root:/root \
-v ${PWD}/../tari:/work \
-w /work \
-p 0.0.0.0:1230-1240:1230-1240 \
-u root \
--platform linux/arm64 \
ubuntu:18.04 bash
```

# Prep Ubuntu v18.04 for development
# From - https://github.com/tari-project/tari/blob/development/scripts/install_ubuntu_dependencies.sh
```bash
sudo apt-get update
sudo apt-get install \
sudo apt-get install --no-install-recommends --assume-yes \
apt-transport-https \
ca-certificates \
curl \
gpg \
bash \
less \
openssl \
libssl-dev \
pkg-config \
libsqlite3-dev \
clang-10 \
libsqlite3-0 \
libreadline-dev \
git \
cmake \
dh-autoreconf \
clang \
g++ \
libc++-dev \
libc++abi-dev \
libprotobuf-dev \
protobuf-compiler \
libncurses5-dev \
libncursesw5-dev \
libudev-dev \
libhidapi-dev \
zip
```

# Prep Ubuntu for cross-compile aarch64/arm64 on x86_64
# Prep Ubuntu for a different CPU architecture than native CPU
an example from arm64 build to x86_64
```bash
sudo apt-get install \
pkg-config-aarch64-linux-gnu \
gcc-aarch64-linux-gnu \
g++-aarch64-linux-gnu
export CROSS_DEB_ARCH=amd64
bash ./scripts/cross_compile_ubuntu_18-pre-build.sh x86_64-unknown-linux-gnu
```
an example from x86_64 build to arm64
```bash
export CROSS_DEB_ARCH=arm64
bash ./scripts/cross_compile_ubuntu_18-pre-build.sh aarch64-unknown-linux-gnu
```

# Install rust
Expand All @@ -52,13 +88,14 @@ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
```

```bash
export PATH="$HOME/.cargo/bin:$PATH"
source "$HOME/.cargo/env"
```

# Prep rust for cross-compile aarch64/arm64 on x86_64
```bash
rustup target add aarch64-unknown-linux-gnu
rustup toolchain install stable-aarch64-unknown-linux-gnu
rustup toolchain install stable-aarch64-unknown-linux-gnu --force-non-host
```

# Check was tools chains rust has in place
Expand Down Expand Up @@ -125,16 +162,20 @@ cargo build --locked \
--target aarch64-unknown-linux-gnu
```

# Using a single command line build using Docker
# Using a single command line build using cross-rs
```bash
cross build --locked \
--release --features safe \
--target aarch64-unknown-linux-gnu
```
or
# Building Raspberry Pi Linux compatible binaries on your faster x86_64 or aarch64 computer
```bash
cross build --locked \
--release --features safe \
--target aarch64-unknown-linux-gnu \
--bin minotari_node --bin minotari_console_wallet \
--bin minotari_merge_mining_proxy --bin minotari_miner
--bin minotari_node \
--bin minotari_console_wallet \
--bin minotari_merge_mining_proxy \
--bin minotari_miner
```
Empty file modified scripts/cross_compile_tooling.sh
100644 → 100755
Empty file.
8 changes: 4 additions & 4 deletions scripts/cross_compile_ubuntu_18-pre-build.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ apt-get install --no-install-recommends --assume-yes \
dh-autoreconf \
clang \
g++ \
g++-7 \
libc++-dev \
libc++abi-dev \
libprotobuf-dev \
protobuf-compiler \
libncurses5-dev \
libncursesw5-dev \
libudev-dev \
libhidapi-dev \
zip

echo "Installing rust ..."
Expand Down Expand Up @@ -154,13 +154,13 @@ EoF

# packages needed for Ledger and hidapi
apt-get --assume-yes install \
libhidapi-dev:${CROSS_DEB_ARCH} \
libudev-dev:${CROSS_DEB_ARCH}
libudev-dev:${CROSS_DEB_ARCH} \
libhidapi-dev:${CROSS_DEB_ARCH}

fi

rustup target add ${targetBuild}
rustup toolchain install stable-${targetBuild} --force-non-host

rustup target list
rustup target list --installed
rustup toolchain list
2 changes: 1 addition & 1 deletion scripts/install_ubuntu_dependencies-rust-arm64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
#
export PATH="$HOME/.cargo/bin:$PATH"
rustup target add aarch64-unknown-linux-gnu
rustup toolchain install stable-aarch64-unknown-linux-gnu
rustup toolchain install stable-aarch64-unknown-linux-gnu --force-non-host
1 change: 1 addition & 0 deletions scripts/install_ubuntu_dependencies-rust.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
#
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
export PATH="$HOME/.cargo/bin:$PATH"
. "$HOME/.cargo/env"
3 changes: 3 additions & 0 deletions scripts/install_ubuntu_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ apt-get install --no-install-recommends --assume-yes \
git \
cmake \
dh-autoreconf \
clang \
g++ \
libc++-dev \
libc++abi-dev \
libprotobuf-dev \
protobuf-compiler \
libncurses5-dev \
libncursesw5-dev \
libudev-dev \
libhidapi-dev \
zip

0 comments on commit 561ac67

Please sign in to comment.