Skip to content

Releases: toyobayashi/emnapi

v0.29.1

09 Feb 09:23
Compare
Choose a tag to compare
  • Port emmalloc, publish libemmalloc.a

v0.29.0

07 Feb 12:51
Compare
Choose a tag to compare
  • 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 initialization

    import { 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

24 Jan 15:06
Compare
Choose a tag to compare

0.28.0 breaks the -O3 build, fixed

v0.28.0

23 Jan 17:04
Compare
Choose a tag to compare

#27

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

21 Jan 14:33
Compare
Choose a tag to compare

v0.27.0

20 Jan 13:57
Compare
Choose a tag to compare

v0.26.1

16 Jan 14:06
Compare
Choose a tag to compare

same as v0.26.0

v0.26.0

16 Jan 13:45
Compare
Choose a tag to compare
  • 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

13 Jan 14:51
Compare
Choose a tag to compare
  • fix esm runtime build (#24)
  • force add emnapiInit to EXPORTED_RUNTIME_METHODS

v0.25.0

13 Jan 13:56
Compare
Choose a tag to compare
  • 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()
})