build mpt-crypto within release #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build MPT Crypto Libraries | |
| on: | |
| workflow_call: | |
| inputs: | |
| git_ref: | |
| description: "Git ref to checkout (branch, tag, or SHA)" | |
| required: false | |
| type: string | |
| workflow_dispatch: | |
| inputs: | |
| git_ref: | |
| description: "Git ref to checkout (branch, tag, or SHA)" | |
| required: false | |
| type: string | |
| push: | |
| branches: | |
| - confidential-mpt | |
| paths: | |
| - ".github/workflows/build_mpt_crypto_libs.yml" | |
| jobs: | |
| build_linux: | |
| name: Build for Linux (x86_64) | |
| runs-on: ubuntu-22.04 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ inputs.git_ref || github.ref }} | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| - name: Install dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y cmake build-essential libssl-dev ninja-build | |
| pip install conan | |
| - name: Setup Conan profile | |
| run: | | |
| conan profile detect --force | |
| conan remote add --index 0 xrplf https://conan.ripplex.io | |
| - name: Clone mpt-crypto | |
| run: | | |
| git clone --branch mpt-utility https://github.com/yinyiqian1/mpt-crypto.git /tmp/mpt-crypto | |
| - name: Copy header files | |
| run: | | |
| mkdir -p xrpl/core/confidential/include/utility | |
| cp /tmp/mpt-crypto/include/secp256k1_mpt.h xrpl/core/confidential/include/ | |
| cp /tmp/mpt-crypto/include/utility/mpt_utility.h xrpl/core/confidential/include/utility/ | |
| - name: Build mpt-crypto | |
| run: | | |
| cd /tmp/mpt-crypto | |
| mkdir -p build && cd build | |
| conan install .. --build="*" -o "&:tests=False" -o "&:fPIC=True" | |
| cmake .. -DCMAKE_BUILD_TYPE=Release \ | |
| -G Ninja \ | |
| -DCMAKE_TOOLCHAIN_FILE=build/generators/conan_toolchain.cmake \ | |
| -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ | |
| -DENABLE_TESTS=OFF | |
| ninja | |
| - name: Copy libraries | |
| run: | | |
| rm -rf xrpl/core/confidential/libs/linux | |
| mkdir -p xrpl/core/confidential/libs/linux | |
| MPT_LIB=$(find /tmp/mpt-crypto/build -name "libmpt-crypto.a" | head -n 1) | |
| SECP_LIB=$(find ~/.conan2/p -path "*/p/lib/libsecp256k1.a" 2>/dev/null | head -n 1) | |
| if [ -z "$SECP_LIB" ]; then | |
| SECP_LIB=$(find /tmp/mpt-crypto/build -name "libsecp256k1.a" 2>/dev/null | head -n 1) | |
| fi | |
| CRYPTO_LIB=$(find ~/.conan2 -name "libcrypto.a" 2>/dev/null | head -n 1) | |
| if [ -n "$MPT_LIB" ] && [ -f "$MPT_LIB" ]; then | |
| cp "$MPT_LIB" xrpl/core/confidential/libs/linux/ | |
| else | |
| echo "Error: libmpt-crypto.a not found!" | |
| exit 1 | |
| fi | |
| if [ -n "$SECP_LIB" ] && [ -f "$SECP_LIB" ]; then | |
| cp "$SECP_LIB" xrpl/core/confidential/libs/linux/ | |
| else | |
| echo "Error: libsecp256k1.a not found!" | |
| exit 1 | |
| fi | |
| if [ -n "$CRYPTO_LIB" ] && [ -f "$CRYPTO_LIB" ]; then | |
| cp "$CRYPTO_LIB" xrpl/core/confidential/libs/linux/ | |
| echo "Bundled OpenSSL: $CRYPTO_LIB" | |
| else | |
| echo "Error: libcrypto.a not found in Conan cache!" | |
| echo "Searching for any OpenSSL libraries..." | |
| find ~/.conan2 -name "libcrypto*" 2>/dev/null || echo "No libcrypto files found" | |
| exit 1 | |
| fi | |
| - name: Verify bundled libraries | |
| run: | | |
| echo "=== Verifying bundled libraries ===" | |
| LIBS_DIR="xrpl/core/confidential/libs/linux" | |
| echo "Library files:" | |
| ls -la "$LIBS_DIR/" | |
| echo "" | |
| echo "Library sizes:" | |
| du -h "$LIBS_DIR/"* | |
| echo "" | |
| echo "Checking required libraries exist:" | |
| REQUIRED_LIBS=("libmpt-crypto.a" "libsecp256k1.a" "libcrypto.a") | |
| MISSING=0 | |
| for lib in "${REQUIRED_LIBS[@]}"; do | |
| if [ -f "$LIBS_DIR/$lib" ]; then | |
| echo " ✓ $lib ($(du -h "$LIBS_DIR/$lib" | cut -f1))" | |
| else | |
| echo " ✗ $lib MISSING" | |
| MISSING=1 | |
| fi | |
| done | |
| if [ $MISSING -eq 1 ]; then | |
| echo "" | |
| echo "ERROR: Missing required libraries!" | |
| exit 1 | |
| fi | |
| echo "" | |
| echo "=== All required libraries verified ===" | |
| - name: Upload libraries and headers | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: mpt-crypto-linux-x86_64 | |
| path: | | |
| xrpl/core/confidential/libs/linux/*.a | |
| xrpl/core/confidential/include/*.h | |
| xrpl/core/confidential/include/utility/*.h | |
| build_macos: | |
| name: Build for macOS (universal) | |
| runs-on: macos-14 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ inputs.git_ref || github.ref }} | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| - name: Install dependencies | |
| run: | | |
| brew install cmake openssl ninja | |
| pip install conan | |
| - name: Setup Conan profile | |
| run: | | |
| conan profile detect --force | |
| conan remote add --index 0 xrplf https://conan.ripplex.io | |
| - name: Clone mpt-crypto | |
| run: | | |
| git clone --branch mpt-utility https://github.com/yinyiqian1/mpt-crypto.git /tmp/mpt-crypto | |
| - name: Copy header files | |
| run: | | |
| mkdir -p xrpl/core/confidential/include/utility | |
| cp /tmp/mpt-crypto/include/secp256k1_mpt.h xrpl/core/confidential/include/ | |
| cp /tmp/mpt-crypto/include/utility/mpt_utility.h xrpl/core/confidential/include/utility/ | |
| - name: Build mpt-crypto | |
| run: | | |
| cd /tmp/mpt-crypto | |
| mkdir -p build && cd build | |
| conan install .. --build="*" -o "&:tests=False" -s arch=armv8 -o "&:fPIC=True" | |
| cmake .. -DCMAKE_BUILD_TYPE=Release \ | |
| -G Ninja \ | |
| -DCMAKE_TOOLCHAIN_FILE=build/generators/conan_toolchain.cmake \ | |
| -DCMAKE_OSX_ARCHITECTURES=arm64 \ | |
| -DCMAKE_POSITION_INDEPENDENT_CODE=ON \ | |
| -DENABLE_TESTS=OFF | |
| ninja | |
| - name: Copy libraries | |
| run: | | |
| rm -rf xrpl/core/confidential/libs/darwin | |
| mkdir -p xrpl/core/confidential/libs/darwin | |
| MPT_LIB=$(find /tmp/mpt-crypto/build -name "libmpt-crypto.a" | head -n 1) | |
| SECP_LIB=$(find ~/.conan2 -name "libsecp256k1.a" 2>/dev/null | head -n 1) | |
| if [ -z "$SECP_LIB" ]; then | |
| SECP_LIB=$(find /tmp/mpt-crypto/build -name "libsecp256k1.a" 2>/dev/null | head -n 1) | |
| fi | |
| CRYPTO_LIB=$(find ~/.conan2 -name "libcrypto.a" 2>/dev/null | head -n 1) | |
| if [ -n "$MPT_LIB" ] && [ -f "$MPT_LIB" ]; then | |
| cp "$MPT_LIB" xrpl/core/confidential/libs/darwin/ | |
| else | |
| echo "Error: libmpt-crypto.a not found!" | |
| exit 1 | |
| fi | |
| if [ -n "$SECP_LIB" ] && [ -f "$SECP_LIB" ]; then | |
| cp "$SECP_LIB" xrpl/core/confidential/libs/darwin/ | |
| else | |
| echo "Error: libsecp256k1.a not found!" | |
| exit 1 | |
| fi | |
| if [ -n "$CRYPTO_LIB" ] && [ -f "$CRYPTO_LIB" ]; then | |
| cp "$CRYPTO_LIB" xrpl/core/confidential/libs/darwin/ | |
| echo "Bundled OpenSSL: $CRYPTO_LIB" | |
| else | |
| echo "Error: libcrypto.a not found in Conan cache!" | |
| echo "Searching for any OpenSSL libraries..." | |
| find ~/.conan2 -name "libcrypto*" 2>/dev/null || echo "No libcrypto files found" | |
| exit 1 | |
| fi | |
| - name: Verify bundled libraries | |
| run: | | |
| echo "=== Verifying bundled libraries ===" | |
| LIBS_DIR="xrpl/core/confidential/libs/darwin" | |
| echo "Library files:" | |
| ls -la "$LIBS_DIR/" | |
| echo "" | |
| echo "Library sizes:" | |
| du -h "$LIBS_DIR/"* | |
| echo "" | |
| echo "Checking required libraries exist:" | |
| REQUIRED_LIBS=("libmpt-crypto.a" "libsecp256k1.a" "libcrypto.a") | |
| MISSING=0 | |
| for lib in "${REQUIRED_LIBS[@]}"; do | |
| if [ -f "$LIBS_DIR/$lib" ]; then | |
| echo " ✓ $lib ($(du -h "$LIBS_DIR/$lib" | cut -f1))" | |
| else | |
| echo " ✗ $lib MISSING" | |
| MISSING=1 | |
| fi | |
| done | |
| if [ $MISSING -eq 1 ]; then | |
| echo "" | |
| echo "ERROR: Missing required libraries!" | |
| exit 1 | |
| fi | |
| echo "" | |
| echo "=== All required libraries verified ===" | |
| - name: Upload libraries and headers | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: mpt-crypto-darwin-universal | |
| path: | | |
| xrpl/core/confidential/libs/darwin/*.a | |
| xrpl/core/confidential/include/*.h | |
| xrpl/core/confidential/include/utility/*.h | |
| build_windows: | |
| name: Build for Windows (x86_64) with MSVC | |
| runs-on: windows-2022 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ inputs.git_ref || github.ref }} | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| - name: Install dependencies | |
| run: | | |
| pip install conan | |
| - name: Setup Conan profile | |
| run: | | |
| conan profile detect --force | |
| conan remote add --index 0 xrplf https://conan.ripplex.io | |
| - name: Clone mpt-crypto | |
| run: | | |
| git clone --branch mpt-utility https://github.com/yinyiqian1/mpt-crypto.git C:\mpt-crypto | |
| - name: Copy header files | |
| shell: pwsh | |
| run: | | |
| New-Item -ItemType Directory -Force -Path xrpl/core/confidential/include/utility | |
| Copy-Item C:\mpt-crypto\include\secp256k1_mpt.h -Destination xrpl/core/confidential/include/ | |
| Copy-Item C:\mpt-crypto\include\utility\mpt_utility.h -Destination xrpl/core/confidential/include/utility/ | |
| - name: Patch mpt_utility.cpp for Windows | |
| shell: pwsh | |
| run: | | |
| $utilityFile = "C:\mpt-crypto\src\utility\mpt_utility.cpp" | |
| $lines = Get-Content $utilityFile | |
| $newLines = @() | |
| foreach ($line in $lines) { | |
| if ($line -match '#include <arpa/inet\.h>') { | |
| $newLines += '#ifdef _WIN32' | |
| $newLines += '#include <winsock2.h>' | |
| $newLines += '#else' | |
| $newLines += '#include <arpa/inet.h>' | |
| $newLines += '#endif' | |
| } else { | |
| $newLines += $line | |
| } | |
| } | |
| $newLines | Set-Content $utilityFile | |
| - name: Setup MSVC environment | |
| uses: ilammy/msvc-dev-cmd@v1 | |
| - name: Build mpt-crypto with MSVC | |
| shell: pwsh | |
| run: | | |
| Set-Location C:\mpt-crypto | |
| $cmakeContent = Get-Content CMakeLists.txt -Raw | |
| $cmakeContent = $cmakeContent -replace 'add_library\(mpt-crypto', 'add_library(mpt-crypto STATIC' | |
| Set-Content CMakeLists.txt $cmakeContent | |
| New-Item -ItemType Directory -Force -Path build | |
| Set-Location build | |
| conan install .. --build="secp256k1/*" -o "&:tests=False" | |
| cmake .. -G "Visual Studio 17 2022" -A x64 ` | |
| -DCMAKE_BUILD_TYPE=Release ` | |
| -DCMAKE_TOOLCHAIN_FILE="C:\mpt-crypto\build\generators\conan_toolchain.cmake" ` | |
| -DBUILD_SHARED_LIBS=OFF ` | |
| -DENABLE_TESTS=OFF | |
| cmake --build . --config Release | |
| - name: Copy libraries | |
| shell: pwsh | |
| run: | | |
| Remove-Item -Path xrpl/core/confidential/libs/win32 -Recurse -Force -ErrorAction SilentlyContinue | |
| New-Item -ItemType Directory -Force -Path xrpl/core/confidential/libs/win32 | |
| $mptCryptoLib = Get-ChildItem -Path C:\mpt-crypto\build\Release -Filter mpt-crypto.lib -ErrorAction SilentlyContinue | Select-Object -First 1 | |
| if (-not $mptCryptoLib) { | |
| $mptCryptoLib = Get-ChildItem -Path C:\mpt-crypto\build -Recurse -Filter mpt-crypto.lib -ErrorAction SilentlyContinue | Select-Object -First 1 | |
| } | |
| if ($mptCryptoLib) { | |
| Copy-Item $mptCryptoLib.FullName -Destination xrpl/core/confidential/libs/win32/ | |
| } else { | |
| Write-Error "Error: mpt-crypto.lib not found!" | |
| exit 1 | |
| } | |
| $secp256k1 = Get-ChildItem -Path $env:USERPROFILE\.conan2 -Recurse -Filter secp256k1.lib -ErrorAction SilentlyContinue | Select-Object -First 1 | |
| if (-not $secp256k1) { | |
| $secp256k1 = Get-ChildItem -Path $env:USERPROFILE\.conan2 -Recurse -Filter *secp256k1*.lib -ErrorAction SilentlyContinue | Select-Object -First 1 | |
| } | |
| if (-not $secp256k1) { | |
| $secp256k1 = Get-ChildItem -Path C:\mpt-crypto\build -Recurse -Filter *secp256k1*.lib -ErrorAction SilentlyContinue | Select-Object -First 1 | |
| } | |
| if ($secp256k1) { | |
| Copy-Item $secp256k1.FullName -Destination "xrpl/core/confidential/libs/win32/secp256k1.lib" | |
| } else { | |
| Write-Error "Error: secp256k1.lib not found!" | |
| exit 1 | |
| } | |
| $cryptoLib = Get-ChildItem -Path $env:USERPROFILE\.conan2 -Recurse -Filter libcrypto.lib -ErrorAction SilentlyContinue | Select-Object -First 1 | |
| if (-not $cryptoLib) { | |
| $cryptoLib = Get-ChildItem -Path $env:USERPROFILE\.conan2 -Recurse -Filter crypto.lib -ErrorAction SilentlyContinue | Select-Object -First 1 | |
| } | |
| if ($cryptoLib) { | |
| Copy-Item $cryptoLib.FullName -Destination "xrpl/core/confidential/libs/win32/crypto.lib" | |
| } else { | |
| Write-Error "Error: crypto.lib not found!" | |
| exit 1 | |
| } | |
| $zlibLib = Get-ChildItem -Path $env:USERPROFILE\.conan2 -Recurse -Filter zlib.lib -ErrorAction SilentlyContinue | Select-Object -First 1 | |
| if (-not $zlibLib) { | |
| $zlibLib = Get-ChildItem -Path $env:USERPROFILE\.conan2 -Recurse -Filter *zlib*.lib -ErrorAction SilentlyContinue | Select-Object -First 1 | |
| } | |
| if ($zlibLib) { | |
| Copy-Item $zlibLib.FullName -Destination "xrpl/core/confidential/libs/win32/zlib.lib" | |
| } else { | |
| Write-Error "Error: zlib.lib not found!" | |
| exit 1 | |
| } | |
| - name: Verify bundled libraries | |
| shell: pwsh | |
| run: | | |
| Write-Host "=== Verifying bundled libraries ===" -ForegroundColor Cyan | |
| $libsDir = "xrpl/core/confidential/libs/win32" | |
| Write-Host "" | |
| Write-Host "Library files:" | |
| Get-ChildItem -Path $libsDir | Format-Table Name, Length | |
| Write-Host "" | |
| Write-Host "Checking required libraries exist:" | |
| $requiredLibs = @("mpt-crypto.lib", "secp256k1.lib", "crypto.lib", "zlib.lib") | |
| $missing = $false | |
| foreach ($lib in $requiredLibs) { | |
| $libPath = Join-Path $libsDir $lib | |
| if (Test-Path $libPath) { | |
| $size = (Get-Item $libPath).Length / 1KB | |
| Write-Host " ✓ $lib ($([math]::Round($size, 1)) KB)" -ForegroundColor Green | |
| } else { | |
| Write-Host " ✗ $lib MISSING" -ForegroundColor Red | |
| $missing = $true | |
| } | |
| } | |
| if ($missing) { | |
| Write-Host "" | |
| Write-Error "ERROR: Missing required libraries!" | |
| exit 1 | |
| } | |
| Write-Host "" | |
| Write-Host "=== All required libraries verified ===" -ForegroundColor Cyan | |
| - name: Upload libraries and headers | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: mpt-crypto-win32-x86_64 | |
| path: | | |
| xrpl/core/confidential/libs/win32/*.lib | |
| xrpl/core/confidential/include/*.h | |
| xrpl/core/confidential/include/utility/*.h | |
| test_libraries: | |
| name: Test libraries on ${{ matrix.os }} | |
| needs: [build_linux, build_macos, build_windows] | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| os: [ubuntu-22.04, macos-14, windows-2022] | |
| python-version: ["3.9", "3.11", "3.12"] | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ inputs.git_ref || github.ref }} | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Check Python architecture | |
| shell: bash | |
| run: | | |
| python -c "import platform; print(f'Python architecture: {platform.machine()}')" | |
| file $(which python) || true | |
| uname -m | |
| - name: Install system dependencies | |
| shell: bash | |
| run: | | |
| if [ "$RUNNER_OS" == "Linux" ]; then | |
| sudo apt-get update | |
| sudo apt-get install -y libssl-dev | |
| elif [ "$RUNNER_OS" == "macOS" ]; then | |
| brew install openssl | |
| elif [ "$RUNNER_OS" == "Windows" ]; then | |
| choco install openssl --no-progress | |
| fi | |
| - name: Install Poetry | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install poetry | |
| - name: Install project dependencies | |
| run: | | |
| poetry install --no-root --extras confidential | |
| # Install setuptools explicitly for Python 3.12+ (required by cffi) | |
| poetry run pip install setuptools | |
| - name: Download libraries for this platform | |
| uses: actions/download-artifact@v4 | |
| with: | |
| pattern: mpt-crypto-* | |
| path: artifacts | |
| - name: Copy libraries and headers to correct locations | |
| shell: bash | |
| run: | | |
| mkdir -p xrpl/core/confidential/libs/linux | |
| mkdir -p xrpl/core/confidential/libs/darwin | |
| mkdir -p xrpl/core/confidential/libs/win32 | |
| mkdir -p xrpl/core/confidential/include | |
| mkdir -p xrpl/core/confidential/include/utility | |
| # Copy libraries - try both direct path and nested path | |
| cp artifacts/mpt-crypto-linux-x86_64/libs/linux/*.a xrpl/core/confidential/libs/linux/ 2>/dev/null || \ | |
| cp artifacts/mpt-crypto-linux-x86_64/xrpl/core/confidential/libs/linux/*.a xrpl/core/confidential/libs/linux/ 2>/dev/null || true | |
| cp artifacts/mpt-crypto-darwin-universal/libs/darwin/*.a xrpl/core/confidential/libs/darwin/ 2>/dev/null || \ | |
| cp artifacts/mpt-crypto-darwin-universal/xrpl/core/confidential/libs/darwin/*.a xrpl/core/confidential/libs/darwin/ 2>/dev/null || \ | |
| cp artifacts/mpt-crypto-darwin-universal/*.a xrpl/core/confidential/libs/darwin/ 2>/dev/null || true | |
| cp artifacts/mpt-crypto-win32-x86_64/libs/win32/*.lib xrpl/core/confidential/libs/win32/ 2>/dev/null || \ | |
| cp artifacts/mpt-crypto-win32-x86_64/xrpl/core/confidential/libs/win32/*.lib xrpl/core/confidential/libs/win32/ 2>/dev/null || \ | |
| cp artifacts/mpt-crypto-win32-x86_64/*.lib xrpl/core/confidential/libs/win32/ 2>/dev/null || true | |
| # Copy main headers | |
| if [ -d "artifacts/mpt-crypto-linux-x86_64/include" ]; then | |
| cp artifacts/mpt-crypto-linux-x86_64/include/*.h xrpl/core/confidential/include/ | |
| elif [ -d "artifacts/mpt-crypto-linux-x86_64/xrpl/core/confidential/include" ]; then | |
| cp artifacts/mpt-crypto-linux-x86_64/xrpl/core/confidential/include/*.h xrpl/core/confidential/include/ | |
| elif [ -f "artifacts/mpt-crypto-linux-x86_64/secp256k1_mpt.h" ]; then | |
| cp artifacts/mpt-crypto-linux-x86_64/*.h xrpl/core/confidential/include/ | |
| else | |
| find artifacts/mpt-crypto-linux-x86_64 -name "secp256k1_mpt.h" -exec cp {} xrpl/core/confidential/include/ \; | |
| fi | |
| # Copy utility headers | |
| if [ -d "artifacts/mpt-crypto-linux-x86_64/include/utility" ]; then | |
| cp artifacts/mpt-crypto-linux-x86_64/include/utility/*.h xrpl/core/confidential/include/utility/ | |
| elif [ -d "artifacts/mpt-crypto-linux-x86_64/xrpl/core/confidential/include/utility" ]; then | |
| cp artifacts/mpt-crypto-linux-x86_64/xrpl/core/confidential/include/utility/*.h xrpl/core/confidential/include/utility/ | |
| fi | |
| - name: Build C extension | |
| shell: bash | |
| run: | | |
| cd xrpl/core/confidential | |
| if [ "$RUNNER_OS" == "macOS" ]; then | |
| export ARCHFLAGS="-arch arm64" | |
| export _PYTHON_HOST_PLATFORM="macosx-14.0-arm64" | |
| fi | |
| poetry run python build_mpt_crypto.py | |
| - name: Run confidential MPT tests | |
| run: | | |
| poetry run python -m unittest discover -s tests/unit/core/confidential -v |