From: yoshihitoh Date: Tue, 30 Jun 2020 16:40:15 +0000 (+0900) Subject: Enable docker based Emscripten build on single file library test if emcc is not avail... X-Git-Tag: v1.4.7~126^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a035654ab804afb5883dd84155f9f812fe5bb0ed;p=thirdparty%2Fzstd.git Enable docker based Emscripten build on single file library test if emcc is not available. --- diff --git a/contrib/single_file_libs/build_decoder_test.sh b/contrib/single_file_libs/build_decoder_test.sh index 74e3f1c57..2ed25bce1 100755 --- a/contrib/single_file_libs/build_decoder_test.sh +++ b/contrib/single_file_libs/build_decoder_test.sh @@ -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 diff --git a/contrib/single_file_libs/build_library_test.sh b/contrib/single_file_libs/build_library_test.sh index 3b8b16a05..54b3eae20 100755 --- a/contrib/single_file_libs/build_library_test.sh +++ b/contrib/single_file_libs/build_library_test.sh @@ -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