WebAssembly is not limited to running in a web browser. We support running the compiled WASM binaries also using Wasmtime, though without rendering.
Warning
|
Trying to render anything in Wasmtime will fail, as we don’t have access to WebGL API and context. So you cannot even create TCastleWindow , i.e. it will fail inside Wasmtime with
Exception: Failed to load OpenGL(ES) library
and we don’t have immediate plans to make it work. But, at least everything else (all the code up to the rendering) will work on Wasmtime.
If you know of an easy way to pass WebGL API and context to application run in Wasmtime (e.g. implementing WebGL by OpenGL(ES) on the desktop), let us know. And note that we prefer to pass WebGL API, not OpenGL(ES) API, to our application run in Wasmtime. We want the wasmtime to work as close to web browser as possible, 1. because it avoids wasmtime -specific maintenance, 2. because it makes wasmtime more suited to debugging what happens on the web, which is its main use-case for us.
|
Just run then like this on the command-line:
export WASMTIME_BACKTRACE_DETAILS=1 # get a more detailed backtrace
wasmtime <project-name>.wasm
The WASM file is in the project top-level directory if you compiled using
castle-engine compile --os=wasi --cpu=wasm32 --mode=debug
or inside castle-engine-output/web/dist/
if you compiled using
castle-engine compile -web=target --mode=debug
The main use-case of this is additional debugging approach. In case of a crash, the wasmtime
will give you a useful stack trace with line numbers (if only you compiled with --mode=debug
, as shown above).
6.1. Running engine test-suite on WASM
As a particular application of the above ("you can run engine code using wasmtime, except rendering"), you can run our test suite on WASM.
Warning
|
Making castle-tester.wasm work this way is a work-in-progress. The time_measurements_tests.wasm mentioned below works already.
|
cd tests/
castle-engine compile --os=wasi --cpu=wasm32 --mode=debug
wasmtime castle-tester.wasm --console --no-window-create
cd time_measurements_tests/ # enter tests/time_measurements_tests/ in CGE
castle-engine compile --os=wasi --cpu=wasm32 --mode=debug
wasmtime time_measurements_tests.wasm