Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mischnic/parcel-plugin-emscripten
📦 Import C(++) files with Parcel
https://github.com/mischnic/parcel-plugin-emscripten
c cpp emscripten parcel parcel-bundler parcel-plugin wasm webassembly
Last synced: 3 months ago
JSON representation
📦 Import C(++) files with Parcel
- Host: GitHub
- URL: https://github.com/mischnic/parcel-plugin-emscripten
- Owner: mischnic
- License: mit
- Created: 2018-02-10T21:22:33.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-02-13T15:51:28.000Z (almost 7 years ago)
- Last Synced: 2024-10-04T20:12:36.902Z (3 months ago)
- Topics: c, cpp, emscripten, parcel, parcel-bundler, parcel-plugin, wasm, webassembly
- Language: JavaScript
- Homepage: https://npm.im/parcel-plugin-emscripten
- Size: 64.5 KB
- Stars: 9
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Parcel plugin for Emscripten
[![Build Status](https://travis-ci.org/mischnic/parcel-plugin-emscripten.svg?branch=master)](https://travis-ci.org/mischnic/parcel-plugin-emscripten)
A [Parcel](https://parceljs.org/) plugin to enable importing a C(++) file inside a JS file.
Emscripten has to be installed and `emcc` needs to be in `PATH`.
Example:
```js
import Module from './test.c';
const Instance = Module();Instance.then(()=>{
console.log(Instance._add(10,20));
});// equivalent to
Instance.then((v)=>{
console.log(v._add(10,20));
});
``````c
//test.c
#includeint EMSCRIPTEN_KEEPALIVE add(int x, int y) {
return x + y;
}
```For more complex examples, see the [example](example/src) directory.
**`Instance.then` is quite fragile and not a thenable, see [https://github.com/kripken/emscripten/issues/5820](https://github.com/kripken/emscripten/issues/5820)**
Using multiple Modules (= importing multiple C files) is supported, but it isn't very filesize efficient. Consider writing a single C-wrapper and importing that instead!
To pass additional arguments to `emcc` (change optimization, link another C file or a library, ...), specify them in the first line of your main C file: (this would disable optimizations and compile and link `lib.c` as well)
```c
//parcel: -O0 lib.c
#include ...
```