mirror of https://github.com/pyodide/pyodide.git
Fix #4: Use WASM
This commit is contained in:
parent
191ca2c7bd
commit
7e5b45a08e
|
@ -1,4 +1,4 @@
|
|||
root/
|
||||
|
||||
python.asm.*
|
||||
pyodide.asm.*
|
||||
*.bc
|
||||
|
|
16
Makefile
16
Makefile
|
@ -7,6 +7,7 @@ CXX=em++
|
|||
OPTFLAGS=-O2
|
||||
CXXFLAGS=-std=c++14 $(OPTFLAGS) -g -I $(CPYTHON_EMSCRIPTEN_ROOT)/installs/python-$(PYVERSION)/include/python$(PYMINOR)/ -Wno-warn-absolute-paths
|
||||
LDFLAGS=$(OPTFLAGS) $(CPYTHON_EMSCRIPTEN_ROOT)/installs/python-$(PYVERSION)/lib/libpython$(PYMINOR).a \
|
||||
-s "BINARYEN_METHOD='native-wasm,interpret-binary,interpret-asm2wasm'" \
|
||||
-s TOTAL_MEMORY=268435456 \
|
||||
-s ASSERTIONS=2 \
|
||||
-s EMULATE_FUNCTION_POINTER_CASTS=1 \
|
||||
|
@ -14,27 +15,22 @@ LDFLAGS=$(OPTFLAGS) $(CPYTHON_EMSCRIPTEN_ROOT)/installs/python-$(PYVERSION)/lib/
|
|||
--memory-init-file 0
|
||||
|
||||
|
||||
all: python.asm.js
|
||||
all: pyodide.asm.html
|
||||
|
||||
|
||||
python.asm.js: main.bc root
|
||||
$(CC) --bind -o $@ $(filter %.bc,$^) $(LDFLAGS) \
|
||||
pyodide.asm.html: main.bc root
|
||||
$(CC) -s WASM=1 --bind -o $@ $(filter %.bc,$^) $(LDFLAGS) \
|
||||
$(foreach d,$(wildcard root/*),--preload-file $d@/$(notdir $d))
|
||||
|
||||
|
||||
serve: python.asm.js
|
||||
@echo "Serving on port 8062"
|
||||
python -m SimpleHTTPServer 8062
|
||||
|
||||
|
||||
clean:
|
||||
-rm -fr root
|
||||
-rm python.asm.js python.asm.data python.asm.wasm
|
||||
-rm pyodide.asm.*
|
||||
-rm *.bc
|
||||
|
||||
|
||||
%.bc: %.cpp $(CPYTHON_EMSCRIPTEN_ROOT)/installs/python-$(PYVERSION)/lib/python$(PYMINOR)
|
||||
$(CXX) -o $@ $< $(CXXFLAGS)
|
||||
$(CXX) --bind -o $@ $< $(CXXFLAGS)
|
||||
|
||||
|
||||
root: $(CPYTHON_EMSCRIPTEN_ROOT)/installs/python-$(PYVERSION)/lib/python$(PYMINOR)
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
var Module = {}
|
||||
|
||||
{
|
||||
let wasmURL = 'pyodide.asm.wasm';
|
||||
let wasmXHR = new XMLHttpRequest();
|
||||
wasmXHR.open('GET', wasmURL, true);
|
||||
wasmXHR.responseType = 'arraybuffer';
|
||||
wasmXHR.onload = function() {
|
||||
if (wasmXHR.status === 200 || wasmXHR.status === 0) {
|
||||
Module.wasmBinary = wasmXHR.response;
|
||||
} else {
|
||||
var wasmURLBytes = tryParseAsDataURI(wasmURL);
|
||||
if (wasmURLBytes) {
|
||||
Module.wasmBinary = wasmURLBytes.buffer;
|
||||
}
|
||||
}
|
||||
|
||||
var memoryInitializer = 'pyodide.asm.html.mem';
|
||||
if (typeof Module['locateFile'] === 'function') {
|
||||
memoryInitializer = Module['locateFile'](memoryInitializer);
|
||||
} else if (Module['memoryInitializerPrefixURL']) {
|
||||
memoryInitializer = Module['memoryInitializerPrefixURL'] + memoryInitializer;
|
||||
}
|
||||
Module['memoryInitializerRequestURL'] = memoryInitializer;
|
||||
var meminitXHR = Module['memoryInitializerRequest'] = new XMLHttpRequest();
|
||||
meminitXHR.open('GET', memoryInitializer, true);
|
||||
meminitXHR.responseType = 'arraybuffer';
|
||||
meminitXHR.send(null);
|
||||
|
||||
var script = document.createElement('script');
|
||||
script.src = "pyodide.asm.js";
|
||||
document.body.appendChild(script);
|
||||
|
||||
};
|
||||
wasmXHR.send(null);
|
||||
}
|
Loading…
Reference in New Issue