title: Why are there "wasi_snapshot_preview_1" imports in this wasm module?
body: <p>Recently I tried to experiment with webassembly with as few helpers as possible.</p>
  <p>So I created a c project, included some libraries (<code>stb_image.h</code>) and tried to compile it.</p>
  <p>Here is a short reproducible example:</p>
  <pre class="lang-c prettyprint-override"><code>#include &lt;emscripten.h&gt;
  #define STBI_NO_STDIO
  #define STBI_NO_FAILURE_STRINGS
  #define STB_IMAGE_IMPLEMENTATION
  
  #include &quot;stb_image.h&quot;
  
  EMSCRIPTEN_KEEPALIVE
  void test(){
      stbi_load_from_memory(NULL, 0, NULL, NULL, NULL, 0);
  }
  
  </code></pre>
  <p>Here is the command I used:</p>
  <p><code>emcc converter.c -s STANDALONE_WASM -o converter.wasm --no-entry</code></p>
  <p>This worked fine and gave me a valid wasm file.</p>
  <p>But then I tried to instantiate it in a browser with javascript and nothing else:</p>
  <pre><code>let wasm = await Webassembly.instantiateStreaming(fetch('converter.wasm'), {});
  </code></pre>
  <p>But I get this error:</p>
  <blockquote>
  <p>Uncaught (in promise) TypeError: WebAssembly.instantiate(): Import #0 module=&quot;wasi_snapshot_preview1&quot; error: module is not an object or function</p>
  </blockquote>
  <p>I inspected the webassembly, and indeed my webassembly need these functions:</p>
  <pre><code>  (func $wasi_snapshot_preview1.fd_close (;0;) (import &quot;wasi_snapshot_preview1&quot; &quot;fd_close&quot;) (param i32) (result i32))
    (func $wasi_snapshot_preview1.fd_seek (;1;) (import &quot;wasi_snapshot_preview1&quot; &quot;fd_seek&quot;) (param i32 i64 i32 i32) (result i32))
    (func $wasi_snapshot_preview1.fd_write (;2;) (import &quot;wasi_snapshot_preview1&quot; &quot;fd_write&quot;) (param i32 i32 i32 i32) (result i32))
    (func $wasi_snapshot_preview1.proc_exit (;3;) (import &quot;wasi_snapshot_preview1&quot; &quot;proc_exit&quot;) (param i32))
  </code></pre>
  <p>I understand that these are functions that are not supported in a pure wasm module (like os calls maybe ?) but I can't find any documentation on what each of them are exactly.</p>
  <p>So my questions are:</p>
  <ul>
  <li>What are these functions ?</li>
  <li>Why do I need these imported functions if the <code>stb_image</code> header is supposed to just manipulate bits in the ram with no i/o ?</li>
  <li>How can I tell my compiler to not use these functions (disabling the stdio library could work but I don't know how to do it)</li>
  </ul>
  <p>Any insignt is apreciated !</p>
  <h2>EDIT</h2>
  <p>After experimenting with compilation of the c standard libraries, I understand what these functions are for:</p>
  <ul>
  <li><code>fd_write</code> is for printing (normally to the stdout in the os)</li>
  <li><code>fd_seek</code> and <code>fd_close</code> are for file manipulation</li>
  </ul>
  <blockquote>
  <p>there is also <code>fd_read</code> to read a file but I don't need that in this code</p>
  </blockquote>
  <ul>
  <li><code>proc_exit</code> to terminate the process and potentially raise an error</li>
  </ul>