OpenDAL C# bindings
Possible binding libraries -
- https://github.com/Cysharp/csbindgen
- https://crates.io/crates/interoptopus_backend_csharp
Materials -
- https://www.youtube.com/watch?v=0B1U3fVCIX0
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
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
Release assignment. I may not have too much time on this direction recently.
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.
For build script inetgration -
- https://github.com/KodrAus/rust-csharp-ffi/blob/master/dotnet/Native.targets
About distribution - https://learn.microsoft.com/en-us/nuget/create-packages/supporting-multiple-target-frameworks#architecture-specific-folders