opendal icon indicating copy to clipboard operation
opendal copied to clipboard

OpenDAL C# bindings

Open tisonkun opened this issue 2 years ago • 6 comments

Possible binding libraries -

  • https://github.com/Cysharp/csbindgen
  • https://crates.io/crates/interoptopus_backend_csharp

Materials -

  • https://www.youtube.com/watch?v=0B1U3fVCIX0

tisonkun avatar Jun 07 '23 08:06 tisonkun

Blocking -

We shall not need to use any binding libraries but simply P/Invoke + extern "C". The binding code can be a bit different to the C bindings for better P/Invoke marshaling. Maybe we can just use the C bindings if later it's figured out not so much difference.

Async -

Using TaskCompletionSource may help. Also, use delegate to callback set up the TaskCompletionSource. But we can postpone this part.

Overall, I still need some time to understand how a dotnet project is organized and loading the native lib.

Ref -

  • P/Invoke https://learn.microsoft.com/en-us/dotnet/standard/native-interop/pinvoke
  • Reserved P/Invoke https://learn.microsoft.com/en-us/dotnet/standard/native-interop/pinvoke#invoking-managed-code-from-unmanaged-code
  • Type Marshalling https://learn.microsoft.com/en-us/dotnet/standard/native-interop/type-marshalling

tisonkun avatar Jun 12 '23 05:06 tisonkun

TODO - properly distribute

Perhaps refer to librdkafka.redist -

  • https://github.com/confluentinc/librdkafka/wiki/librdkafka.redist
  • https://github.com/confluentinc/librdkafka/blob/master/packaging/nuget/templates/librdkafka.redist.props
  • https://github.com/confluentinc/confluent-kafka-dotnet

Originally posted by @tisonkun in https://github.com/apache/incubator-opendal/pull/2485#discussion_r1233235301

tisonkun avatar Jun 18 '23 09:06 tisonkun

Release assignment. I may not have too much time on this direction recently.

tisonkun avatar Jun 18 '23 09:06 tisonkun

For handling memory releasing, take a look at System.Runtime.InteropServices's SafeHandle.

I think we can reimplement the whole confluent-kafka-dotnet solution for bindings.

tisonkun avatar Jun 18 '23 16:06 tisonkun

For build script inetgration -

  • https://github.com/KodrAus/rust-csharp-ffi/blob/master/dotnet/Native.targets

tisonkun avatar Jun 19 '23 13:06 tisonkun

About distribution - https://learn.microsoft.com/en-us/nuget/create-packages/supporting-multiple-target-frameworks#architecture-specific-folders

tisonkun avatar Jan 22 '24 19:01 tisonkun