microsoft / angle

ANGLE: OpenGL ES to DirectX translation
Other
615 stars 166 forks source link

Adding the ANGLE NuGet package to Visual C# UAP projects #99

Closed humairl closed 7 years ago

humairl commented 7 years ago

Adding the ANGLE.WindowsStore NuGet package as a dependency of a Visual C# UAP project does not add the corresponding libraries to the final build, as the package only targets the native framework.

Our setup consists of such a Visual C# UAP project which has a dependency to a shared library running unmanaged code. This library can optionally make use of the GPU in case of GLES and EGL libraries being present. Hence, it would be great if we could include ANGLE for GPU support.

Are you aware of any known workarounds for this problem? We would also be happy to work on a patch for the NuGet package to solve our problem.

austinkinross commented 7 years ago

Hi humairl, I'll try to investigate this soon. We've had some trouble in the past with the NuGet package in C# projects, but I thought those issues were all resolved.

One potential solution is to manually add the ANGLE binaries to your C# project. If you download the ANGLE NuGet package (which should be a .nupkg file) and rename it to a .zip, then you can find the ANGLE binaries in the "bin\UAP" folder.

JimSEOW commented 7 years ago

Would you consider providing templates for c# Angle project? https://github.com/Microsoft/angle/issues/93

humairl commented 7 years ago

Hi austinkinross, thank you for investigating the issue. I already tried to add the binaries manually for testing, which worked for me. We are planning to release NuGet packages with our software in the future. Hence, it would be great if we could add ANGLE as a dependency instead of having to also maintain the ANGLE binaries in our own package.

humairl commented 7 years ago

Do you already know a time frame for fixing the C# project support? Please tell us if we can help fixing this issue by contributing something.

austinkinross commented 7 years ago

Are you able to make your native project reference the NuGet package?

NuGet references should be transitive, so if your unmanaged library references the NuGet package then your C# project should automatically pick up the ANGLE binaries. This is typically how we've solved this problem in the past when we've been working with C# projects that reference native projects using ANGLE (and is the problem we fixed in issue 43 above).

austinkinross commented 7 years ago

(Also: I'm afraid that the code for creating our NuGet package isn't on GitHub, sorry!)

humairl commented 7 years ago

In our scenario we do not actually have a native project to reference the NuGet package. Our use-case is a customer having a C# project who adds our NuGet package as a dependency. This NuGet package wraps unmanaged code capable of (optionally) loading the ANGLE binaries at runtime. If the ANGLE libraries are included in the application, they are used by our native code, if not, we use a different code path. ANGLE is essentially an optional dependency in our use-case and the user may decide to not include it if he doesn't agree to the license terms of the ANGLE project. Currently this use-case is not supported by the ANGLE NuGet package because the ANGLE libraries are not correctly picked up when the ANGLE dependency is added to the C# project.

Would you consider adding the NuGet packaging sources on GitHub, so we could make a suggestion of how to support C# projects?

austinkinross commented 7 years ago

Thank you for explaining your scenario! If you investigate the required changes to the NuGet package then we would be happy to update the package.

Our code for creating the NuGet package really just calls 'nuget.exe pack' with our ANGLE.WindowsStore.nuspec file. My recommendation would be to open up the .nupkg and try modifying the various NuGet files in-place to see if you can make them fully support C# projects.

The .nuspec that we pass to 'nuget.exe' is similar to the one that can be found inside the NuGet package itself if you rename it to a .zip file:

<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
    <metadata>
        <id>ANGLE.WindowsStore</id>
        <version>0.0.0-SpecifyVersionOnCommandline</version>
        <title>ANGLE for Windows Store (UWP)</title>
        <authors>Microsoft</authors>
        <owners>angle,microsoft</owners>
        <description>Runs OpenGL ES content on Windows by translating OpenGL ES API calls to DirectX 11 API calls.
Targets Universal Windows 10 apps (UWP). See 'ANGLE.WindowsStore.win81' for 8.1 apps.</description>
        <projectUrl>http://github.com/MSOpenTech/angle/wiki</projectUrl>
        <licenseUrl>http://github.com/MSOpenTech/angle/blob/ms-master/LICENSE</licenseUrl>
        <requireLicenseAcceptance>false</requireLicenseAcceptance>
        <copyright>Copyright (C) 2002-2013 The ANGLE Project Authors. Portions Copyright (C) Microsoft Corporation.</copyright>
        <tags>OpenGL ES GLES GLSL Direct3D graphics 3D</tags>
    </metadata>

    <files>
      <!-- UAP -->
      <file src="$bin$\10\src\Release_Win32\libEGL.dll" target="bin\UAP\Win32" />
      <file src="$bin$\10\src\Release_Win32\libGLESv2.dll" target="bin\UAP\Win32" />
      <file src="..\Enlistment\winrt\10\src\Release_Win32\lib\libEGL.lib" target="bin\UAP\Win32" />
      <file src="..\Enlistment\winrt\10\src\Release_Win32\lib\libGLESv2.lib" target="bin\UAP\Win32" />

      <file src="$bin$\10\src\Release_x64\libEGL.dll" target="bin\UAP\x64" />
      <file src="$bin$\10\src\Release_x64\libGLESv2.dll" target="bin\UAP\x64" />
      <file src="..\Enlistment\winrt\10\src\Release_x64\lib\libEGL.lib" target="bin\UAP\x64" />
      <file src="..\Enlistment\winrt\10\src\Release_x64\lib\libGLESv2.lib" target="bin\UAP\x64" />

      <file src="$bin$\10\src\Release_ARM\libEGL.dll" target="bin\UAP\ARM" />
      <file src="$bin$\10\src\Release_ARM\libGLESv2.dll" target="bin\UAP\ARM" />
      <file src="..\Enlistment\winrt\10\src\Release_ARM\lib\libEGL.lib" target="bin\UAP\ARM" />
      <file src="..\Enlistment\winrt\10\src\Release_ARM\lib\libGLESv2.lib" target="bin\UAP\ARM" />

      <!-- Headers -->
      <file src="..\Enlistment\include\GLES2\gl2.h" target="Include\GLES2" />
      <file src="..\Enlistment\include\GLES2\gl2ext.h" target="Include\GLES2" />
      <file src="..\Enlistment\include\GLES2\gl2platform.h" target="Include\GLES2" />
      <file src="..\Enlistment\include\GLES3\gl3.h" target="Include\GLES3" />
      <file src="..\Enlistment\include\GLES3\gl3platform.h" target="Include\GLES3" />
      <file src="..\Enlistment\include\GLES3\gl31.h" target="Include\GLES3" />
      <file src="..\Enlistment\include\GLES3\gl32.h" target="Include\GLES3" />
      <file src="..\Enlistment\include\EGL\egl.h" target="Include\EGL" />
      <file src="..\Enlistment\include\EGL\eglext.h" target="Include\EGL" />
      <file src="..\Enlistment\include\EGL\eglplatform.h" target="Include\EGL" />
      <file src="..\Enlistment\include\KHR\khrplatform.h" target="Include\KHR" />
      <file src="..\Enlistment\include\angle_windowsstore.h" target="Include" />

      <!-- Build scripts -->
      <file src="ANGLE.WindowsStore.targets" target="build\native" />

      <!-- Other files -->
      <file src="..\Enlistment\AUTHORS" />
      <file src="..\Enlistment\CONTRIBUTORS" />
      <file src="..\Enlistment\LICENSE" />
      <file src="privacy.txt" />

      <!-- SHA-1 hash of the git HEAD this package was built from -->
      <file src="obj\ANGLE.githash.txt" />
    </files>
</package>

Other than this, I can't think of anything else to share that will be useful to your investigation!

I hope this helps and good luck!

humairl commented 7 years ago

Thank you for your explanation and the .nuspec file. I finally had some time to investigate the necessary changes. A solution to support C# projects would be to add the ANGLE.WindowsStore.managed.targets file (see below) for uwp, win81 and wpa81 targets. Essentially, it just copies the ANGLE binaries to the final executable.

ANGLE.WindowsStore.managed.targets:

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <PropertyGroup>
    <angle-DeviceType Condition="'$(TargetPlatformIdentifier)' == 'UAP'">UAP</angle-DeviceType>
    <angle-DeviceType Condition="'$(TargetPlatformIdentifier)' == 'Windows'">Windows</angle-DeviceType>
    <angle-DeviceType Condition="'$(TargetPlatformIdentifier)' == 'WindowsPhoneApp'">Phone</angle-DeviceType>

    <angle-Platform Condition="'$(Platform)' != 'x86'">$(Platform)</angle-Platform>
    <angle-Platform Condition="'$(Platform)' == 'x86'">Win32</angle-Platform>

    <angle-BinPath>$(MSBuildThisFileDirectory)..\..\bin\$(angle-DeviceType)\$(angle-Platform)</angle-BinPath>
  </PropertyGroup>

  <ItemGroup Label="ANGLE">
    <NativeLibs Include="$(angle-BinPath)\*.dll" />
    <Content Include="@(NativeLibs)">
      <Link>%(FileName)%(Extension)</Link>
      <Visible>true</Visible>
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
  </ItemGroup>

</Project>

The following lines have to be added to the .nupkg files to include ANGLE.WindowsStore.managed.targets in the final NuGet package:

Angle.WindowsStore:

<file src="ANGLE.WindowsStore.managed.targets" target="build\uap\ANGLE.WindowsStore.targets" />

Angle.WindowsStore.win81:

<file src="ANGLE.WindowsStore.managed.targets" target="build\win81\ANGLE.WindowsStore.win81.targets" />
<file src="ANGLE.WindowsStore.managed.targets" target="build\wpa81\ANGLE.WindowsStore.win81.targets" />

What do you think of this solution?

austinkinross commented 7 years ago

Thanks a lot for taking the time to investigate this. We are validating a similar change internally, which we hope to include in our next NuGet package (which should be released soon).

Thanks again! Austin

humairl commented 7 years ago

Sounds good, thank you for the feedback!

Looking forward to the next release. :) Luc

austinkinross commented 7 years ago

The latest version of the UWP NuGet package (v2.1.13) should now support your C# scenario. Please let us know if you have any problems with it.

Thanks for your interest in ANGLE!