Skip to content

Commit

Permalink
Add targets files for new .net6 frameworks (#12016)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
skottmckay authored and RandyShuai committed Jul 6, 2022
1 parent c2f52cd commit e849139
Show file tree
Hide file tree
Showing 13 changed files with 155 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'">
Expand Down
8 changes: 0 additions & 8 deletions csharp/src/Microsoft.ML.OnnxRuntime/NativeLib.android.cs

This file was deleted.

8 changes: 0 additions & 8 deletions csharp/src/Microsoft.ML.OnnxRuntime/NativeLib.ios.cs

This file was deleted.

8 changes: 0 additions & 8 deletions csharp/src/Microsoft.ML.OnnxRuntime/NativeLib.net.cs

This file was deleted.

8 changes: 0 additions & 8 deletions csharp/src/Microsoft.ML.OnnxRuntime/NativeLib.netstandard.cs

This file was deleted.

15 changes: 15 additions & 0 deletions csharp/src/Microsoft.ML.OnnxRuntime/NativeMethods.shared.cs
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,21 @@ static NativeMethods()
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();

Expand Down
Original file line number Diff line number Diff line change
@@ -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>
21 changes: 21 additions & 0 deletions csharp/src/Microsoft.ML.OnnxRuntime/targets/net6.0-ios/targets.xml
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions tools/ci_build/github/azure-pipelines/templates/c-api-cpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
81 changes: 80 additions & 1 deletion tools/nuget/generate_nuspec_for_native_nuget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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">')
Expand Down Expand Up @@ -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"
Expand All @@ -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(
Expand Down

0 comments on commit e849139

Please sign in to comment.