-
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web): POC of Core WASM integration into Keyman Web
- add temporary function to Core for this POC - add new CoreProcessor to access Keyman Core WASM - add unit tests for new core processor - add code to KeymanEngine and InputProcessor to load the new CoreProcessor - add web server to manual tests and new action `start` to build script This change requires the manual tests to be loaded from a web server instead of loaded as file, because otherwise the wasm code won't be loaded. Currently we always load CoreProcessor. This should be improved in a future change to only load when it is actually needed. Part-of: #11293
- Loading branch information
1 parent
153683c
commit 0abc250
Showing
22 changed files
with
339 additions
and
10 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 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 |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#ifdef __EMSCRIPTEN__ | ||
#ifdef __EMSCRIPTEN__ | ||
#include <emscripten/emscripten.h> | ||
#include <emscripten/bind.h> | ||
|
||
#else | ||
#define EMSCRIPTEN_KEEPALIVE | ||
#endif | ||
|
||
#ifdef __cplusplus | ||
#define EXTERN extern "C" EMSCRIPTEN_KEEPALIVE | ||
#else | ||
#define EXTERN EMSCRIPTEN_KEEPALIVE | ||
#endif | ||
|
||
#include <keyman_core.h> | ||
|
||
constexpr km_core_attr const engine_attrs = { | ||
256, | ||
KM_CORE_LIB_CURRENT, | ||
KM_CORE_LIB_AGE, | ||
KM_CORE_LIB_REVISION, | ||
KM_CORE_TECH_KMX, | ||
"SIL International" | ||
}; | ||
|
||
EMSCRIPTEN_KEEPALIVE km_core_attr const & tmp_wasm_attributes() { | ||
return engine_attrs; | ||
} | ||
|
||
EMSCRIPTEN_BINDINGS(compiler_interface) { | ||
|
||
// emscripten::class_<WasmCallbackInterface>("WasmCallbackInterface") | ||
// .function("message", &WasmCallbackInterface::message, emscripten::pure_virtual()) | ||
// .function("loadFile", &WasmCallbackInterface::loadFile, emscripten::pure_virtual()) | ||
// .allow_subclass<WasmCallbackInterfaceWrapper>("WasmCallbackInterfaceWrapper") | ||
// ; | ||
|
||
// emscripten::class_<KMCMP_COMPILER_OPTIONS>("CompilerOptions") | ||
// .constructor<>() | ||
// .property("saveDebug", &KMCMP_COMPILER_OPTIONS::saveDebug) | ||
// .property("compilerWarningsAsErrors", &KMCMP_COMPILER_OPTIONS::compilerWarningsAsErrors) | ||
// .property("warnDeprecatedCode", &KMCMP_COMPILER_OPTIONS::warnDeprecatedCode) | ||
// .property("shouldAddCompilerVersion", &KMCMP_COMPILER_OPTIONS::shouldAddCompilerVersion) | ||
// .property("target", &KMCMP_COMPILER_OPTIONS::target) | ||
// ; | ||
|
||
// emscripten::class_<WASM_COMPILER_RESULT>("CompilerResult") | ||
// .constructor<>() | ||
// .property("result", &WASM_COMPILER_RESULT::result) | ||
// .property("kmx", &WASM_COMPILER_RESULT::kmx) | ||
// .property("kmxSize", &WASM_COMPILER_RESULT::kmxSize) | ||
// .property("extra", &WASM_COMPILER_RESULT::extra) | ||
// ; | ||
|
||
// emscripten::class_<KMCMP_COMPILER_RESULT_MESSAGE>("CompilerResultMessage") | ||
// .constructor<>() | ||
// .property("errorCode", &KMCMP_COMPILER_RESULT_MESSAGE::errorCode) | ||
// .property("lineNumber", &KMCMP_COMPILER_RESULT_MESSAGE::lineNumber) | ||
// .property("columnNumber", &KMCMP_COMPILER_RESULT_MESSAGE::columnNumber) | ||
// .property("filename", &KMCMP_COMPILER_RESULT_MESSAGE::filename) | ||
// .property("parameters", &KMCMP_COMPILER_RESULT_MESSAGE::parameters) | ||
// ; | ||
|
||
// emscripten::class_<KMCMP_COMPILER_RESULT_EXTRA>("CompilerResultExtra") | ||
// .constructor<>() | ||
// .property("targets", &KMCMP_COMPILER_RESULT_EXTRA::targets) | ||
// .property("kmnFilename", &KMCMP_COMPILER_RESULT_EXTRA::kmnFilename) | ||
// .property("kvksFilename", &KMCMP_COMPILER_RESULT_EXTRA::kvksFilename) | ||
// .property("displayMapFilename", &KMCMP_COMPILER_RESULT_EXTRA::displayMapFilename) | ||
// .property("stores", &KMCMP_COMPILER_RESULT_EXTRA::stores) | ||
// .property("groups", &KMCMP_COMPILER_RESULT_EXTRA::groups) | ||
// ; | ||
|
||
// emscripten::value_object<KMCMP_COMPILER_RESULT_EXTRA_STORE>("CompilerResultExtraStore") | ||
// .field("storeType", &KMCMP_COMPILER_RESULT_EXTRA_STORE::storeType) | ||
// .field("name", &KMCMP_COMPILER_RESULT_EXTRA_STORE::name) | ||
// .field("line", &KMCMP_COMPILER_RESULT_EXTRA_STORE::line) | ||
// ; | ||
|
||
emscripten::value_object<km_core_attr>("km_core_attr") | ||
.field("max_context", &km_core_attr::max_context) | ||
.field("current", &km_core_attr::current) | ||
.field("revision", &km_core_attr::revision) | ||
.field("age", &km_core_attr::age) | ||
.field("technology", &km_core_attr::technology) | ||
//.field("vendor", &km_core_attr::vendor, emscripten::allow_raw_pointers()) | ||
; | ||
|
||
emscripten::function("tmp_wasm_attributes", &tmp_wasm_attributes); | ||
} | ||
#endif |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
src/import/ |
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/usr/bin/env bash | ||
|
||
## START STANDARD BUILD SCRIPT INCLUDE | ||
# adjust relative paths as necessary | ||
THIS_SCRIPT="$(readlink -f "${BASH_SOURCE[0]}")" | ||
. "${THIS_SCRIPT%/*}/../../../../resources/build/builder.inc.sh" | ||
## END STANDARD BUILD SCRIPT INCLUDE | ||
|
||
SUBPROJECT_NAME=engine/core-processor | ||
|
||
. "${KEYMAN_ROOT}/web/common.inc.sh" | ||
. "${KEYMAN_ROOT}/resources/shellHelperFunctions.sh" | ||
|
||
# ################################ Main script ################################ | ||
|
||
builder_describe "Keyman Core WASM integration" \ | ||
"@/core:wasm" \ | ||
"clean" \ | ||
"configure" \ | ||
"build" \ | ||
"test" \ | ||
"--ci+ Set to utilize CI-based test configurations & reporting." | ||
|
||
builder_describe_outputs \ | ||
configure "/web/src/engine/core-processor/src/import/core/core-interface.d.ts" \ | ||
build "/web/build/${SUBPROJECT_NAME}/lib/index.mjs" | ||
|
||
builder_parse "$@" | ||
|
||
#### Build action definitions #### | ||
|
||
do_clean() { | ||
rm -rf "${KEYMAN_ROOT}/web/build/${SUBPROJECT_NAME}" | ||
rm -rf "src/import/" | ||
} | ||
|
||
do_configure() { | ||
verify_npm_setup | ||
|
||
mkdir -p "src/import/core/" | ||
# we don't need this file here, but it's nice to have for reference and auto-completion | ||
cp "${KEYMAN_ROOT}/core/build/wasm/${BUILDER_CONFIGURATION}/src/core-interface.d.ts" "src/import/core/" | ||
} | ||
|
||
copy_deps() { | ||
mkdir -p "${KEYMAN_ROOT}/web/build/${SUBPROJECT_NAME}/obj/import/core/" | ||
cp "${KEYMAN_ROOT}/core/build/wasm/${BUILDER_CONFIGURATION}/src/"core{.js,.wasm,-interface.d.ts} "${KEYMAN_ROOT}/web/build/${SUBPROJECT_NAME}/obj/import/core/" | ||
} | ||
|
||
do_build () { | ||
copy_deps | ||
compile "${SUBPROJECT_NAME}" | ||
|
||
${BUNDLE_CMD} "${KEYMAN_ROOT}/web/build/${SUBPROJECT_NAME}/obj/index.js" \ | ||
--out "${KEYMAN_ROOT}/web/build/${SUBPROJECT_NAME}/lib/index.mjs" \ | ||
--format esm | ||
} | ||
|
||
builder_run_action clean do_clean | ||
builder_run_action configure do_configure | ||
builder_run_action build do_build | ||
|
||
# No headless tests for this child project. Currently, DOM-based unit & | ||
# integrated tests are run solely by the top-level $KEYMAN_ROOT/web project. |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
type km_core_attr = import('./import/core/core-interface.js').km_core_attr; | ||
|
||
export class CoreProcessor { | ||
private instance: any; | ||
|
||
/** | ||
* Initialize Core Processor | ||
* @param baseurl - The url where core.js is located | ||
*/ | ||
public async init(baseurl: string): Promise<boolean> { | ||
|
||
if (!this.instance) { | ||
try { | ||
const module = await import(baseurl + '/core.js'); | ||
this.instance = await module.default({ | ||
locateFile: function (path: string, scriptDirectory: string) { | ||
return baseurl + '/' + path; | ||
} | ||
}); | ||
} catch (e: any) { | ||
return false; | ||
} | ||
} | ||
return !!this.instance; | ||
}; | ||
|
||
public tmp_wasm_attributes(): km_core_attr { | ||
return this.instance.tmp_wasm_attributes(); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './core-processor.js'; |
Oops, something went wrong.