Coder Social home page Coder Social logo

mischnic / parcel-plugin-emscripten Goto Github PK

View Code? Open in Web Editor NEW
9.0 3.0 2.0 66 KB

๐Ÿ“ฆ Import C(++) files with Parcel

Home Page: https://npm.im/parcel-plugin-emscripten

License: MIT License

JavaScript 85.15% Python 2.08% HTML 0.85% C 10.29% C++ 1.63%
emscripten parcel-plugin parcel-bundler parcel c cpp webassembly wasm

parcel-plugin-emscripten's Introduction

Parcel plugin for Emscripten

Build Status

A Parcel plugin to enable importing a C(++) file inside a JS file.

Emscripten has to be installed and emcc needs to be in PATH.

Example:

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));
});
//test.c
#include <emscripten.h>

int EMSCRIPTEN_KEEPALIVE add(int x, int y) {
    return x + y;
}

For more complex examples, see the example directory.

Instance.then is quite fragile and not a thenable, see emscripten-core/emscripten#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)

//parcel: -O0 lib.c
#include ...

parcel-plugin-emscripten's People

Contributors

mischnic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

parcel-plugin-emscripten's Issues

Doesn't work on Windows due to lack of PATHEXT support

On Windows we need to call emcc.bat instead of emcc. Node doesn't respect PATHEXT so doesn't do this automatically. This plugin should probably do something like process.platform === 'win32' ? 'emcc.bat' : 'emcc'. Current behaviour is ENOENT.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.