4 ms·
If you invent the next image format, compression scheme, encryption scheme, etc., and you write a Go library for it, then it can be used by Go programmers. If y
by jeffdavis 7y ago
If you invent the next image format, compression scheme, encryption scheme, etc., and you write a Go library for it, then it can be used by Go programmers. If you write a C/C++ library, it can be used by any programmer (perhaps with a wrapper) on billions of devices.
Now, we add Rust to the list. You can write that library in Rust and it can be used by anyone, too. That's because there is no GC or other extraneous code, and because you can make structures with specifically-defined layout in memory.
Making a list of options go from two to three is a big deal. Especially when, a lot of the time, C++ ends up looking like C when you need to interface it with something else. So Rust is kind of like going from one to two optons.
I'm ignoring other good languages, I know, but those are often just not chosen for a variety of reasons. Rust seems to be breaking out of that trap because of a good community, a few nice features, the fact that it's new, and a bit of luck.
- pjmlp 7y agoIn Windows I just implement in COM and it can also be used by any language on the platform, without resorting to plain old C.
- Ygg2 7y agoYes. But then you have to use COM :P
- smitty1e 7y agoI knew this one guy who still did a little VBA when he thought no one was looking. . .
- pjmlp 7y agoAll major Windows APIs are based on COM since Vista, as the .NET Longhorn ideas got rebooted as COM libraries. With Windows 8, it got a new facelift (WinRT, UAP, UWP) and the large majority of Win32 APIs are as they were in Windows 7. Anyone doing modern Windows development, has to use COM in some form.
- Const-me 7y agoAlso COM ABI is really small, easily portable to other OSes. I’ve recently ported to Linux and implemented .NET core interop. The C++ runtime is just a couple pages of code. https://github.com/Const-me/ComLightInterop https://github.com/Const-me/ComLightInterop
- contextfree 7y agoIncidentally I recently added better support for classic COM interop to the Rust WinRT projection, this allows it to work with Windows.UI.Composition for example (albeit still awkwardly since we still don't support WinRT inheritance yet): https://github.com/contextfree/rust-winui-experiments https://github.com/contextfree/rust-winui-experiments
- colejohnson66 7y ago> Now, we add Rust to the list. You can write that library in Rust and it can be used by anyone, too. That's because there is no GC or other extraneous code, and because you can make structures with specifically-defined layout in memory. Genuine question: Can you link a Rust binary with a C/C++ binary?
- steveklabnik 7y agoAbsolutely.
- baq 7y agonotably firefox has a few modules implemented in rust.
- mlindner 7y agoYou can link a Rust library to a C/C++ binary and you can link a C/C++ library to a Rust binary. https://doc.rust-lang.org/nomicon/ffi.html https://doc.rust-lang.org/nomicon/ffi.html Notably you need to use the C ABI to call things from C++ as Rust FFI doesn't support C++ directly.
- mrbonner 7y agoI have written a proof of concept for making a lib in Rust and then use JNR (a wrapper of the abominable JNI) to call and be called from that lib. I was surprised to see how much easy it is to write an ABI in rust to be used in the JVM. I am sure this lib will even have an easier time integrating with Python/Ruby comparing to Java. With that in mind, I think for my future native ABI development, I would be seriously considering building in Rust instead of C/C++.
- trulyrandom 7y agoFun fact: you can expose a Go library in the same way using the c-shared build mode.
- jeffdavis 7y agoBut how many want to link the Go runtime into their program? Maybe they just don't want it there, or maybe they already have other runtimes linked in their program and don't want one more, or maybe they have runtime version conflicts, etc. Also, such interfaces generally require more copying around of structures to match the format the language is expecting. With rust, it can use plain C structs directly without translation.