website icon indicating copy to clipboard operation
website copied to clipboard

Compile a WebAssembly module From Python3

Open yourlovemyall opened this issue 4 years ago • 4 comments

Compile a WebAssembly module From Python

Is there currently planned support? I am looking forward to using it.

yourlovemyall avatar Jan 17 '22 07:01 yourlovemyall

It depends what are trying to do exactly.

Are you trying to build a module form scratch? If so, then https://pypi.org/project/pybinaryen/ is probably what you want.

Or are you trying to build from C/C++ sources, in which case you probably just want to call out to emcc as a subproccess.

Or are you trying to run python code inside of webassembly, in which case you probably are looking for https://github.com/pyodide/pyodide

sbc100 avatar Jan 17 '22 14:01 sbc100

I want to build Python Code into wasm file , then run wasm file in wasmerio https://github.com/wasmerio/wasmer-go

yourlovemyall avatar Jan 18 '22 03:01 yourlovemyall

You can't compile Python code to Wasm, because Python is a dynamic language and Wasm is intended as a target for statically typed languages. Your best bet is running it in something like Pyodide which @sbc100 linked above.

RReverser avatar Jan 18 '22 13:01 RReverser

OTOH, if you're going to run Python in Pyodide, Pyodide in Wasmer, and, in turn, use Wasmer from Go, that just keeps adding levels of indirection which would likely lead to very poor performance... why not invoke Python executable directly from Go?

RReverser avatar Jan 18 '22 13:01 RReverser