Fix #28: Compile side modules asyncronously

Requires upstream changes to emscripten
This commit is contained in:
Michael Droettboom 2018-06-07 09:33:05 -04:00
parent d562ed9744
commit a81603286b
2 changed files with 27 additions and 8 deletions

View File

@ -31,7 +31,8 @@ LDFLAGS=\
-s USE_FREETYPE=1 \
-std=c++14 \
-lstdc++ \
--memory-init-file 0
--memory-init-file 0 \
--minify 0
SIX_ROOT=six/six-1.11.0/build/lib
SIX_LIBS=$(SIX_ROOT)/six.py
@ -62,7 +63,7 @@ build/pyodide.asm.js: src/main.bc src/jsimport.bc src/jsproxy.bc src/js2python.b
build/pyodide.asm.data: root/.built
python2 $(FILEPACKAGER) build/pyodide.asm.data --preload root/lib@lib --js-output=build/pyodide.asm.data.js
python2 $(FILEPACKAGER) build/pyodide.asm.data --preload root/lib@lib --js-output=build/pyodide.asm.data.js --use-preload-plugins
uglifyjs build/pyodide.asm.data.js -o build/pyodide.asm.data.js

View File

@ -71,22 +71,40 @@ var languagePluginLoader = new Promise((resolve, reject) => {
let Module = {};
window.Module = Module;
Module.noImageDecoding = true;
Module.noAudioDecoding = true;
let wasm_promise = WebAssembly.compileStreaming(fetch(wasmURL));
Module.instantiateWasm = (info, receiveInstance) => {
wasm_promise.then(module => WebAssembly.instantiate(module, info))
.then(instance => receiveInstance(instance));
wasm_promise
.then(module => WebAssembly.instantiate(module, info))
.then(instance => receiveInstance(instance));
return {};
};
Module.filePackagePrefixURL = baseURL;
Module.postRun = () => {
delete window.Module;
fetch(`${baseURL}packages.json`)
var postRunPromise = new Promise((resolve, reject) => {
Module.postRun = () => {
delete window.Module;
fetch(`${baseURL}packages.json`)
.then((response) => response.json())
.then((json) => {
window.pyodide.packages = json;
resolve();
});
};
};
});
var dataLoadPromise = new Promise((resolve, reject) => {
Module.monitorRunDependencies = (n) => {
if (n === 0) {
delete Module.monitorRunDependencies;
resolve();
}
}
});
Promise.all([postRunPromise, dataLoadPromise]).then(() => resolve());
let data_script = document.createElement('script');
data_script.src = `${baseURL}pyodide.asm.data.js`;