Releases: toyobayashi/emnapi
v0.29.1
- Port
emmalloc
, publishlibemmalloc.a
v0.29.0
-
Add basic support for standard clang
wasm32-unknown-unknown
target, wasi-sdk and napi-rs, without async work and tsfn. #29 -
Publish
@tybys/emnapi-core
package for non-emscripten, which can be used for raw wasm initializationimport { createNapiModule } from '@tybys/emnapi-core' import { createContext } from '@tybys/emnapi-runtime' const context = createContext() const napiModule = createNapiModule({ context }) WebAssembly.instantiate(wasmBuffer, { env: { ...napiModule.imports.env, // Currently napi-rs imports all symbols from env module ...napiModule.imports.napi, ...napiModule.imports.emnapi }, // clang napi: napiModule.imports.napi, emnapi: napiModule.imports.emnapi }).then(({ instance }) => { const binding = napiModule.init(instance, instance.exports.memory, instance.exports.__indirect_function_table) // binding === napiModule.exports })
Using WASI on Node.js
import { createNapiModule } from '@tybys/emnapi-core' import { createContext } from '@tybys/emnapi-runtime' + import { WASI } from 'node:wasi' const context = createContext() const napiModule = createNapiModule({ context }) + const wasi = new WASI({ /* ... */ }) WebAssembly.instantiate(wasmBuffer, { + wasi_snapshot_preview1: wasi.wasiImport, env: { ...napiModule.imports.env, // Currently napi-rs imports all symbols from env module ...napiModule.imports.napi, ...napiModule.imports.emnapi }, // clang napi: napiModule.imports.napi, emnapi: napiModule.imports.emnapi }).then(({ instance }) => { + wasi.initialize(instance) const binding = napiModule.init(instance, instance.exports.memory, instance.exports.__indirect_function_table) // binding === napiModule.exports })
Using WASI on browser, I have made a WASI polyfill in wasm-util, and memfs-browser
import { createNapiModule } from '@tybys/emnapi-core' import { createContext } from '@tybys/emnapi-runtime' + import { WASI } from '@tybys/wasm-util' + import { Volumn, createFsFromVolume } from 'memfs-browser' const context = createContext() const napiModule = createNapiModule({ context }) + const fs = createFsFromVolume(Volume.from({ /* ... */ }) + const wasi = WASI.createSync({ fs, /* ... */ }) WebAssembly.instantiate(wasmBuffer, { + wasi_snapshot_preview1: wasi.wasiImport, env: { ...napiModule.imports.env, // Currently napi-rs imports all symbols from env module ...napiModule.imports.napi, ...napiModule.imports.emnapi }, // clang napi: napiModule.imports.napi, emnapi: napiModule.imports.emnapi }).then(({ instance }) => { + wasi.initialize(instance) const binding = napiModule.init(instance, instance.exports.memory, instance.exports.__indirect_function_table) // binding === napiModule.exports })
-
Publish precompiled static library in
@tybys/emnapi
package, include targets:wasm32-unknown-unknown
,wasm32-wasi
,wasm32-unknown-emscripten
-
Port dlmalloc for
wasm32-unknown-unknown
v0.28.1
0.28.0 breaks the -O3 build, fixed
v0.28.0
Add custom asynchronous operations API support and async_resource
parameter of napi_create_async_work
and napi_create_threadsafe_function
on Node.js
- napi_async_init
- napi_async_destroy
- napi_make_callback
return napi_generic_failure
on browser or nodeBinding
is not provided when initializing.
Module.emnapiInit({
context,
nodeBinding: require('@tybys/emnapi-node-binding')
})
v0.27.1
v0.27.0
v0.26.1
v0.26.0
napi_fatal_exception
node_api_get_module_file_name
napi_add_env_cleanup_hook
napi_remove_env_cleanup_hook
napi_add_async_cleanup_hook
napi_remove_async_cleanup_hook
v0.25.1
v0.25.0
- Initialization breaking change (#22)
Initialization Breaking Change:
before
Module.onEmnapiInitialized = function (err, emnapiExports) {
if (err) {
console.error(err)
return
}
emnapiExports.doSomething()
}
Module.onRuntimeInitialized = function () {
Module.emnapiExports.doSomething()
}
// -sMODULARIZE=1
Module().then(function (Module) {
Module.emnapiExports.doSomething()
})
after
npm install @tybys/emnapi-runtime
<script src="node_modules/@tybys/emnapi-runtime/dist/emnapi.min.js"></script>
const emnapi = require('@tybys/emnapi-runtime') // Node.js
const emnapi = window.emnapi // Browser
const context = emnapi.createContext()
Module.onRuntimeInitialized = function () {
try {
var binding = Module.emnapiInit({ context })
} catch (err) {
console.error(err)
return
}
binding.doSomething()
}
// -sMODULARIZE=1
Module().then(function (Module) {
try {
var binding = Module.emnapiInit({ context })
} catch (err) {
console.error(err)
return
}
binding.doSomething()
})