-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Refactor props and targets of Microsoft.ML.OnnxRuntime and DllImport #27351
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
|
|
||
| <!-- ========================================================= --> | ||
| <!-- Native include path --> | ||
| <!-- ========================================================= --> | ||
| <ItemDefinitionGroup> | ||
| <ClCompile> | ||
| <AdditionalIncludeDirectories> | ||
| $(MSBuildThisFileDirectory)include; | ||
| %(AdditionalIncludeDirectories) | ||
| </AdditionalIncludeDirectories> | ||
| </ClCompile> | ||
| </ItemDefinitionGroup> | ||
|
|
||
| <!-- ========================================================= --> | ||
| <!-- Windows native linking --> | ||
| <!-- ========================================================= --> | ||
| <ItemDefinitionGroup Condition="'$(PlatformTarget)' == 'x64'"> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this condition also check the target is Windows or do we not have x64/arm64 as platform targets on Linux? |
||
| <Link> | ||
| <AdditionalDependencies> | ||
| $(MSBuildThisFileDirectory)..\..\runtimes\win-x64\native\onnxruntime.lib; | ||
| %(AdditionalDependencies) | ||
| </AdditionalDependencies> | ||
| </Link> | ||
| </ItemDefinitionGroup> | ||
|
|
||
| <ItemDefinitionGroup Condition="'$(PlatformTarget)' == 'ARM64'"> | ||
| <Link> | ||
| <AdditionalDependencies> | ||
| $(MSBuildThisFileDirectory)..\..\runtimes\win-arm64\native\onnxruntime.lib; | ||
| %(AdditionalDependencies) | ||
| </AdditionalDependencies> | ||
| </Link> | ||
| </ItemDefinitionGroup> | ||
|
|
||
| </Project> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
| <!-- ========================================================= --> | ||
| <!-- Block unsupported x86 --> | ||
| <!-- ========================================================= --> | ||
| <Target Name="OnnxRuntime_BlockX86" | ||
| BeforeTargets="Build" | ||
| Condition="'$(PlatformTarget)' == 'x86'"> | ||
| <Error Text="Microsoft.ML.OnnxRuntime does not support x86. Please use x64 or ARM64." /> | ||
| </Target> | ||
| </Project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,146 +1,37 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
|
|
||
| <!-- ========================================================= --> | ||
| <!-- Native include path --> | ||
| <!-- ========================================================= --> | ||
| <ItemDefinitionGroup> | ||
| <ClCompile> | ||
| <AdditionalIncludeDirectories>$(MSBuildThisFileDirectory)../../build/native/include/;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | ||
| <AdditionalIncludeDirectories> | ||
| $(MSBuildThisFileDirectory)..\native\include; | ||
| %(AdditionalIncludeDirectories) | ||
| </AdditionalIncludeDirectories> | ||
| </ClCompile> | ||
| <ResourceCompile> | ||
| <AdditionalIncludeDirectories>$(MSBuildThisFileDirectory)../../build/native/include/;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | ||
| </ResourceCompile> | ||
| </ItemDefinitionGroup> | ||
|
|
||
| <ItemDefinitionGroup Condition="'$(PlatformTarget)' == 'ARM64'"> | ||
| <!-- ========================================================= --> | ||
| <!-- Windows native linking --> | ||
| <!-- ========================================================= --> | ||
| <ItemDefinitionGroup Condition="'$(PlatformTarget)' == 'x64'"> | ||
| <Link> | ||
| <AdditionalDependencies>$(MSBuildThisFileDirectory)../../runtimes/win-arm64/native/onnxruntime.lib;%(AdditionalDependencies)</AdditionalDependencies> | ||
| <AdditionalDependencies> | ||
| $(MSBuildThisFileDirectory)..\..\runtimes\win-x64\native\onnxruntime.lib; | ||
| %(AdditionalDependencies) | ||
| </AdditionalDependencies> | ||
| </Link> | ||
| </ItemDefinitionGroup> | ||
|
|
||
| <ItemDefinitionGroup Condition="'$(PlatformTarget)' == 'ARM'"> | ||
| <ItemDefinitionGroup Condition="'$(PlatformTarget)' == 'ARM64'"> | ||
| <Link> | ||
| <AdditionalDependencies>$(MSBuildThisFileDirectory)../../runtimes/win-arm/native/onnxruntime.lib;%(AdditionalDependencies)</AdditionalDependencies> | ||
| <AdditionalDependencies> | ||
| $(MSBuildThisFileDirectory)..\..\runtimes\win-arm64\native\onnxruntime.lib; | ||
| %(AdditionalDependencies) | ||
| </AdditionalDependencies> | ||
| </Link> | ||
| </ItemDefinitionGroup> | ||
|
|
||
| <ItemDefinitionGroup Condition="'$(PlatformTarget)' == 'x64' OR ('$(PlatformTarget)' == 'AnyCPU' AND '$(Prefer32Bit)' != 'true')"> | ||
| <Link> | ||
| <AdditionalDependencies>$(MSBuildThisFileDirectory)../../runtimes/win-x64/native/onnxruntime.lib;%(AdditionalDependencies)</AdditionalDependencies> | ||
| </Link> | ||
| </ItemDefinitionGroup> | ||
|
|
||
| <PropertyGroup> | ||
| <EnginePlatform Condition="'$(Platform)' == 'ARM64'">arm64</EnginePlatform> | ||
| <EnginePlatform Condition="'$(Platform)' == 'ARM'">arm</EnginePlatform> | ||
| <EnginePlatform Condition="'$(Platform)' != 'Win32' AND '$(Platform)' != 'ARM64'">$(Platform)</EnginePlatform> | ||
| </PropertyGroup> | ||
|
|
||
| <PropertyGroup> | ||
| <OnnxRuntimeBinary>$(MSBuildThisFileDirectory)..\..\runtimes\win-$(EnginePlatform)\native\onnxruntime.dll</OnnxRuntimeBinary> | ||
| </PropertyGroup> | ||
|
|
||
| <!-- Assume apps using the Microsoft.ML.OnnxRuntime.DirectML package only want the DirectML binaries (no need for a build dependency). --> | ||
| <PropertyGroup Label="Globals" Condition="Exists('$(MSBuildThisFileDirectory)include\dml_provider_factory.h')"> | ||
| <Microsoft_AI_DirectML_SkipDebugLayerCopy>true</Microsoft_AI_DirectML_SkipDebugLayerCopy> | ||
| <Microsoft_AI_DirectML_SkipLink>true</Microsoft_AI_DirectML_SkipLink> | ||
| <Microsoft_AI_DirectML_SkipIncludeDir>true</Microsoft_AI_DirectML_SkipIncludeDir> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <!-- x64 --> | ||
| <None Include="$(MSBuildThisFileDirectory)..\..\runtimes\win-x64\native\onnxruntime.dll" | ||
| Condition="('$(PlatformTarget)' == 'x64' OR ('$(PlatformTarget)' == 'AnyCPU' AND '$(Prefer32Bit)' != 'true')) AND | ||
| Exists('$(MSBuildThisFileDirectory)..\..\runtimes\win-x64\native\onnxruntime.dll')"> | ||
| <Link>onnxruntime.dll</Link> | ||
| <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
| <Visible>false</Visible> | ||
| </None> | ||
| <None Include="$(MSBuildThisFileDirectory)..\..\runtimes\win-x64\native\onnxruntime_providers_shared.dll" | ||
| Condition="('$(PlatformTarget)' == 'x64' OR ('$(PlatformTarget)' == 'AnyCPU' AND '$(Prefer32Bit)' != 'true')) AND | ||
| Exists('$(MSBuildThisFileDirectory)..\..\runtimes\win-x64\native\onnxruntime_providers_shared.dll')"> | ||
| <Link>onnxruntime_providers_shared.dll</Link> | ||
| <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
| <Visible>false</Visible> | ||
| </None> | ||
| <None Include="$(MSBuildThisFileDirectory)..\..\runtimes\win-x64\native\onnxruntime_providers_cuda.dll" | ||
| Condition="('$(PlatformTarget)' == 'x64' OR ('$(PlatformTarget)' == 'AnyCPU' AND '$(Prefer32Bit)' != 'true')) AND | ||
| Exists('$(MSBuildThisFileDirectory)..\..\runtimes\win-x64\native\onnxruntime_providers_cuda.dll')"> | ||
| <Link>onnxruntime_providers_cuda.dll</Link> | ||
| <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
| <Visible>false</Visible> | ||
| </None> | ||
| <None Include="$(MSBuildThisFileDirectory)..\..\runtimes\win-x64\native\onnxruntime_providers_dnnl.dll" | ||
| Condition="('$(PlatformTarget)' == 'x64' OR ('$(PlatformTarget)' == 'AnyCPU' AND '$(Prefer32Bit)' != 'true')) AND | ||
| Exists('$(MSBuildThisFileDirectory)..\..\runtimes\win-x64\native\onnxruntime_providers_dnnl.dll')"> | ||
| <Link>onnxruntime_providers_dnnl.dll</Link> | ||
| <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
| <Visible>false</Visible> | ||
| </None> | ||
| <None Include="$(MSBuildThisFileDirectory)..\..\runtimes\win-x64\native\onnxruntime_providers_tensorrt.dll" | ||
| Condition="('$(PlatformTarget)' == 'x64' OR ('$(PlatformTarget)' == 'AnyCPU' AND '$(Prefer32Bit)' != 'true')) AND | ||
| Exists('$(MSBuildThisFileDirectory)..\..\runtimes\win-x64\native\onnxruntime_providers_tensorrt.dll')"> | ||
| <Link>onnxruntime_providers_tensorrt.dll</Link> | ||
| <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
| <Visible>false</Visible> | ||
| </None> | ||
| <None Include="$(MSBuildThisFileDirectory)..\..\runtimes\win-x64\native\onnxruntime_providers_openvino.dll" | ||
| Condition="('$(PlatformTarget)' == 'x64' OR ('$(PlatformTarget)' == 'AnyCPU' AND '$(Prefer32Bit)' != 'true')) AND | ||
| Exists('$(MSBuildThisFileDirectory)..\..\runtimes\win-x64\native\onnxruntime_providers_openvino.dll')"> | ||
| <Link>onnxruntime_providers_openvino.dll</Link> | ||
| <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
| <Visible>false</Visible> | ||
| </None> | ||
| <None Include="$(MSBuildThisFileDirectory)..\..\runtimes\win-x64\native\dnnl.dll" | ||
| Condition="('$(PlatformTarget)' == 'x64' OR ('$(PlatformTarget)' == 'AnyCPU' AND '$(Prefer32Bit)' != 'true')) AND | ||
| Exists('$(MSBuildThisFileDirectory)..\..\runtimes\win-x64\native\dnnl.dll')"> | ||
| <Link>dnnl.dll</Link> | ||
| <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
| <Visible>false</Visible> | ||
| </None> | ||
| <None Include="$(MSBuildThisFileDirectory)..\..\runtimes\win-x64\native\mklml.dll" | ||
| Condition="('$(PlatformTarget)' == 'x64' OR ('$(PlatformTarget)' == 'AnyCPU' AND '$(Prefer32Bit)' != 'true')) AND | ||
| Exists('$(MSBuildThisFileDirectory)..\..\runtimes\win-x64\native\mklml.dll')"> | ||
| <Link>mklml.dll</Link> | ||
| <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
| <Visible>false</Visible> | ||
| </None> | ||
| <None Include="$(MSBuildThisFileDirectory)..\..\runtimes\win-x64\native\libiomp5md.dll" | ||
| Condition="('$(PlatformTarget)' == 'x64' OR ('$(PlatformTarget)' == 'AnyCPU' AND '$(Prefer32Bit)' != 'true')) AND | ||
| Exists('$(MSBuildThisFileDirectory)..\..\runtimes\win-x64\native\libiomp5md.dll')"> | ||
| <Link>libiomp5md.dll</Link> | ||
| <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
| <Visible>false</Visible> | ||
| </None> | ||
|
|
||
| <!-- arm64 --> | ||
| <None Include="$(MSBuildThisFileDirectory)..\..\runtimes\win-arm64\native\onnxruntime.dll" | ||
| Condition="'$(PlatformTarget)' == 'ARM64' AND | ||
| Exists('$(MSBuildThisFileDirectory)..\..\runtimes\win-arm64\native\onnxruntime.dll')"> | ||
| <Link>onnxruntime.dll</Link> | ||
| <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
| <Visible>false</Visible> | ||
| </None> | ||
| <None Include="$(MSBuildThisFileDirectory)..\..\runtimes\win-arm64\native\onnxruntime_providers_shared.dll" | ||
| Condition="'$(PlatformTarget)' == 'ARM64' AND | ||
| Exists('$(MSBuildThisFileDirectory)..\..\runtimes\win-arm64\native\onnxruntime_providers_shared.dll')"> | ||
| <Link>onnxruntime_providers_shared.dll</Link> | ||
| <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
| <Visible>false</Visible> | ||
| </None> | ||
|
|
||
| <!-- arm --> | ||
| <None Include="$(MSBuildThisFileDirectory)..\..\runtimes\win-arm\native\onnxruntime.dll" | ||
| Condition="'$(PlatformTarget)' == 'ARM' AND | ||
| Exists('$(MSBuildThisFileDirectory)..\..\runtimes\win-arm\native\onnxruntime.dll')"> | ||
| <Link>onnxruntime.dll</Link> | ||
| <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
| <Visible>false</Visible> | ||
| </None> | ||
| <None Include="$(MSBuildThisFileDirectory)..\..\runtimes\win-arm\native\onnxruntime_providers_shared.dll" | ||
| Condition="'$(PlatformTarget)' == 'ARM' AND | ||
| Exists('$(MSBuildThisFileDirectory)..\..\runtimes\win-arm\native\onnxruntime_providers_shared.dll')"> | ||
| <Link>onnxruntime_providers_shared.dll</Link> | ||
| <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
| <Visible>false</Visible> | ||
| </None> | ||
| </ItemGroup> | ||
| </Project> | ||
| </Project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,44 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
| <Target Name="Microsoft_ML_OnnxRuntime_CheckPrerequisites" BeforeTargets="BeforeBuild"> | ||
| <!-- | ||
| Special case .NET Core portable applications. When building a portable .NET Core app, | ||
| the PlatformTarget is empty, and you don't know until runtime (i.e. which dotnet.exe) | ||
| what processor architecture will be used. | ||
| --> | ||
| <Error Condition="('$(PlatformTarget)' != 'x64' AND '$(PlatformTarget)' != 'arm32' AND '$(PlatformTarget)' != 'arm64' AND '$(PlatformTarget)' != 'x86' AND '$(PlatformTarget)' != 'AnyCPU') AND | ||
| ('$(OutputType)' == 'Exe' OR '$(OutputType)'=='WinExe') AND | ||
| !('$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND '$(PlatformTarget)' == '') AND | ||
| $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) != 'ios' AND | ||
| '$(SuppressOnnxRuntimePlatformCompatibilityError)' != 'true'" | ||
| Text="Microsoft.ML.OnnxRuntime only supports the AnyCPU, x64, arm32, arm64 and x86 platforms at this time."/> | ||
| <!-- ========================================================= --> | ||
| <!-- 1. Block unsupported x86 --> | ||
| <!-- ========================================================= --> | ||
| <Target Name="OnnxRuntime_BlockUnsupportedPlatform" | ||
| BeforeTargets="Build" | ||
| Condition=" | ||
| '$(SuppressOnnxRuntimePlatformCompatibilityError)' != 'true' AND | ||
| $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) != 'ios' AND | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AFAIK there are no 32-bit iOS builds. |
||
| $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) != 'android' AND | ||
| '$(PlatformTarget)' == 'x86'"> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need a check for an AnyCPU build (based on the previous implementation I'm guessing PlatformTarget may not have a value in that case) with Prefer32Bit set to true? |
||
|
|
||
| <Error Text="Microsoft.ML.OnnxRuntime does not support x86. Please use x64 or ARM64." /> | ||
|
|
||
| </Target> | ||
|
|
||
|
|
||
| <!-- ========================================================= --> | ||
| <!-- 2. Legacy .NET Framework fallback copy logic --> | ||
| <!-- (ONLY for non-SDK projects, which only run on Windows.) --> | ||
| <!-- ========================================================= --> | ||
| <PropertyGroup Condition="'$(UsingMicrosoftNETSdk)' != 'true' AND '$(OS)' == 'Windows_NT'"> | ||
| <!-- Normalize architecture. Default to x64 for AnyCPU/unspecified as we don't support x86. --> | ||
| <_OrtArch>x64</_OrtArch> | ||
| <_OrtArch Condition="'$(PlatformTarget)' == 'ARM64' OR '$(Platform)' == 'ARM64'">arm64</_OrtArch> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup Condition="'$(UsingMicrosoftNETSdk)' != 'true' AND '$(_OrtArch)' != '' AND '$(OS)' == 'Windows_NT'"> | ||
| <_OrtNativeFiles Include="$(MSBuildThisFileDirectory)..\..\runtimes\win-$(_OrtArch)\native\*.dll" /> | ||
| </ItemGroup> | ||
|
|
||
| <Target Name="OnnxRuntime_CopyNativeFallback" | ||
| AfterTargets="Build" | ||
| Condition="'$(UsingMicrosoftNETSdk)' != 'true' AND '@(_OrtNativeFiles)' != ''"> | ||
|
|
||
| <Message Importance="Low" | ||
| Text="Copying ONNX Runtime native binaries for legacy project." /> | ||
|
|
||
| <Copy SourceFiles="@(_OrtNativeFiles)" | ||
| DestinationFolder="$(OutDir)" | ||
| SkipUnchangedFiles="true" /> | ||
| </Target> | ||
| </Project> | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need this for development scenarios using an AnyCPU build? If that is the case dotnet might not copy from the runtimes directory to the build output as I don't think there's a specific RID at that point. It would do the copy when publishing though.