Repository
<p dir="auto"><span><a href="https://github.com/DrSensor/rollup-plugin-rust" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">https://github.com/DrSensor/rollup-plugin-rust
<p dir="auto">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.
<div class="table-responsive"><table>
<thead>
<tr><th>update<th>pull request
<tbody>
<tr><td>async compile/load + call JS function from Rust<td><span><a href="https://github.com/DrSensor/rollup-plugin-rust/pull/10" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">https://github.com/DrSensor/rollup-plugin-rust/pull/10
<tr><td>fix failed smoke-test in stenciljs while also add additional smoke-test<td><span><a href="https://github.com/DrSensor/rollup-plugin-rust/pull/9" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">https://github.com/DrSensor/rollup-plugin-rust/pull/9
<tr><td>additional smoke-test (example using it in nodejs project)<td><span><a href="https://github.com/DrSensor/example-node-rust-wasm/tree/smoke-test" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">https://github.com/DrSensor/example-node-rust-wasm/tree/smoke-test
<hr />
<h4>New Features
<h5>Asynchronous load/compile Wasm code
<p dir="auto">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, <strong>maybe<sup><a href="https://github.com/rollup/rollup-plugin-wasm#sync-modules" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">[ref]). See <a href="https://github.com/DrSensor/rollup-plugin-rust#options" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">README.md##options.export for more info.
<p dir="auto"><center><img src="https://images.hive.blog/768x0/https://ipfs.busy.org/ipfs/QmWBtNWycFdyYrEzd5mXYNex9UTGmiYewrtdADf3sRU3NM" srcset="https://images.hive.blog/768x0/https://ipfs.busy.org/ipfs/QmWBtNWycFdyYrEzd5mXYNex9UTGmiYewrtdADf3sRU3NM 1x, https://images.hive.blog/1536x0/https://ipfs.busy.org/ipfs/QmWBtNWycFdyYrEzd5mXYNex9UTGmiYewrtdADf3sRU3NM 2x" /><center><sub>resolve value of the exported function depend on <code>export option you choose
<p dir="auto">However, if the wasm file compiled from Rust code is really really huge, it's better to use <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">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 <a href="https://hacks.mozilla.org/2018/01/oxidizing-source-maps-with-rust-and-webassembly/" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">here, see <code>Using WebAssembly APIs in JavaScript section) but seems I need to wait for <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compileStreaming#Specifications" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">WebAssembly.compileStreaming to be implemented in the most major browser first.
<h5>Call Javascript function in Rust code
<p dir="auto">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 <code>async function in all <code>async* mode, it's better to make <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate#Secondary_overload_%E2%80%94_taking_a_module_object_instance" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">importObject as an argument and pass it when instantiating wasm code.
<blockquote>
<p dir="auto">It's possible to <code>call JS function in WASM in the non-async mode, but I strongly suggest using <code>async mode (or <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">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.
<p dir="auto"><center><img src="https://images.hive.blog/768x0/https://ipfs.busy.org/ipfs/QmPXHHzZ5APfwZevdj7M2ir79ptHjA25H6ZVm8EDgnppSr" srcset="https://images.hive.blog/768x0/https://ipfs.busy.org/ipfs/QmPXHHzZ5APfwZevdj7M2ir79ptHjA25H6ZVm8EDgnppSr 1x, https://images.hive.blog/1536x0/https://ipfs.busy.org/ipfs/QmPXHHzZ5APfwZevdj7M2ir79ptHjA25H6ZVm8EDgnppSr 2x" /><center><sub>call <code>console.log inside wasm instance
<hr />
<h4>Bug Fixes
<h5>Fix failed smoke-test for stenciljs (<a href="https://github.com/DrSensor/rollup-plugin-rust/pull/9" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">#9)
<p dir="auto">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:
<p dir="auto"><center><img src="https://images.hive.blog/768x0/https://ipfs.busy.org/ipfs/QmP92XaRyw1x9baXEcTSENc9HGxjWkjybLhQjwv4yurYaP" srcset="https://images.hive.blog/768x0/https://ipfs.busy.org/ipfs/QmP92XaRyw1x9baXEcTSENc9HGxjWkjybLhQjwv4yurYaP 1x, https://images.hive.blog/1536x0/https://ipfs.busy.org/ipfs/QmP92XaRyw1x9baXEcTSENc9HGxjWkjybLhQjwv4yurYaP 2x" /><center><sub>error message cause by stack-size is not enough
<p dir="auto">Usually, an error like <code>RangeError: Maximum call stack size exceeded cause by calling the recursive function to deep (or indefinite). The solution for this is simply by defining <code>NODE_OPTIONS=--stack-size=1200 in my local machines but CircleCI prohibits setting <code>--stack-size flag (but not <code>--max-old-space-size, security reason probably). I also add additional <a href="https://github.com/DrSensor/rollup-plugin-rust/pull/9/files?utf8=%E2%9C%93&diff=unified#diff-8903239df476d7401cf9e76af0252622R6" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">smoke-test for nodejs (the repo is in <a href="https://github.com/DrSensor/example-node-rust-wasm/tree/smoke-test" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">here) just for comparison which surprisingly there is no <code>RangeError: Maximum call stack size exceeded error (it build using <code>rollup -c, not <code>stencil build). As the last resort, I <a href="https://github.com/DrSensor/rollup-plugin-rust/pull/9/commits/23e24d8594d850e94a218526fd07e44af401c62e" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">move smoke-stencil job to TravisCI xD
<blockquote>
<p dir="auto"><sub>FYI: <i>python runtime also has this kind of limit called <code>recursionlimit
<p dir="auto">Unfornutaley moving it to TravisCI cause another error.
<p dir="auto"><center><img src="https://images.hive.blog/768x0/https://ipfs.busy.org/ipfs/QmUvSSYQaDTEAjFjy9Qmxw7b97znF8bgVzUbAYqCzwSrQV" srcset="https://images.hive.blog/768x0/https://ipfs.busy.org/ipfs/QmUvSSYQaDTEAjFjy9Qmxw7b97znF8bgVzUbAYqCzwSrQV 1x, https://images.hive.blog/1536x0/https://ipfs.busy.org/ipfs/QmUvSSYQaDTEAjFjy9Qmxw7b97znF8bgVzUbAYqCzwSrQV 2x" /><center><sub>kind of error message cause by hitting the memory limit
<p dir="auto">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 <a href="https://github.com/DrSensor/example-stencil-rust/commit/590f31b1cd707170970d8fce77fd33776fc7f9e7" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">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 <a href="https://busy.org/@drsensor/mix-rust-code-webassembly-with-vue-component-optimization-analyze-wasm-call-graph-and-shrink-the-size" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">tutorial before xD)
<h5>Fix <code>buffer is imported but could not be resolved (<a href="https://github.com/DrSensor/rollup-plugin-rust/pull/10/commits/d87c1d346c6297d8d6eeb7a0a930fe6474dcbfd6" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">d87c1d3)
<p dir="auto">In the previous release, we will get this kind of warning (marked in orange bold) when we do not specify <code>buffer as the external dependency in the <a href="https://github.com/DrSensor/example-node-rust-wasm/commit/bdd22485948a3e755e07adbdeac3aef5652b3c85#diff-ff6e5f22a9c7e66987b19c0199636480" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">rollup.config.js file.
<p dir="auto"><center><img src="https://images.hive.blog/768x0/https://ipfs.busy.org/ipfs/QmWLoYYNb46R8QCV34ozZN28nAiikq7Y4dnZQ1b1QK3Atd" srcset="https://images.hive.blog/768x0/https://ipfs.busy.org/ipfs/QmWLoYYNb46R8QCV34ozZN28nAiikq7Y4dnZQ1b1QK3Atd 1x, https://images.hive.blog/1536x0/https://ipfs.busy.org/ipfs/QmWLoYYNb46R8QCV34ozZN28nAiikq7Y4dnZQ1b1QK3Atd 2x" /><center><sub>when build the examples or smoke-tests
<p dir="auto">And when I run the unit-tests locally, I will get this warning message:
<p dir="auto"><center><img src="https://images.hive.blog/768x0/https://ipfs.busy.org/ipfs/QmXn367pXsv49trmu9rxFsSBJbEqK4EtYUhCuth56ahYBN" srcset="https://images.hive.blog/768x0/https://ipfs.busy.org/ipfs/QmXn367pXsv49trmu9rxFsSBJbEqK4EtYUhCuth56ahYBN 1x, https://images.hive.blog/1536x0/https://ipfs.busy.org/ipfs/QmXn367pXsv49trmu9rxFsSBJbEqK4EtYUhCuth56ahYBN 2x" /><center><sub>when running unit-tests
<p dir="auto">This update will dismiss that warning by specifying <code>buffer as the external dependency <em>automatically when registering this plugin in <code>rollup.config.js. This fix inspired from <a href="https://github.com/stevenbenisek/rollup-plugin-auto-external" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">rollup-plugin-auto-external.
<h5>Strange behaviour when bundling using Rollup <code>.generate() function (<a href="https://github.com/DrSensor/rollup-plugin-rust/pull/10/commits/c941c62d862a331ae89ff9c9da995e63f3f68e11?utf8=%E2%9C%93&diff=split" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">c941c62)
<p dir="auto">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 <a href="https://rollupjs.org/guide/en#command-line-reference" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">CLI and <a href="https://rollupjs.org/guide/en#javascript-api" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">JS API when doing <code>export * from './content.js' with content <code>export default function() {}. It's hard to explain, so probably will create a reproducible repo and submit bug issue to Rollup next week.
<hr />
<blockquote>
<p dir="auto"><em>Parting words: I leave small feature/mode (<a href="https://github.com/DrSensor/rollup-plugin-rust/issues/11" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">#11) that purposely not being implemented in this update to see if I can invite and onboard contribution in this way 😋
<hr />
<h4>GitHub Account
<p dir="auto"><span><a href="https://github.com/DrSensor" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">https://github.com/DrSensor
Thanks for the contribution, @drsensor! Seems like a cool little feature and also reading about the bug fixes was very interesting, haha. I don't really have much feedback to give about the code in general, but I think that comments like
<pre><code>// Usage <p dir="auto">could be replaced with comments that actually improve the readability. <p dir="auto"><span>As for issue #11, maybe you could create a task request for it (or ask <a href="/@tensor">@tensor, he might be interested!). Keep up the good work, it's always great to see contributors like yourself in the development category. <p dir="auto">Your contribution has been evaluated according to <a href="https://join.utopian.io/guidelines" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category. <p dir="auto">To view those questions and the relevant answers related to your post, <a href="https://review.utopian.io/result/3/1321213" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">click here. <hr /> <p dir="auto"><br /> Chat with us on <a href="https://discord.gg/uTyJkNm" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">Discord.<br /> <a href="https://join.utopian.io/" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">[utopian-moderator]<span>Need help? Write a ticket on <a href="https://support.utopian.io/" target="_blank" rel="noreferrer noopener" title="This link will take you away from hive.blog" class="external_link">https://support.utopian.io/.Thank you for your review, @amosbastian!
So far this week you've reviewed 3 contributions. Keep up the good work!
<hr /> <blockquote> <pre><code>// Usage <p dir="auto">could be replaced with comments that actually improve the readability. <span> Well, actually, it's label, not comments xD. Comments are something that explains *what* or *why* the code is about. Seems I need to put comments on *why* it's being used that way 🙂. Nice spot on <a href="/@amosbastian">@amosbastian!For task request, maybe later if the issue #11 hanging for a long time (1-3 weeks maybe). I want to experiment if creating an issue with obvious solution and step by step guide can invite contribution. There are many tools/websites out there that spot on issue label
good first issue
andhelp wanted
.Yes, really love it if @tensor could contribute to this plugin. For this kind of lib/plug, I want to avoid it to become a one-man project 😂. (I have a bad habit to abandon library that I don't use anymore)Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!Hey @drsensor
Want to chat? Join us on Discord https://discord.gg/h52nFrV.
Vote for Utopian Witness!