Skip to content
Open
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ jobs:
with:
path: |
~/x-tools
key: ${{ runner.os }}-musl-${{ hashFiles('**/musl-toolchain/preset.sh') }}
key: ${{ runner.os }}-musl-${{ hashFiles('**/musl-toolchain/build-amd64.sh') }}
restore-keys: |
${{ runner.os }}-musl-

Expand All @@ -403,6 +403,6 @@ jobs:
if: runner.os == 'Linux'
run: |
# Run build script for musl toolchain
source musl-toolchain/build.sh
source musl-toolchain/build-amd64.sh
# Build for musl
cargo --verbose build --bin kaspad --bin rothschild --bin kaspa-wallet --release --target x86_64-unknown-linux-musl
105 changes: 77 additions & 28 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,25 @@ jobs:
strategy:
fail-fast: false
matrix:
# Build gnu-linux on ubuntu-18.04 and musl on ubuntu latest
# os: [ ubuntu-18.04, ubuntu-latest, windows-latest, macos-latest ]
os: [ ubuntu-latest, windows-latest, macos-latest ]
name: Building, ${{ matrix.os }}
include:
- os: ubuntu-latest
TARGET: linux-musl/amd64
- os: ubuntu-latest
TARGET: linux-musl/aarch64
- os: windows-latest
TARGET: windows
- os: macos-latest
TARGET: macos/amd64
- os: macos-latest
TARGET: macos/aarch64
name: Building ${{ matrix.TARGET }}
steps:
- name: Fix CRLF on Windows
if: runner.os == 'Windows'
if: matrix.os == 'windows-latest'
run: git config --global core.autocrlf false

- name: Checkout sources
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install Protoc
uses: arduino/setup-protoc@v3
Expand All @@ -30,31 +38,32 @@ jobs:
uses: dtolnay/rust-toolchain@stable

- name: Cache Cargo Build Outputs
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
key: ${{ matrix.TARGET }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Cache Toolchain
if: contains(matrix.TARGET, 'linux-musl')
uses: actions/cache@v4
with:
path: |
~/x-tools
key: ${{ runner.os }}-musl-${{ hashFiles('**/musl-toolchain/preset.sh') }}
key: ${{ runner.os }}-musl-${{ hashFiles('**/musl-toolchain/build-amd64.sh', '**/musl-toolchain/build-aarch64.sh') }}
restore-keys: |
${{ runner.os }}-musl-
${{ matrix.TARGET }}-musl-

- name: Build on Linux
if: runner.os == 'Linux'
- name: Build for linux-musl/amd64
if: matrix.TARGET == 'linux-musl/amd64'
# We're using musl to make the binaries statically linked and portable
run: |
# Run build script for musl toolchain
source musl-toolchain/build.sh
source musl-toolchain/build-amd64.sh

# Go back to the workspace
cd $GITHUB_WORKSPACE
Expand All @@ -71,8 +80,30 @@ jobs:
echo "archive=${archive}" >> $GITHUB_ENV
echo "asset_name=${asset_name}" >> $GITHUB_ENV

- name: Build on Windows
if: runner.os == 'Windows'
- name: Build for linux-musl/aarch64
if: matrix.TARGET == 'linux-musl/aarch64'
# We're using musl to make the binaries statically linked and portable
run: |
# Run build script for musl toolchain
source musl-toolchain/build-aarch64.sh

# Go back to the workspace
cd $GITHUB_WORKSPACE

# Build for musl
cargo --verbose build --bin kaspad --bin rothschild --bin kaspa-wallet --release --target aarch64-unknown-linux-musl
mkdir bin || true
cp target/aarch64-unknown-linux-musl/release/kaspad bin/
cp target/aarch64-unknown-linux-musl/release/rothschild bin/
cp target/aarch64-unknown-linux-musl/release/kaspa-wallet bin/
archive="bin/rusty-kaspa-${{ github.event.release.tag_name }}-linux-aarch64.zip"
asset_name="rusty-kaspa-${{ github.event.release.tag_name }}-linux-aarch64.zip"
zip -r "${archive}" ./bin/*
echo "archive=${archive}" >> $GITHUB_ENV
echo "asset_name=${asset_name}" >> $GITHUB_ENV

- name: Build for Windows
if: matrix.TARGET == 'windows'
shell: bash
run: |
cargo build --bin kaspad --release
Expand All @@ -88,18 +119,36 @@ jobs:
echo "archive=${archive}" >> $GITHUB_ENV
echo "asset_name=${asset_name}" >> $GITHUB_ENV

- name: Build on MacOS
if: runner.os == 'macOS'
- name: Build for macos/amd64
if: matrix.TARGET == 'macos/amd64'
run: |
cargo build --bin kaspad --release
cargo build --bin rothschild --release
cargo build --bin kaspa-wallet --release
rustup target add x86_64-apple-darwin
cargo build --target x86_64-apple-darwin --bin kaspad --release
cargo build --target x86_64-apple-darwin --bin rothschild --release
cargo build --target x86_64-apple-darwin --bin kaspa-wallet --release
mkdir bin || true
cp target/x86_64-apple-darwin/release/kaspad bin/
cp target/x86_64-apple-darwin/release/rothschild bin/
cp target/x86_64-apple-darwin/release/kaspa-wallet bin/
archive="bin/rusty-kaspa-${{ github.event.release.tag_name }}-macos-amd64.zip"
asset_name="rusty-kaspa-${{ github.event.release.tag_name }}-macos-amd64.zip"
zip -r "${archive}" ./bin/*
echo "archive=${archive}" >> $GITHUB_ENV
echo "asset_name=${asset_name}" >> $GITHUB_ENV

- name: Build for macos/aarch64
if: matrix.TARGET == 'macos/aarch64'
run: |
rustup target add aarch64-apple-darwin
cargo build --target aarch64-apple-darwin --bin kaspad --release
cargo build --target aarch64-apple-darwin --bin rothschild --release
cargo build --target aarch64-apple-darwin --bin kaspa-wallet --release
mkdir bin || true
cp target/release/kaspad bin/
cp target/release/rothschild bin/
cp target/release/kaspa-wallet bin/
archive="bin/rusty-kaspa-${{ github.event.release.tag_name }}-osx.zip"
asset_name="rusty-kaspa-${{ github.event.release.tag_name }}-osx.zip"
cp target/aarch64-apple-darwin/release/kaspad bin/
cp target/aarch64-apple-darwin/release/rothschild bin/
cp target/aarch64-apple-darwin/release/kaspa-wallet bin/
archive="bin/rusty-kaspa-${{ github.event.release.tag_name }}-macos-aarch64.zip"
asset_name="rusty-kaspa-${{ github.event.release.tag_name }}-macos-aarch64.zip"
zip -r "${archive}" ./bin/*
echo "archive=${archive}" >> $GITHUB_ENV
echo "asset_name=${asset_name}" >> $GITHUB_ENV
Expand All @@ -119,7 +168,7 @@ jobs:
name: Building WASM32 SDK
steps:
- name: Checkout sources
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install Protoc
uses: arduino/setup-protoc@v3
Expand Down Expand Up @@ -168,15 +217,15 @@ jobs:
run: npm install --global typedoc typescript

- name: Cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
key: wasm-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Build WASM32 SDK
run: |
Expand Down
97 changes: 97 additions & 0 deletions musl-toolchain/build-aarch64.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/bin/bash

# Config presets
PRESET_HASH_FILE="${HOME}/x-tools/aarch64_preset_hash"
CTNG_PRESET="aarch64-unknown-linux-musl"

# Calculate and show the hash of this script file
CURRENT_PRESET_HASH=$(sha256sum ${GITHUB_WORKSPACE}/musl-toolchain/build-aarch64.sh | awk '{print $1}')
echo "Current preset hash: ${CURRENT_PRESET_HASH}"

# Traverse to working directory
cd "${GITHUB_WORKSPACE}/musl-toolchain"

# If the toolchain is not installed or the preset has changed or the preset hash file does not exist.
if [ ! -d "${HOME}/x-tools/${CTNG_PRESET}" ] || [ ! -f "${PRESET_HASH_FILE}" ] || [ "$(cat ${PRESET_HASH_FILE})" != "${CURRENT_PRESET_HASH}" ]; then

# Install dependencies
sudo apt-get update
sudo apt-get install -y autoconf automake libtool libtool-bin unzip help2man python3-dev gperf bison flex texinfo gawk libncurses5-dev libc6-dev-arm64-cross gcc-aarch64-linux-gnu g++-aarch64-linux-gnu libc6-dev-arm64-cross

# Clone crosstool-ng.
git clone https://github.com/crosstool-ng/crosstool-ng

# Configure and build crosstool-ng
cd crosstool-ng

# Use version 1.27
git checkout crosstool-ng-1.27.0
./bootstrap
./configure "--prefix=${HOME}/ctng"
make
make install

# Add crosstool-ng to PATH
export PATH="${HOME}/ctng/bin:${PATH}"

# Load toolchain configuration.
ct-ng "${CTNG_PRESET}"

# Build the toolchain
ct-ng build > build.log 2>&1

# Set status to the exit code of the build
status="${?}"

# We store the log in a file because it bloats the screen too much
# on GitHub Actions. We print it only if the build fails.
echo "Build result:"
if [ "${status}" -eq 0 ]; then
echo "Build succeeded"
ls -la "${HOME}/x-tools"

# Store the current hash of this script after successful build
echo "${CURRENT_PRESET_HASH}" > "${PRESET_HASH_FILE}"
else
echo "Build failed, here's the log:"
cat .config
cat build.log
exit 1
fi
fi

# Update toolchain variables: C compiler, C++ compiler, linker, and archiver
export CC="${HOME}/x-tools/${CTNG_PRESET}/bin/${CTNG_PRESET}-gcc"
export CXX="${HOME}/x-tools/${CTNG_PRESET}/bin/${CTNG_PRESET}-g++"
export LD="${HOME}/x-tools/${CTNG_PRESET}/bin/${CTNG_PRESET}-ld"
export AR="${HOME}/x-tools/${CTNG_PRESET}/bin/${CTNG_PRESET}-ar"

# Exports for cc crate.
# https://docs.rs/cc/latest/cc/#external-configuration-via-environment-variables
export RANLIB_aarch64_unknown_linux_musl="${HOME}/x-tools/${CTNG_PRESET}/bin/${CTNG_PRESET}-ranlib"
export CC_aarch64_unknown_linux_musl="${CC}"
export CXX_aarch64_unknown_linux_musl="${CXX}"
export AR_aarch64_unknown_linux_musl="${AR}"
export LD_aarch64_unknown_linux_musl="${LD}"

# Set environment variables for static linking
export OPENSSL_STATIC="true"
export RUSTFLAGS="-C link-arg=-static"

# We specify the compiler that will invoke linker
export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER="${CC}"

# Add target
rustup target add aarch64-unknown-linux-musl

# Install missing dependencies
cargo fetch --target aarch64-unknown-linux-musl

# Patch missing include in librocksdb-sys-0.16.0+8.10.0. Credit: @supertypo
FILE_PATH=$(find "${HOME}/.cargo/registry/src/" -path "*/librocksdb-sys-0.16.0+8.10.0/*/offpeak_time_info.h")

if [ -n "${FILE_PATH}" ]; then
sed -i '1i #include <cstdint>' "${FILE_PATH}"
else
echo "No such file for sed modification."
fi
97 changes: 97 additions & 0 deletions musl-toolchain/build-amd64.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/bin/bash

# Config presets
PRESET_HASH_FILE="${HOME}/x-tools/amd64_preset_hash"
CTNG_PRESET="x86_64-multilib-linux-musl"

# Calculate and show the hash of this script file
CURRENT_PRESET_HASH=$(sha256sum ${GITHUB_WORKSPACE}/musl-toolchain/build-amd64.sh | awk '{print $1}')
echo "Current preset hash: ${CURRENT_PRESET_HASH}"

# Traverse to working directory
cd "${GITHUB_WORKSPACE}/musl-toolchain"

# If the toolchain is not installed or the preset has changed or the preset hash file does not exist.
if [ ! -d "${HOME}/x-tools/${CTNG_PRESET}" ] || [ ! -f "${PRESET_HASH_FILE}" ] || [ "$(cat ${PRESET_HASH_FILE})" != "${CURRENT_PRESET_HASH}" ]; then

# Install dependencies
sudo apt-get update
sudo apt-get install -y autoconf automake libtool libtool-bin unzip help2man python3-dev gperf bison flex texinfo gawk libncurses5-dev

# Clone crosstool-ng
git clone https://github.com/crosstool-ng/crosstool-ng

# Configure and build crosstool-ng
cd crosstool-ng

# Use version 1.27
git checkout crosstool-ng-1.27.0
./bootstrap
./configure "--prefix=${HOME}/ctng"
make
make install

# Add crosstool-ng to PATH
export PATH="${HOME}/ctng/bin:${PATH}"

# Load toolchain configuration
ct-ng "${CTNG_PRESET}"

# Build the toolchain
ct-ng build > build.log 2>&1

# Set status to the exit code of the build
status="${?}"

# We store the log in a file because it bloats the screen too much
# on GitHub Actions. We print it only if the build fails.
echo "Build result:"
if [ "${status}" -eq 0 ]; then
echo "Build succeeded"
ls -la "${HOME}/x-tools"

# Store the current hash of this script after successful build
echo "${CURRENT_PRESET_HASH}" > "${PRESET_HASH_FILE}"
else
echo "Build failed, here's the log:"
cat .config
cat build.log
exit 1
fi
fi

# Update toolchain variables: C compiler, C++ compiler, linker, and archiver
export CC="${HOME}/x-tools/${CTNG_PRESET}/bin/${CTNG_PRESET}-gcc"
export CXX="${HOME}/x-tools/${CTNG_PRESET}/bin/${CTNG_PRESET}-g++"
export LD="${HOME}/x-tools/${CTNG_PRESET}/bin/${CTNG_PRESET}-ld"
export AR="${HOME}/x-tools/${CTNG_PRESET}/bin/${CTNG_PRESET}-ar"

# Exports for cc crate.
# https://docs.rs/cc/latest/cc/#external-configuration-via-environment-variables
export RANLIB_x86_64_unknown_linux_musl="${HOME}/x-tools/${CTNG_PRESET}/bin/${CTNG_PRESET}-ranlib"
export CC_x86_64_unknown_linux_musl="${CC}"
export CXX_x86_64_unknown_linux_musl="${CXX}"
export AR_x86_64_unknown_linux_musl="${AR}"
export LD_x86_64_unknown_linux_musl="${LD}"

# Set environment variables for static linking
export OPENSSL_STATIC="true"
export RUSTFLAGS="-C link-arg=-static"

# We specify the compiler that will invoke linker
export CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER="${CC}"

# Add target
rustup target add x86_64-unknown-linux-musl

# Install missing dependencies
cargo fetch --target x86_64-unknown-linux-musl

# Patch missing include in librocksdb-sys-0.16.0+8.10.0. Credit: @supertypo
FILE_PATH=$(find "${HOME}/.cargo/registry/src/" -path "*/librocksdb-sys-0.16.0+8.10.0/*/offpeak_time_info.h")

if [ -n "${FILE_PATH}" ]; then
sed -i '1i #include <cstdint>' "${FILE_PATH}"
else
echo "No such file for sed modification."
fi
Loading