Skip to content

ZXC: Build Library

ZXC: Build Library #8

name: "ZXC: Build Library"
on:
workflow_call:
workflow_dispatch:
inputs:
run-windows-builds:
description: "Select this option when you want to run the Windows builds."
type: boolean
required: false
default: false
run-macos-builds:
description: "Select this option when you want to run the MacOS builds."
type: boolean
required: false
default: false
defaults:
run:
shell: bash
permissions:
contents: read
jobs:
build:
name: Build
runs-on: hiero-client-sdk-linux-large
env:
HIERO_NETWORK: localhost
strategy:
matrix:
include:
- os: Linux
preset: linux-x64
steps:
- name: Harden Runner
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
with:
egress-policy: audit
- name: Setup Control Groups
id: cgroup
run: |
echo "::group::Get System Configuration"
USR_ID="$(id -un)"
GRP_ID="$(id -gn)"
SDK_CPP_MEM_LIMIT="30064771072"
AGENT_MEM_LIMIT="2147483648"
USER_SLICE="user.slice/user-$(id -u).slice"
USER_SERVICE="${USER_SLICE}/user@$(id -u).service"
SDK_CPP_GROUP_NAME="${USER_SERVICE}/sdk-cpp-${{ github.run_id }}"
AGENT_GROUP_NAME="${USER_SERVICE}/agent-${{ github.run_id }}"
echo "::endgroup::"
echo "::group::Install Control Group Tools"
if ! command -v cgcreate >/dev/null 2>&1; then
sudo apt-get update
sudo apt-get install -y cgroup-tools
fi
echo "::endgroup::"
echo "::group::Create Control Groups"
sudo cgcreate -g cpu,memory:${USER_SLICE} -a ${USR_ID}:${GRP_ID} -t ${USR_ID}:${GRP_ID}
sudo cgcreate -g cpu,memory:${USER_SERVICE} -a ${USR_ID}:${GRP_ID} -t ${USR_ID}:${GRP_ID}
sudo cgcreate -g cpu,memory:${SDK_CPP_GROUP_NAME} -a ${USR_ID}:${GRP_ID} -t ${USR_ID}:${GRP_ID}
sudo cgcreate -g cpu,memory:${AGENT_GROUP_NAME} -a ${USR_ID}:${GRP_ID} -t ${USR_ID}:${GRP_ID}
echo "::endgroup::"
echo "::group::Set Control Group Limits"
cgset -r cpu.weight=768 ${SDK_CPP_GROUP_NAME}
cgset -r cpu.weight=500 ${AGENT_GROUP_NAME}
cgset -r memory.max=${SDK_CPP_MEM_LIMIT} ${SDK_CPP_GROUP_NAME}
cgset -r memory.max=${AGENT_MEM_LIMIT} ${AGENT_GROUP_NAME}
cgset -r memory.swap.max=${SDK_CPP_MEM_LIMIT} ${SDK_CPP_GROUP_NAME}
cgset -r memory.swap.max=${AGENT_MEM_LIMIT} ${AGENT_GROUP_NAME}
echo "::endgroup::"
echo "::group::Move Runner Processes to Control Groups"
sudo cgclassify --sticky -g cpu,memory:${AGENT_GROUP_NAME} $(pgrep 'Runner.Listener' | tr '\n' ' ')
sudo cgclassify -g cpu,memory:${AGENT_GROUP_NAME} $(pgrep 'Runner.Worker' | tr '\n' ' ')
echo "::endgroup::"
CG_EXEC="cgexec -g cpu,memory:${SDK_CPP_GROUP_NAME} --sticky ionice -c 2 -n 2 nice -n 19"
echo "exec=${CG_EXEC}" >> "${GITHUB_OUTPUT}"
- name: Checkout Code
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
submodules: true
# - name: Run Clang-Format
# uses: jidicula/clang-format-action@c74383674bf5f7c69f60ce562019c1c94bc1421a # v4.13.0
# with:
# clang-format-version: "17"
# check-path: "src"
- name: Use Node.js 22
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: 22
- name: Install Local Node
run: sudo npm install -g @hashgraph/[email protected]
- name: Install Linux Prerequisites
run: |
sudo apt-get update
sudo apt-get install -y pkg-config libc6-dbg libgtest-dev build-essential
- name: Ensure Binary Cache Path Exists
run: mkdir -p "${{ github.workspace }}/b/vcpkg_cache"
- name: Install CMake & Ninja
uses: lukka/get-cmake@5979409e62bdf841487c5fb3c053149de97a86d3 # v3.31.2
- name: Setup VCPkg
uses: lukka/run-vcpkg@5e0cab206a5ea620130caf672fce3e4a6b5666a1 # v11.5
with:
binaryCachePath: ${{ github.workspace }}/b/vcpkg_cache
- name: Convert VCPkg to Full Clone
working-directory: vcpkg
run: git fetch --unshallow --prune
# - name: CMake Build (Debug)
# uses: lukka/run-cmake@2ce8982be71b8e9a3c4d5e432135035afd1e76a7 # v10.7
# env:
# VCPKG_BINARY_SOURCES: clear
# with:
# configurePreset: ${{ matrix.preset }}-debug
# buildPreset: ${{ matrix.preset }}-debug
- name: CMake Build (Debug)
env:
VCPKG_BINARY_SOURCES: clear
run: |
echo "::group::Configure Project"
${{ steps.cgroup.outputs.exec }} cmake --preset ${{ matrix.preset }}-debug -DBUILD_TESTS=ON
echo "::endgroup::"
echo "::group::Build Project"
${{ steps.cgroup.outputs.exec }} cmake --build -j 6 --preset ${{ matrix.preset }}-debug
echo "::endgroup::"
# - name: CMake Build (Release)
# if: github.event.pull_request.merged == true
# uses: lukka/run-cmake@2ce8982be71b8e9a3c4d5e432135035afd1e76a7 # v10.7
# env:
# VCPKG_BINARY_SOURCES: clear
# with:
# configurePreset: ${{ matrix.preset }}-release
# buildPreset: ${{ matrix.preset }}-release
- name: CMake Build (Release)
if: github.event.pull_request.merged == true
env:
VCPKG_BINARY_SOURCES: clear
run: |
echo "::group::Configure Project"
${{ steps.cgroup.outputs.exec }} cmake --preset ${{ matrix.preset }}-release -DBUILD_TESTS=ON
echo "::endgroup::"
echo "::group::Build Project"
${{ steps.cgroup.outputs.exec }} cmake --build -j 6 --preset ${{ matrix.preset }}-release
echo "::endgroup::"
# - name: List Directory Structure
# if: ${{ contains(runner.os, 'Windows') && always() }}
# shell: pwsh
# run: tree /F build
- name: Start the local node
run: npx hedera start --verbose=trace --detached --network-tag=0.57.0
- name: Start CTest suite (Debug)
run: ${{ steps.cgroup.outputs.exec }} ctest -j 6 -C Debug --test-dir build/${{ matrix.preset }}-debug --output-on-failure
- name: Start CTest suite (Release)
if: github.event.pull_request.merged == true
run: ${{ steps.cgroup.outputs.exec }} ctest -j 6 -C Debug --test-dir build/${{ matrix.preset }}-release --output-on-failure
- name: Stop the local node
run: sudo npx @hashgraph/hedera-local stop
- name: Compute Short SHA
id: sha
run: echo "short=$(echo -n "${{ github.sha }}" | cut -c1-8)" >> $GITHUB_OUTPUT
- name: Attach Artifact
if: github.event.pull_request.merged == true
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: hapi-library-${{ runner.os }}-${{ steps.sha.outputs.short }}
path: package/
if-no-files-found: warn
build-windows:
name: Build (Windows)
runs-on: windows-latest
if: ${{ (inputs.run-windows-builds) && !cancelled() }}
env:
HEDERA_NETWORK: localhost
steps:
- name: Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
with:
egress-policy: audit
- name: Checkout Code
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
with:
fetch-depth: 0
- name: Setup-msbuild
uses: microsoft/setup-msbuild@6fb02220983dee41ce7ae257b6f4d8f9bf5ed4ce # v2
with:
msbuild-architecture: x64
- name: Setup-perl
uses: shogo82148/actions-setup-perl@9c1eca9952ccc07f9ca4a2097b63df93d9d138e9 # v1.31.3
with:
perl-version: "5.32"
distribution: strawberry
- name: Setup-nasm
uses: ilammy/setup-nasm@13cbeb366c45c4379d3478cdcbadd8295feb5028 # v1.5.1
- name: Enable Git long paths
run: git config --global core.longpaths true
- name: Build (Debug)
run: |
git submodule update --init
cmake --preset windows-x64-debug
cmake --build --preset windows-x64-debug -j 4
- name: Build (Release)
run: |
cmake --preset windows-x64-release
cmake --build --preset windows-x64-release -j 4
- name: Compute Short SHA
id: sha
shell: pwsh
run: |
$sha = "${{ github.sha }}"
$short = $sha.Substring(0, 8)
Add-Content -Path $env:GITHUB_OUTPUT -Value "short=$short"
- name: Attach Artifact
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: hapi-library-${{ runner.os }}-${{ steps.sha.outputs.short }}
path: package/
if-no-files-found: warn
build-macos:
name: Build (MacOS)
runs-on: macos-latest
if: ${{ (inputs.run-macos-builds) && !cancelled() }}
env:
HEDERA_NETWORK: localhost
steps:
- name: Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
with:
egress-policy: audit
- name: Checkout Code
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
with:
fetch-depth: 0
- name: Install Ninja
uses: seanmiddleditch/gha-setup-ninja@96bed6edff20d1dd61ecff9b75cc519d516e6401 # v5.0.0
- name: Build (Debug)
run: |
git submodule update --init
cmake --preset macos-arm64-debug
cmake --build --preset macos-arm64-debug -j 4
- name: Build (Release)
run: |
cmake --preset macos-arm64-release
cmake --build --preset macos-arm64-release -j 4
- name: Compute Short SHA
id: sha
run: echo "short=$(echo -n "${{ github.sha }}" | cut -c1-8)" >> $GITHUB_OUTPUT
- name: Attach Artifact
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
name: hapi-library-${{ runner.os }}-${{ steps.sha.outputs.short }}
path: package/
if-no-files-found: warn