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

Not supported: WebAssembly(wasm) #41

Closed
appcypher opened this issue Dec 16, 2017 · 22 comments
Closed

Not supported: WebAssembly(wasm) #41

appcypher opened this issue Dec 16, 2017 · 22 comments
Labels
question Question asked about Nuitka unsupported

Comments

@appcypher
Copy link

It's a beautiful project you have here. I admire it quite a lot and come around once in a while to learn from it even though I don't use it directly in my work.
I understand the core developer of this project may have a lot on his plate but I've often wondered if Nuitka could have a wasm codegen phase.
The idea of having Python run in the browser is fascinating and I can't wait to see the possible applications of it. I, for one, would love to write some of my web apps in Python, I believe a lot of people would too.
I know my way around wasm and wast and I could help out with the codegen, but if there is a reason this idea won't work I would like to know.

@kayhayen kayhayen added enhancement An improvement rather than a bug help wanted Please help with this, we think you can question Question asked about Nuitka labels Jan 5, 2018
@kayhayen
Copy link
Member

kayhayen commented Jan 5, 2018

Nuitka depends on "libpython" to work. If you can load that, it's fine, but I doubt it.

@kayhayen kayhayen changed the title WebAssembly(wasm) support Not supported: WebAssembly(wasm) Jan 5, 2018
@rafi16jan
Copy link

libpython is a C library right? isn't Webassembly compiles a LLVM compatible code (and its dependencies) to byte code? I want to try this

@kayhayen
Copy link
Member

@rafi16jan Go ahead, you are welcome.

@kayhayen kayhayen assigned kayhayen and unassigned kayhayen Jul 20, 2018
@kayhayen
Copy link
Member

Meh, cannot assign you, but consider yourself in charge until you give up @rafi16jan

@rafi16jan
Copy link

Ok, I'll report

@rafi16jan
Copy link

After weeks of busy routines I finally have the time to try to tinker with Nuitka and the Emscripten Compiler... And no avail, everything that needs the Python Runtime won't work (Nuitka, Cython, Pyrex, I only tried these 3).. But I found RPython, basicly it have a translator/transpiler that can translate/transpile a subset of python "staticly" to C without the Python runtime. By staticly means it can't be dynamic (one variable can only be one type, no lambda, only higher order functions, etc) and it surprisingly able to be compiled with emcc (Emscripten). Although the produced llvm give an error about unresolved symbol when executed in WebAssembly:

warning: unresolved symbol: pypy_debug_tracebacks

Even though I know this is Nuitka Github Repo but I want to ask for your help @kayhayen and any Pythonista who are fluent in C that came accross because I think this is the right idea to bring Python to the Web (performance wise). Compiling the full CPython or any other Python Runtime will make the download size very large and bringing many problems.

@kayhayen kayhayen added unsupported and removed enhancement An improvement rather than a bug help wanted Please help with this, we think you can labels Aug 15, 2018
@kayhayen
Copy link
Member

Thanks for reporting. I do not mind reading good things about PyPy, which is behind RPython. I think it is good for what it does. I actually once contributed a small patch to it, a decade ago. :)

I am putting this to unsupported then, leaving the question tag, so people will find it.

@rafi16jan
Copy link

Can you (or maybe the right question is, do you have time :D) to give us newbies guide/advice to debug this RPython and the C source it generated. We younglings aren't like you guys that can understand C the same way we understand Python. It's heaven and earth to us (maybe hell). We're generation that aren't used to compile things, unless it is java or .net haha

@kayhayen
Copy link
Member

Not enough time for Nuitka as it stands.

@rafi16jan
Copy link

Ok I understand

@ids1024
Copy link

ids1024 commented Aug 15, 2018

Hm, rpython+wasm is an interesting option.

warning: unresolved symbol: pypy_debug_tracebacks

Try grepping the rpython/pypy source code for that function to see where it's defined and find out why it isn't being compiled/linked properly. From the name, I'm guessing you could replace it with an empty function with the same signature, at the cost of breaking tracebacks.

@CrazyPython
Copy link

@rafi16jan I know a bit of C, I’m willing to help.

@CrazyPython
Copy link

Maybe we can ask on the PyPy mailing list.

@rafi16jan
Copy link

rafi16jan commented Feb 1, 2019

@CrazyPython Nice, where do we start?

@rafi16jan
Copy link

rafi16jan commented Feb 1, 2019

Although RPython will be the fastest subset of python for compilation, but it feels like it won't be that easy to target it to wasm. The current viable one is actually MicroPython, there are working POC for it

https://github.com/numworks/epsilon/tree/master/python
https://github.com/pmp-p/micropython-ports-wasm

But I am more interested in RPython performance wise, but if it is too complex to be targeted to wasm maybe we can search for another alternative like MicroPython.

@rafi16jan
Copy link

@wolfv Sorry for tagging you hehe, how's your experience with the new MicroPython javascript port?

@wolfv
Copy link

wolfv commented Mar 19, 2019

It's quite straightforward nowadays to compile to webassembly. you just need to know which functions to export.
Nowadays you should also be able to find libpython compiled to webassembly. however, it will be much larger than micropython (which is the big advantage). MicroPython compiled is only ~200kb, so in the same range as modern JS frameworks.

@rafi16jan
Copy link

@wolfv Is there already a way to interact with DOM or WebAPIs? Because I ask another port to WASM what's the difference between his port and the official port, he promises that he will add DOM interaction and even asyncio support with requestAnimationFrame. Take a look at this

@rafi16jan
Copy link

Not related to Nuitka, but I have make an ES6 Module of the official MicroPython WASM port. https://www.npmjs.com/package/micropython

@appcypher @ids1024 @CrazyPython

@pmp-p
Copy link

pmp-p commented Sep 25, 2019

Nuitka depends on "libpython" to work. If you can load that, it's fine, but I doubt it.

@kayhayen libpython3.8.a is (now) easy to build with clang 10 ( emsdk tot-upstream ) and i did not find any problem running standard stdlib python code in repl.

https://pmp-p.github.io/python-next/test.html patches here https://github.com/pmp-p/pydk/tree/master/sources.em

If anyone would like to experiment Nuitka on that lib i'm ready to help ( i'm on gitter and freenode )

@rafi16jan i made the asyncio micropython DOM support compatible with cpython too with the same module see the test page above.

@dhiahassen
Copy link

@pmp-p @rafi16jan @wolfv @CrazyPython , i am a very experienced C/C++ programmer , i will be there for help for any C/C++ related things

@rafi16jan
Copy link

rafi16jan commented Dec 2, 2019

@pmp-p @rafi16jan @wolfv @CrazyPython , i am a very experienced C/C++ programmer , i will be there for help for any C/C++ related things

Great! Months ago I've successfully fork RPython to be able to compile to WASM. Please give any feedback here https://github.com/rafi16jan/rpython-wasm

I would like to see someone continue the work since I'm busy with other things right now, also pardon me if there's bad C code since I'm very bad at C and strong typed languages in general

@Nuitka Nuitka locked and limited conversation to collaborators Oct 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Question asked about Nuitka unsupported
Projects
None yet
Development

No branches or pull requests

8 participants