nandi/vflutter_ffipublic Fork 0
472eb493bac94bdcb79a38829ccca0c541256fef
Commits
Clone
git clone https://git.rickub.com/nandi/vflutter_ffi.git
git clone ssh://git@rickub.com/nandi/vflutter_ffi.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

build_wasm.sh · 61 lines · 2.6 KBBash Blame HistoryRaw
Add a WebAssembly backend for the example 728acaa nandithebull 18h ago1#!/usr/bin/env bash
Replace V with Nim 472eb49 nandithebull 17h ago2# Nim -> WebAssembly, for the Flutter web build of the example.
Add a WebAssembly backend for the example 728acaa nandithebull 18h ago3#
4# Nothing is installed system-wide. tool/bin/emcc is a DotSlash file pinning
5# emscripten by content hash; DotSlash fetches it on first run (~285 MB) and
6# caches it under ~/.cache/dotslash. Only `dotslash` itself has to be on PATH.
7#
8# Output lands in example/web/ and is loaded by a <script> tag in
Replace V with Nim 472eb49 nandithebull 17h ago9# example/web/index.html. Re-run after editing src/nimflutter.nim.
Add a WebAssembly backend for the example 728acaa nandithebull 18h ago10set -euo pipefail
11cd "$(dirname "$0")/.."
12
Replace V with Nim 472eb49 nandithebull 17h ago13nim_bin="${NIM:-nim}"
14command -v "$nim_bin" >/dev/null || {
15 echo "Nim compiler not on PATH (set NIM=/path/to/nim)"; exit 1; }
Add a WebAssembly backend for the example 728acaa nandithebull 18h ago16command -v node >/dev/null || { echo "node not on PATH (emscripten needs it)"; exit 1; }
17command -v dotslash >/dev/null || {
18 echo "dotslash not on PATH — https://dotslash-cli.com/docs/installation/" >&2
19 exit 1
20}
21
Replace V with Nim 472eb49 nandithebull 17h ago22nim_lib="$(dirname "$(dirname "$(command -v "$nim_bin")")")/lib"
Add a WebAssembly backend for the example 728acaa nandithebull 18h ago23out=example/web
24mkdir -p build "$out"
25
26# Fetches on first call, then just prints the cached path.
27emcc_path="$(dotslash -- fetch tool/bin/emcc)"
28root="$(dirname "$(dirname "$emcc_path")")"
29
30# emcc wants a config file; the DotSlash cache is content-addressed and must
31# stay read-only, so the config and the sysroot cache live under build/.
Replace V with Nim 472eb49 nandithebull 17h ago32cat > build/emscripten.config <<CONFIG
Add a WebAssembly backend for the example 728acaa nandithebull 18h ago33LLVM_ROOT = '$root/bin'
34BINARYEN_ROOT = '$root'
35NODE_JS = '$(command -v node)'
36CACHE = '$PWD/build/emcache'
Replace V with Nim 472eb49 nandithebull 17h ago37CONFIG
Add a WebAssembly backend for the example 728acaa nandithebull 18h ago38export EM_CONFIG="$PWD/build/emscripten.config"
39
Replace V with Nim 472eb49 nandithebull 17h ago40# Nim emits C for the wasm32 target; emcc turns that into wasm. --threads:off
41# because the emscripten module is single-threaded — bands still render, just
42# sequentially (see supportsIsolateParallelism on the Dart side).
43cache=build/nimcache_wasm
44rm -rf "$cache"
45"$nim_bin" c --compileOnly --nimcache:"$cache" --cpu:wasm32 --os:linux \
46 --mm:arc -d:danger --threads:off --noMain src/nimflutter.nim
Add a WebAssembly backend for the example 728acaa nandithebull 18h ago47
Replace V with Nim 472eb49 nandithebull 17h ago48# No -sGLOBAL_BASE here. The V build needed static data pushed above 1 MB to
49# dodge a null-pointer heuristic in its builtin memcpy; Nim's runtime has no
50# such guard, and a string round-trip through the default layout is verified
51# by tool/test_wasm.mjs.
52dotslash tool/bin/emcc "$cache"/*.c -I"$nim_lib" -O3 -o "$out/nimflutter.js" \
Add a WebAssembly backend for the example 728acaa nandithebull 18h ago53 -sMODULARIZE=1 \
Replace V with Nim 472eb49 nandithebull 17h ago54 -sEXPORT_NAME=createNimFlutterModule \
Add a WebAssembly backend for the example 728acaa nandithebull 18h ago55 -sENVIRONMENT=web,worker,node \
56 -sALLOW_MEMORY_GROWTH=1 \
Replace V with Nim 472eb49 nandithebull 17h ago57 -sEXPORTED_FUNCTIONS='["_nf_init","_nf_add","_nf_greet","_nf_free","_nf_mandelbrot","_malloc","_free"]' \
Add a WebAssembly backend for the example 728acaa nandithebull 18h ago58 -sEXPORTED_RUNTIME_METHODS='["ccall","cwrap","UTF8ToString","stringToUTF8","lengthBytesUTF8","HEAPU8"]'
59
Replace V with Nim 472eb49 nandithebull 17h ago60echo "built: $out/nimflutter.js ($(stat -c%s "$out/nimflutter.js") bytes)," \
61 "$out/nimflutter.wasm ($(stat -c%s "$out/nimflutter.wasm") bytes)"