5 ms·
It's pretty easy to call into a Rust library from C. The lack of a garbage collector makes embedding Rust quite nice. Lately I've even been playing with a Ruby
by steveklabnik 12y ago
It's pretty easy to call into a Rust library from C. The lack of a garbage collector makes embedding Rust quite nice.
Lately I've even been playing with a Ruby gem that's a C extension that calls into a Rust .a that exposes itself via extern C.
- blinkingled 12y agoThings get uglier when I want to then call the whole shebang from - let's say - Go! Go -> C -> Rust. Now I am paying the penalty for 2 runtimes!
- SwellJoe 12y agoHow high is that penalty, relative to, say, loading a variety of C shared libraries? At some point safety and security trumps saving a few kilobytes of memory...in a server environment, that point probably has already been passed a decade ago. Of course, if the penalty is hundreds of megabytes, then the equation might add up differently. But, we already have a huge number of system tools and utilities running in a huge number of languages. Python has become the lingua franca of Linux management tools; Perl was in that role in the past, and still exists in a lot of places; bash and shell are integral. All have separate runtimes, and sometimes interact with system-level C libraries, either directly or through command line interfaces. Is it really that big of a deal to have a Rust or Go shared library in a system that already has a half dozen different languages and a variety of shared and unshared libraries existing at once? I suspect it would be unnoticeable on a modern system. I'd choose safety over shaving a few kilobytes of memory used. There would be a cost in having that interface friction for developers...and we'd be paying that cost for years. But, it seems like both Rust and Go have planned for the languages to be integrated with C libraries from the beginning, so it seems less of a problem. If I were going to attempt such a thing, I'd probably start with the front end utilities that use the libraries and then work my way down to converting the libraries (even though the libraries, in this case, are where the problems lie). But, maybe it's possible to make Go or Rust code that provide the same C interface as the existing libraries...I don't know enough to even guess.
- steveklabnik 12y agoNope, you can use Rust without the runtime, so you're not _forced_ into paying the overhead.
- blinkingled 12y agoSo the Rust library you write is fully self sufficient without calling into any Rust stdlib functions or without using any runtime initialization mechanisms like ctors and dtors? That sounds too good to be true - If I am calling Rust then I am getting the Rust runtime just like if I can strlen I am getting the C library.
- bronson 12y agoC is fully self sufficient without calling into libc. Otherwise all the libc alternatives couldn't exist. Sure, you don't get to call strlen (actually, you do if the compiler treats it as an intrinsic), but that's no big deal.
- blinkingled 12y agoSo we would need to write Rust libraries without using Rust stdlib? Not exactly a great advantage in that case. Especially so when you are rewriting a ton of C code.
- bronson 12y agoSo what are you complaining about? Do you want to use runtime libs or not? It sounds like you're dissatisfied either way.
- blinkingled 12y agoIt's about the context - rewriting ton of code that is in C libraries right now. If that had to be done using Rust without its runtime libs it is an huge disadvantage to solve the issue at hand.
- 12y ago
- dllthomas 12y agoArguably 3.
- Animats 12y agoI just hope the Rust developers don't screw up. We badly need a safe, fast, low-level language to replace C. Once Rust settles down, the next step is academic work to automatically translate existing C into Rust.
- pjmlp 12y agoAda, Modula-2, Object Pascal, Oberon, Modula-3, ... Sadly, the list of better system programming languages that the industry decided to ignore is quite big.
- vezzy-fnord 12y agoAll but one of these are Wirthian languages. They all had overhead for their time period, and many of them were academic rather than pragmatic (consequently becoming influential for language designers). Ada? You're trying too hard. It used to be a government standard and wasn't ignored in the least (see: http://www.seas.gwu.edu/~mfeldman/ada-project-summary.html http://www.seas.gwu.edu/~mfeldman/ada-project-summary.html)... much to a lot of people's chagrin. It's widely regarded as an example of a monster language, but it is still absolutely used where the safety is critical.
- pjmlp 12y ago> They all had overhead for their time period, and many of them were academic rather than pragmatic What overhead? The one spread by C crowed without experience in the said languages? I used a few commercial compilers for those languages. They were quite comparable in terms of generated code quality to C compilers of the same generation, back in the day. C was also a research language until AT&T made the code available. > It's widely regarded as an example of a monster language, but it is still absolutely used where the safety is critical. Actually, I would dare to say that Ada 2012 is smaller than C++14. Its use has increased in Europe thanks to what is being discussed here, namely the amount of money lost in security issues thanks to the industry adoption of C due to its relation to UNIX. I included Ada in the list, because most developers aren't aware that it still exists and is being used. Or that GNAT is just one of many compilers that are still available.