Skip to content

v0.29.0

Compare
Choose a tag to compare
@github-actions github-actions released this 07 Feb 12:51
· 347 commits to main since this release
  • 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