38 ms·
I want something that could easily be embedded into dynamic languages VMs like Ruby, Python, PHP, Lua, Node.js, etc. I like Rust a lot, but for better or worse
by haberman 8y ago
I want something that could easily be embedded into dynamic languages VMs like Ruby, Python, PHP, Lua, Node.js, etc. I like Rust a lot, but for better or worse, all the infrastructure around this is currently built around C/C++.
- TomMarius 8y agoNot really? Almost everything (except V8 support and some experiments and a few minor (by code size) exceptions) regarding WASM is written in Rust, there are libraries like yew[0], Rust compiler has excellent support... And I'm not really sure what does it have to do with embedability, because Rust shouldn't restrict anything; at the same time, you don't really embed JVM into Python most of the time, rather the other way around. [0] https://github.com/DenisKolodin/yew https://github.com/DenisKolodin/yew
- kodablah 8y agoIncorrect. Rust does very well at embedding into those dynamic languages. It exports the same ABI C. In fact, due to how well its compilation tools work, IMO it's actually easier to use Rust than C to embed into those languages. The "infrastructure" is usually a just a C header. For Node.js it's more C++, but you'd need to write C++-to-C glue anyways just like you'd need C++-to-Rust glue (of course there's neon [0] that makes this easy). Basically, for most FFI-based use cases, anything that C can do Rust can do. 0 - https://github.com/neon-bindings/neon https://github.com/neon-bindings/neon
- haberman 8y ago> The "infrastructure" is usually a just a C header. It's more than that. These languages often come with build systems for building extensions. For example, Ruby's 'mkmf'. You just list your .o files and mkmf creates a Makefile that builds against the correct headers with the correct flags: https://github.com/google/protobuf/blob/master/ruby/ext/google/protobuf_c/extconf.rb https://github.com/google/protobuf/blob/master/ruby/ext/goog... This tool knows about C/C++. It sadly doesn't know about Rust.
- kodablah 8y agoRust can make .o files just fine. But yes, PHP had some of these types of tools (at least back in the day, haven't looked lately) for PECL extensions. Like Node, if it's C++ only or requires actual C source, writing glue is trivial, should have no performance cost, and is a way better option than completely switching WASM impl choices because of these limiting platforms. If you don't want to manually write this glue, there are often projects (like [0] for Ruby) that will help. Again, better than artificially constraining the implementation language. 0 - https://github.com/tildeio/helix https://github.com/tildeio/helix
- curun1r 8y agoI think you're missing his point, and I say this as someone who's deployed native Node modules using Rust/Neon in our production environment and advocate that approach whole-heartedly. Writing my own Node modules in Rust works great. But I can't write a node module in Rust and distribute it via npm the way that C++ authors can. When someone adds their module as a dependency and does an npm install, npm will duly run node-gyp to compile their C++. There's no Rust equivalent of that and, until there is, Rust will always be a second-class citizen when it comes to embedding into those languages. As you point out, there's nothing technically stopping the ecosystem tools for those languages from supporting Rust, but they just don't--likely because they'd prefer to not have to bundle an entire Rust toolchain with their distribution. But whether the reason is technical or not is immaterial...I still can't push a Rust-implemented module to npm. If the goal is to create a module that the larger Node community can use to embed wasm in Node, Rust simply isn't an option because distribution via npm is a given.
- TomMarius 8y agoWe are talking about a new technology, of course the support is not that strong. You said the most important bit yourself: > As you point out, there's nothing technically stopping the ecosystem tools for those languages from supporting Rust There of course would be a problem if it was technically impossible, but that's not true, it just might be impractical right now.
- 8y ago
- steveklabnik 8y agoThe first production usage of Rust was extending Ruby.