Skip to content

Continuous Integration #144

Continuous Integration

Continuous Integration #144

Workflow file for this run

# Copyright 2024 The Tongsuo Project Authors. All Rights Reserved.
#
# Licensed under the Apache License 2.0 (the "License"). You may not use
# this file except in compliance with the License. You can obtain a copy
# in the file LICENSE in the source distribution or at
# https://github.com/Tongsuo-Project/Tongsuo/blob/master/LICENSE.txt
name: Continuous Integration
on:
workflow_dispatch:
pull_request:
schedule:
# Run every day at midnight UTC
- cron: '0 0 * * *'
permissions:
contents: write
env:
# Define the Tongsuo reference version once
TONGSUO_VERSION: 8.4-stable
jobs:
# ==================================================================================
# Phase 1: Prepare Source Code
# ==================================================================================
prepare-source:
name: Prepare Source
runs-on: ubuntu-latest
steps:
- name: Clone Tongsuo Repository
uses: actions/checkout@v6
with:
repository: Tongsuo-Project/Tongsuo
ref: ${{ env.TONGSUO_VERSION }}
path: Tongsuo
- name: Archive Tongsuo Source
uses: actions/upload-artifact@v6
with:
name: tongsuo-src
path: ${{ github.workspace }}/Tongsuo
# ==================================================================================
# Phase 2: Static Build & Test
# ==================================================================================
ci-static:
name: Static - ${{ matrix.platform.name }}
needs: prepare-source
strategy:
fail-fast: false
matrix:
platform:
- { os: ubuntu-24.04, target: linux-x86_64, name: Linux-x64 }
- { os: ubuntu-24.04-arm, target: linux-aarch64, name: Linux-ARM64 }
- { os: macos-14, target: darwin64-x86_64, name: macOS-x64, use_qemu: true }
- { os: macos-14, target: darwin64-arm64, name: macOS-ARM64 }
- { os: windows-latest, target: VC-WIN64A, name: Windows-x64 }
- { os: windows-latest, target: VC-WIN64-ARM, name: Windows-ARM64, arch: arm64 }
runs-on: ${{ matrix.platform.os }}
timeout-minutes: 30
steps:
- name: Show System Architecture
shell: bash
run: |
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "System Architecture Information"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "Runner OS: ${{ runner.os }}"
echo "Platform target: ${{ matrix.platform.target }}"
echo "Platform name: ${{ matrix.platform.name }}"
echo ""
if [[ "${{ runner.os }}" == "macOS" ]]; then
echo "macOS Architecture (uname -m): $(uname -m)"
echo "macOS Architecture (arch): $(arch)"
echo "Available architectures:"
lipo -info $(which clang) 2>/dev/null || echo " clang: $(file $(which clang))"
echo ""
echo "Java version and architecture:"
java -version 2>&1
file $(which java)
elif [[ "${{ runner.os }}" == "Linux" ]]; then
echo "Linux Architecture (uname -m): $(uname -m)"
echo "CPU info:"
lscpu | grep -E "Architecture|Model name" || true
elif [[ "${{ runner.os }}" == "Windows" ]]; then
echo "Windows Architecture:"
systeminfo | findstr /B /C:"System Type" || echo "N/A"
fi
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
- name: Set Environment Variables
shell: bash
run: |
echo "TONGSUO_HOME=${{ runner.temp }}/tongsuo" >> $GITHUB_ENV
# Set architecture-specific flags for macOS
if [[ "${{ runner.os }}" == "macOS" ]]; then
if [[ "${{ matrix.platform.target }}" == "darwin64-x86_64" ]]; then
# Cross-compilation for x86_64 on ARM runners with Rosetta 2
echo "CC=clang -arch x86_64" >> $GITHUB_ENV
echo "CXX=clang++ -arch x86_64" >> $GITHUB_ENV
echo "CFLAGS=-arch x86_64" >> $GITHUB_ENV
echo "CXXFLAGS=-arch x86_64" >> $GITHUB_ENV
echo "LDFLAGS=-arch x86_64" >> $GITHUB_ENV
echo "ORG_GRADLE_PROJECT_ldFlags=-arch x86_64" >> $GITHUB_ENV
echo "ORG_GRADLE_PROJECT_cFlags=-arch x86_64" >> $GITHUB_ENV
echo "ORG_GRADLE_PROJECT_cppFlags=-arch x86_64" >> $GITHUB_ENV
elif [[ "${{ matrix.platform.target }}" == "darwin64-arm64" ]]; then
# Native ARM64 build - macos-14 is ARM64 by default, no flags needed
echo "Building natively for ARM64"
fi
fi
- name: Set up Rosetta 2 for x86_64 emulation (macOS)
if: runner.os == 'macOS' && matrix.platform.use_qemu == true
shell: bash
run: |
# Rosetta 2 is already installed on macOS ARM runners
# Verify it's available
if ! arch -x86_64 uname -m; then
echo "Installing Rosetta 2..."
softwareupdate --install-rosetta --agree-to-license
fi
echo "Rosetta 2 is available"
- name: Set up Rosetta (x86_64 for macOS x64)
if: runner.os == 'macOS' && matrix.platform.use_qemu == true
shell: bash
run: |
# Rosetta 2 is already installed on macOS ARM runners
# Verify it's available
if ! arch -x86_64 uname -m; then
echo "Installing Rosetta 2..."
softwareupdate --install-rosetta --agree-to-license
fi
echo "Rosetta 2 is available"
- name: Set up JDK 11 (x86_64 for macOS x64)
if: runner.os == 'macOS' && matrix.platform.target == 'darwin64-x86_64'
uses: actions/setup-java@v5
with:
distribution: 'temurin'
java-version: 11
architecture: x64
- name: Set up JDK 11 (ARM64 for macOS ARM64)
if: runner.os == 'macOS' && matrix.platform.target == 'darwin64-arm64'
uses: actions/setup-java@v5
with:
distribution: 'temurin'
java-version: 11
architecture: aarch64
- name: Set up JDK 11 (default)
if: "(runner.os != 'macOS') && (matrix.platform.cross_compile != true)"
uses: actions/setup-java@v5
with:
distribution: 'temurin'
java-version: 11
architecture: x64
- uses: actions/checkout@v6
- name: Download Tongsuo Source
uses: actions/download-artifact@v7
with:
name: tongsuo-src
path: ${{ github.workspace }}/Tongsuo
continue-on-error: true
id: download_artifact
- name: Clone Tongsuo Directly (Fallback for Windows)
if: steps.download_artifact.outcome == 'failure'
uses: actions/checkout@v6
with:
repository: Tongsuo-Project/Tongsuo
ref: ${{ env.TONGSUO_VERSION }}
path: Tongsuo
# -----------------------------------------------------------
# Build Tongsuo C Lib (Unix: Linux / macOS)
# -----------------------------------------------------------
- name: Build Tongsuo Static (Unix)
if: runner.os != 'Windows'
shell: bash
run: |
cd ${{ github.workspace }}/Tongsuo
mkdir -p $TONGSUO_HOME
# Fix permissions
chmod +x Configure config
# Determine configuration target
CONFIG_TARGET="${{ matrix.platform.target }}"
CONFIG_ARGS=""
STRICT_WARNINGS="--strict-warnings"
echo "Configuring ${CONFIG_TARGET}..."
./Configure ${CONFIG_TARGET} \
--prefix=$TONGSUO_HOME \
--libdir=$TONGSUO_HOME/lib \
enable-weak-ssl-ciphers enable-ntls no-shared \
${STRICT_WARNINGS} --release -fstack-protector-strong \
${CONFIG_ARGS}
echo "Building..."
make -s -j4
echo "Installing..."
make install
# -----------------------------------------------------------
# Build Tongsuo C Lib (Windows)
# -----------------------------------------------------------
- uses: ilammy/msvc-dev-cmd@v1
if: runner.os == 'Windows'
with:
arch: ${{ matrix.platform.arch == 'arm64' && 'amd64_arm64' || 'amd64' }}
- uses: ilammy/setup-nasm@v1
if: runner.os == 'Windows' && matrix.platform.target == 'VC-WIN64A'
- uses: shogo82148/actions-setup-perl@v1
if: runner.os == 'Windows'
- name: Build Tongsuo Static (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
cd ${{ github.workspace }}\Tongsuo
# Set configuration args
$configArgs = ""
if ("${{ matrix.platform.arch }}" -eq "arm64") {
$configArgs = "no-asm"
Write-Host "Configuring ${{ matrix.platform.target }} for ARM64 cross-compilation..."
} else {
Write-Host "Configuring ${{ matrix.platform.target }}..."
}
# Build configure command based on architecture
if ("${{ matrix.platform.arch }}" -eq "arm64") {
perl .\Configure ${{ matrix.platform.target }} `
--prefix=$Env:TONGSUO_HOME `
no-capieng no-makedepend `
enable-weak-ssl-ciphers enable-ntls no-shared --release `
no-asm
} else {
perl .\Configure ${{ matrix.platform.target }} `
--prefix=$Env:TONGSUO_HOME `
no-capieng no-makedepend `
enable-weak-ssl-ciphers enable-ntls no-shared --release
}
Write-Host "Building..."
nmake /S
Write-Host "Installing..."
nmake install
# -----------------------------------------------------------
# Gradle Build & Test
# -----------------------------------------------------------
- name: Setup Gradle Repository Override
shell: bash
run: |
# Create init.gradle to override repositories with official Maven Central
mkdir -p ~/.gradle
cat > ~/.gradle/init.gradle << 'INITGRADLE'
allprojects {
buildscript {
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}
repositories {
google()
mavenCentral()
}
}
INITGRADLE
echo "Created Gradle init script to use official repositories"
- name: Gradle Check
# Skip Windows ARM64 - Gradle Native doesn't support MSVC ARM64 cross-compilation from x64 host
if: ${{ !(runner.os == 'Windows' && matrix.platform.arch == 'arm64') }}
shell: bash
run: |
GRADLE_ARGS=""
TASK="check"
GRADLE_CMD="./gradlew"
# For macOS x86_64 on ARM, use Rosetta 2 to run x86_64 JDK
if [[ "${{ matrix.platform.target }}" == "darwin64-x86_64" ]]; then
GRADLE_ARGS="-Parch=x86_64 -PldFlags=\"-arch x86_64\" -PcFlags=\"-arch x86_64\" -PcppFlags=\"-arch x86_64\""
# Run Gradle under Rosetta 2 for x86_64 emulation
GRADLE_CMD="arch -x86_64 ./gradlew"
fi
# Windows ARM64: Build only, skip tests (can't run ARM64 on x64)
if [[ "${{ runner.os }}" == "Windows" && "${{ matrix.platform.arch }}" == "arm64" ]]; then
TASK="assemble"
echo "⚠️ Windows ARM64: Building only (tests require ARM64 hardware)"
fi
# For macOS ARM64, let it build natively (no special flags needed)
# The JDK and toolchain will be ARM64 by default on macos-14
# Windows: Normalize path to forward slashes for Gradle
if [[ "${{ runner.os }}" == "Windows" ]]; then
export PATH=$TONGSUO_HOME/bin:$TONGSUO_HOME/lib:$PATH
# Convert to Unix-style path with forward slashes (Gradle accepts this on Windows)
if command -v cygpath >/dev/null 2>&1; then
TONGSUO_HOME_GRADLE=$(cygpath -m "$TONGSUO_HOME")
else
# Fallback: just use as-is and normalize to forward slashes
TONGSUO_HOME_GRADLE=$(echo "$TONGSUO_HOME" | sed 's|\\|/|g')
fi
echo "Normalized TONGSUO_HOME for Gradle: $TONGSUO_HOME -> $TONGSUO_HOME_GRADLE"
else
TONGSUO_HOME_GRADLE="$TONGSUO_HOME"
fi
echo "Running Gradle $TASK with args: $GRADLE_ARGS..."
eval $GRADLE_CMD $TASK -PcheckErrorQueue -PtongsuoHome="$TONGSUO_HOME_GRADLE" $GRADLE_ARGS
- name: Verify Windows ARM64 Build
if: runner.os == 'Windows' && matrix.platform.arch == 'arm64'
shell: bash
run: |
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "⚠️ Windows ARM64 Build Status"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
# Verify Tongsuo libraries exist (Windows uses .lib extension)
libPath="$TONGSUO_HOME/lib"
libCrypto="$libPath/libcrypto.lib"
libSsl="$libPath/libssl.lib"
if [[ -f "$libCrypto" && -f "$libSsl" ]]; then
echo "✅ Tongsuo C libraries built successfully:"
ls -lh "$libCrypto"
ls -lh "$libSsl"
echo ""
echo "❌ Java SDK (JNI) NOT built - Gradle Native doesn't support MSVC ARM64 cross-compilation"
else
echo "❌ Tongsuo libraries not found at:"
echo " $libCrypto"
echo " $libSsl"
echo ""
echo "Contents of $TONGSUO_HOME:"
ls -laR "$TONGSUO_HOME" || true
exit 1
fi
echo ""
echo "✅ C libraries ready for Java SDK build"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
- name: Build Test JAR (Linux x64 Only)
if: matrix.platform.target == 'linux-x86_64'
shell: bash
run: ./gradlew :tongsuo-openjdk:testJar -PcheckErrorQueue -PtongsuoHome=$TONGSUO_HOME
# -----------------------------------------------------------
# Artifacts & Logs
# -----------------------------------------------------------
- name: Upload Logs on Failure
if: failure()
uses: actions/upload-artifact@v6
with:
name: logs-static-${{ matrix.platform.name }}
path: |
${{ github.workspace }}/Tongsuo/*.log
*.log
if-no-files-found: ignore
- name: Upload Test JAR
if: matrix.platform.target == 'linux-x86_64'
uses: actions/upload-artifact@v6
with:
name: jar-static-${{ matrix.platform.name }}
path: openjdk/build/libs/tongsuo-openjdk-*.jar
if-no-files-found: ignore
# ==================================================================================
# Phase 3: Dynamic Build & Test
# ==================================================================================
ci-dynamic:
name: Dynamic - ${{ matrix.platform.name }}
needs: prepare-source
strategy:
fail-fast: false
matrix:
platform:
- { os: ubuntu-24.04, target: linux-x86_64, name: Linux-x64 }
- { os: ubuntu-24.04-arm, target: linux-aarch64, name: Linux-ARM64 }
- { os: macos-14, target: darwin64-x86_64, name: macOS-x64, use_qemu: true }
- { os: macos-14, target: darwin64-arm64, name: macOS-ARM64 }
- { os: windows-latest, target: VC-WIN64A, name: Windows-x64 }
- { os: windows-latest, target: VC-WIN64-ARM, name: Windows-ARM64, arch: arm64 }
runs-on: ${{ matrix.platform.os }}
timeout-minutes: 30
steps:
- name: Show System Architecture
shell: bash
run: |
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "System Architecture Information"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "Runner OS: ${{ runner.os }}"
echo "Platform target: ${{ matrix.platform.target }}"
echo "Platform name: ${{ matrix.platform.name }}"
echo ""
if [[ "${{ runner.os }}" == "macOS" ]]; then
echo "macOS Architecture (uname -m): $(uname -m)"
echo "macOS Architecture (arch): $(arch)"
echo "Available architectures:"
lipo -info $(which clang) 2>/dev/null || echo " clang: $(file $(which clang))"
echo ""
echo "Java version and architecture:"
java -version 2>&1
file $(which java)
elif [[ "${{ runner.os }}" == "Linux" ]]; then
echo "Linux Architecture (uname -m): $(uname -m)"
echo "CPU info:"
lscpu | grep -E "Architecture|Model name" || true
elif [[ "${{ runner.os }}" == "Windows" ]]; then
echo "Windows Architecture:"
systeminfo | findstr /B /C:"System Type" || echo "N/A"
fi
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
- name: Set Environment Variables
shell: bash
run: |
echo "TONGSUO_HOME=${{ runner.temp }}/tongsuo" >> $GITHUB_ENV
# Set architecture-specific flags for macOS
if [[ "${{ runner.os }}" == "macOS" ]]; then
if [[ "${{ matrix.platform.target }}" == "darwin64-x86_64" ]]; then
# Cross-compilation for x86_64 on ARM runners with Rosetta 2
echo "CC=clang -arch x86_64" >> $GITHUB_ENV
echo "CXX=clang++ -arch x86_64" >> $GITHUB_ENV
echo "CFLAGS=-arch x86_64" >> $GITHUB_ENV
echo "CXXFLAGS=-arch x86_64" >> $GITHUB_ENV
echo "LDFLAGS=-arch x86_64" >> $GITHUB_ENV
echo "ORG_GRADLE_PROJECT_ldFlags=-arch x86_64" >> $GITHUB_ENV
echo "ORG_GRADLE_PROJECT_cFlags=-arch x86_64" >> $GITHUB_ENV
echo "ORG_GRADLE_PROJECT_cppFlags=-arch x86_64" >> $GITHUB_ENV
elif [[ "${{ matrix.platform.target }}" == "darwin64-arm64" ]]; then
# Native ARM64 build - macos-14 is ARM64 by default, no flags needed
echo "Building natively for ARM64"
fi
fi
- name: Set up Rosetta 2 for x86_64 emulation (macOS)
if: runner.os == 'macOS' && matrix.platform.use_qemu == true
shell: bash
run: |
# Rosetta 2 is already installed on macOS ARM runners
# Verify it's available
if ! arch -x86_64 uname -m; then
echo "Installing Rosetta 2..."
softwareupdate --install-rosetta --agree-to-license
fi
echo "Rosetta 2 is available"
- name: Set up JDK 11 (x86_64 for macOS x64)
if: runner.os == 'macOS' && matrix.platform.target == 'darwin64-x86_64'
uses: actions/setup-java@v5
with:
distribution: 'temurin'
java-version: 11
architecture: x64
- name: Set up JDK 11 (ARM64 for macOS ARM64)
if: runner.os == 'macOS' && matrix.platform.target == 'darwin64-arm64'
uses: actions/setup-java@v5
with:
distribution: 'temurin'
java-version: 11
architecture: aarch64
- name: Set up JDK 11 (default)
if: "(runner.os != 'macOS') && (matrix.platform.cross_compile != true)"
uses: actions/setup-java@v5
with:
distribution: 'temurin'
java-version: 11
architecture: x64
- uses: actions/checkout@v6
- name: Download Tongsuo Source
uses: actions/download-artifact@v7
with:
name: tongsuo-src
path: ${{ github.workspace }}/Tongsuo
continue-on-error: true
id: download_artifact
- name: Clone Tongsuo Directly (Fallback for Windows)
if: steps.download_artifact.outcome == 'failure'
uses: actions/checkout@v6
with:
repository: Tongsuo-Project/Tongsuo
ref: ${{ env.TONGSUO_VERSION }}
path: Tongsuo
# -----------------------------------------------------------
# Build Tongsuo C Lib (Unix Dynamic)
# -----------------------------------------------------------
- name: Build Tongsuo Dynamic (Unix)
if: runner.os != 'Windows'
shell: bash
run: |
cd ${{ github.workspace }}/Tongsuo
mkdir -p $TONGSUO_HOME
# Fix permissions
chmod +x Configure config
# Determine configuration target
CONFIG_TARGET="${{ matrix.platform.target }}"
CONFIG_ARGS=""
STRICT_WARNINGS="--strict-warnings"
echo "Configuring ${CONFIG_TARGET} (dynamic)..."
./Configure ${CONFIG_TARGET} \
--prefix=$TONGSUO_HOME \
--libdir=$TONGSUO_HOME/lib \
enable-weak-ssl-ciphers enable-ntls \
${STRICT_WARNINGS} --release \
${CONFIG_ARGS}
echo "Building..."
make -s -j4
echo "Installing..."
make install
# -----------------------------------------------------------
# Build Tongsuo C Lib (Windows Dynamic)
# -----------------------------------------------------------
- uses: ilammy/msvc-dev-cmd@v1
if: runner.os == 'Windows'
with:
arch: ${{ matrix.platform.arch == 'arm64' && 'amd64_arm64' || 'amd64' }}
- uses: ilammy/setup-nasm@v1
if: runner.os == 'Windows' && matrix.platform.target == 'VC-WIN64A'
- uses: shogo82148/actions-setup-perl@v1
if: runner.os == 'Windows'
- name: Build Tongsuo Dynamic (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
cd ${{ github.workspace }}\Tongsuo
# Build configure command based on architecture
if ("${{ matrix.platform.arch }}" -eq "arm64") {
Write-Host "Configuring ${{ matrix.platform.target }} (ARM64 cross-compilation)..."
perl .\Configure ${{ matrix.platform.target }} `
--prefix=$Env:TONGSUO_HOME `
no-capieng no-makedepend `
enable-weak-ssl-ciphers enable-ntls --release `
no-asm
} else {
Write-Host "Configuring ${{ matrix.platform.target }} (dynamic)..."
perl .\Configure ${{ matrix.platform.target }} `
--prefix=$Env:TONGSUO_HOME `
no-capieng no-makedepend `
enable-weak-ssl-ciphers enable-ntls --release
}
Write-Host "Building..."
nmake /S
if ($LASTEXITCODE -ne 0) {
Write-Host "❌ Build failed with exit code $LASTEXITCODE"
exit 1
}
Write-Host "Installing..."
nmake install
if ($LASTEXITCODE -ne 0) {
Write-Host "❌ Install failed with exit code $LASTEXITCODE"
exit 1
}
# Verify library files exist
Write-Host "`n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
Write-Host "Verifying Tongsuo installation..."
Write-Host "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
if (Test-Path "$Env:TONGSUO_HOME\lib") {
Write-Host "✅ lib directory exists"
Get-ChildItem "$Env:TONGSUO_HOME\lib" | Format-Table Name, Length
} else {
Write-Host "❌ lib directory NOT found"
exit 1
}
if (Test-Path "$Env:TONGSUO_HOME\include\openssl") {
Write-Host "✅ include directory exists"
} else {
Write-Host "❌ include directory NOT found"
exit 1
}
# Check for required library files
if (-not (Test-Path "$Env:TONGSUO_HOME\lib\libssl.lib")) {
Write-Host "❌ libssl.lib NOT found"
exit 1
}
if (-not (Test-Path "$Env:TONGSUO_HOME\lib\libcrypto.lib")) {
Write-Host "❌ libcrypto.lib NOT found"
exit 1
}
Write-Host "✅ Required library files found"
# -----------------------------------------------------------
# Gradle Build & Test (Dynamic)
# -----------------------------------------------------------
- name: Set PATH for Dynamic Libraries (Windows)
if: runner.os == 'Windows'
shell: bash
run: |
echo "$TONGSUO_HOME/bin" >> $GITHUB_PATH
echo "$TONGSUO_HOME/lib" >> $GITHUB_PATH
- name: Setup Gradle Repository Override
shell: bash
run: |
# Create init.gradle to override repositories with official Maven Central
mkdir -p ~/.gradle
cat > ~/.gradle/init.gradle << 'INITGRADLE'
allprojects {
buildscript {
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}
repositories {
google()
mavenCentral()
}
}
INITGRADLE
echo "Created Gradle init script to use official repositories"
- name: Gradle Check
# Skip Windows ARM64 - Gradle Native doesn't support MSVC ARM64 cross-compilation from x64 host
if: ${{ !(runner.os == 'Windows' && matrix.platform.arch == 'arm64') }}
shell: bash
run: |
GRADLE_ARGS=""
TASK="check"
GRADLE_CMD="./gradlew"
# MacOS x86_64: Use Rosetta 2 to run x86_64 JDK and tests
if [[ "${{ matrix.platform.target }}" == "darwin64-x86_64" ]]; then
GRADLE_ARGS="-Parch=x86_64 -PldFlags=\"-arch x86_64\" -PcFlags=\"-arch x86_64\" -PcppFlags=\"-arch x86_64\""
# Run Gradle under Rosetta 2 for x86_64 emulation
GRADLE_CMD="arch -x86_64 ./gradlew"
TASK="check"
echo "✅ Running tests for macOS x86_64 using Rosetta 2 emulation"
fi
# Windows ARM64: Build only, skip tests (can't run ARM64 on x64)
if [[ "${{ runner.os }}" == "Windows" && "${{ matrix.platform.arch }}" == "arm64" ]]; then
TASK="assemble"
echo "⚠️ Windows ARM64: Building only (tests require ARM64 hardware)"
fi
# For macOS ARM64, let it build natively (no special flags needed)
# The JDK and toolchain will be ARM64 by default on macos-14
# Windows: Normalize path to forward slashes for Gradle
if [[ "${{ runner.os }}" == "Windows" ]]; then
export PATH=$TONGSUO_HOME/bin:$TONGSUO_HOME/lib:$PATH
# Convert to Unix-style path with forward slashes (Gradle accepts this on Windows)
if command -v cygpath >/dev/null 2>&1; then
TONGSUO_HOME_GRADLE=$(cygpath -m "$TONGSUO_HOME")
else
# Fallback: just use as-is and normalize to forward slashes
TONGSUO_HOME_GRADLE=$(echo "$TONGSUO_HOME" | sed 's|\\|/|g')
fi
echo "Normalized TONGSUO_HOME for Gradle: $TONGSUO_HOME -> $TONGSUO_HOME_GRADLE"
else
TONGSUO_HOME_GRADLE="$TONGSUO_HOME"
fi
echo "Running Gradle $TASK with args: $GRADLE_ARGS..."
eval $GRADLE_CMD $TASK -PcheckErrorQueue -PtongsuoHome="$TONGSUO_HOME_GRADLE" $GRADLE_ARGS
- name: Fix Dynamic Library Paths (macOS)
if: runner.os == 'macOS'
shell: bash
run: |
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "Fixing macOS Dynamic Library Paths"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
# Find the JNI library
JNI_LIB=$(find openjdk/build/libs -name "libconscrypt_openjdk_jni.dylib" | head -1)
if [ -n "$JNI_LIB" ]; then
echo "Found JNI library: $JNI_LIB"
echo ""
echo "Current dependencies:"
otool -L "$JNI_LIB"
echo ""
# Change absolute paths to @rpath
install_name_tool -change "$TONGSUO_HOME/lib/libssl.3.dylib" "@rpath/libssl.3.dylib" "$JNI_LIB" || true
install_name_tool -change "$TONGSUO_HOME/lib/libcrypto.3.dylib" "@rpath/libcrypto.3.dylib" "$JNI_LIB" || true
# Add @loader_path as rpath (search relative to the library itself)
install_name_tool -add_rpath "@loader_path" "$JNI_LIB" || true
install_name_tool -add_rpath "@loader_path/." "$JNI_LIB" || true
# Add system library paths
install_name_tool -add_rpath "/usr/local/lib" "$JNI_LIB" || true
install_name_tool -add_rpath "/opt/homebrew/lib" "$JNI_LIB" || true
echo "Fixed dependencies:"
otool -L "$JNI_LIB"
echo "✅ Dynamic library paths fixed"
else
echo "⚠️ No JNI library found (might be skipped for this platform)"
fi
- name: Fix Dynamic Library Paths (Linux)
if: runner.os == 'Linux'
shell: bash
run: |
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "Fixing Linux Dynamic Library Paths"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
# Find the JNI library
JNI_LIB=$(find openjdk/build/libs -name "libconscrypt_openjdk_jni.so" | head -1)
if [ -n "$JNI_LIB" ]; then
echo "Found JNI library: $JNI_LIB"
echo ""
echo "Current dependencies:"
ldd "$JNI_LIB" || true
echo ""
# Set rpath to search in common locations
patchelf --set-rpath '$ORIGIN:/usr/local/lib:/usr/lib:/lib' "$JNI_LIB" || true
echo "Fixed dependencies:"
ldd "$JNI_LIB" || true
echo "✅ Dynamic library paths fixed"
else
echo "⚠️ No JNI library found (might be skipped for this platform)"
fi
- name: Verify Windows ARM64 Build (Dynamic)
if: runner.os == 'Windows' && matrix.platform.arch == 'arm64'
shell: bash
run: |
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "⚠️ Windows ARM64 Build Status (Dynamic)"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo "✅ Tongsuo C libraries built successfully (verified in PowerShell step)"
echo "❌ Java SDK (JNI) NOT built - Gradle Native doesn't support MSVC ARM64 cross-compilation"
echo ""
echo "Library files:"
echo " - libcrypto.lib"
echo " - libssl.lib"
echo ""
echo "Reason for skipping JNI:"
echo " Gradle Native plugin detects host architecture (x64) instead of target (ARM64)"
echo " This causes x64 JNI code to be compiled, which cannot link with ARM64 libraries"
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
- name: Build Test JAR with Dynamic Lib Dep (Linux x64 Only)
if: runner.os != 'Windows'
shell: bash
run: |
export LD_LIBRARY_PATH=$TONGSUO_HOME/lib:$LD_LIBRARY_PATH
./gradlew :tongsuo-openjdk:testJar -PcheckErrorQueue -PtongsuoDynamic=1 -PtongsuoHome=$TONGSUO_HOME
# -----------------------------------------------------------
# Error Handling
# -----------------------------------------------------------
- name: Upload Logs on Failure
if: failure()
uses: actions/upload-artifact@v6
with:
name: logs-dynamic-${{ matrix.platform.name }}
path: |
${{ github.workspace }}/Tongsuo/*.log
*.log
if-no-files-found: ignore
- name: Upload Test JAR
if: runner.os != 'Windows'
uses: actions/upload-artifact@v6
with:
name: jar-dynamic-${{ matrix.platform.name }}
path: openjdk/build/libs/tongsuo-openjdk-*.jar
if-no-files-found: ignore