Add targets files for new .net6 frameworks (#12016)

* Add net6 targets.
Remove maccatalyst as we don't have a native build targetting that.

* Set platform in macos targets

* Add targetFramework entries

* Move NativeLib.DllName definition and set using preprocessor values for simplicity. Couldn't get it to build with the preprocessor based setup when it was in a separate file.

Update the nuspec generation to set platform version for .net6 targets. TODO: Validate versions. I copied them from the managed nuget package the packaging pipeline generated prior to adding targets. Possibly w could/should lower some of the versions.

Hopefully the need to specify a version goes away when the release version of VS2022 supports .net6.

* Try android 31.1 as https://github.com/actions/virtual-environments/blob/main/images/win/Windows2022-Readme.md suggests that should be available on the CI machines

* Fix patch version mismatch
Add some extra debug info in case it helps

* Debug nuget location in CI

* Add workspace entry back in

* Add steps

* One more attempt with hardcoded nuget.exe path and original android31.0 version

* Better fix - found explicit nuget download and updated version there.

* flake8 fixes

* Fix black complaints.

* Exit Microsoft_ML_OnnxRuntime_CheckPrerequisites for net6 iOS.

* Removed outdated comment
This commit is contained in:
Scott McKay 2022-07-02 02:13:55 +10:00 committed by GitHub
parent 3e6b8d159a
commit bfe1eca10c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 155 additions and 42 deletions

View file

@ -37,7 +37,7 @@
we can add .net6 support to other packages later as needed -->
<PropertyGroup Condition="('$(OrtPackageId)' == 'Microsoft.ML.OnnxRuntime' OR
'$(OrtPackageId)' == 'Microsoft.ML.OnnxRuntime.Gpu')">
<Net6Targets>net6.0;net6.0-android;net6.0-ios;net6.0-maccatalyst;net6.0-macos</Net6Targets>
<Net6Targets>net6.0;net6.0-android;net6.0-ios;net6.0-macos</Net6Targets>
</PropertyGroup>
<PropertyGroup Condition="'$(SelectedTargets)'=='PreNet6'">

View file

@ -1,8 +0,0 @@
namespace Microsoft.ML.OnnxRuntime
{
internal class NativeLib
{
// define the library name required for android
internal const string DllName = "libonnxruntime.so";
}
}

View file

@ -1,8 +0,0 @@
namespace Microsoft.ML.OnnxRuntime
{
internal class NativeLib
{
// define the library name required for iOS
internal const string DllName = "__Internal";
}
}

View file

@ -1,8 +0,0 @@
namespace Microsoft.ML.OnnxRuntime
{
internal class NativeLib
{
// define the library name required for net targets
internal const string DllName = "onnxruntime";
}
}

View file

@ -1,8 +0,0 @@
namespace Microsoft.ML.OnnxRuntime
{
internal class NativeLib
{
// define the library name required for netstandard targets
internal const string DllName = "onnxruntime";
}
}

View file

@ -425,6 +425,21 @@ namespace Microsoft.ML.OnnxRuntime
typeof(DSessionOptionsAppendExecutionProvider));
}
internal class NativeLib
{
#if __ANDROID__
// define the library name required for android
internal const string DllName = "libonnxruntime.so";
#elif __IOS__
// define the library name required for iOS
internal const string DllName = "__Internal";
#else
internal const string DllName = "onnxruntime";
#endif
// TODO: Does macos need special handling or will 'onnxruntime' -> libonnxruntime.dylib?
}
[DllImport(NativeLib.DllName, CharSet = CharSet.Ansi)]
public static extern ref OrtApiBase OrtGetApiBase();

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Condition=" '$(AndroidApplication)'=='true' ">
<AndroidLibrary Include="$(MSBuildThisFileDirectory)..\..\runtimes\android\native\*">
<Link>%(Filename)%(Extension)</Link>
</AndroidLibrary>
</ItemGroup>
</Project>

View file

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Condition="('$(OutputType)'!='Library' OR '$(IsAppExtension)'=='True')">
<NativeReference Condition="'$(Platform)' == 'iPhoneSimulator'" Include="$(MSBuildThisFileDirectory)..\..\runtimes\ios\native\onnxruntime.xcframework\ios-arm64_x86_64-simulator\onnxruntime.framework">
<Kind>Framework</Kind>
<IsCxx>True</IsCxx>
<SmartLink>True</SmartLink>
<ForceLoad>True</ForceLoad>
<LinkerFlags>-lc++</LinkerFlags>
<WeakFrameworks>CoreML</WeakFrameworks>
</NativeReference>
<NativeReference Condition="'$(Platform)' == 'iPhone'" Include="$(MSBuildThisFileDirectory)..\..\runtimes\ios\native\onnxruntime.xcframework\ios-arm64\onnxruntime.framework">
<Kind>Framework</Kind>
<IsCxx>True</IsCxx>
<SmartLink>True</SmartLink>
<ForceLoad>True</ForceLoad>
<LinkerFlags>-lc++</LinkerFlags>
<WeakFrameworks>CoreML</WeakFrameworks>
</NativeReference>
</ItemGroup>
</Project>

View file

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Condition="('$(OutputType)'!='Library' OR '$(IsAppExtension)'=='True')">
<NativeReference Condition="'$(Platform)' == 'arm64'" Include="$(MSBuildThisFileDirectory)..\..\runtimes\osx.10.14-arm64\native\libonnxruntime.dylib">
<Kind>Framework</Kind>
<IsCxx>True</IsCxx>
<SmartLink>True</SmartLink>
<ForceLoad>True</ForceLoad>
<LinkerFlags>-lc++</LinkerFlags>
<WeakFrameworks>CoreML</WeakFrameworks>
</NativeReference>
<NativeReference Condition="'$(Platform)' == 'x64'" Include="$(MSBuildThisFileDirectory)..\..\runtimes\osx.10.14-x64\native\libonnxruntime.dylib">
<Kind>Framework</Kind>
<IsCxx>True</IsCxx>
<SmartLink>True</SmartLink>
<ForceLoad>True</ForceLoad>
<LinkerFlags>-lc++</LinkerFlags>
<WeakFrameworks>CoreML</WeakFrameworks>
</NativeReference>
</ItemGroup>
</Project>

View file

@ -9,7 +9,8 @@
<Error Condition="('$(PlatformTarget)' != 'x64' AND '$(PlatformTarget)' != 'x86' AND '$(PlatformTarget)' != 'AnyCPU') AND
('$(OutputType)' == 'Exe' OR '$(OutputType)'=='WinExe') AND
!('$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND '$(PlatformTarget)' == '') AND
'$(TargetFrameworkIdentifier)' != 'Xamarin.iOS' AND
('$(TargetFrameworkIdentifier)' != 'Xamarin.iOS' AND
$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) != 'ios') AND
'$(SuppressOnnxRuntimePlatformCompatibilityError)' != 'true'"
Text="Microsoft.ML.OnnxRuntime only supports the AnyCPU, x64, and x86 platforms at this time."/>
</Target>

View file

@ -485,16 +485,16 @@ jobs:
displayName: 'Create models link'
- task: NuGetToolInstaller@0
displayName: Use Nuget 5.7.0
displayName: Use Nuget 6.2.1
inputs:
versionSpec: 5.7.0
versionSpec: 6.2.1
- task: PowerShell@2
displayName: Install .NET 6 workloads
inputs:
targetType: 'inline'
script: |
dotnet workload install android ios maccatalyst macos
dotnet workload install android ios macos
workingDirectory: '$(Build.SourcesDirectory)\csharp'
- task: PowerShell@2

View file

@ -423,18 +423,18 @@ jobs:
workingDirectory: '$(Build.BinariesDirectory)'
displayName: 'Create models link'
- task: NuGetToolInstaller@0
displayName: Use Nuget 5.7.0
displayName: Use Nuget 6.2.1
inputs:
versionSpec: 5.7.0
versionSpec: 6.2.1
- task: PowerShell@2
displayName: Install .NET 6 workloads
inputs:
targetType: 'inline'
script: |
dotnet workload install android ios maccatalyst macos
dotnet workload install android ios macos
workingDirectory: '$(Build.SourcesDirectory)\csharp'
- task: PowerShell@2
displayName: Build Microsoft.ML.OnnxRuntime .NET 6 targets using dotnet
inputs:

View file

@ -240,6 +240,18 @@ def generate_dependencies(xml_text, package_name, version, dependency_id, depend
xml_text.append('<group targetFramework="xamarinios10">')
xml_text.append('<dependency id="Microsoft.ML.OnnxRuntime.Managed"' + ' version="' + version + '"/>')
xml_text.append("</group>")
# Support net6.0-android
xml_text.append('<group targetFramework="net6.0-android31.0">')
xml_text.append('<dependency id="Microsoft.ML.OnnxRuntime.Managed"' + ' version="' + version + '"/>')
xml_text.append("</group>")
# Support net6.0-ios
xml_text.append('<group targetFramework="net6.0-ios15.4">')
xml_text.append('<dependency id="Microsoft.ML.OnnxRuntime.Managed"' + ' version="' + version + '"/>')
xml_text.append("</group>")
# Support net6.0-macos
xml_text.append('<group targetFramework="net6.0-macos12.3">')
xml_text.append('<dependency id="Microsoft.ML.OnnxRuntime.Managed"' + ' version="' + version + '"/>')
xml_text.append("</group>")
# Support Native C++
if include_dml:
xml_text.append('<group targetFramework="native">')
@ -861,7 +873,6 @@ def generate_files(list, args):
"monoandroid11.0",
args.package_name + ".targets",
)
os.system(copy_command + " " + monoandroid_source_targets + " " + monoandroid_target_targets)
xamarinios_source_targets = os.path.join(
args.sources_path, "csharp", "src", "Microsoft.ML.OnnxRuntime", "targets", "xamarinios10", "targets.xml"
@ -875,17 +886,85 @@ def generate_files(list, args):
"xamarinios10",
args.package_name + ".targets",
)
net6_android_source_targets = os.path.join(
args.sources_path,
"csharp",
"src",
"Microsoft.ML.OnnxRuntime",
"targets",
"net6.0-android",
"targets.xml",
)
net6_android_target_targets = os.path.join(
args.sources_path,
"csharp",
"src",
"Microsoft.ML.OnnxRuntime",
"targets",
"net6.0-android",
args.package_name + ".targets",
)
net6_ios_source_targets = os.path.join(
args.sources_path, "csharp", "src", "Microsoft.ML.OnnxRuntime", "targets", "net6.0-ios", "targets.xml"
)
net6_ios_target_targets = os.path.join(
args.sources_path,
"csharp",
"src",
"Microsoft.ML.OnnxRuntime",
"targets",
"net6.0-ios",
args.package_name + ".targets",
)
net6_macos_source_targets = os.path.join(
args.sources_path, "csharp", "src", "Microsoft.ML.OnnxRuntime", "targets", "net6.0-macos", "targets.xml"
)
net6_macos_target_targets = os.path.join(
args.sources_path,
"csharp",
"src",
"Microsoft.ML.OnnxRuntime",
"targets",
"net6.0-macos",
args.package_name + ".targets",
)
os.system(copy_command + " " + monoandroid_source_targets + " " + monoandroid_target_targets)
os.system(copy_command + " " + xamarinios_source_targets + " " + xamarinios_target_targets)
os.system(copy_command + " " + net6_android_source_targets + " " + net6_android_target_targets)
os.system(copy_command + " " + net6_ios_source_targets + " " + net6_ios_target_targets)
os.system(copy_command + " " + net6_macos_source_targets + " " + net6_macos_target_targets)
files_list.append("<file src=" + '"' + monoandroid_target_targets + '" target="build\\monoandroid11.0" />')
files_list.append(
"<file src=" + '"' + monoandroid_target_targets + '" target="buildTransitive\\monoandroid11.0" />'
)
files_list.append("<file src=" + '"' + xamarinios_target_targets + '" target="build\\xamarinios10" />')
files_list.append(
"<file src=" + '"' + xamarinios_target_targets + '" target="buildTransitive\\xamarinios10" />'
)
files_list.append(
"<file src=" + '"' + net6_android_target_targets + '" target="build\\net6.0-android31.0" />'
)
files_list.append(
"<file src=" + '"' + net6_android_target_targets + '" target="buildTransitive\\net6.0-android31.0" />'
)
files_list.append("<file src=" + '"' + net6_ios_target_targets + '" target="build\\net6.0-ios15.4" />')
files_list.append(
"<file src=" + '"' + net6_ios_target_targets + '" target="buildTransitive\\net6.0-ios15.4" />'
)
files_list.append("<file src=" + '"' + net6_macos_target_targets + '" target="build\\net6.0-macos12.3" />')
files_list.append(
"<file src=" + '"' + net6_macos_target_targets + '" target="buildTransitive\\net6.0-macos12.3" />'
)
# Process License, ThirdPartyNotices, Privacy
files_list.append("<file src=" + '"' + os.path.join(args.sources_path, "LICENSE.txt") + '" target="LICENSE.txt" />')
files_list.append(