https://github.com/elct9620/mwc
The tool to compile mruby on WebAssembly
https://github.com/elct9620/mwc
gem mruby ruby webassembly
Last synced: 9 months ago
JSON representation
The tool to compile mruby on WebAssembly
- Host: GitHub
- URL: https://github.com/elct9620/mwc
- Owner: elct9620
- License: mit
- Created: 2019-11-29T10:35:34.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-16T00:53:54.000Z (almost 3 years ago)
- Last Synced: 2024-11-24T23:25:51.494Z (about 1 year ago)
- Topics: gem, mruby, ruby, webassembly
- Language: Ruby
- Size: 104 KB
- Stars: 18
- Watchers: 4
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
MWC
===
[](https://badge.fury.io/rb/mwc) [](https://travis-ci.com/elct9620/mwc) [](https://codeclimate.com/github/elct9620/mwc/maintainability) [](https://codeclimate.com/github/elct9620/mwc/test_coverage)
The tool for the developer to help them create mruby applications on the WebAssembly.
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'mwc'
```
And then execute:
$ bundle
Or install it yourself as:
$ gem install mwc
## Requirement
* Curl
* Tar
* Emscripten SDK
* Ruby 2.6+
> Please make sure you can execute `emcc` before use `mwc compile`
## Usage
### Create Project
Execute below command with your project name:
$ mwc init my_mrb
This gem will create a directory `my_mrb` with anything you need to play with mruby on WebAssembly.
### Source code detect
* `src/**/*.c` the normal C code
* `src/js/**/*.lib.js` the JavaScript library can be called in C
* `src/js/**/*.pre.js` the JavaScript prepend to WebAssembly JS
* `src/js/**/*.post.js` the JavaScript append to WebAssembly JS
### Compile
To compile `*.c` to `.wasm` you have to execute `compile` command:
$ mwc compile
You can specify compile environment to change with different options:
$ mwc compile --env=dev
To see more usage with `help` command:
$ mwc help compile
### Serve compiled files
The `mwc` has built-in static file server to help preview or debug:
$ mwc server
And then, open the `http://localhost:8080` you will see the Emscripten web shell and `Hello World` is printed.
## Configure
We use DSL to define the compile preferences in `.mwcrc`
```ruby
project.name = 'mruby'
mruby.version = '2.1.3'
env :dev do
project.source_map = true
end
```
### Project
|Name|Type|Description
|----|----|-----------
|name|string| The project name, will change the generated file name. ex. `mruby.wasm`
|shell|string| The shell file template, if you want to use your own html template
|source_map|boolean| Enable source map for debug
|options|array| Extra compile options. ex. `-s ALLOW_MEMORY_GROWTH=1`
### mruby
|Name|Type|Description
|----|----|-----------
|version|string| The prefer mruby version
## Roadmap
* [ ] Unit Test
* [ ] Download options for mruby
* [x] Archive
* [ ] Git Submodule
* [ ] Integrate to Webpack
* [ ] Watch Mode
* [x] Auto re-compile
* [ ] Add LiveReload support
## Development
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/elct9620/mwc. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
## Code of Conduct
Everyone interacting in the Mwc project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/elct9620/mwc/blob/master/CODE_OF_CONDUCT.md).