ユーザ用ツール

サイト用ツール


software:webassembly

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン前のリビジョン
次のリビジョン
前のリビジョン
software:webassembly [2021/10/29 21:06] – [Emscripten (emsdk)] ogasoftware:webassembly [2021/10/29 23:06] (現在) – [WASI] oga
行 27: 行 27:
 <code cpp> <code cpp>
 #include <stdio.h> #include <stdio.h>
-#include <emscripten.h>+#if __EMSCRIPTEN__ 
 +# include <emscripten.h> 
 +#endif
  
 int main() int main()
 { {
 +#if __EMSCRIPTEN__
     EM_ASM(     EM_ASM(
         FS.mkdir( '/cur' );         FS.mkdir( '/cur' );
         FS.mount( NODEFS, { root: '.' }, '/cur' );         FS.mount( NODEFS, { root: '.' }, '/cur' );
 +        FS.chdir( '/cur' );
     );     );
 +#endif
  
-    FILE*   fp= fopen( "/cur/test.txt", "r" );+    FILE*   fp= fopen( "test.txt", "r" );
     if( fp ){     if( fp ){
         char    buffer[128];         char    buffer[128];
行 55: 行 60:
 $ node a.out.js $ node a.out.js
 </code> </code>
 +
 +
 +===== WASI =====
 +
 +Emscripten とは異なり、共通の Systemcall を使用した wasm の実行環境があります。
 +
 +  * https://github.com/WebAssembly/wasi-sdk
 +
 +
 +<code>
 +$ $WASI_SDK_ROOT/bin/clang --target=wasm32-wasi --sysroot=$WASI_SDK_ROOT/share/wasi-sysroot  main.cpp
 +$ wasmtime a.out
 +</code>
 +
 +
 +  * 実行するには専用のランタイムが必要です。
 +
 +
 +
 +
 +
  
  
software/webassembly.1635509163.txt.gz · 最終更新: 2021/10/29 21:06 by oga

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki