【问题标题】:compile hello world to wasm and run in node将 hello world 编译为 wasm 并在节点中运行
【发布时间】:2017-03-17 08:29:18
【问题描述】:

我正在尝试在 node.js 中运行一个 webassembly 模块,我得到了一个Wasm decoding failedResult。我认为我的问题是将节点Buffer 转换为ArrayBuffer。这是我的适用代码:

fs.readFileAsync( WASM_PATH )
  .then( buf => buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength) )
  .then( arrayBuffer => Wasm.instantiateModule(arrayBuffer) )
  .then( results => console.log(results.instance) )
  .catch( err => console.error(err) );

我得到这个错误:

(relevant details) 

Wasm decoding failedResult = expected version 0c 00 00 00, found 01 00 00 00 @+4

当我使用emcc hello_world.c -s WASM=1 -o hello.html 时,我可以加载模块并在浏览器中运行它。所以,我很确定这是我的问题,或者可能是一些兼容性问题。提前致谢。

【问题讨论】:

    标签: node.js webassembly


    【解决方案1】:

    您的节点版本使用旧的 MVP 前 V8 版本,需要版本 0xC。您的工具链发出 now-stable MVP version 0x1

    节点 roughly follows Chrome releasesChrome 57 添加了对 MVP WebAssembly 的支持。该页面显示 Chrome 57 的 V8 版本是 5.7.492.65。

    因此,在 Node 中支持 MVP 迫在眉睫。

    您也可以使用较旧的 Emscripten 工具链。不过它会很旧:0xd 是 MVP 之前的版本(0xd 实际上与 MVP 相同,以版本为模)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-24
      • 2012-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-19
      相关资源
      最近更新 更多