Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mezum/emcc-loader
Webpack loader that compiles some c/c++ file into a wasm using Emscripten.
https://github.com/mezum/emcc-loader
Last synced: 3 days ago
JSON representation
Webpack loader that compiles some c/c++ file into a wasm using Emscripten.
- Host: GitHub
- URL: https://github.com/mezum/emcc-loader
- Owner: mezum
- License: mit
- Created: 2018-02-23T01:53:12.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2023-03-04T02:36:12.000Z (over 1 year ago)
- Last Synced: 2024-10-27T15:33:22.782Z (9 days ago)
- Language: TypeScript
- Homepage:
- Size: 283 KB
- Stars: 8
- Watchers: 2
- Forks: 2
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# emcc-loader
Webpack loader that compiles some c/c++ files into a wasm using Emscripten.## Install
```
npm install --save-dev emcc-loader
```## Usage
First of all, create .clist file written relative paths from the clist to c/c++ file like this:```
# comment
foobar.c# indent is also ok.
foo/bar.cpp
baz.cc
qux.cxx# --pre-js
^pre.js# --post-js
$post.js
```Ofcourse, write c/c++ files!
```
#include
#include#ifdef __cplusplus
extern "C" {
#endifEMSCRIPTEN_KEEPALIVE
void sayHello() {
printf("hello!\n");
}#ifdef __cplusplus
}
#endif
```Next, edit your webpack.config.js:
```
loaders: [
{
test: /\.clist$/,
use: [
{
loader: 'emcc-loader',
options: {
buildDir: `${__dirname}/build`,
commonFlags: [ '-O2' ],
cFlags: [ '-std=c11' ],
cxxFlags: [ '-std=c++14' ],
ldFlags: [
'-s', "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall', 'cwrap']",
'-s', 'DEMANGLE_SUPPORT=1',
]
}
}
]
}
]
```Now, you can import a wasm file like this:
```
import wasm from './module.clist';wasm.initialize().then(module => {
module._sayHello();
});
```## Options
emcc-loader is configuable on webpack.config.js.- buildDir : string
-- [Required] absolute path to temporary directory used by emcc.
- cc : string
-- [default=emcc] c compiler path.
- cxx : string
-- [default=em++] c++ compiler path.
- ld : string
-- [default=emcc] linker path.
- commonFlags : string[]
-- [default=[]] array of flags passed to all emcc/em++ commands.
- cFlags : string[]
-- [default=[]] array of flags passed to emcc compiling C.
- cxxFlags : string[]
-- [default=[]] array of flags passed to em++ compiling C++.
- ldFlags : string[]
-- [default=[]] array of flags passed to emcc linking all object files.## Dependencies
- Emscripten## License
MIT License## Inspiration
Inspired by [cpp-wasm-loader](https://github.com/kobzol/cpp-wasm-loader).