4

I have successfully installed Emscripten and have it running on an Ubuntu 16.04 virtual machine. I have also successfully converted a helloworld.c file to web assembly. Currently, I am attempting to convert python to web assembly with emscripten. The issue is that emscripten does not support python currently, so as a work around I have attempted to convert the python code to C with Cython, which I successfully did. Though I am getting an error when attempting to convert the cython c file to Web assembly. Here is the console log:

$emcc pony_gp.c -o pony_gp.html

In file included from pony_gp.c:11:
In file included from /usr/include/python2.7/Python.h:58:
/usr/include/python2.7/pyport.h:886:2: error: "LONG_BIT definition appears 
wrong for platform (bad gcc/glibc config?)."
#error "LONG_BIT definition appears wrong for platform (bad gcc/glibc config?)."
ERROR:root:compiler frontend failed to generate LLVM bitcode, halting

According to pyport.h, this error is generated because in some 32 bit systems LONG_BIT is defined incorrectly as 64 when it should be 32. I have tried commenting out this line, but this only allowed the program to silently run, in the end without producing any web assembly code, only html and javascript.

I have read here, that the issue is because "cmake is picking up one version of the python dylib and a separate version of python for the headers". This makes sense as I recently downgraded from Python 2.7.13-1 to Python 2.7.11-1 because Python 2.7.13-1 was not compatible with python-dev packages. Though, I don't know how I would fix this.

Does anyone have an idea on what to do?

iehrlich
  • 3,572
  • 4
  • 34
  • 43
Robbie
  • 1,733
  • 2
  • 13
  • 20
  • 1
    it would be helpful if you post the python code and the steps to convert it to cython. That would increase your chances to get an answer. – Adnan Y Jul 01 '17 at 07:44

1 Answers1

3

While not a full answer, you should be able to compile pony_gp.c directly to LLVM (.ll) using clang, preferably the same clang provided with Emscripten, for example:

source ~/emsdk/emsdk_env.sh
cython hello.py
clang `python2-config --cflags` -S -emit-llvm hello.c

Then, the generated .ll file could be fed directly to Emscripten.

For producing a fully working Python -> WebAssembly you should probably also need to link against the Python runtime - you could use the one distributed with emcc which is already compiled into LLVM bytecode (.bc), emsdk/emscripten/incoming/tests/python/python.bc.

Also, this may be of help: https://github.com/dgym/cpython-emscripten

valiano
  • 16,433
  • 7
  • 64
  • 79