Skip to content

Commit 0f59a90

Browse files
authored
1 parent b3dfed6 commit 0f59a90

18 files changed

+215
-37
lines changed

.pipelines/nuget-publishing.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ parameters:
3838
type: boolean
3939
default: true
4040

41+
- name: enable_android
42+
displayName: 'Whether Android AAR package is built.'
43+
type: boolean
44+
default: true
45+
4146
- name: enable_apple_framework
4247
displayName: 'Whether Apple framework for iOS & MacCatalyst is built.'
4348
type: boolean
@@ -94,6 +99,7 @@ stages:
9499
enable_win_dml: ${{ parameters.enable_win_dml }}
95100
enable_win_arm64: ${{ parameters.enable_win_arm64 }}
96101
enable_macos_cpu: ${{ parameters.enable_macos_cpu }}
102+
enable_android: ${{ parameters.enable_android }}
97103
enable_apple_framework: ${{ parameters.enable_apple_framework }}
98104
ort_version: ${{ parameters.ort_version }}
99105
ort_cuda_version: ${{ parameters.ort_cuda_version }}
@@ -110,6 +116,7 @@ stages:
110116
enable_win_dml: ${{ parameters.enable_win_dml }}
111117
enable_win_arm64: ${{ parameters.enable_win_arm64 }}
112118
enable_macos_cpu: ${{ parameters.enable_macos_cpu }}
119+
enable_android: ${{ parameters.enable_android }}
113120
enable_apple_framework: ${{ parameters.enable_apple_framework }}
114121
ort_version: ${{ parameters.ort_version }}
115122
ort_cuda_version: ${{ parameters.ort_cuda_version }}

.pipelines/stages/capi-packaging-stage.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ parameters:
1313
type: boolean
1414
- name: enable_macos_cpu
1515
type: boolean
16+
- name: enable_android
17+
type: boolean
1618
- name: enable_apple_framework
1719
type: boolean
1820
- name: ort_version
@@ -114,6 +116,12 @@ stages:
114116
os: 'osx'
115117
build_config: ${{ parameters.build_config }}
116118

119+
- ${{ if eq(parameters.enable_android, true) }}:
120+
- template: jobs/android-java-api-aar.yml
121+
parameters:
122+
ort_version: ${{ parameters.ort_version }}
123+
build_config: ${{ parameters.build_config }}
124+
117125
- ${{ if eq(parameters.enable_apple_framework, true) }}:
118126
- template: jobs/capi-packaging-job.yml
119127
parameters:

.pipelines/stages/jobs/android-java-api-aar.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,18 @@ jobs:
2626

2727
- template: steps/utils/use-android-ndk.yml
2828
- template: steps/utils/set-genai-version.yml
29+
- template: steps/utils/set-cmake-build-type.yml
30+
parameters:
31+
build_config: ${{parameters.build_config}}
2932

3033
- task: CmdLine@2
3134
displayName: Build Android AAR Packages
3235
inputs:
3336
script: |
3437
set -e -x
35-
38+
3639
BUILD_DIR=$(Build.BinariesDirectory)
37-
BUILD_CONFIG=${{parameters.build_config}}
40+
BUILD_CONFIG=$(cmake_build_type)
3841
GENAI_VERSION=$(genai_version)
3942
PACKAGE_NAME=${{parameters.package_name}}
4043
ARTIFACTS_DIR=$(Build.ArtifactStagingDirectory)

.pipelines/stages/jobs/nuget-packaging-job.yml

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ parameters:
3737
type: boolean
3838
default: false
3939

40+
- name: enable_android
41+
displayName: 'Whether Android AAR package is built.'
42+
type: boolean
43+
default: false
44+
4045
- name: enable_apple_framework
4146
displayName: 'Whether Apple framework for iOS & MacCatalyst is built.'
4247
type: boolean
@@ -153,6 +158,20 @@ jobs:
153158
ArtifactName: onnxruntime-genai-osx-cpu-arm64-capi
154159
TargetPath: '$(Build.BinariesDirectory)/artifact-downloads'
155160

161+
- ${{ if eq(parameters.enable_apple_framework, true) }}:
162+
- template: steps/utils/flex-download-pipeline-artifact.yml
163+
parameters:
164+
StepName: 'Download iOS XCFramework Artifacts'
165+
ArtifactName: onnxruntime-genai-ios-xcframework
166+
TargetPath: '$(Build.BinariesDirectory)/artifact-downloads'
167+
168+
- ${{ if eq(parameters.enable_android, true) }}:
169+
- template: steps/utils/flex-download-pipeline-artifact.yml
170+
parameters:
171+
StepName: 'Download Android AAR Artifacts'
172+
ArtifactName: drop-android
173+
TargetPath: '$(Build.BinariesDirectory)/artifact-downloads'
174+
156175
- checkout: self
157176
path: onnxruntime-genai
158177
clean: true
@@ -162,7 +181,7 @@ jobs:
162181

163182
- powershell: |
164183
dotnet --info
165-
dotnet build Microsoft.ML.OnnxRuntimeGenAI.csproj -p:Configuration="$(buildConfig)" --verbosity normal
184+
dotnet build Microsoft.ML.OnnxRuntimeGenAI.csproj -p:Configuration="$(buildConfig)" -p:IncludeMobileTargets=true --verbosity normal
166185
displayName: 'Build CSharp'
167186
workingDirectory: '$(Build.Repository.LocalPath)\src\csharp'
168187
@@ -181,10 +200,12 @@ jobs:
181200
- powershell: |
182201
$artifacts_dir = '$(Build.BinariesDirectory)/artifact-downloads'
183202
Write-Host "List downloaded artifacts"
184-
$artifacts = Get-ChildItem -Path $artifacts_dir/* -Include *.zip,*.tar.gz
203+
$artifacts = Get-ChildItem -Path $artifacts_dir/* -Include *.zip,*.tar.gz,*.aar
185204
Write-Host $artifacts
186205
187206
$outputDir = '$(Build.Repository.LocalPath)/$(buildDir)'
207+
Write-Host "List extracted artifacts"
208+
Get-ChildItem -Path $nativeBuildOutputDir -Recurse
188209
189210
mkdir -Force $outputDir
190211
foreach ($file in $artifacts) {
@@ -195,28 +216,42 @@ jobs:
195216
$rid = $Matches.1
196217
}
197218
else {
198-
Write-Host "Invalid artifact name" $file
199-
return
219+
$rid_match = $a -match "onnxruntime-genai-(android|ios)-$(genai_version)(.+?)?(\.zip|\.aar)"
220+
if ($rid_match) {
221+
$rid = $Matches.1
222+
}
223+
else {
224+
Write-Host "Invalid artifact name" $file
225+
return
226+
}
200227
}
201-
mkdir -Force $outputDir/$rid
202228
203-
if ($a -like "*.zip") {
204-
Expand-Archive -Path $file -DestinationPath $outputDir/$rid
229+
mkdir -Force $outputDir/$rid
230+
mkdir -Force $outputDir/$rid/$(buildConfig)
231+
if ($rid -like "ios") {
232+
Move-Item $file $outputDir/$rid/$(buildConfig)/onnxruntime-genai.xcframework.zip
233+
}
234+
elseif ($a -like "*.aar") {
235+
Move-Item $file $outputDir/$rid/$(buildConfig)/onnxruntime-genai.aar
205236
}
206-
elseif ($a -like "*.tar.gz") {
207-
tar -xf $file -C $outputDir/$rid
237+
else {
238+
if ($a -like "*.zip") {
239+
Expand-Archive -Path $file -DestinationPath $outputDir/$rid
240+
}
241+
elseif ($a -like "*.tar.gz") {
242+
tar -xf $file -C $outputDir/$rid
243+
}
208244
}
209245
210-
mkdir -Force $outputDir/$rid/$(buildConfig)
211246
$b = $file.Basename
212247
$b = $b -split '.tar'
213248
$b = $b[0]
214-
Move-Item $outputDir/$rid/$b/lib/* $outputDir/$rid/$(buildConfig) -Force
249+
if (Test-Path $outputDir/$rid/$b/lib/) {
250+
Move-Item $outputDir/$rid/$b/lib/* $outputDir/$rid/$(buildConfig) -Force
251+
}
252+
Get-ChildItem -Path $outputDir/$rid -Recurse
215253
}
216254
217-
Write-Host "List extracted artifacts"
218-
Get-ChildItem -Path $nativeBuildOutputDir -Recurse
219-
220255
displayName: 'Extract Artifacts & Prepare Native Libraries'
221256
workingDirectory: '$(Build.BinariesDirectory)/artifact-downloads'
222257

.pipelines/stages/jobs/steps/capi-appleframework-step.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@ steps:
2222
tools/ci_build/github/apple/default_full_ios_framework_build_settings.json
2323
2424
mkdir $(Build.BinariesDirectory)/artifacts
25-
mkdir -p $(Build.BinariesDirectory)/artifacts_staging/onnxruntime-genai-ios-xcframework-$(genai_version)
25+
mkdir -p $(Build.BinariesDirectory)/artifacts_staging/onnxruntime-genai.xcframework
2626
cp -R $(Build.BinariesDirectory)/apple_framework/framework_out/onnxruntime-genai.xcframework \
27-
$(Build.BinariesDirectory)/artifacts_staging/onnxruntime-genai-ios-xcframework-$(genai_version)
27+
$(Build.BinariesDirectory)/artifacts_staging/
2828
pushd $(Build.BinariesDirectory)/artifacts_staging
29-
zip -vr $(Build.BinariesDirectory)/artifacts/onnxruntime_genai_ios_xcframework.zip \
30-
onnxruntime-genai-ios-xcframework-$(genai_version)
29+
zip -vr $(Build.BinariesDirectory)/artifacts/onnxruntime-genai-ios-$(genai_version).zip \
30+
onnxruntime-genai.xcframework
3131
popd
3232
displayName: 'Build Apple XCFramework'
3333
workingDirectory: '$(Build.Repository.LocalPath)'
3434

3535
- task: PublishBuildArtifacts@1
3636
displayName: 'Publish Artifact: ONNXRuntime GenAI XCFramework'
3737
inputs:
38-
ArtifactName: capi-onnxruntime-genai-ios-xcframework
38+
ArtifactName: onnxruntime-genai-ios-xcframework
3939
PathtoPublish: '$(Build.BinariesDirectory)/artifacts'
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
parameters:
2+
- name: build_config
3+
type: string
4+
steps:
5+
- task: PowerShell@2
6+
displayName: 'Set CMake Build Type'
7+
inputs:
8+
workingDirectory: $(Build.SourcesDirectory)
9+
targetType: inline
10+
script: |
11+
$chosen_build_config = "${{ parameters.build_config }}"
12+
$cmake_build_type = $chosen_build_config;
13+
if ($chosen_build_config -eq "release") {
14+
$cmake_build_type = "Release"
15+
}
16+
elseif ($chosen_build_config -eq "relwithdebinfo") {
17+
$cmake_build_type = "RelWithDebInfo"
18+
}
19+
elseif ($chosen_build_config -eq "debug") {
20+
$cmake_build_type = "Debug"
21+
}
22+
Write-Host "Current build type: $cmake_build_type"
23+
Write-Host "##vso[task.setvariable variable=cmake_build_type]$cmake_build_type"

.pipelines/stages/nuget-packaging-stage.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,15 @@ parameters:
3434
type: boolean
3535
default: true
3636

37+
- name: enable_android
38+
displayName: 'Whether Android AAR package is built.'
39+
type: boolean
40+
default: true
41+
3742
- name: enable_apple_framework
3843
displayName: 'Whether Apple framework for iOS & MacCatalyst is built.'
3944
type: boolean
40-
default: false
45+
default: true
4146

4247
- name: ort_version
4348
type: string
@@ -62,6 +67,7 @@ stages:
6267
enable_win_cpu: ${{ parameters.enable_win_cpu }}
6368
enable_win_arm64: ${{ parameters.enable_win_arm64 }}
6469
enable_macos_cpu: ${{ parameters.enable_macos_cpu }}
70+
enable_android: ${{ parameters.enable_android }}
6571
enable_apple_framework: ${{ parameters.enable_apple_framework }}
6672
- ${{ if or(eq(parameters.enable_linux_cuda, true), eq(parameters.enable_win_cuda, true)) }}:
6773
- template: jobs/nuget-packaging-job.yml
@@ -74,7 +80,7 @@ stages:
7480
- ${{ if eq(parameters.enable_win_dml, true) }}:
7581
- template: jobs/nuget-packaging-job.yml
7682
parameters:
77-
ep: 'directml'
83+
ep: 'directml'
7884
ort_version: ${{ parameters.ort_dml_version }}
7985
build_config: ${{ parameters.build_config }}
8086
enable_win_dml: ${{ parameters.enable_win_dml }}

nuget/Microsoft.ML.OnnxRuntimeGenAI.Managed.nuspec

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
<dependencies>
1616
<group targetFramework="net8.0" />
1717
<group targetFramework="netstandard2.0" />
18+
<group targetFramework="net8.0-android31.0" />
19+
<group targetFramework="net8.0-ios15.4" />
20+
<group targetFramework="net8.0-maccatalyst14.0" />
1821
</dependencies>
1922
</metadata>
2023
<files>
@@ -27,6 +30,16 @@
2730
<file src="..\src\csharp\bin\$configuration$\net8.0\Microsoft.ML.OnnxRuntimeGenAI.dll" target="lib\net8.0" />
2831
<file src="..\src\csharp\bin\$configuration$\net8.0\Microsoft.ML.OnnxRuntimeGenAI.pdb" target="lib\net8.0" />
2932

33+
<file src="..\src\csharp\bin\$configuration$\net8.0-android\Microsoft.ML.OnnxRuntimeGenAI.dll" target="lib\net8.0-android31.0" />
34+
<file src="..\src\csharp\bin\$configuration$\net8.0-android\Microsoft.ML.OnnxRuntimeGenAI.pdb" target="lib\net8.0-android31.0" />
35+
<file src="..\src\csharp\bin\$configuration$\net8.0-android\Microsoft.ML.OnnxRuntimeGenAI.xml" target="lib\net8.0-android31.0" />
36+
37+
<file src="..\src\csharp\bin\$configuration$\net8.0-ios\Microsoft.ML.OnnxRuntimeGenAI.dll" target="lib\net8.0-ios15.4" />
38+
<file src="..\src\csharp\bin\$configuration$\net8.0-ios\Microsoft.ML.OnnxRuntimeGenAI.pdb" target="lib\net8.0-ios15.4" />
39+
40+
<file src="..\src\csharp\bin\$configuration$\net8.0-maccatalyst\Microsoft.ML.OnnxRuntimeGenAI.dll" target="lib\net8.0-maccatalyst14.0" />
41+
<file src="..\src\csharp\bin\$configuration$\net8.0-maccatalyst\Microsoft.ML.OnnxRuntimeGenAI.pdb" target="lib\net8.0-maccatalyst14.0" />
42+
3043
<!-- Targets -->
3144
<file src="targets\Microsoft.ML.OnnxRuntimeGenAI.Managed.targets" target="build\netstandard2.0" />
3245
<file src="targets\Microsoft.ML.OnnxRuntimeGenAI.Managed.targets" target="build\net8.0" />
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Condition=" '$(AndroidApplication)'=='true' ">
4+
<AndroidLibrary Bind="false" Include="$(MSBuildThisFileDirectory)..\..\runtimes\android\native\*">
5+
<Link>%(Filename)%(Extension)</Link>
6+
</AndroidLibrary>
7+
</ItemGroup>
8+
</Project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Condition="('$(OutputType)'!='Library' OR '$(IsAppExtension)'=='True')">
4+
<NativeReference Include="$(MSBuildThisFileDirectory)..\..\runtimes\ios\native\onnxruntime-genai.xcframework">
5+
<Kind>Static</Kind>
6+
<IsCxx>True</IsCxx>
7+
<SmartLink>True</SmartLink>
8+
<ForceLoad>True</ForceLoad>
9+
<LinkerFlags>-lc++</LinkerFlags>
10+
<WeakFrameworks>CoreML</WeakFrameworks>
11+
</NativeReference>
12+
</ItemGroup>
13+
</Project>

0 commit comments

Comments
 (0)