Skip to content
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

1DS C++ SDK bindings for Unity C# layer #1099

Open
wants to merge 31 commits into
base: main
Choose a base branch
from

Conversation

maxgolov
Copy link
Contributor

@maxgolov maxgolov commented Feb 12, 2023

C# projection layer - old work item #4

It took us a few years to realize that we finally need 1DS C++ SDK bindings for Unity C# code in Microsoft Mesh.

Implementation should work well under the following environments:

  • Unity WebAssembly IL2CPP (Unity transpiles C# to C++ to WebAssembly)
  • Unity Editor with Mono 2.x
  • Unity based on NETStandard 2.x+

List of changes:

  • mod mat.h to pack structure. This enables predictable C API interop between C# layer and C.
  • example that shows how to P/Invoke from .NET to shared 1DS library.

Unity wrapper will be maintained elsewhere outside of this repo.

@maxgolov maxgolov changed the title Maxgolov/shared library 1DS C++ SDK bindings for Unity C# layer Feb 12, 2023
@maxgolov maxgolov changed the title 1DS C++ SDK bindings for Unity C# layer [WIP] 1DS C++ SDK bindings for Unity C# layer Feb 12, 2023
@maxgolov maxgolov marked this pull request as draft February 12, 2023 22:27
@maxgolov maxgolov marked this pull request as ready for review February 14, 2023 18:08
@maxgolov maxgolov changed the title [WIP] 1DS C++ SDK bindings for Unity C# layer 1DS C++ SDK bindings for Unity C# layer Feb 14, 2023
<Content Include="$(ProjectDir)\..\..\Solutions\out\Debug\x64\win32-dll\*.*" Visible="False" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Json" Version="4.7.0" />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this works for .NET Standard 2.x , unfortunately Newtonsoft works better in Unity. I'm not changing it here since this will be taken care of elsewhere, in the implementation of Unity Package outside of 1DS repository.

using System.Diagnostics;
using Microsoft.Telemetry.Core;

#if HAVE_SYSTEM_JSON
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to define it.

@@ -0,0 +1,19 @@
# .NET Core wrapper example for 1DS C/C++ SDK

Note that this wrapper is incomplete simple reference implementation that illustrates how to use 1DS C API from cross-platform .NET Core application.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll change the wording of incomplete to provides the same level of functionality as C API, i.e. some features are accessible only from C++ layer. This still allows the native code initializer to use SetContext(...) efficiently, to populate common known fields, like session id, etc.. C# layer becomes guest to host initialized by native library.

@lalitb
Copy link
Contributor

lalitb commented Mar 2, 2023

In case the code under wrappers/netcore is to demonstrate calling capi from C# code using P/Invoke, should we move this code under example directory. The capi related code changes look good in general, though I am not expert on P/Invoke part of example code.

@maxgolov
Copy link
Contributor Author

maxgolov commented Mar 6, 2023

should we move this code under example directory?

I can split it into two parts:

  • EventNativeAPI.cs - belongs in wrappers dir. This is nearly identical to what we use in the product.
  • Program.cs - belongs in examples dir.

@lalitb
Copy link
Contributor

lalitb commented Mar 7, 2023

I can split it into two parts:

Yes, that will make sense. Thanks.

@maxgolov
Copy link
Contributor Author

Sorry for delay. We integrated it on our end, so I put it on a back-burner.
I'll get back to this.

@maxgolov maxgolov self-assigned this Aug 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants