Commit Detail
Commit 73617a4
Refactor Python startup code to prepare for Python pools For Python pools, we have to run `instantiateEmscriptenModule` before we bind the feature flags and set up the global scope and module registry. We will need to bundle all of the relevant code into a single script with no imports. This PR makes most of the typescript changes that will be needed to enable this. I split part of `python.ts` into a new file called `emscriptenSetup.ts` which intended for execution as part of the pool. To do this, `emscriptenSetup.ts` cannot import anything that uses C++ APIs. After this PR, it nearly satisfies this constraint except for the use of UnsafeEval by `newWasmModule`. I will fix that in a followup. Aside from moving code from `python.ts` to `emscriptenSetup.ts`, the code changes relate to the fact that `emscriptenSettings` cannot receive information from snapshot.ts. We have to cause the relevant effects dynamically. Instead of setting `INITIAL_MEMORY`, we use `Module.growMemory`. We patch Emscripten to read the value of `Module.noInitialRun` directly before calling `main()` (instead of loading it early and ignoring subsequent changes). And instead of calling `preloadDynamicLibs()` from a prerun hook, we use `addRunDependency()` to stall the initialization of the runtime until we have a chance to load the dynamic libraries.