-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(loadmodule): support single file binary load
BREAKING CHANGE: now runs on native-wasm supported runtime only
- Loading branch information
Showing
3 changed files
with
19 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,28 @@ | ||
import { ENVIRONMENT, isWasmEnabled } from 'emscripten-wasm-loader'; | ||
import { ENVIRONMENT, getModuleLoader } from 'emscripten-wasm-loader'; | ||
import { CldAsmModule } from './cldAsmModule'; | ||
import { CldFactory } from './cldFactory'; | ||
import { getLoader } from './getLoader'; | ||
import { cldLoader } from './cldLoader'; | ||
import { log } from './util/logger'; | ||
|
||
/** | ||
* Load, initialize wasm / asm.js binary to use actual cld wasm instances. | ||
* | ||
* @param {binaryEndpoint} [string] For overring path to wasm binary on node.js or browser. | ||
* @param {environment} [ENVIRONMENT] For overriding running environment | ||
* | ||
* @returns {Promise<CldFactory>} Factory function of cld to allow create instance of cld. | ||
* @returns {(environment?: ENVIRONMENT) => Promise<CldFactory>} Function to load module | ||
*/ | ||
const loadModule: (binaryEndpoint?: string, environment?: ENVIRONMENT) => Promise<CldFactory> = async ( | ||
binaryEndpoint?: string, | ||
environment?: ENVIRONMENT | ||
) => { | ||
const binaryPath = `./lib/${isWasmEnabled() ? 'wasm' : 'asm'}`; | ||
const loadModule = async (environment?: ENVIRONMENT) => { | ||
log(`loadModule: loading cld3 module`); | ||
|
||
try { | ||
return await getLoader(binaryPath, binaryEndpoint, environment); | ||
} catch (e) { | ||
log(`loadModule: cannot load module from `, binaryPath); | ||
//imports MODULARIZED emscripten preamble | ||
const runtimeModule = require(`./lib/cld3`); //tslint:disable-line:no-require-imports no-var-requires | ||
|
||
if (!isWasmEnabled()) { | ||
throw e; | ||
} else { | ||
log(`loadModule: try to fallback to asm.js runtime`); | ||
return await getLoader(`./lib/asm`, binaryEndpoint, environment); | ||
} | ||
} | ||
const moduleLoader = await getModuleLoader<CldFactory, CldAsmModule>( | ||
(runtime: CldAsmModule, env: ENVIRONMENT) => cldLoader(runtime, env), | ||
runtimeModule | ||
); | ||
|
||
return moduleLoader(environment); | ||
}; | ||
|
||
export { loadModule }; |