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

Experimental .Net support #371

Open
wants to merge 57 commits into
base: master
Choose a base branch
from
Open

Conversation

AdamRzepka
Copy link

@AdamRzepka AdamRzepka commented Jan 8, 2021

Generating .Net glue code. This time, I had a chance to dive into the typemap system of flapigen and I was able to do this module in more "idiomatic" fashion (in contrast to Python support).

Stability

I still haven't grasp the test framework of flapigen. However, the example dotnet_tests project performs basic tests. The module was also tested in our production code with quite big glue.rs.in files (6k lines in total). We use exactly the same file to export C++ and Python bindings.

How to use it

It generates two artifacts:

  • Native dll (or so or dylib), tailored for PInvoke usage. The client application must be able to find this dll at runtime. The simplest way for this is to put it into the same directory as exe file.
  • C# project with generated code, that wraps raw PInvoke calls with high-level C# API. It produces second dll - managed one. The client application csproj must reference this dll.

Take a look at dotnet_tests project and test_dotnet function in ci_build_and_test to get the idea, how to integrate this into your application.

What's missing

  • Interfaces
  • Callbacks

@sisso
Copy link

sisso commented Sep 6, 2021

@AdamRzepka As your last commit was some time ago, I am curious about what is state of this work. It is just experimental? Or maybe you are able to fill your requirements to a real use and leave at current state?

@AdamRzepka
Copy link
Author

@sisso We do use this internally for quite some time and it works fine. The state of missing features (interfaces, callbacks) hasn't changed, as we don't need them.

@sisso
Copy link

sisso commented Sep 11, 2021

@AdamRzepka Giving your experience on this changes. Do you think that have a flag to generate code loading those libraries dynamically too hard?

I am amateur in FFI. From what I understand It would require a different life cycle as you need to call "dlopen" to load the library, "dlsym" to get the functions and "dlclose" to dispose the library.

Context: I am experimenting using rust with unity3d, flapi-gen solve mostly of problems. But dynamic load is require to be able to apply changes without have to restart the engine. My current implementation with state/dynamic load: https://github.com/sisso/test-unity3d-rust/blob/8b0e95ae6d2230cb164d0262895c3a8d0a15549e/unity3d/Assets/src/Domain/Ffi/Native.cs

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