Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Make/export Emception as a library. #7

Open
james-pre opened this issue Oct 19, 2022 · 11 comments
Open

[Feature Request] Make/export Emception as a library. #7

james-pre opened this issue Oct 19, 2022 · 11 comments

Comments

@james-pre
Copy link

james-pre commented Oct 19, 2022

This is a really cool project, though it's difficult to use a part of a project due to the lengthy build and compilation. Could we have Emception as a library?

For example (on a website):

<script src="emception.min.js"></script>
<script>
  let emception = new Emception();
  emception.run('echo "check out this!"').then(stdout => {
    //do stuff
  }).catch(stderr => {
    //do stuff
  });
  
</script>

A few things to note:

  • This is just an example, the actual API may vary greatly
  • It doesn't use the module system (UMD could work though)
  • For distribution you could add the js to the demo branch (maybe under a /dist folder)

Why do we need a library?

  • Saves developers time using it in their projects (the building takes hours)
  • Can be used without dependencies and such (devs just need to include a single file)
  • Much easier to use (adding the script tag vs currently having to clone the entire repo and all of Emception's dependencies, and building them from scratch)
@james-pre
Copy link
Author

@jprendes What do you think? If I can fix #8, I can try to do this myself.

@jprendes
Copy link
Owner

Definitely! PR's are welcome!
You can find pre-built artifacts in the 'demo' branch.

@cesare-montresor
Copy link

@jprendes @dr-vortex Are there any updates on making this awesome project easy to integrate?

I'm asking because I'm currently developing an educational coding app for learning Algorithms and Complexity:
LIVE DEMO: https://talco-team.github.io/TALightDesktop/

It's almost at RC1, at the moment I'm finishing off version one, using dyodide, which so far, it's working pretty well.

I really would like to add support for C/C++ once this project becomes stable. Emception is probably the most mature result I've seen out there, however for the time being, I'm having issues just compiling it on my local machine, with or without docker, (same issues as described in #11)

@james-pre
Copy link
Author

@cesare-montresor JSCPP is really cool: https://github.com/felixhao28/JSCPP

@cesare-montresor
Copy link

@cesare-montresor JSCPP is really cool: https://github.com/felixhao28/JSCPP

I like that project, but I like the idea of having gcc

@alienself
Copy link

@cesare-montresor were you able to build it? I am also unable to create a build because of python errors:

The necessary bits to build these optional modules were not found:
_bz2                  _ctypes               _ctypes_test
_curses               _curses_panel         _dbm
_gdbm                 _hashlib              _lzma
_ssl                  _tkinter              _uuid
readline
To find the necessary bits, look in configure.ac and config.log.

Could not build the ssl module!
Python requires a OpenSSL 1.1.1 or newer

configure: error: invalid or missing build python binary
make: make -j32
make: *** No targets specified and no makefile found.  Stop.

@cesare-montresor
Copy link

@cesare-montresor were you able to build it? I am also unable to create a build because of python errors:

The necessary bits to build these optional modules were not found:
_bz2                  _ctypes               _ctypes_test
_curses               _curses_panel         _dbm
_gdbm                 _hashlib              _lzma
_ssl                  _tkinter              _uuid
readline
To find the necessary bits, look in configure.ac and config.log.

Could not build the ssl module!
Python requires a OpenSSL 1.1.1 or newer

configure: error: invalid or missing build python binary
make: make -j32
make: *** No targets specified and no makefile found.  Stop.

Yes, same issue, probably the docker machine needs an update.

@alienself
Copy link

@cesare-montresor did you come across a similar project that works with emscripten?
I wish we could have something official from the emscripten folks or at least something more stable with an easy build step.
Be able to compile C++ directly in the browser would definitely be a great step forward

@jprendes any chance to get a fix?

@james-pre
Copy link
Author

@alienself @cesare-montresor

I can't remember where I saw it, but the python errors have to do with the newer version of pyodide being used when we try to build being different from the one @jprendes used. A hardcoded commit id in the pyodide clone/checkout should fix it.

@jcbhmr
Copy link

jcbhmr commented Mar 2, 2023

Here's some of my un-educated ideas for how an API might be modeled after some other existing "similarish" APIs:

Here's something like Node.js' node:vm API:

import { CPPSourceTextModule, CPPSTLLinker } from "./emception.js";

const module = new CPPSourceTextModule(String.raw`
#include <string>
#include <iostream>

int main() {
  std::string message = "Hello world!";
  std::cout << message << "\n";
}
`);
await module.link(CPPSTLLinker);
await module.evaluate();
// Any exports (if isn't main module)
console.log(module.namespace);

Or, maybe something more like the current WASM pipeline:

import { Emception } from "./emception.js";

const module = await Emception.compileStreaming(fetch("./index.cpp"));
// Somehow fetch all required functions...?
console.log(Emception.Module.imports(module));
const instance = await Emception.instantiate(module, { ... });
const exitCode = instance.exports.main(1, ["/hello"]);

Then again, I think this is a bit too low-level for the kind of abstract C++ compilation that most users want. Something higher-level is probably desired.

Or maybe something like what Pyodide does (pyodide.runPython() or https://pyodide.org/en/stable/usage/loading-custom-python-code.html)

import { unpackArchive, cppimport, runCPP } from "./emception.js";

await runCPP(`
#include <string>
#include <iostream>

int main() {
  std::string message = "Hello world!";
  std::cout << message << "\n";
}
`);

const response = await fetch("https://example.org/your_package.tar.gz");
const buffer = await response.arrayBuffer();
await unpackArchive(buffer);
cppimport("your_package");

Then again, you could implement them all if you really wanted to! 😉 These are just brainstorming ideas that I had and wanted to share.

@james-pre
Copy link
Author

... @dr-vortex Are there any updates on making this awesome project easy to integrate?

@cesare-montresor I've updated my GitHub username from @dr-vortex to @james-pre. Please update your comment, and I can delete this one. I'm writing this comment when I can't make the change myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants