mirror of
https://github.com/facebook/zstd.git
synced 2025-11-09 17:41:01 +03:00
Enable docker based Emscripten build on single file library test if emcc is not available.
This commit is contained in:
@@ -6,6 +6,56 @@ OUT_FILE="tempbin"
|
|||||||
# Optional temporary compiled WebAssembly
|
# Optional temporary compiled WebAssembly
|
||||||
OUT_WASM="temp.wasm"
|
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
|
# Amalgamate the sources
|
||||||
./create_single_file_decoder.sh
|
./create_single_file_decoder.sh
|
||||||
# Did combining work?
|
# Did combining work?
|
||||||
@@ -35,21 +85,7 @@ if [ $retVal -ne 0 ]; then
|
|||||||
fi
|
fi
|
||||||
echo "Running simple.c: PASSED"
|
echo "Running simple.c: PASSED"
|
||||||
|
|
||||||
# Is Emscripten available?
|
# Try Emscripten build if emcc or docker command is available.
|
||||||
which emcc > /dev/null
|
try_emscripten_build
|
||||||
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
|
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|||||||
@@ -9,6 +9,56 @@ OUT_FILE="tempbin"
|
|||||||
# Optional temporary compiled WebAssembly
|
# Optional temporary compiled WebAssembly
|
||||||
OUT_WASM="temp.wasm"
|
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
|
# Amalgamate the sources
|
||||||
./create_single_file_library.sh
|
./create_single_file_library.sh
|
||||||
# Did combining work?
|
# Did combining work?
|
||||||
@@ -41,21 +91,7 @@ if [ $retVal -ne 0 ]; then
|
|||||||
fi
|
fi
|
||||||
echo "Running roundtrip.c: PASSED"
|
echo "Running roundtrip.c: PASSED"
|
||||||
|
|
||||||
# Is Emscripten available?
|
# Try Emscripten build if emcc or docker command is available.
|
||||||
which emcc > /dev/null
|
try_emscripten_build
|
||||||
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
|
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|||||||
Reference in New Issue
Block a user