Paul Krill
Editor at Large

Rust language gets direct WebAssembly compilation

news
Nov 29, 20172 mins
Software DevelopmentWeb Development

If you use the latest unofficial nightly build of Rust, you no longer need extra tools to compile to the WebAssembly portable code format

chain rust link heavy iron metal
Credit: cortixxx

Rust, the Mozilla-sponsored programming language geared to developing fast system-level software, can now compile to the WebAssembly portable code format without the need for additional tools.

Although still not officially supported, this feature was added via a pull request to enable WebAssembly as a back end by default. Through a nightly build this week, the wasm32-unknown-unknown target became natively available in Rust. (Nightly builds are unsupported test offshoots of the formal Rust language code, but their capabilities often get merged into the official build later.)

This week’s nightly build uses the LLVM tool chain more directly to support WebAssembly, with simpler setup and a bit more control over the output. LLVM provides the tool chain for Rust as well as for the Swift and Clang languages. At this point, Rust’s WebAssembly compilation has just limited support and documentation.

Mozilla says the Rust nightly build’s WebAssembly compilation capability is an improvement over the existing (and still-official) WebAssembly support, which uses the Emscripten tool.

There is also a tool, called wasm-gc, to further compress WebAssembly modules generated in Rust. The tool looks for unused parts of code, such as unused imports or functions, and removes them. This results in a .wasm file that is smaller but with the same functionality, with just extraneous code removed. You can download wasm-gc on GitHub.

WebAsembly promises faster web applications by besting JavaScript in the execution of computationally intense operations. It is supported in all major browsers, those from Apple, Google, Microsoft, and Mozilla.

Paul Krill

Paul Krill is editor at large at InfoWorld. Paul has been covering computer technology as a news and feature reporter for more than 35 years, including 30 years at InfoWorld. He has specialized in coverage of software development tools and technologies since the 1990s, and he continues to lead InfoWorldโ€™s news coverage of software development platforms including Java and .NET and programming languages including JavaScript, TypeScript, PHP, Python, Ruby, Rust, and Go. Long trusted as a reporter who prioritizes accuracy, integrity, and the best interests of readers, Paul is sought out by technology companies and industry organizations who want to reach InfoWorldโ€™s audience of software developers and other information technology professionals. Paul has won a โ€œBest Technology News Coverageโ€ award from IDG.

More from this author