Add ability to create a 'dummy' nuget package using build with no ops (#573)

* Add ability to create a 'dummy' nuget package from a build with no ops. This is required on iOS due to the ORT C# package including the ability to register custom ops. That creates a compile time dependency for the RegisterCustomOps symbol to exist. If the user can't (Xamarin) or does not want to use extensions that results in usage of ORT being broken.

For simplicity, consistency and to minimize changes to the build infrastructure we build a nuget package for all platforms so everything is 1:1 with the real package except the build uses an empty config to select the ops to include. Technically we only need something with iOS builds.

We should only need to publish this once unless the RegisterCustomOps API changes.

* Address PR comments

* Update .pipelines/nuget.yml

Co-authored-by: Edward Chen <18449977+edgchen1@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: Edward Chen <18449977+edgchen1@users.noreply.github.com>

---------

Co-authored-by: Edward Chen <18449977+edgchen1@users.noreply.github.com>
This commit is contained in:
Scott McKay 2023-10-21 09:44:26 +10:00 коммит произвёл GitHub
Родитель 92d17b0a52
Коммит 2cf9bab611
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
7 изменённых файлов: 161 добавлений и 43 удалений

Просмотреть файл

@ -14,6 +14,11 @@ parameters:
type: boolean
default: false
- name: IsDummyPackage
displayName: Is this a build of Microsoft.ML.OnnxRuntime.Extensions.Dummy package that has no operators?
type: boolean
default: false
- name: NugetVersionSuffix
displayName: Update nuget version suffix (e.g. alpha/beta/rc, only if publishing to nuget.org, otherwise leave as "none").
type: string
@ -28,12 +33,24 @@ pr:
branches:
include:
- "*"
stages:
- template: templates/build-package-for-nuget.yml
parameters:
DoCompliance: ${{ parameters.DoCompliance }}
DoEsrp: ${{ parameters.DoEsrp }}
IsReleaseBuild: ${{ parameters.IsReleaseBuild }}
NugetVersionSuffix: ${{ parameters.NugetVersionSuffix }}
OrtNugetPackageId: 'Microsoft.ML.OnnxRuntime.Extensions'
- ${{ if eq(parameters.IsDummyPackage, false) }}:
- template: templates/build-package-for-nuget.yml
parameters:
DoCompliance: ${{ parameters.DoCompliance }}
DoEsrp: ${{ parameters.DoEsrp }}
IsReleaseBuild: ${{ parameters.IsReleaseBuild }}
NugetVersionSuffix: ${{ parameters.NugetVersionSuffix }}
- ${{ else }}:
- template: templates/build-package-for-nuget.yml
parameters:
DoCompliance: ${{ parameters.DoCompliance }}
DoEsrp: ${{ parameters.DoEsrp }}
IsReleaseBuild: ${{ parameters.IsReleaseBuild }}
NugetVersionSuffix: ${{ parameters.NugetVersionSuffix }}
IsDummyPackage: true
# set flags to do a build with no operators for the dummy package
OperatorSelectionFlags: ''
AdditionalBuildFlags: '--include_ops_by_config ./tools/ci_build/no_ops.config --skip_tests --cmake_extra_defines OCOS_ENABLE_CTEST=OFF'

Просмотреть файл

@ -20,11 +20,11 @@ stages:
- template: mac-shared-lib-build.yml
parameters:
MacosArch: 'arm64'
AdditionalBuildFlags: "${{ parameters.AdditionalBuildFlags }} CMAKE_OSX_ARCHITECTURES=arm64"
AdditionalBuildFlags: "${{ parameters.AdditionalBuildFlags }} --cmake_extra_defines CMAKE_OSX_ARCHITECTURES=arm64"
- template: mac-shared-lib-build.yml
parameters:
MacosArch: 'universal2'
AdditionalBuildFlags: "${{ parameters.AdditionalBuildFlags }} CMAKE_OSX_ARCHITECTURES=\"arm64;x86_64\""
AdditionalBuildFlags: "${{ parameters.AdditionalBuildFlags }} --cmake_extra_defines CMAKE_OSX_ARCHITECTURES=\"arm64;x86_64\""
- job: MacOS_C_API_Package_Publish_All
dependsOn:
- MacOS_C_API_Packaging_CPU_x86_64

Просмотреть файл

@ -14,15 +14,15 @@ parameters:
type: boolean
default: false
- name: IsDummyPackage
displayName: Is this a build of Microsoft.ML.OnnxRuntime.Extensions.Dummy package that has no operators?
type: boolean
default: false
- name: NugetVersionSuffix
displayName: Nuget version suffix
type: string
- name: OrtNugetPackageId
displayName: Package name for nuget
type: string
default: 'Microsoft.ML.OnnxRuntime.Extensions'
- name: OperatorSelectionFlags
displayName: Flags to select operators included. Default is to disable OCOS_ENABLE_CV2 and OCOS_ENABLE_BLINGFIRE
type: string
@ -128,7 +128,6 @@ stages:
# VS2019 has no support for net6 and we need to use msbuild (from the VS install) to do the packing
pool: 'Azure-Pipelines-EO-Windows2022-aiinfra'
variables:
OrtPackageId: ${{ parameters.OrtNugetPackageId }}
breakCodesignValidationInjection: ${{ parameters.DoEsrp }}
steps:
@ -214,20 +213,41 @@ stages:
inputs:
versionSpec: 6.2.1
- task: PowerShell@2
displayName: 'Updating NuSpec'
inputs:
targetType: 'inline'
script: |
$OrtExtVersion=(cat ./version.txt)
python $(Build.SourcesDirectory)\tools\ci_build\update_nuspec_for_native_nuget.py `
--package_version $OrtExtVersion `
--commit_id $(Build.SourceVersion) `
--is_release_build ${{ parameters.IsReleaseBuild }} `
--nuget_version_suffix ${{ parameters.NugetVersionSuffix }}
- ${{ if eq(parameters.IsDummyPackage, false) }}:
- task: PowerShell@2
displayName: 'Updating NativeNuget.NuSpec'
inputs:
targetType: 'inline'
script: |
$OrtExtVersion=(cat ./version.txt)
python $(Build.SourcesDirectory)\tools\ci_build\update_nuspec_for_native_nuget.py `
--package_version $OrtExtVersion `
--commit_id $(Build.SourceVersion) `
--is_release_build ${{ parameters.IsReleaseBuild }} `
--nuget_version_suffix ${{ parameters.NugetVersionSuffix }}
cat $(Build.SourcesDirectory)\nuget\NativeNuget.nuspec
workingDirectory: '$(Build.SourcesDirectory)'
cat $(Build.SourcesDirectory)\nuget\NativeNuget.nuspec
workingDirectory: '$(Build.SourcesDirectory)'
- ${{ else }}:
- task: PowerShell@2
displayName: 'Updating DummyNativeNuget.NuSpec, and props and targets filenames'
inputs:
targetType: 'inline'
script: |
$OrtExtVersion=(cat ./version.txt)
python $(Build.SourcesDirectory)\tools\ci_build\update_nuspec_for_native_nuget.py `
--package_version $OrtExtVersion `
--commit_id $(Build.SourceVersion) `
--is_release_build ${{ parameters.IsReleaseBuild }} `
--nuget_version_suffix ${{ parameters.NugetVersionSuffix }} `
--nuspec_path $(Build.SourcesDirectory)\nuget\DummyNativeNuget.nuspec
gci $(Build.SourcesDirectory)/nuget -Filter *.props -Recurse | Rename-Item -NewName { $_.name -replace 'Extensions', 'Extensions.Dummy' }
gci $(Build.SourcesDirectory)/nuget -Filter *.targets -Recurse | Rename-Item -NewName { $_.name -replace 'Extensions', 'Extensions.Dummy' }
cat $(Build.SourcesDirectory)\nuget\DummyNativeNuget.nuspec
workingDirectory: '$(Build.SourcesDirectory)'
- task: PowerShell@2
displayName: 'Setup for packing'
@ -241,12 +261,21 @@ stages:
workingDirectory: '$(Build.SourcesDirectory)'
- task: NuGetCommand@2
displayName: Packing onnxruntime extensions NuGet-package
inputs:
command: 'pack'
packagesToPack: '$(Build.BinariesDirectory)\nuget\NativeNuget.nuspec'
packDestination: $(Build.ArtifactStagingDirectory)
- ${{ if eq(parameters.IsDummyPackage, false) }}:
- task: NuGetCommand@2
displayName: Packing Microsoft.ML.OnnxRuntime.Extensions NuGet-package
inputs:
command: 'pack'
packagesToPack: '$(Build.BinariesDirectory)\nuget\NativeNuget.nuspec'
packDestination: $(Build.ArtifactStagingDirectory)
- ${{ else }}:
- task: NuGetCommand@2
displayName: Packing Microsoft.ML.OnnxRuntime.Extensions.Dummy NuGet-package
inputs:
command: 'pack'
packagesToPack: '$(Build.BinariesDirectory)\nuget\DummyNativeNuget.nuspec'
packDestination: $(Build.ArtifactStagingDirectory)
- template: esrp_nuget.yml
parameters:

Просмотреть файл

@ -102,6 +102,7 @@ function(disable_all_operators)
set(OCOS_ENABLE_CV2 OFF CACHE INTERNAL "" FORCE)
set(OCOS_ENABLE_VISION OFF CACHE INTERNAL "" FORCE)
set(OCOS_ENABLE_AZURE OFF CACHE INTERNAL "" FORCE)
set(OCOS_ENABLE_AUDIO OFF CACHE INTERNAL "" FORCE)
endfunction()
if (CMAKE_GENERATOR_PLATFORM)

Просмотреть файл

@ -0,0 +1,70 @@
<?xml version='1.0' encoding='utf-8'?>
<package>
<metadata>
<id>Microsoft.ML.OnnxRuntime.Extensions.Dummy</id>
<version>0.1.0</version>
<authors>Microsoft</authors>
<owners>Microsoft</owners>
<description>ONNX Runtime Extensions Dummy NuGet Package</description>
<releaseNotes>
Dummy NuGet package for the .NET platform. The package does not include any custom operator implementations.
It is for usage on iOS with the Microsoft.ML.OnnxRuntime.Managed package to provide a dummy implementation of
the RegisterCustomOps symbol to resolve an iOS specific compile time requirement for that symbol to exist.
This package is required when the user does NOT need to use the real Microsoft.ML.OnnxRuntime.Extensions package.
</releaseNotes>
<copyright>© Microsoft Corporation. All rights reserved.</copyright>
<tags>ONNX ONNXRuntime AI Machine Learning</tags>
<icon>ORT_icon_for_light_bg.png</icon>
<license type="file">LICENSE.txt</license>
<readme>README.md</readme>
<projectUrl>https://github.com/Microsoft/onnxruntime-extensions</projectUrl>
<repository type="git" url="https://github.com/Microsoft/onnxruntime-extensions.git" commit="COMMIT_ID" />
</metadata>
<!-- For simplicity and consistency with the 'real' package we include all the same targets -->
<files>
<file src="LICENSE.txt" target="LICENSE.txt" />
<file src="README.md" target="README.md" />
<file src="ORT_icon_for_light_bg.png" target="ORT_icon_for_light_bg.png" />
<file src="..\ThirdPartyNotices.txt" target="ThirdPartyNotices.txt" />
<!--
NOTE: If you wish to create a local nuget package for testing, update the relevant src paths below
to point to the local build you wish to test, and comment out the entries for any platforms you don't
need in the nuget package.
You will need to rename the existing props and targets files to add the '.Dummy' segment,
as the filename must match the package name.
After renaming the props and targets files run `nuget pack DummyNativeNuget.nuspec` from this directory
to produce the package for local testing.
-->
<!-- Windows and Linux via netstandard -->
<file src="..\nuget-artifacts\onnxruntime-extensions-win-x64\lib\ortextensions.dll" target="runtimes\win-x64\native" />
<file src="..\nuget-artifacts\onnxruntime-extensions-win-x86\lib\ortextensions.dll" target="runtimes\win-x86\native" />
<file src="..\nuget-artifacts\onnxruntime-extensions-win-arm64\lib\ortextensions.dll" target="runtimes\win-arm64\native" />
<file src="..\nuget-artifacts\onnxruntime-extensions-win-arm\lib\ortextensions.dll" target="runtimes\win-arm\native" />
<file src="..\nuget-artifacts\onnxruntime-extensions-linux-aarch64\lib\libortextensions.so" target="runtimes\linux-arm64\native" />
<file src="..\nuget-artifacts\onnxruntime-extensions-linux-x64\lib\libortextensions.so" target="runtimes\linux-x64\native" />
<file src="targets\netstandard\Microsoft.ML.OnnxRuntime.Extensions.Dummy.props" target="build\netstandard1.1" />
<file src="targets\netstandard\Microsoft.ML.OnnxRuntime.Extensions.Dummy.props" target="build\netstandard2.0" />
<file src="targets\netstandard\Microsoft.ML.OnnxRuntime.Extensions.Dummy.targets" target="build\netstandard1.1" />
<file src="targets\netstandard\Microsoft.ML.OnnxRuntime.Extensions.Dummy.targets" target="build\netstandard2.0" />
<!-- Android via Xamarin/MAUI -->
<file src="..\nuget-artifacts\onnxruntime-extensions-android\onnxruntime-extensions.aar" target="runtimes\android\native" />
<file src="targets\monoandroid11.0\Microsoft.ML.OnnxRuntime.Extensions.Dummy.targets" target="build\monoandroid11.0" />
<file src="targets\monoandroid11.0\Microsoft.ML.OnnxRuntime.Extensions.Dummy.targets" target="buildTransitive\monoandroid11.0" />
<file src="targets\net6.0-android\Microsoft.ML.OnnxRuntime.Extensions.Dummy.targets" target="build\net6.0-android31.0" />
<file src="targets\net6.0-android\Microsoft.ML.OnnxRuntime.Extensions.Dummy.targets" target="buildTransitive\net6.0-android31.0" />
<!-- iOS via Xamarin/MAUI. -->
<file src="..\nuget-artifacts\onnxruntime_extensions.xcframework\**" target="runtimes\ios\native\onnxruntime_extensions.xcframework" />
<file src="targets\xamarinios10\Microsoft.ML.OnnxRuntime.Extensions.Dummy.targets" target="build\xamarinios10" />
<file src="targets\xamarinios10\Microsoft.ML.OnnxRuntime.Extensions.Dummy.targets" target="buildTransitive\xamarinios10" />
<file src="targets\net6.0-ios\Microsoft.ML.OnnxRuntime.Extensions.Dummy.targets" target="build\net6.0-ios15.4" />
<file src="targets\net6.0-ios\Microsoft.ML.OnnxRuntime.Extensions.Dummy.targets" target="buildTransitive\net6.0-ios15.4" />
<!-- .net 6 macOS -->
<file src="..\nuget-artifacts\onnxruntime-extensions-osx-x86_64\lib\libortextensions.dylib" target="runtimes\osx.10.14-x64\native" />
<file src="..\nuget-artifacts\onnxruntime-extensions-osx-arm64\lib\libortextensions.dylib" target="runtimes\osx.10.14-arm64\native"/>
<file src="targets\net6.0-macos\Microsoft.ML.OnnxRuntime.Extensions.Dummy.targets" target="build\net6.0-macos12.3" />
<file src="targets\net6.0-macos\Microsoft.ML.OnnxRuntime.Extensions.Dummy.targets" target="buildTransitive\net6.0-macos12.3" />
</files>
</package>

Просмотреть файл

@ -23,7 +23,7 @@ _log = get_logger("build_aar")
def build_for_abi(
build_dir: Path, config: str, abi: str, api_level: int, sdk_path: Path, ndk_path: Path, other_args: list[str]
build_dir: Path, config: str, abi: str, api_level: int, sdk_path: Path, ndk_path: Path, build_py_args: list[str]
):
build_cmd = [
sys.executable,
@ -40,7 +40,7 @@ def build_for_abi(
f"--android_api={api_level}",
f"--android_home={sdk_path}",
f"--android_ndk_path={ndk_path}",
] + other_args
] + build_py_args
run(*build_cmd)
@ -53,7 +53,7 @@ def do_build_by_mode(
api_level: int,
sdk_path: Path,
ndk_path: Path,
other_args: list[str],
build_py_args: list[str]
):
output_dir = output_dir.resolve()
@ -69,7 +69,7 @@ def do_build_by_mode(
if mode in ["build_so_only", "build_aar"]:
for abi in abis:
build_dir = intermediates_dir / abi
build_for_abi(build_dir, config, abi, api_level, sdk_path, ndk_path, other_args)
build_for_abi(build_dir, config, abi, api_level, sdk_path, ndk_path, build_py_args)
# copy JNI library files to jnilibs_dir
jnilibs_dir = base_jnilibs_dir / abi
@ -201,7 +201,7 @@ def parse_args():
"For example: 'build_aar.py <build_aar.py options> -- <build.py options>'.",
)
args, unknown_args = parser.parse_known_args()
args = parser.parse_args()
args.abis = args.abis or _supported_abis.copy()
@ -213,11 +213,11 @@ def parse_args():
args.ndk_path is not None
), "Android NDK path must be provided with --ndk_path or environment variable ANDROID_NDK_HOME."
return args, unknown_args
return args
def main():
args, unknown_args = parse_args()
args = parse_args()
_log.info(f"Building AAR for ABIs: {args.abis}")
@ -229,7 +229,7 @@ def main():
api_level=args.api_level,
sdk_path=args.sdk_path,
ndk_path=args.ndk_path,
other_args=unknown_args,
build_py_args=args.build_py_args
)
_log.info("AAR build complete.")

Просмотреть файл

@ -0,0 +1 @@
# empty config file with no operators for use in build of Microsoft.ML.OnnxRuntime.Extensions.Dummy