Introducing rollup-plugin-rust

in #utopian-io6 years ago

Repository

RepositoryLink
rollup-plugin-rusthttps://github.com/DrSensor/rollup-plugin-rust
Example usagehttps://github.com/DrSensor/example-stencil-rust

About rollup-plugin-rust

This is a rollup plugin that makes Rust code can be used in Javascript. The main motivation I build this because I need to incorporate Rust in WebComponent module made using Stencil. This plugin is based on the webpack loader called rust-native-wasm-loader.

Current features

Technology Stack

Main Dependencies

The main dependencies used by this project is rust-native-wasm-loader. However, rust-native-wasm-loader will not get installed when the consumer installs this plugin because only some part of that loader used by this plugin is pre-bundled. This is the reasons why rust-native-wasm-loader is in devDependencies section (and not in dependencies).

cargo.js is helper code that is product of [rust-native-wasm][] when build executed

Test Framework/Approach

The test framework I used for this project is Jest running on Nodejs v8 or higher. The reason the minimum Nodejs is not v6 because the WebAssembly support begins in Nodejs v8. For the approach, I implement 2 kinds of test: unit-tests and smoke-tests. The unit-tests use Jest which automatically confirms that the generated code can be run in Nodejs ≥8.x. The smoke-tests itself written as example-stencil-rust (linked as git submodule) which automatically confirm that it can be used in the front-end code. (need to figure out how to set up e2e-tests in Stencil just for my future references)

TestLinkenvironment
unithttps://github.com/DrSensor/rollup-plugin-rust/tree/master/testnodejs
smokehttps://github.com/DrSensor/example-stencil-rust/tree/smoke-testbrowser
CI and Build Tools

As usual, I use CircleCI for the automated build process. The CI workflow is based on webpack-defaults which I also use in binaryen-loader. The difference is I disable the test jobs for node6-latest and node8-canary (also add smoke-test for Stencil). For node8-canary, I disable it because there is no rollup@next or beta version yet.

CI workflow of release process when tagged

Release Convention

This is also based on webpack-defaults which use standard-version. The difference is I split it into 2 processes:

  • npm run release: only for generating changelog and bumping version so I can review and change it before commit + tag
  • npm run release:ok: after verifying the generated changelog is correct, run this command to commit changes and make tag release

command for tag release and generate changelog from commit messages

Under the hood, it uses commitlint to enforce the commit message so that the autogenerated changelog will always work. Summary if anyone makes changes, do commit but the message format doesn't follow conventionalcommits then it will complain and the changes don't get committed.

Linter and Static Typing

As many common projects out there, I use eslint + prettier to enforce code-style. One thing I added here is the linter will also run when doing commit changes. That setup was done using husky + lint-staged. Another thing that I used is flow to have static typing in my code to make it more maintainable in the long run (though I still like Typescript 😆). The thing is somehow I manage to make flow eat my RAM about 3.6GB 😂. Probably this happens because I close and open my VSCode frequently.

memory leak in flow and amazed I can make that achievement 😂

Extra Note

Something interesting that I found when generate Stencil project using create-stencil:

  • The official stencil template has many security vulnerability problems in their dependencies. Probably because the script doesn't perform npm audit fix after installing the dependencies.

    need to execute npm audit fix after running npm init stencil components <projectName>

  • Upon starting the generated project by running npm start


stencil hello world

Future Plans

How to contribute?

Just DM's me, make a Github issue or writes a comment below if someone interested. For guidelines, see Contributing section.

References/Credits

Proof of Works

RepositoryLink
preparationhttps://github.com/DrSensor/rollup-plugin-rust/commits/3b552c06122f6efa99686fb81f531aea1faa9b5e
feature/wasmhttps://github.com/DrSensor/rollup-plugin-rust/pull/1/commits
smoke-testhttps://github.com/DrSensor/example-stencil-rust/commits/smoke-test

GitHub Account

https://github.com/DrSensor


Sort:  

Thanks for the contribution, @drsensor!

Sorry for the delay in reviewing your contribution! It was caused by the fact that all of us (I think) don't really have experience using Rust, so I asked @tensor to check it out on Monday. Unfortunately I was busy all day yesterday so only had time now to check back in and properly review it.

He seemed pretty excited about it and that's a great indication for the quality of the project, and that's honestly enough for me! You have also done a great job documenting everything, giving usage examples, setting up everything so people can easily contribute etc. so I have decided to staff pick it - keep up the amazing work!


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

Thank you for your review, @amosbastian!

So far this week you've reviewed 11 contributions. Keep up the good work!

Very cool piece of technology. I've covered some fairly basic Rust WASM libraries and techniques in my tutorials here on Steemit/utopian. It's great to see more options in this arena. I like your approach here and the code looks solid. I am looking forward to seeing where this project goes and will perhaps do a tutorial on it to give it a bit of exposure.

Cheers,

Tensor

Thanks. PR, bug report, and feature request are always welcome 🤗

Hey @drsensor
Thanks for contributing on Utopian.
Congratulations! Your contribution was Staff Picked to receive a maximum vote for the development category on Utopian for being of significant value to the project and the open source community.

We’re already looking forward to your next contribution!

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Coin Marketplace

STEEM 0.19
TRX 0.15
JST 0.029
BTC 62890.35
ETH 2544.51
USDT 1.00
SBD 2.94