Open7

V WASM study

zztkmzztkm

とりあえず現状直接のビルドはできないので、Cにコンパイルしてから WASM を作らないといけないっぽい

Discord眺めてたらこんな感じにビルドできるっぽい

./v -bare-builtin-dir vlib/builtin/wasm_bare -freestanding file.v -o file.c
# then change <inttypes.h> include to <stdint.h>
clang-12 file.c --no-standard-libraries -target wasm32 -o file.wasm
wasm-interp file.wasm

上記を試してみたところ、V->C はでたが C -> WASM ができなかった。。

ソースコード上の問題なのか、これができたときとのバージョンの違いなのかはわかっていない。

zztkmzztkm

とりあえずV言語のDiscordでWASMについて初学者向けの情報がないか消いてみてる

zztkmzztkm

久しぶりに V に触れたら、wasm ビルドのドキュメントが増えてた。

$ v help build-wasm
This command compiles the given target, along with their dependencies,
into an executable using the WebAssembly code generation backend.

Usage:
  v -b wasm [-options] ['run'] <target.v|target_directory> [run options]


For more general build help, see also `v help build`.

# Interfacing WebAssembly code generation, passing options to it:
   -wasm-validate
      After compiling the WebAssembly module, execute wasm-validate to validate the module.
      Useful for debugging the compiler.

   -wasm-stack-top
      Overrides the default stack_top value used by the WebAssembly compiler.
      Useful for some platforms with unusual memory requirements.

   -os <browser|wasi>, -target-os <browser|wasi>
      Change the target WebAssembly execution environment that V compiles for.

      The `wasi` target is the default execution environment.
        When targeting WASI, the generated WebAssembly module can be run in a variety
                of environments that support the WASI specification.
        WASI provides a standardized interface to interact with the host operating system,
                allowing WebAssembly modules to perform tasks like file I/O, networking, and more.
        The specific version of the WASI specification targeted by V is 'wasi_snapshot_preview1'.

      The `browser` target is an experimental environment that compiles for a stripped down
            builtin, for use in browsers. The produced WebAssembly module will have functions
                exported that are `pub` and inside the `module main`. See `examples/wasm/mandelbrot`
                for an example.