From a4c46703e1cf60ba880f8203818ebb74488b8271 Mon Sep 17 00:00:00 2001 From: Nikolay Igotti Date: Tue, 24 Dec 2024 14:34:21 +0300 Subject: [PATCH] WIP loader Signed-off-by: Nikolay Igotti --- interop/src/interop/loadLibraries.ts | 12 +----------- interop/src/node/loader.ts | 11 +++++++++++ interop/src/ohos/loader.ts | 3 +++ interop/tsconfig.json | 3 ++- 4 files changed, 17 insertions(+), 12 deletions(-) create mode 100644 interop/src/node/loader.ts create mode 100644 interop/src/ohos/loader.ts diff --git a/interop/src/interop/loadLibraries.ts b/interop/src/interop/loadLibraries.ts index be37ebb22..ca9e6515d 100644 --- a/interop/src/interop/loadLibraries.ts +++ b/interop/src/interop/loadLibraries.ts @@ -1,18 +1,8 @@ -import * as path from "path" -import * as process from "process" -import * as os from "os" +import { loadLibrary } from "#platform/loader" const nativeModulesToLoad: Map = new Map() const lateInitNativeModules: Map = new Map() -function loadLibrary(name: string): Record { - const libPath = path.resolve(name + ".node"); // TODO lib dir, support es6 modules, etc. - console.debug("Loading native library from " + libPath) - const exports = {} - ;(process as any).dlopen({ exports }, libPath, (os.constants as any).dlopen.RTLD_NOW) ; //TODO fix @types/node - return exports -} - export function loadLibraries(libraries: string[]) { for (const lib of libraries) { const modules = loadLibrary(lib) diff --git a/interop/src/node/loader.ts b/interop/src/node/loader.ts new file mode 100644 index 000000000..9008e568d --- /dev/null +++ b/interop/src/node/loader.ts @@ -0,0 +1,11 @@ +import * as path from "path" +import * as process from "process" +import * as os from "os" + +export function loadLibrary(name: string): Record { + const libPath = path.resolve(name + ".node"); // TODO lib dir, support es6 modules, etc. + console.debug("Loading native library from " + libPath) + const exports = {} + ;(process as any).dlopen({ exports }, libPath, (os.constants as any).dlopen.RTLD_NOW) ; //TODO fix @types/node + return exports +} diff --git a/interop/src/ohos/loader.ts b/interop/src/ohos/loader.ts new file mode 100644 index 000000000..fa4949204 --- /dev/null +++ b/interop/src/ohos/loader.ts @@ -0,0 +1,3 @@ +export function loadLibrary(name: string): Record { + return requireNapi(name) +} diff --git a/interop/tsconfig.json b/interop/tsconfig.json index 61ede472f..a920ec7b2 100644 --- a/interop/tsconfig.json +++ b/interop/tsconfig.json @@ -19,7 +19,8 @@ "types": ["node"], "paths": { "@koalaui/common": ["../incremental/common/src"], - "#common/wrappers/*": ["./src/napi/wrappers/*", "./src/wasm/wrappers/*"] + "#common/wrappers/*": ["./src/napi/wrappers/*", "./src/wasm/wrappers/*"], + "#platform/*": ["./src/ohos/*", "./src/node/*"] } }, "include": ["src/**/*"], -- Gitee