Native Binary DLL C# Support for a Rust Library that compiles to DLL

Hi.

Over the Holidays I’ve been working on interfacing a C# .NET Project with a Library DLL produced as a result of a Rust Cargo compilation.

The Rust compiler is currently targeting my PC with Visual Studio (Clang, CMake etc), so it outputs a DLL; which I can consume in C# with P/Invoke Dll Import. If I compiled with other settings I’d get a .so, a., .lib etc. for other platforms.

It’s a bit fiddly, as you have to pin and unpin a GCHandle to pass data buffers back and forth with pointers, but it works.

The compiled library is quite small 4MB, though it also needs Google Protocol Buffers to work, which are obtained through Nuget.

I have a Meadow Dev Board. So curious to know if it’s possible to compile the DLL (as a native binary) for Meadow as a target architecture and then import it as a DLL Import on Meadow C#; to make use of it. Ideally with access to Protocol Buffers for serialisation.

Thanks and Happy New Year!

Dynamic loading is under internal testing now and should be part of the released OS in the near future.