From cad515fbc3a8bff0a92b87ff55ca0f7342563827 Mon Sep 17 00:00:00 2001 From: Syoyo Fujita Date: Thu, 22 Sep 2022 04:36:58 +0900 Subject: [PATCH] Add WASI build procedure. --- README.md | 6 ++++++ wasm/Makefile | 11 +++++++++++ wasm/README.md | 31 +++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 wasm/Makefile create mode 100644 wasm/README.md diff --git a/README.md b/README.md index 143212e..d36cc1c 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,12 @@ In extension(`ExtensionMap`), JSON number value is parsed as int or float(number * [basic](examples/basic) : Basic glTF viewer with texturing support. * [build-gltf](examples/build-gltf) : Build simple glTF scene from a scratch. +### WASI/WASM build + +Users who want to run TinyGLTF securely and safely(e.g. need to handle malcious glTF file to serve online glTF conver), +I recommend to build TinyGLTF for WASM target. +WASI build example is located in [wasm](wasm) . + ## Projects using TinyGLTF * px_render Single header C++ Libraries for Thread Scheduling, Rendering, and so on... https://github.com/pplux/px diff --git a/wasm/Makefile b/wasm/Makefile new file mode 100644 index 0000000..133f54b --- /dev/null +++ b/wasm/Makefile @@ -0,0 +1,11 @@ +WASI_VERSION=16 +WASI_VERSION_FULL=${WASI_VERSION}.0 + +WASI_SDK_PATH=$(HOME)/local/wasi-sdk-${WASI_VERSION_FULL} + +CC=${WASI_SDK_PATH}/bin/clang +CXX=${WASI_SDK_PATH}/bin/clang++ +CXXFLAGS=-fno-rtti -fno-exceptions -g -Os + +all: + $(CXX) ../loader_example.cc $(CXXFLAGS) -I../ diff --git a/wasm/README.md b/wasm/README.md new file mode 100644 index 0000000..d1d50e2 --- /dev/null +++ b/wasm/README.md @@ -0,0 +1,31 @@ +Experimental WASI/WASM build + +## Build + +Download wasi-sdk https://github.com/WebAssembly/wasi-sdk + +Compile tinygltf with C++ exceptions and threads off. See `Makefile` for details +(NOTE: TinyGLTF itself does not use RTTI and threading feature(C++ threads, posix, win32 thread)) + +## Build examples and Run + +Build `loader_example.cc` + +``` +$ /path/to/wasi-sdk-16.0/bin/clang++ ../loader_example.cc -fno-rtti -fno-exceptions -g -Os -I../ -o loader_example.wasi +``` + +Tested with wasmtime. https://github.com/bytecodealliance/wasmtime + + +Set a folder containing .gltf file to `--dir` + +``` +$ wasmtime --dir=../models loader_example.wasi ../models/Cube/Cube.gltf +``` + +## Emscripen + +T.B.W. ... + +EoL.