changeset 1492:4b5ec9ea268e

Building WebAssembly samples using Docker
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 25 Jun 2020 09:13:56 +0200
parents c5627b8493f3
children c9bdf73a8817
files Samples/WebAssembly/NOTES.txt Samples/WebAssembly/docker-build.sh Samples/WebAssembly/docker-internal.sh
diffstat 3 files changed, 79 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Samples/WebAssembly/NOTES.txt	Thu Jun 25 09:13:56 2020 +0200
@@ -0,0 +1,22 @@
+
+Building WebAssembly samples using Docker
+=========================================
+
+The script "./docker-build.sh" can be used to quickly build the
+WebAssembly samples on any GNU/Linux distribution equipped with
+Docker. This avoids newcomers to install Emscripten and learn the
+CMake options. Just type:
+
+$ ./docker-build.sh Release
+
+After successful build, the binaries will be installed in the
+following folder (i.e. in the folder "wasm-binaries" at the root of
+the source distribution):
+
+$ ls -l ../../wasm-binaries
+
+
+NB: The source code of the Docker build environment can be found at
+the following location:
+https://github.com/jodogne/OrthancDocker/tree/master/wasm-builder
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Samples/WebAssembly/docker-build.sh	Thu Jun 25 09:13:56 2020 +0200
@@ -0,0 +1,27 @@
+#!/bin/bash
+
+set -ex
+
+IMAGE=jodogne/wasm-builder:1.39.17-upstream
+
+if [ "$1" != "Debug" -a "$1" != "Release" ]; then
+    echo "Please provide build type: Debug or Release"
+    exit -1
+fi
+
+if [ -t 1 ]; then
+    # TTY is available => use interactive mode
+    DOCKER_FLAGS='-i'
+fi
+
+ROOT_DIR=`dirname $(readlink -f $0)`/../..
+
+mkdir -p ${ROOT_DIR}/wasm-binaries
+
+docker run -t ${DOCKER_FLAGS} --rm \
+    --user $(id -u):$(id -g) \
+    -v ${ROOT_DIR}:/source:ro \
+    -v ${ROOT_DIR}/wasm-binaries:/target:rw ${IMAGE} \
+    bash /source/Samples/WebAssembly/docker-internal.sh $1
+
+ls -lR ${ROOT_DIR}/wasm-binaries/
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Samples/WebAssembly/docker-internal.sh	Thu Jun 25 09:13:56 2020 +0200
@@ -0,0 +1,30 @@
+#!/bin/bash
+set -ex
+
+source /opt/emsdk/emsdk_env.sh
+
+# Use a folder that is writeable by non-root users for the Emscripten cache
+export EM_CACHE=/tmp/emscripten-cache
+
+# Get the Orthanc framework
+cd /tmp/
+hg clone https://hg.orthanc-server.com/orthanc/
+
+# Make a copy of the source code in a writeable folder, because of
+# "DownloadPackage.cmake" that writes to the "ThirdPartyDownloads"
+# folder next to the "CMakeLists.txt"
+cd /source
+hg archive /tmp/source-writeable
+
+mkdir /tmp/build
+cd /tmp/build
+
+cmake /tmp/source-writeable/Samples/WebAssembly \
+      -DCMAKE_BUILD_TYPE=$1 \
+      -DCMAKE_INSTALL_PREFIX=/target \
+      -DCMAKE_TOOLCHAIN_FILE=${EMSDK}/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake \
+      -DORTHANC_FRAMEWORK_ROOT=/tmp/orthanc \
+      -DSTATIC_BUILD=ON \
+      -G Ninja
+
+ninja -j2 install