rollup-plugin-rust minor update: v1.1.0 - asynchronous compile/load, call Javascript function on Rust code, some bug fixes
Repository
https://github.com/DrSensor/rollup-plugin-rust
This minor update consists of 2 things, bug fixes and adding features to support async load/compile. Also, JS function now can be called in Rust code.
| update | pull request |
|---|---|
| async compile/load + call JS function from Rust | https://github.com/DrSensor/rollup-plugin-rust/pull/10 |
| fix failed smoke-test in stenciljs while also add additional smoke-test | https://github.com/DrSensor/rollup-plugin-rust/pull/9 |
| additional smoke-test (example using it in nodejs project) | https://github.com/DrSensor/example-node-rust-wasm/tree/smoke-test |
New Features
Asynchronous load/compile Wasm code
This feature makes it possible to load/compile wasm code asynchronously to avoid blocking code/execution. This mode are suitable if the wasm code we want to load/compile are big (more than >4KB, maybe[ref]). See README.md##options.export for more info.
export option you chooseHowever, if the wasm file compiled from Rust code is really really huge, it's better to use WebAssembly.instantiateStreaming to fetch-compile the wasm file. I actually want to add an additional option for compile/load wasm code in streaming fashion (taking inspiration from here, see Using WebAssembly APIs in JavaScript section) but seems I need to wait for WebAssembly.compileStreaming to be implemented in the most major browser first.
Call Javascript function in Rust code
This feature is really handy if we want to implement lifecycle hook in our wasm code (written in Rust). Well, it's WebAssmebly API feature but since I export async function in all async* mode, it's better to make importObject as an argument and pass it when instantiating wasm code.
It's possible to
call JS function in WASMin the non-async mode, but I strongly suggest usingasync mode(or WebAssembly.instantiateStreaming) to avoid undeterministic execution. If you only need to call functions defined inside the wasm code, then it's fine to use non-async mode.
console.log inside wasm instanceBug Fixes
Fix failed smoke-test for stenciljs (#9)
This bug happens because of CircleCI recently limit the stack size of nodejs runtime (not sure if they do it directly via it's docker image or its just side effect of fine-tunning the server). Limiting the stack-size of nodejs cause this kind of error:
Usually, an error like RangeError: Maximum call stack size exceeded cause by calling the recursive function to deep (or indefinite). The solution for this is simply by defining NODE_OPTIONS=--stack-size=1200 in my local machines but CircleCI prohibits setting --stack-size flag (but not --max-old-space-size, security reason probably). I also add additional smoke-test for nodejs (the repo is in here) just for comparison which surprisingly there is no RangeError: Maximum call stack size exceeded error (it build using rollup -c, not stencil build). As the last resort, I move smoke-stencil job to TravisCI xD
FYI: python runtime also has this kind of limit called
recursionlimit
Unfornutaley moving it to TravisCI cause another error.
Guess I'm lucky for this. The cause for this error is too many strings (generated code) to be cached. The solution is simple, just enable LTO optimization and the wasm code will be much smaller which make fewer strings (generated code) to be cached. (Glad that I try to explore this in form of tutorial before xD)
Fix buffer is imported but could not be resolved (d87c1d3)
In the previous release, we will get this kind of warning (marked in orange bold) when we do not specify buffer as the external dependency in the rollup.config.js file.
And when I run the unit-tests locally, I will get this warning message:
This update will dismiss that warning by specifying buffer as the external dependency automatically when registering this plugin in rollup.config.js. This fix inspired from rollup-plugin-auto-external.
Strange behaviour when bundling using Rollup .generate() function (c941c62)
This is actually a bug in Rollup that I found when adding another test case. The interesting thing is the bundle result are different between CLI and JS API when doing export * from './content.js' with content export default function() {}. It's hard to explain, so probably will create a reproducible repo and submit bug issue to Rollup next week.
Parting words: I leave small feature/mode (#11) that purposely not being implemented in this update to see if I can invite and onboard contribution in this way 😋
GitHub Account
Leave rollup-plugin-rust minor update: v1.1.0 - asynchronous compile/load, call Javascript function on Rust code, some bug fixes to:
Read more #utopian-io posts
Best Posts From Fahmi Akbar Wildana
We have not curated any of drsensor's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From Fahmi Akbar Wildana
- ~
- Scdlang v0.2 update overview
- Introducing Scdlang (Statecharts Description Language), a universal description language for defining State Machine
- Byteball Bot Wars progress report - Github Attestation Bot
- Concept for Fearless and Agile Firmware Development #1
- Byteduino: Create your own Hardware Cosigner for Byteball
- Programming ESP µC - Setup and program NodeMCU esp8266 using Visual Studio Code extension for Arduino
- GUC-Desktop update: integration with fluent-git and move posting key from experimental to stable feature :yay:
- Some though about IoT, WebAssembly, and Blockchain
- rs-jest and rollup-plugin-rust Update: Integrating with webassembly-loader and Some Bug Fixes
- Introducing webassembly-loader: Yet another webpack-loader for importing wasm code 😂
- Introducing fluent-git: A JS/TS library to make using git fluently 😎
- GUC Desktop: Notes taking app for creating development updates seamlessly
- Demo GUC
- Byteball Use-a-Thon: A way to contract/reward Contributor efficiently - High level detail and the direction
- Introducing rs-jest. A Jest preprocessor for transforming Rust code into Javascript module
- Byteball Use-a-Thon: A way to contract/reward Contributor efficiently - Architecture
- rollup-plugin-rust minor update: v1.1.0 - asynchronous compile/load, call Javascript function on Rust code, some bug fixes
- Byteball Use-a-Thon: A way to contract/reward Contributor efficiently
- Introducing rollup-plugin-rust