mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-28 20:11:22 +00:00
Pipeline changes to build full ORT package for Android (#10654)
* Add android package build settings for full build Co-authored-by: gwang0000 <62914304+gwang0000@users.noreply.github.com> Co-authored-by: Scott McKay <skottmckay@gmail.com> Co-authored-by: Edward Chen <18449977+edgchen1@users.noreply.github.com>
This commit is contained in:
parent
6072c6b65e
commit
7aa706854f
10 changed files with 56 additions and 21 deletions
|
|
@ -7,6 +7,8 @@ def headersDir = System.properties['headersDir']
|
|||
def publishDir = System.properties['publishDir']
|
||||
def minSdkVer = System.properties['minSdkVer']
|
||||
def targetSdkVer = System.properties['targetSdkVer']
|
||||
def buildVariant = System.properties['buildVariant'] ?: "Full"
|
||||
boolean isMobileBuild = (buildVariant == "Mobile")
|
||||
|
||||
// Since Android requires a higher numbers indicating more recent versions
|
||||
// This function assume ORT version number will be in formart of A.B.C such as 1.7.0
|
||||
|
|
@ -24,7 +26,17 @@ project.buildDir = buildDir
|
|||
project.version = rootProject.file('../VERSION_NUMBER').text.trim()
|
||||
project.group = "com.microsoft.onnxruntime"
|
||||
|
||||
def mavenArtifactId = project.name + '-mobile'
|
||||
def mavenArtifactId = isMobileBuild ? project.name + '-mobile' : project.name + '-android'
|
||||
def mobileDescription = 'The ONNX Runtime Mobile package is a size optimized inference library for executing ONNX ' +
|
||||
'(Open Neural Network Exchange) models on Android. This package is built from the open source inference engine ' +
|
||||
'but with reduced disk footprint targeting mobile platforms. To minimize binary size this library supports a ' +
|
||||
'reduced set of operators and types aligned to typical mobile applications. The ONNX model must be converted to ' +
|
||||
'ORT format in order to use it with this package. ' +
|
||||
'See https://onnxruntime.ai/docs/reference/ort-model-format.html for more details.'
|
||||
def defaultDescription = 'ONNX Runtime is a performance-focused inference engine for ONNX (Open Neural Network ' +
|
||||
'Exchange) models. This package contains the Android (aar) build of ONNX Runtime. It includes support for all ' +
|
||||
'types and operators, for ONNX format models. All standard ONNX models can be executed with this package. ' +
|
||||
'As such the binary size and memory usage will be larger than the onnxruntime-mobile package.'
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
|
|
@ -126,9 +138,7 @@ publishing {
|
|||
|
||||
pom {
|
||||
name = 'onnx-runtime'
|
||||
description = 'ONNX Runtime Mobile package is a size optimized inference library for executing ' +
|
||||
'ONNX (Open Neural Network Exchange) models. This package is built from the open source ' +
|
||||
'inference engine targeting reduced disk footprint for mobile platforms.'
|
||||
description = isMobileBuild ? mobileDescription : defaultDescription
|
||||
url = 'https://microsoft.github.io/onnxruntime/'
|
||||
licenses {
|
||||
license {
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ else
|
|||
fi
|
||||
|
||||
# Copy the built artifacts to give folder for publishing
|
||||
PACKAGE_NAME=onnxruntime-mobile
|
||||
BASE_PATH=/build/aar_out/${BUILD_CONFIG}/com/microsoft/onnxruntime/${PACKAGE_NAME}/${ORT_VERSION}
|
||||
cp ${BASE_PATH}/${PACKAGE_NAME}-${ORT_VERSION}-javadoc.jar /home/onnxruntimedev/.artifacts
|
||||
cp ${BASE_PATH}/${PACKAGE_NAME}-${ORT_VERSION}-sources.jar /home/onnxruntimedev/.artifacts
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
|
|||
REPO_DIR = os.path.normpath(os.path.join(SCRIPT_DIR, "..", "..", "..", ".."))
|
||||
BUILD_PY = os.path.join(REPO_DIR, "tools", "ci_build", "build.py")
|
||||
JAVA_ROOT = os.path.join(REPO_DIR, "java")
|
||||
DEFAULT_BUILD_VARIANT = "Full"
|
||||
|
||||
sys.path.insert(0, os.path.join(REPO_DIR, "tools", "python"))
|
||||
from util import is_windows # noqa: E402
|
||||
|
|
@ -70,6 +71,8 @@ def _parse_build_settings(args):
|
|||
))
|
||||
|
||||
build_settings['build_params'] = build_params
|
||||
build_settings["build_variant"] = build_settings_data.get("build_variant", DEFAULT_BUILD_VARIANT)
|
||||
|
||||
return build_settings
|
||||
|
||||
|
||||
|
|
@ -145,7 +148,8 @@ def _build_aar(args):
|
|||
'-DheadersDir=' + header_files_path,
|
||||
'-DpublishDir=' + aar_publish_dir,
|
||||
'-DminSdkVer=' + str(build_settings['android_min_sdk_version']),
|
||||
'-DtargetSdkVer=' + str(build_settings['android_target_sdk_version'])
|
||||
'-DtargetSdkVer=' + str(build_settings['android_target_sdk_version']),
|
||||
'-DbuildVariant=' + str(build_settings['build_variant'])
|
||||
]
|
||||
|
||||
# If not using shell on Window, will not be able to find gradle in path
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
],
|
||||
"android_min_sdk_version": 21,
|
||||
"android_target_sdk_version": 24,
|
||||
"build_variant": "Mobile",
|
||||
"build_params": [
|
||||
"--android",
|
||||
"--parallel",
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ jobs:
|
|||
artifactName: 'onnxruntime-android-mobile-aar'
|
||||
job_name_suffix: 'For_React_Native'
|
||||
pool_name: '${{variables.pool_name}}'
|
||||
packageName: 'onnxruntime-mobile'
|
||||
|
||||
- job: ReactNative_CI
|
||||
pool:
|
||||
|
|
@ -100,7 +101,7 @@ jobs:
|
|||
npm ci
|
||||
workingDirectory: '$(Build.SourcesDirectory)/js'
|
||||
displayName: npm ci js
|
||||
|
||||
|
||||
- script: |
|
||||
npm ci
|
||||
workingDirectory: '$(Build.SourcesDirectory)/js/common'
|
||||
|
|
@ -277,14 +278,14 @@ jobs:
|
|||
contents: onnxruntime-common*.tgz
|
||||
targetFolder: $(Build.ArtifactStagingDirectory)
|
||||
displayName: 'Create Artifacts onnxruntime-common'
|
||||
|
||||
|
||||
- task: CopyFiles@2
|
||||
inputs:
|
||||
sourceFolder: $(Build.SourcesDirectory)/js/react_native
|
||||
contents: onnxruntime-react-native*.tgz
|
||||
targetFolder: $(Build.ArtifactStagingDirectory)
|
||||
displayName: Create Artifacts onnxruntime-react-native
|
||||
|
||||
|
||||
- task: PublishPipelineArtifact@0
|
||||
inputs:
|
||||
artifactName: 'NPM_packages'
|
||||
|
|
|
|||
|
|
@ -9,6 +9,12 @@ parameters:
|
|||
type: string
|
||||
default: ''
|
||||
|
||||
- name: packageName
|
||||
# now we can build onnxruntime-android or onnxruntime-mobile for Android, need specify it here
|
||||
displayName: Package Name
|
||||
type: string
|
||||
default: 'onnxruntime-android'
|
||||
|
||||
jobs:
|
||||
- job: Final_AAR_Testing_Android_${{ parameters.job_name_suffix }}
|
||||
workspace:
|
||||
|
|
@ -49,7 +55,7 @@ jobs:
|
|||
cp -av $(Build.SourcesDirectory)/java/src/test/android ./
|
||||
cd ./android
|
||||
mkdir -p app/libs
|
||||
cp $(Build.BinariesDirectory)/final-android-aar/onnxruntime-mobile-$(OnnxRuntimeVersion).aar app/libs/onnxruntime-mobile.aar
|
||||
cp $(Build.BinariesDirectory)/final-android-aar/${{parameters.packageName}}-$(OnnxRuntimeVersion).aar app/libs/onnxruntime-mobile.aar
|
||||
$(Build.SourcesDirectory)/java/gradlew --no-daemon clean connectedDebugAndroidTest
|
||||
displayName: Run E2E test using Emulator
|
||||
workingDirectory: $(Build.BinariesDirectory)
|
||||
|
|
|
|||
|
|
@ -35,6 +35,12 @@ parameters:
|
|||
type: string
|
||||
default: 'Linux-CPU'
|
||||
|
||||
- name: packageName
|
||||
# now we can build onnxruntime or onnxruntime-mobile for Android, need specify it here
|
||||
displayName: Package Name
|
||||
type: string
|
||||
default: 'onnxruntime-android'
|
||||
|
||||
jobs:
|
||||
- job: Android_Java_API_AAR_Packaging_${{ parameters.job_name_suffix }}
|
||||
timeoutInMinutes: 120
|
||||
|
|
@ -88,6 +94,7 @@ jobs:
|
|||
-e BUILD_CONFIG=${{parameters.buildConfig}} \
|
||||
-e ORT_VERSION=$(OnnxRuntimeVersion) \
|
||||
-e PUBLISH_EXECUTABLES=${{parameters.publish_executables}} \
|
||||
-e PACKAGE_NAME=${{parameters.packageName}} \
|
||||
onnxruntimecpubuild \
|
||||
/bin/bash /onnxruntime_src/tools/ci_build/github/android/build_aar_and_copy_artifacts.sh
|
||||
workingDirectory: $(Build.SourcesDirectory)
|
||||
|
|
|
|||
|
|
@ -183,6 +183,7 @@ jobs:
|
|||
includedOpsConfig: '$(Build.SourcesDirectory)/tools/ci_build/github/android/mobile_package.required_operators.config'
|
||||
artifactName: 'onnxruntime-android-mobile-aar'
|
||||
job_name_suffix: 'Mobile'
|
||||
packageName: 'onnxruntime-mobile'
|
||||
|
||||
- template: android-java-api-aar.yml
|
||||
parameters:
|
||||
|
|
@ -1061,5 +1062,9 @@ jobs:
|
|||
parameters:
|
||||
artifactName: 'onnxruntime-android-mobile-aar'
|
||||
job_name_suffix: 'Mobile'
|
||||
packageName: 'onnxruntime-mobile'
|
||||
|
||||
|
||||
- template: android-java-api-aar-test.yml
|
||||
parameters:
|
||||
artifactName: 'onnxruntime-android-full-aar'
|
||||
job_name_suffix: 'Full'
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
],
|
||||
"android_min_sdk_version": 21,
|
||||
"android_target_sdk_version": 24,
|
||||
"build_variant": "Mobile",
|
||||
"build_params": [
|
||||
"--android",
|
||||
"--parallel",
|
||||
|
|
@ -18,4 +19,4 @@
|
|||
"--use_nnapi",
|
||||
"--skip_tests"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
@ -10,16 +10,16 @@ New-Item -Path $nuget_artifacts_dir -ItemType directory
|
|||
|
||||
## .zip files
|
||||
# unzip directly
|
||||
Get-ChildItem $Env:BUILD_BINARIESDIRECTORY\nuget-artifact -Filter *.zip |
|
||||
Get-ChildItem $Env:BUILD_BINARIESDIRECTORY\nuget-artifact -Filter *.zip |
|
||||
Foreach-Object {
|
||||
$cmd = "7z.exe x $($_.FullName) -y -o$nuget_artifacts_dir"
|
||||
Write-Output $cmd
|
||||
Invoke-Expression -Command $cmd
|
||||
Invoke-Expression -Command $cmd
|
||||
}
|
||||
|
||||
## .tgz files
|
||||
# first extract the tar file from the tgz
|
||||
Get-ChildItem $Env:BUILD_BINARIESDIRECTORY\nuget-artifact -Filter *.tgz |
|
||||
Get-ChildItem $Env:BUILD_BINARIESDIRECTORY\nuget-artifact -Filter *.tgz |
|
||||
Foreach-Object {
|
||||
$cmd = "7z.exe x $($_.FullName) -y -o$Env:BUILD_BINARIESDIRECTORY\nuget-artifact"
|
||||
Write-Output $cmd
|
||||
|
|
@ -27,16 +27,17 @@ Foreach-Object {
|
|||
}
|
||||
|
||||
# now extract the actual folder structure from the tar file to the build dir
|
||||
Get-ChildItem $Env:BUILD_BINARIESDIRECTORY\nuget-artifact -Filter *.tar |
|
||||
Get-ChildItem $Env:BUILD_BINARIESDIRECTORY\nuget-artifact -Filter *.tar |
|
||||
Foreach-Object {
|
||||
$cmd = "7z.exe x $($_.FullName) -y -o$nuget_artifacts_dir"
|
||||
Write-Output $cmd
|
||||
Invoke-Expression -Command $cmd
|
||||
}
|
||||
|
||||
# copy android AAR.
|
||||
# should only be one .aar file called onnxruntime-mobile-x.y.z.aar but sanity check that
|
||||
$aars = Get-ChildItem $Env:BUILD_BINARIESDIRECTORY\nuget-artifact -Filter onnxruntime-mobile-*.aar
|
||||
# copy android AAR.
|
||||
# for full build of onnxruntime Android AAR, there should only be one .aar file
|
||||
# called onnxruntime-android-x.y.z.aar but sanity check that
|
||||
$aars = Get-ChildItem $Env:BUILD_BINARIESDIRECTORY\nuget-artifact -Filter onnxruntime-android-*.aar
|
||||
|
||||
if ($aars.Count -eq 1) {
|
||||
$aar = $aars[0]
|
||||
|
|
@ -61,11 +62,11 @@ Copy-Item -Path $Env:BUILD_BINARIESDIRECTORY\extra-artifact\protoc.exe $Env:BUIL
|
|||
$ort_dirs = Get-ChildItem -Directory -Path $nuget_artifacts_dir\onnxruntime-*
|
||||
foreach ($ort_dir in $ort_dirs)
|
||||
{
|
||||
# remove the last '-xxx' segment from the dir name. typically that's the architecture.
|
||||
# remove the last '-xxx' segment from the dir name. typically that's the architecture.
|
||||
$dirname = Split-Path -Path $ort_dir -Leaf
|
||||
$dirname = $dirname.SubString(0,$dirname.LastIndexOf('-'))
|
||||
Write-Output "Renaming $ort_dir to $dirname"
|
||||
Rename-Item -Path $ort_dir -NewName $nuget_artifacts_dir\$dirname
|
||||
Rename-Item -Path $ort_dir -NewName $nuget_artifacts_dir\$dirname
|
||||
}
|
||||
|
||||
# List artifacts
|
||||
|
|
|
|||
Loading…
Reference in a new issue