]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Enable docker based Emscripten build on single file library test if emcc is not avail...
authoryoshihitoh <yoshihito.arih@gmail.com>
Tue, 30 Jun 2020 16:40:15 +0000 (01:40 +0900)
committeryoshihitoh <yoshihito.arih@gmail.com>
Sun, 5 Jul 2020 13:25:20 +0000 (22:25 +0900)
contrib/single_file_libs/build_decoder_test.sh
contrib/single_file_libs/build_library_test.sh

index 74e3f1c57336250e0931f9156008bb8091b1343d..2ed25bce16892823e6de5c60e51a355939ead6e5 100755 (executable)
@@ -6,6 +6,56 @@ OUT_FILE="tempbin"
 # Optional temporary compiled WebAssembly
 OUT_WASM="temp.wasm"
 
+# Source files to compile using Emscripten.
+IN_FILES="examples/emscripten.c"
+
+# Emscripten build using emcc.
+emscripten_emcc_build() {
+  # Compile the the same example as above
+  CC_FLAGS="-Wall -Wextra -Werror -Os -g0 -flto"
+  emcc $CC_FLAGS -s WASM=1 -I. -o $OUT_WASM $IN_FILES
+  # Did compilation work?
+  if [ $? -ne 0 ]; then
+    echo "Compiling ${IN_FILES}: FAILED"
+    exit 1
+  fi
+  echo "Compiling ${IN_FILES}: PASSED"
+  rm -f $OUT_WASM
+}
+
+# Emscripten build using docker.
+emscripten_docker_build() {
+  docker container run --rm \
+    --volume $PWD:/code \
+    --workdir /code \
+    trzeci/emscripten \
+    emcc $CC_FLAGS -s WASM=1 -I. -o $OUT_WASM $IN_FILES
+  # Did compilation work?
+  if [ $? -ne 0 ]; then
+      echo "Compiling ${IN_FILES} (using docker): FAILED"
+    exit 1
+  fi
+  echo "Compiling ${IN_FILES} (using docker): PASSED"
+  rm -f $OUT_WASM
+}
+
+# Try Emscripten build using emcc or docker.
+try_emscripten_build() {
+  which emcc > /dev/null
+  if [ $? -eq 0 ]; then
+    emscripten_emcc_build
+    return $?
+  fi
+
+  which docker > /dev/null
+  if [ $? -eq 0 ]; then
+    emscripten_docker_build
+    return $?
+  fi
+
+  echo "(Skipping Emscripten test)"
+}
+
 # Amalgamate the sources
 ./create_single_file_decoder.sh
 # Did combining work?
@@ -35,21 +85,7 @@ if [ $retVal -ne 0 ]; then
 fi
 echo "Running simple.c: PASSED"
 
-# Is Emscripten available?
-which emcc > /dev/null
-if [ $? -ne 0 ]; then
-  echo "(Skipping Emscripten test)"
-else
-  # Compile the Emscripten example
-  CC_FLAGS="-Wall -Wextra -Werror -Os -g0 -flto --llvm-lto 3 -lGL -DNDEBUG=1"
-  emcc $CC_FLAGS -s WASM=1 -o $OUT_WASM examples/emscripten.c
-  # Did compilation work?
-  if [ $? -ne 0 ]; then
-    echo "Compiling emscripten.c: FAILED"
-    exit 1
-  fi
-  echo "Compiling emscripten.c: PASSED"
-  rm -f $OUT_WASM
-fi
+# Try Emscripten build if emcc or docker command is available.
+try_emscripten_build
 
 exit 0
index 3b8b16a058056f128fccad49f2a2895b2db7244d..54b3eae2068f65edc57eb54e86b8bde3a6139e91 100755 (executable)
@@ -9,6 +9,56 @@ OUT_FILE="tempbin"
 # Optional temporary compiled WebAssembly
 OUT_WASM="temp.wasm"
 
+# Source files to compile using Emscripten.
+IN_FILES="zstd.c examples/roundtrip.c"
+
+# Emscripten build using emcc.
+emscripten_emcc_build() {
+  # Compile the the same example as above
+  CC_FLAGS="-Wall -Wextra -Werror -Os -g0 -flto"
+  emcc $CC_FLAGS -s WASM=1 -I. -o $OUT_WASM $IN_FILES
+  # Did compilation work?
+  if [ $? -ne 0 ]; then
+    echo "Compiling ${IN_FILES}: FAILED"
+    exit 1
+  fi
+  echo "Compiling ${IN_FILES}: PASSED"
+  rm -f $OUT_WASM
+}
+
+# Emscripten build using docker.
+emscripten_docker_build() {
+  docker container run --rm \
+    --volume $PWD:/code \
+    --workdir /code \
+    trzeci/emscripten \
+    emcc $CC_FLAGS -s WASM=1 -I. -o $OUT_WASM $IN_FILES
+  # Did compilation work?
+  if [ $? -ne 0 ]; then
+      echo "Compiling ${IN_FILES} (using docker): FAILED"
+    exit 1
+  fi
+  echo "Compiling ${IN_FILES} (using docker): PASSED"
+  rm -f $OUT_WASM
+}
+
+# Try Emscripten build using emcc or docker.
+try_emscripten_build() {
+  which emcc > /dev/null
+  if [ $? -eq 0 ]; then
+    emscripten_emcc_build
+    return $?
+  fi
+
+  which docker > /dev/null
+  if [ $? -eq 0 ]; then
+    emscripten_docker_build
+    return $?
+  fi
+
+  echo "(Skipping Emscripten test)"
+}
+
 # Amalgamate the sources
 ./create_single_file_library.sh
 # Did combining work?
@@ -41,21 +91,7 @@ if [ $retVal -ne 0 ]; then
 fi
 echo "Running roundtrip.c: PASSED"
 
-# Is Emscripten available?
-which emcc > /dev/null
-if [ $? -ne 0 ]; then
-  echo "(Skipping Emscripten test)"
-else
-  # Compile the the same example as above
-  CC_FLAGS="-Wall -Wextra -Werror -Os -g0 -flto"
-  emcc $CC_FLAGS -s WASM=1 -I. -o $OUT_WASM zstd.c examples/roundtrip.c
-  # Did compilation work?
-  if [ $? -ne 0 ]; then
-    echo "Compiling emscripten.c: FAILED"
-    exit 1
-  fi
-  echo "Compiling emscripten.c: PASSED"
-  rm -f $OUT_WASM
-fi
+# Try Emscripten build if emcc or docker command is available.
+try_emscripten_build
 
 exit 0