-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support custom import namespace for functions implemented in JavaScript #20035
Comments
At this point we do not have any way to support this, but such a feature does seem potentially useful. Can you explain why using |
@sbc100 Currently emnapi is maintaining a modified version of Node-API headers. In this PR nodejs/node#49037 I want to make Node.js node-api official header can be used by emnapi, but Node.js intentionally already expands For this, there are two options:
Both are breaking changes for users. So I'm wondering if emscripten could provide this feature. |
Another option might be modify In the long term I can see that this would be useful feature in emscripten, I'm just not sure when we will have time to add such a thing. |
yeah I have done this but Node.js doesn‘t recommend doing this as you can see the comments in that PR so reverted those changes. it will be really nice to add this feature. |
@sbc100 Lines 932 to 946 in 097290d
to // "imports" is the name used in MINIMAL_RUNTIME
var imports = {
env: wasmImports,
// ...
};
function createWasm() {
// ...
} So that users can add symbol to custom namespace via mergeInto(LibraryManager.library, {
napi_create_int32: function (env, value, result) {
// ...
},
napi_create_int32__sig: 'ipip',
napi_create_int32__postset: '(imports.napi = imports.napi || {}).napi_create_int32 = napi_create_int32;'
}) |
It would be nice to have a hook that just allows modifying imports. I don't have any issue with implementing a custom |
Oh but I guess #20130 is indeed an alternative solution where a hook isn't added. The benefit of the hook is that you could add code to be run after all other setup but before instantiation -- not sure if this is important. I have a patch to add a hook like this in Pyodide: --- a/src/preamble.js
+++ b/src/preamble.js
@@ -937,6 +941,9 @@ function instantiateAsync(binary, binaryFile, imports, callback) {
// Create the wasm instance.
// Receives the wasm imports, returns the exports.
function createWasm() {
+ if (Module.adjustWasmImports) {
+ Module.adjustWasmImports(wasmImports);
+ }
// prepare imports
var info = {
#if MINIFY_WASM_IMPORTED_MODULES |
@hoodmane Unfortunately adding this hook does not satisfy my scenario, because I am the JavaScript library provider, this way still requires my user modify their code. What I want is that I as the library author can specify the import namespace in the JavaScript library file ( |
Yeah it sounds like these are pretty different use cases -- I build the main module and have downstream users that make custom dynamically linked libraries, whereas your downstream wants to statically link your library. |
Sorry to bother, it has been more than a year, is there any plan or progress on this issue? |
I've tried several times over the year to make this work, and I have yet to come up with a solution. emscripten has a lot of baked in assumption about the flat symbol namespace, and it proved tricky to inject this extra information everywhere. |
Can I specify a custom import namespace for JavaScript function?
compile result
Refs: nodejs/node#49037
The text was updated successfully, but these errors were encountered: