From a81603286b8601015661ee00df31be884d06f6cd Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Thu, 7 Jun 2018 09:33:05 -0400 Subject: [PATCH] Fix #28: Compile side modules asyncronously Requires upstream changes to emscripten --- Makefile | 5 +++-- src/pyodide.js | 30 ++++++++++++++++++++++++------ 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index d879478ed..3fa9bf047 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/src/pyodide.js b/src/pyodide.js index 52fc51fe0..f8aaf0dfc 100644 --- a/src/pyodide.js +++ b/src/pyodide.js @@ -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`;