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

ci(fix): improve cross-compile, add x86_64 target from aarch64 #6352

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build_binaries.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
{
"name": "macos-x86_64",
"runs-on": "macos-11",
"runs-on": "macos-12",
"rust": "stable",
"target": "x86_64-apple-darwin",
"cross": false
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/build_binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ jobs:
- name: Install macOS dependencies
if: startsWith(runner.os,'macOS')
run: |
brew install openssl cmake zip coreutils automake autoconf protobuf
# openssl and cmake already installed
brew install zip coreutils automake autoconf protobuf
rustup target add ${{ matrix.builds.target }}

- name: Install Windows dependencies
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/build_dockers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ jobs:
echo "tag_alias=latest" >> $GITHUB_OUTPUT
echo "build_items=all" >> $GITHUB_OUTPUT
fi
if [[ "${{ github.ref }}" =~ ^refs/heads/build-dockers-* ]] || [[ "${{ github.ref }}" =~ ^refs/heads/build-all-* ]] ; then
echo "Branch Build - limited dual arch"
echo "platforms=linux/arm64, linux/amd64" >> $GITHUB_OUTPUT
echo "tag_alias=latest-weekly" >> $GITHUB_OUTPUT
echo "build_items=minotari_all" >> $GITHUB_OUTPUT
fi
if [ "${{ github.event_name }}" == "workflow_dispatch" ] ; then
echo "Manual Build - selective"
echo "platforms=${{ github.event.inputs.platforms }}" >> $GITHUB_OUTPUT
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 @@ -150,7 +150,8 @@ jobs:
- name: Install macOS dependencies
if: startsWith(runner.os,'macOS')
run: |
brew install openssl cmake coreutils automake autoconf protobuf
# openssl and cmake already installed
brew install coreutils automake autoconf protobuf
rustup target add ${{ matrix.builds.target }}

- name: Setup Rust toolchain
Expand Down
61 changes: 21 additions & 40 deletions Cross.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,66 +18,47 @@ passthrough = [
"TARI_NETWORK_DIR",
]

# Don't forget export:
# CFLAGS=-DMDB_USE_ROBUST=0
[target.x86_64-linux-android]
image = "ghcr.io/cross-rs/x86_64-linux-android:edge"
pre-build = [ """
export DEBIAN_FRONTEND=noninteractive && \
apt-get update && \
apt-get --assume-yes --no-install-recommends install \
curl unzip && \
curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v25.2/protoc-25.2-linux-x86_64.zip && \
unzip -o protoc-25.2-linux-x86_64.zip -d /usr/ && \
curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v26.1/protoc-26.1-linux-x86_64.zip && \
unzip -o protoc-26.1-linux-x86_64.zip -d /usr/ && \
/usr/bin/protoc --version
""" ]

[target.x86_64-linux-android.env]
passthrough = [
"CFLAGS=-DMDB_USE_ROBUST=0",
]

[target.aarch64-linux-android]
image = "ghcr.io/cross-rs/aarch64-linux-android:edge"
pre-build = [ """
export DEBIAN_FRONTEND=noninteractive && \
apt-get update && \
apt-get --assume-yes --no-install-recommends install \
curl unzip && \
curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v25.2/protoc-25.2-linux-x86_64.zip && \
unzip -o protoc-25.2-linux-x86_64.zip -d /usr/ && \
curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v26.1/protoc-26.1-linux-x86_64.zip && \
unzip -o protoc-26.1-linux-x86_64.zip -d /usr/ && \
/usr/bin/protoc --version
""" ]

[target.aarch64-linux-android.env]
passthrough = [
"CFLAGS=-DMDB_USE_ROBUST=0",
]

[target.aarch64-unknown-linux-gnu]
image = "ubuntu:18.04"
# Mergered all scripts/install_ubuntu_dependencies*.sh scripts
pre-build = [ """
apt-get update && \
apt-get -y install \
openssl \
libssl-dev \
pkg-config \
libsqlite3-dev \
clang-10 \
git \
cmake \
dh-autoreconf \
libc++-dev \
libc++abi-dev \
libprotobuf-dev \
protobuf-compiler \
libncurses5-dev \
libncursesw5-dev \
zip \
curl \
pkg-config-aarch64-linux-gnu \
gcc-aarch64-linux-gnu \
g++-aarch64-linux-gnu && \
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && \
export PATH="$HOME/.cargo/bin:$PATH" && \
rustup target add aarch64-unknown-linux-gnu && \
rustup toolchain install stable-aarch64-unknown-linux-gnu
""" ]
# Need to use native aarch64 on Apple silicon
#image.name = "ubuntu:18.04"
#image.toolchain = ["linux/arm64=aarch64-unknown-linux-gnu"]
pre-build = "./scripts/cross_compile_ubuntu_18-pre-build.sh"

[target.aarch64-unknown-linux-gnu.env]
passthrough = [
"CARGO_BUILD_TARGET",
"CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc",
"BINDGEN_EXTRA_CLANG_ARGS=--sysroot /usr/aarch64-linux-gnu/include/",
]
[target.x86_64-unknown-linux-gnu]
image = "ubuntu:18.04"
pre-build = "./scripts/cross_compile_ubuntu_18-pre-build.sh"
2 changes: 1 addition & 1 deletion applications/minotari_miner/linux/start_minotari_miner
2 changes: 1 addition & 1 deletion applications/minotari_miner/osx/start_minotari_miner
166 changes: 166 additions & 0 deletions scripts/cross_compile_ubuntu_18-pre-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
#!/usr/bin/env bash
#
# Single script for Ubuntu 18.04 package setup, mostly used for cross-compiling
#

set -e

USAGE="Usage: $0 target build ie: x86_64-unknown-linux-gnu or aarch64-unknown-linux-gnu"

if [ "$#" == "0" ]; then
echo "$USAGE"
exit 1
fi

if [ -z "${CROSS_DEB_ARCH}" ]; then
echo "Should be run from cross, which sets the env CROSS_DEB_ARCH"
exit 1
fi

targetBuild="${1}"
nativeRunTime=$(uname -m)
echo "Native RunTime is ${nativeRunTime}"

if [ "${nativeRunTime}" == "x86_64" ]; then
nativeArch=amd64
if [ "${targetBuild}" == "aarch64-unknown-linux-gnu" ]; then
targetArch=arm64
targetPlatform=aarch64
else
targetArch=amd64
targetPlatform=x86-64
fi
elif [ "${nativeRunTime}" == "aarch64" ]; then
nativeArch=arm64
if [ "${targetBuild}" == "x86_64-unknown-linux-gnu" ]; then
targetArch=amd64
targetPlatform=x86-64
fi
elif [ "${nativeRunTime}" == "riscv64" ]; then
nativeArch=riscv64
echo "ToDo!"
else
echo "!!Unsupport platform!!"
exit 1
fi

crossArch=${CROSS_DEB_ARCH}
apt-get update

# Base install packages
# scripts/install_ubuntu_dependencies.sh
apt-get install --no-install-recommends --assume-yes \
apt-transport-https \
ca-certificates \
curl \
gpg \
bash \
less \
openssl \
libssl-dev \
pkg-config \
libsqlite3-dev \
libsqlite3-0 \
libreadline-dev \
git \
cmake \
dh-autoreconf \
clang \
g++ \
g++-7 \
libc++-dev \
libc++abi-dev \
libprotobuf-dev \
protobuf-compiler \
libncurses5-dev \
libncursesw5-dev \
libudev-dev \
zip

echo "Installing rust ..."
mkdir -p "$HOME/.cargo/bin/"
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
export PATH="$HOME/.cargo/bin:$PATH"
. "$HOME/.cargo/env"

# Cross-CPU compile setup
if [ "${CROSS_DEB_ARCH}" != "${nativeArch}" ]; then
echo "Setup Cross CPU Compile ..."
sed -i.save -e "s/^deb\ http/deb [arch="${nativeArch}"] http/g" /etc/apt/sources.list

. /etc/lsb-release
ubuntu_tag=${DISTRIB_CODENAME}

if [ "${crossArch}" == "arm64" ]; then
cat << EoF > /etc/apt/sources.list.d/${ubuntu_tag}-${crossArch}.list
deb [arch=${crossArch}] http://ports.ubuntu.com/ubuntu-ports ${ubuntu_tag} main restricted universe multiverse
# deb-src [arch=${crossArch}] http://ports.ubuntu.com/ubuntu-ports ${ubuntu_tag} main restricted universe multiverse

deb [arch=${crossArch}] http://ports.ubuntu.com/ubuntu-ports ${ubuntu_tag}-updates main restricted universe multiverse
# deb-src [arch=${crossArch}] http://ports.ubuntu.com/ubuntu-ports ${ubuntu_tag}-updates main restricted universe multiverse

deb [arch=${crossArch}] http://ports.ubuntu.com/ubuntu-ports ${ubuntu_tag}-backports main restricted universe multiverse
# deb-src [arch=${crossArch}] http://ports.ubuntu.com/ubuntu-ports ${ubuntu_tag}-backports main restricted universe multiverse

deb [arch=${crossArch}] http://ports.ubuntu.com/ubuntu-ports ${ubuntu_tag}-security main restricted universe multiverse
# deb-src [arch=${crossArch}] http://ports.ubuntu.com/ubuntu-ports ${ubuntu_tag}-security main restricted universe multiverse

deb [arch=${crossArch}] http://archive.canonical.com/ubuntu ${ubuntu_tag} partner
# deb-src [arch=${crossArch}] http://archive.canonical.com/ubuntu ${ubuntu_tag} partner
EoF
fi

if [ "${crossArch}" == "amd64" ]; then
cat << EoF > /etc/apt/sources.list.d/${ubuntu_tag}-${crossArch}.list
deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ ${ubuntu_tag} main restricted
# deb-src http://archive.ubuntu.com/ubuntu/ ${ubuntu_tag} main restricted

deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ ${ubuntu_tag}-updates main restricted
# deb-src http://archive.ubuntu.com/ubuntu/ ${ubuntu_tag}-updates main restricted

deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ ${ubuntu_tag} universe
# deb-src http://archive.ubuntu.com/ubuntu/ ${ubuntu_tag} universe
deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ ${ubuntu_tag}-updates universe
# deb-src http://archive.ubuntu.com/ubuntu/ ${ubuntu_tag}-updates universe

deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ ${ubuntu_tag} multiverse
# deb-src http://archive.ubuntu.com/ubuntu/ ${ubuntu_tag} multiverse
deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ ${ubuntu_tag}-updates multiverse
# deb-src http://archive.ubuntu.com/ubuntu/ ${ubuntu_tag}-updates multiverse

deb [arch=amd64] http://archive.ubuntu.com/ubuntu/ ${ubuntu_tag}-backports main restricted universe multiverse
# deb-src http://archive.ubuntu.com/ubuntu/ ${ubuntu_tag}-backports main restricted universe multiverse

# deb http://archive.canonical.com/ubuntu ${ubuntu_tag} partner
# deb-src http://archive.canonical.com/ubuntu ${ubuntu_tag} partner

deb [arch=amd64] http://security.ubuntu.com/ubuntu/ ${ubuntu_tag}-security main restricted
# deb-src http://security.ubuntu.com/ubuntu/ ${ubuntu_tag}-security main restricted
deb [arch=amd64] http://security.ubuntu.com/ubuntu/ ${ubuntu_tag}-security universe
# deb-src http://security.ubuntu.com/ubuntu/ ${ubuntu_tag}-security universe
deb [arch=amd64] http://security.ubuntu.com/ubuntu/ ${ubuntu_tag}-security multiverse
# deb-src http://security.ubuntu.com/ubuntu/ ${ubuntu_tag}-security multiverse
EoF
fi

dpkg --add-architecture ${CROSS_DEB_ARCH}
apt-get update

# scripts/install_ubuntu_dependencies-cross_compile.sh x86-64
apt-get --assume-yes install \
pkg-config-${targetPlatform}-linux-gnu \
gcc-${targetPlatform}-linux-gnu \
g++-${targetPlatform}-linux-gnu

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

fi

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

rustup target list
rustup toolchain list
Loading