Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ stages:
- template: templates/final-jar-testing-linux.yml
parameters:
OS: MacOS
PoolName: 'macOS-14'
PoolName: 'AcesShared'
PoolDemands: 'ImageOverride -equals ACES_VM_SharedPool_Sequoia'

- stage: GPU_JAR_Testing
dependsOn: []
Expand Down
4 changes: 4 additions & 0 deletions tools/ci_build/github/azure-pipelines/templates/c-api-cpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ stages:
- input: pipelineArtifact
artifactName: drop-onnxruntime-java-linux-aarch64
targetPath: '$(Build.BinariesDirectory)\java-artifact\onnxruntime-java-linux-aarch64'

- input: pipelineArtifact
artifactName: drop-onnxruntime-java-osx-arm64
targetPath: '$(Build.BinariesDirectory)\java-artifact\onnxruntime-java-osx-arm64'
outputs:
- output: pipelineArtifact
targetPath: $(Build.BinariesDirectory)\java-artifact\onnxruntime-java-win-x64
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ parameters:
- name: PoolName
type: string

- name: PoolDemands
type: string
default: ''

stages:
- stage: Final_Jar_Testing_${{parameters.OS}}
dependsOn: []
Expand All @@ -17,7 +21,16 @@ stages:
clean: all
${{ if eq(parameters.OS, 'MacOS') }}:
pool:
vmImage: 'macOS-15'
# Use PoolName if provided, otherwise fallback to macOS-15
${{ if ne(parameters.PoolName, '') }}:
${{ if contains(parameters.PoolName, '-') }}:
vmImage: ${{ parameters.PoolName }}
${{ else }}:
name: ${{ parameters.PoolName }}
${{ if ne(parameters.PoolDemands, '') }}:
demands: ${{ parameters.PoolDemands }}
${{ else }}:
vmImage: 'macOS-15'
${{ if eq(parameters.OS, 'Linux') }}:
pool:
name: ${{ parameters.PoolName }}
Expand All @@ -29,24 +42,41 @@ stages:
- template: set-version-number-variables-step.yml

- bash: |
echo "Downloading and installing Maven $(mavenVersion) for Linux..."
echo "Downloading and installing Maven $(mavenVersion)..."
MAVEN_DIR="$(Agent.TempDirectory)/apache-maven-$(mavenVersion)"

# Download Maven binary
wget https://archive.apache.org/dist/maven/maven-3/$(mavenVersion)/binaries/apache-maven-$(mavenVersion)-bin.tar.gz -O $(Agent.TempDirectory)/maven.tar.gz
if command -v wget &> /dev/null; then
wget https://archive.apache.org/dist/maven/maven-3/$(mavenVersion)/binaries/apache-maven-$(mavenVersion)-bin.tar.gz -O $(Agent.TempDirectory)/maven.tar.gz
else
curl -L -o $(Agent.TempDirectory)/maven.tar.gz https://archive.apache.org/dist/maven/maven-3/$(mavenVersion)/binaries/apache-maven-$(mavenVersion)-bin.tar.gz
fi

# Extract to the temp directory
mkdir -p ${MAVEN_DIR}
tar -xzf $(Agent.TempDirectory)/maven.tar.gz -C $(Agent.TempDirectory)

# Add Maven's bin directory to the PATH for subsequent tasks in the job
echo "##vso[task.prependpath]${MAVEN_DIR}/bin"
displayName: 'Install Maven (Linux)'
condition: and(succeeded(), eq(variables['Agent.OS'], 'Linux'))
displayName: 'Install Maven'
condition: and(succeeded(), in(variables['Agent.OS'], 'Linux', 'Darwin'))

- script: |
echo "Maven is now on the PATH."
mvn --version

- script: |
set -e -x
if ! /usr/libexec/java_home -v 17 >/dev/null 2>&1; then
brew install --cask temurin@17
fi
JAVA_HOME=$(/usr/libexec/java_home -v 17)
echo "JAVA_HOME is set to: $JAVA_HOME"
echo "##vso[task.setvariable variable=JAVA_HOME]$JAVA_HOME"
echo "##vso[task.prependpath]$JAVA_HOME/bin"
displayName: 'Install JDK 17 (macOS)'
condition: and(succeeded(), eq(variables['Agent.OS'], 'Darwin'))

- download: build
artifact: 'onnxruntime-java'
displayName: 'Download Final Jar'
Expand All @@ -58,16 +88,17 @@ stages:
goals: 'dependency:copy-dependencies'
options: '-DoutputDirectory=$(Pipeline.Workspace)/build/onnxruntime-java'
publishJUnitTestResults: false
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.17'
mavenVersionOption: 'Default'
${{ if eq(parameters.OS, 'MacOS') }}:
javaHomeOption: 'Path'
jdkDirectory: '$(JAVA_HOME)'
${{ if eq(parameters.OS, 'Linux') }}:
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.17'

- task: Bash@3
displayName: 'Run Java Tests on Linux'
# condition: and(succeeded(), in(variables['Agent.OS'], 'Linux', 'Darwin'))
# MacOS packages have been removed from the JAR here:
# https://github.com/microsoft/onnxruntime/commit/5ed340f7a51f3cbdb62577a874daf2b3f23d6a93#diff-a14cc5ea231eb4fa49f13510a242043c47ae48516c860f8a87b0e55762632f49
condition: and(succeeded(), in(variables['Agent.OS'], 'Linux'))
displayName: 'Run Java Tests'
condition: and(succeeded(), in(variables['Agent.OS'], 'Linux', 'Darwin'))
inputs:
targetType: 'inline'
script: |
Expand All @@ -83,24 +114,54 @@ stages:
cd ..
mkdir tests
cd tests
# 1. Diagnostics
echo "System Info:"
uname -a
if [[ "$(uname)" == "Darwin" ]]; then arch; fi
echo "Java Version"
java -version

# 2. Extract
jar xf $(Pipeline.Workspace)/build/onnxruntime-java/testing.jar
rm -f $(Pipeline.Workspace)/build/onnxruntime-java/testing.jar
ls $(Pipeline.Workspace)/build/tests

# Identify main jar (avoiding sources and javadoc jars)
MAIN_JAR=$(ls $(Pipeline.Workspace)/build/onnxruntime-java/onnxruntime-*.jar | grep -v 'sources' | grep -v 'javadoc' | head -n 1)
echo "Extracting native libs from $MAIN_JAR"
jar xf $MAIN_JAR ai/onnxruntime/native

ls -R $(Pipeline.Workspace)/build/tests/ai
echo "Java Version"
java -version

# Set the correct library path based on the OS

# 3. Find with robustness
os_name=$(uname)
if [[ "$os_name" == "Linux" ]]; then
echo "Platform: Linux. Setting LD_LIBRARY_PATH."
export LD_LIBRARY_PATH="$(pwd):$LD_LIBRARY_PATH"
java -cp '$(Pipeline.Workspace)/build/tests:$(Pipeline.Workspace)/build/onnxruntime-java/*' org.junit.platform.console.ConsoleLauncher --scan-classpath=$(Pipeline.Workspace)/build/tests \
--fail-if-no-tests --disable-banner --reports-dir "$(Build.ArtifactStagingDirectory)/TestResults"
elif [[ "$os_name" == "Darwin" ]]; then
echo "Platform: macOS. Setting DYLD_LIBRARY_PATH."
export DYLD_LIBRARY_PATH="$(pwd):$DYLD_LIBRARY_PATH"
java -DUSE_WEBGPU=1 -DUSE_COREML=1 -cp '$(Pipeline.Workspace)/build/tests:$(Pipeline.Workspace)/build/onnxruntime-java/*' org.junit.platform.console.ConsoleLauncher --scan-classpath=$(Pipeline.Workspace)/build/tests \
--fail-if-no-tests --disable-banner --reports-dir "$(Build.ArtifactStagingDirectory)/TestResults"
if [[ "$os_name" == "Linux" ]]; then S_FILE="libonnxruntime.so"; else S_FILE="libonnxruntime.dylib"; fi

echo "Searching for $S_FILE in $(pwd)..."
# Exclude .dSYM paths and find actual file
NATIVE_LIB_PATH=$(find $(pwd) -name "$S_FILE" -not -path "*.dSYM*" -type f | head -n 1)

if [[ -n "$NATIVE_LIB_PATH" ]]; then
NATIVE_LIB_DIR=$(dirname "$NATIVE_LIB_PATH")
echo "Found native lib dir: $NATIVE_LIB_DIR"

if [[ "$os_name" == "Linux" ]]; then
echo "Platform: Linux. Setting LD_LIBRARY_PATH."
export LD_LIBRARY_PATH="$NATIVE_LIB_DIR:$(pwd):$LD_LIBRARY_PATH"
java -cp '$(Pipeline.Workspace)/build/tests:$(Pipeline.Workspace)/build/onnxruntime-java/*' org.junit.platform.console.ConsoleLauncher --scan-classpath=$(Pipeline.Workspace)/build/tests \
--fail-if-no-tests --disable-banner --reports-dir "$(Build.ArtifactStagingDirectory)/TestResults"
elif [[ "$os_name" == "Darwin" ]]; then
echo "Platform: macOS. Setting DYLD_LIBRARY_PATH."
export DYLD_LIBRARY_PATH="$NATIVE_LIB_DIR:$(pwd):$DYLD_LIBRARY_PATH"
java -DUSE_WEBGPU=1 -DUSE_COREML=1 -cp '$(Pipeline.Workspace)/build/tests:$(Pipeline.Workspace)/build/onnxruntime-java/*' org.junit.platform.console.ConsoleLauncher --scan-classpath=$(Pipeline.Workspace)/build/tests \
--fail-if-no-tests --disable-banner --reports-dir "$(Build.ArtifactStagingDirectory)/TestResults"
fi
else
echo "Error: $S_FILE not found!"
ls -R ai
exit 1
fi


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ steps:
targetPath: '$(Build.ArtifactStagingDirectory)'
artifactName: 'onnxruntime-osx-${{ parameters.MacosArch }}'

- template: java-api-artifacts-package-and-publish-steps-posix.yml
parameters:
arch: 'osx-${{ parameters.MacosArch }}'
buildConfig: 'Release'
artifactName: 'onnxruntime-java-osx-${{ parameters.MacosArch }}'
libraryName: 'libonnxruntime.dylib'
nativeLibraryName: 'libonnxruntime4j_jni.dylib'

- template: nodejs-artifacts-package-and-publish-steps-posix.yml
parameters:
arch: arm64
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,20 @@ jobs:
set -e -x
export ONNX_ML=1
export CMAKE_ARGS="-DONNX_GEN_PB_TYPE_STUBS=ON -DONNX_WERROR=OFF"
python3 -m pip install -r '$(Build.SourcesDirectory)/tools/ci_build/github/linux/docker/scripts/requirements.txt'
python3 -m pip install -r '$(Build.SourcesDirectory)/tools/ci_build/github/linux/docker/scripts/requirements.txt'

- script: |
set -e -x
if ! /usr/libexec/java_home -v 17 >/dev/null 2>&1; then
brew install --cask temurin@17
fi
JAVA_HOME=$(/usr/libexec/java_home -v 17)
echo "JAVA_HOME is set to: $JAVA_HOME"
echo "##vso[task.setvariable variable=JAVA_HOME]$JAVA_HOME"
echo "##vso[task.prependpath]$JAVA_HOME/bin"
displayName: 'Install JDK 17'

- template: mac-cpu-packaging-steps.yml
parameters:
MacosArch: arm64
AdditionalBuildFlags: ${{ parameters.AdditionalBuildFlags }} --build_nodejs --use_coreml --use_webgpu --cmake_extra_defines CMAKE_OSX_ARCHITECTURES=arm64
AdditionalBuildFlags: ${{ parameters.AdditionalBuildFlags }} --build_java --build_nodejs --use_coreml --use_webgpu --cmake_extra_defines CMAKE_OSX_ARCHITECTURES=arm64
1 change: 1 addition & 0 deletions tools/ci_build/github/windows/jar_packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ def run_packaging(package_type: str, build_dir: str):
"platforms": [
{"path": "onnxruntime-java-linux-x64", "lib": "libcustom_op_library.so", "archive_lib": True},
{"path": "onnxruntime-java-linux-aarch64", "lib": "libcustom_op_library.so", "archive_lib": False},
{"path": "onnxruntime-java-osx-arm64", "lib": "libcustom_op_library.dylib", "archive_lib": True},
]
},
"gpu": {
Expand Down
12 changes: 10 additions & 2 deletions tools/ci_build/github/windows/jar_packaging_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,19 @@ def _setup_test_directory(package_type: str, version_string: str):
create_empty_file(linux_native_dir / "libonnxruntime_providers_cuda.so")
(linux_dir / "_manifest" / "spdx_2.2").mkdir(parents=True, exist_ok=True)

# --- Additional platforms (for CPU test) ---
# --- macOS and other platforms (for CPU test) ---
if package_type == "cpu":
# Add linux-aarch64 for CPU test
# Add linux-aarch64 and osx-arm64 for CPU test
linux_aarch64_dir = java_artifact_dir / "onnxruntime-java-linux-aarch64"
linux_aarch64_native_dir = linux_aarch64_dir / "ai" / "onnxruntime" / "native" / "linux-aarch64"
linux_aarch64_native_dir.mkdir(parents=True, exist_ok=True)
create_empty_file(linux_aarch64_dir / "libcustom_op_library.so")

osx_arm64_dir = java_artifact_dir / "onnxruntime-java-osx-arm64"
osx_arm64_native_dir = osx_arm64_dir / "ai" / "onnxruntime" / "native" / "osx-arm64"
osx_arm64_native_dir.mkdir(parents=True, exist_ok=True)
create_empty_file(osx_arm64_dir / "libcustom_op_library.dylib")

return tmp_path

return _setup_test_directory
Expand Down Expand Up @@ -128,9 +133,12 @@ def test_cpu_packaging(directory_setup_factory, version_string):
with zipfile.ZipFile(testing_jar_path, "r") as zf:
jar_contents = zf.namelist()
assert "libcustom_op_library.so" in jar_contents
assert "libcustom_op_library.dylib" in jar_contents

# 3. Verify the custom op libraries were removed from the source directories
linux_dir = temp_build_dir / "java-artifact" / "onnxruntime-java-linux-x64"
linux_aarch64_dir = temp_build_dir / "java-artifact" / "onnxruntime-java-linux-aarch64"
osx_arm64_dir = temp_build_dir / "java-artifact" / "onnxruntime-java-osx-arm64"
assert not (linux_dir / "libcustom_op_library.so").exists()
assert not (linux_aarch64_dir / "libcustom_op_library.so").exists()
assert not (osx_arm64_dir / "libcustom_op_library.dylib").exists()
Loading