Skip to content

Commit

Permalink
Quality of life improvements for static web sample. (iree-org#8240)
Browse files Browse the repository at this point in the history
* Move web server script to scripts/ so it can be used more naturally for other samples
* Fetch easeljs library and use the local server script, to be ready for CORS / SharedArrayBuffer / Emscripten pthreads experiments
* Set `-g -gseparate-dwarf` per https://developer.chrome.com/blog/wasm-debugging-2020/, enabling DWARF debugging instead of source map debugging, then remove the serving directory hack
  * serving the entire source tree with a nested build tree may have also been OOM-ing my tabs... not sure - just serving a 600KB `.wasm` and a 2MB `.debug.wasm` is much better anyways
  • Loading branch information
ScottTodd authored Feb 4, 2022
2 parents b55cefd + 4957d8b commit de1935a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
10 changes: 6 additions & 4 deletions experimental/sample_web_static/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ target_link_options(${_NAME} PRIVATE
#
"-sASSERTIONS=1"
#
"-gsource-map"
"-source-map-base="
# https://developer.chrome.com/blog/wasm-debugging-2020/
"-g"
"-gseparate-dwarf"
)

#-------------------------------------------------------------------------------
Expand Down Expand Up @@ -91,8 +92,9 @@ target_link_options(${_NAME} PRIVATE
#
"-sASSERTIONS=1"
#
"-gsource-map"
"-source-map-base="
# https://developer.chrome.com/blog/wasm-debugging-2020/
"-g"
"-gseparate-dwarf"
#
# https://emscripten.org/docs/porting/pthreads.html#compiling-with-pthreads-enabled
"-pthread"
Expand Down
19 changes: 7 additions & 12 deletions experimental/sample_web_static/build_static_emscripten_demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pushd ${ROOT_DIR?}/build-emscripten
# Note: The sample creates a task device directly, so no drivers are required,
# but some targets are gated on specific CMake options.
emcmake "${CMAKE_BIN?}" -G Ninja .. \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DIREE_HOST_BINARY_ROOT=$PWD/../build-host/install \
-DIREE_BUILD_EXPERIMENTAL_WEB_SAMPLES=ON \
-DIREE_HAL_DRIVER_DEFAULTS=OFF \
Expand All @@ -83,20 +84,14 @@ popd
# Serve the demo using a local webserver #
###############################################################################

echo "=== Copying static files (index.html) to the build directory ==="
echo "=== Copying static files to the build directory ==="

cp ${ROOT_DIR?}/experimental/sample_web_static/index.html ${BINARY_DIR}

echo "=== Running local webserver ==="
echo " open at http://localhost:8000/build-emscripten/experimental/sample_web_static/"
EASELJS_LIBRARY=${BINARY_DIR}/easeljs.min.js
test -f ${EASELJS_LIBRARY} || \
wget https://code.createjs.com/1.0.0/easeljs.min.js -O ${EASELJS_LIBRARY}

# **Note**: this serves from the root so source maps can reference code in the
# source tree. A real deployment would bundle the output artifacts and serve
# them from a build/release directory.
echo "=== Running local webserver, open at http://localhost:8000/ ==="

# local_server.py is needed when using SharedArrayBuffer, with multithreading
# python3 local_server.py --directory ${ROOT_DIR?}

# http.server on its own is fine for single threaded use, and this doesn't
# break CORS for external resources like easeljs from a CDN
python3 -m http.server --directory ${ROOT_DIR?}
python3 ${ROOT_DIR?}/scripts/local_web_server.py --directory ${BINARY_DIR}
3 changes: 1 addition & 2 deletions experimental/sample_web_static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
<title>IREE Static Web Sample</title>
<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- TODO(scotttodd): use local copy for CORS webserver / SharedArrayBuffer workarounds? -->
<script src="https://code.createjs.com/1.0.0/easeljs.min.js"></script>
<script src="./easeljs.min.js"></script>
</head>

<body style="background-color: #2b2c30; color: #ABB2BF">
Expand Down
File renamed without changes.

0 comments on commit de1935a

Please sign in to comment.