4 ms·
Using Rust code in D should be relatively easy: expose C API, compile it into a shared library and use it on the D side as any other library. cbindgen (https://
by newpavlov 4y ago
Using Rust code in D should be relatively easy: expose C API, compile it into a shared library and use it on the D side as any other library. cbindgen (https://github.com/eqrion/cbindgen https://github.com/eqrion/cbindgen) can help with generation of header files. Static linking is possible as well.
Using D code in Rust probably will be much more painful and I am not sure if it can be done 100% safely...
- bachmeier 4y ago> Using D code in Rust probably will be much more painful and I am not sure if it can be done 100% safely... Can you elaborate? Saying it will be "much more painful" without anything further is not especially helpful. I've added D functions to C programs more or less trivially, including compiling to a shared library, with no change to the code.
- newpavlov 4y agoBecause I am not knowledgeable about D runtime I can not say that it will not cause any conflicts with Rust assumptions (thus the use of "probably"). For example, IIRC there are serious issues with integrating Go code into a Rust project. If D code is compiled in the betterC mode, then there should not be any problems.
- yvdriess 4y agoYou can link in and interop fine with C/C++ as long as you link in the D runtime, kind of how you can mix C and C++ by linking in libcxx. D's betterC mode ensures that the binary can run purely on libc without D's runtime library. It's kind of like being able to link and execute C++ code without needing libcxx.
- eptcyka 4y agoThere are serious considerations for including Go code in a rust project, but it's not like there are any showstoppers - one just can't use the default runtime and must rely on Cgo, and the FFI entry points are not performant. Other than that, it's relatively painless. Far less painful than calling into the JVM IMO.
- boundchecked 4y agoI don't think Rust will ever consider FFI'in with another language "100% safe."
- IceWreck 4y agoYou can use C libraries in Rust, even compiled .so files where you dont have the corresponding C headers.
- Doxin 4y ago> Using D code in Rust probably will be much more painful and I am not sure if it can be done 100% safely You can just as easily declare D code to be extern(C) and have rust treat it as a C library.