3 # Where to find the sources (only used to copy zstd.h)
4 ZSTD_SRC_ROOT="../../lib"
6 # Temporary compiled binary
9 # Optional temporary compiled WebAssembly
12 # Source files to compile using Emscripten.
13 IN_FILES="zstd.c examples/roundtrip.c"
15 # Emscripten build using emcc.
16 emscripten_emcc_build() {
17 # Compile the same example as above
18 CC_FLAGS="-Wall -Wextra -Wshadow -Werror -Os -g0 -flto"
19 emcc $CC_FLAGS -s WASM=1 -I. -o $OUT_WASM $IN_FILES
20 # Did compilation work?
22 echo "Compiling ${IN_FILES}: FAILED"
25 echo "Compiling ${IN_FILES}: PASSED"
29 # Emscripten build using docker.
30 emscripten_docker_build() {
31 docker container run --rm \
34 emscripten/emsdk:latest \
35 emcc $CC_FLAGS -s WASM=1 -I. -o $OUT_WASM $IN_FILES
36 # Did compilation work?
38 echo "Compiling ${IN_FILES} (using docker): FAILED"
41 echo "Compiling ${IN_FILES} (using docker): PASSED"
45 # Try Emscripten build using emcc or docker.
46 try_emscripten_build() {
47 which emcc > /dev/null
53 which docker > /dev/null
55 emscripten_docker_build
59 echo "(Skipping Emscripten test)"
62 # Amalgamate the sources
63 ./create_single_file_library.sh
66 echo "Single file library creation script: FAILED"
69 echo "Single file library creation script: PASSED"
71 # Copy the header to here (for the tests)
72 cp "$ZSTD_SRC_ROOT/zstd.h" examples/zstd.h
74 # Compile the generated output
75 cc -Wall -Wextra -Werror -Wshadow -pthread -I. -Os -g0 -o $OUT_FILE zstd.c examples/roundtrip.c
76 # Did compilation work?
78 echo "Compiling roundtrip.c: FAILED"
81 echo "Compiling roundtrip.c: PASSED"
83 # Run then delete the compiled output
88 if [ $retVal -ne 0 ]; then
89 echo "Running roundtrip.c: FAILED"
92 echo "Running roundtrip.c: PASSED"
94 # Try Emscripten build if emcc or docker command is available.