Tested with berry_web commit 9ebc4e2d, Berry commit fa5d4330, Emscripten v3.1.68.
- Open this repo in devcontainer, e.g. using Github Codespaces. Type or copy/paste following commands to devcontainer's terminal.
cd
into the folder of this example:
cd browser-sync-xhr
- Clone the
berry_web
repo. It contains Berry's port to Emscripten platform and has main Berry-lang repo as submodule:
git clone --depth=1 --recurse-submodules https://github.com/berry-lang/berry_web.git
- Copy example's source into the folder
berry_web/platform
:
cp main.c berry_web/platform/berry.c
cd
into the folder ofberry_web
:
cd berry_web
-
Apply the patch:
- Patch Makefile to produce WASM output, enable outbound HTTP requests, and disable Asyncify (to save 650k of wasm file size)
- Patch platform/be_port.c to get rid of Asyncify call
dos2unix Makefile platform/be_port.c
git apply ../no-asyncify.patch
- Compile the example using Emscripten:
make
This command will output docs/berry.js
and docs/berry.wasm
.
cd
back into the folder of this example:
cd ..
- Copy WASM and glue JS into current folder:
cp berry_web/docs/berry.{js,wasm} ./
- Run simple HTTP server to temporarily publish project to Web:
python3 -m http.server
Codespace will show you "Open in Browser" button. Just click that button or obtain web address from "Forwarded Ports" tab.
- As
index.html
, JS files, and a 270k-sizedberry.wasm
are loaded into browser, refer to browser developer console to see the results.
Perform your own experiments if desired.