2
0

build_decoder_test.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #!/bin/sh
  2. # Temporary compiled binary
  3. OUT_FILE="tempbin"
  4. # Optional temporary compiled WebAssembly
  5. OUT_WASM="temp.wasm"
  6. # Source files to compile using Emscripten.
  7. IN_FILES="examples/emscripten.c"
  8. # Emscripten build using emcc.
  9. emscripten_emcc_build() {
  10. # Compile the the same example as above
  11. CC_FLAGS="-Wall -Wextra -Wshadow -Werror -Os -g0 -flto"
  12. emcc $CC_FLAGS -s WASM=1 -I. -o $OUT_WASM $IN_FILES
  13. # Did compilation work?
  14. if [ $? -ne 0 ]; then
  15. echo "Compiling ${IN_FILES}: FAILED"
  16. exit 1
  17. fi
  18. echo "Compiling ${IN_FILES}: PASSED"
  19. rm -f $OUT_WASM
  20. }
  21. # Emscripten build using docker.
  22. emscripten_docker_build() {
  23. docker container run --rm \
  24. --volume $PWD:/code \
  25. --workdir /code \
  26. emscripten/emsdk:latest \
  27. emcc $CC_FLAGS -s WASM=1 -I. -o $OUT_WASM $IN_FILES
  28. # Did compilation work?
  29. if [ $? -ne 0 ]; then
  30. echo "Compiling ${IN_FILES} (using docker): FAILED"
  31. exit 1
  32. fi
  33. echo "Compiling ${IN_FILES} (using docker): PASSED"
  34. rm -f $OUT_WASM
  35. }
  36. # Try Emscripten build using emcc or docker.
  37. try_emscripten_build() {
  38. which emcc > /dev/null
  39. if [ $? -eq 0 ]; then
  40. emscripten_emcc_build
  41. return $?
  42. fi
  43. which docker > /dev/null
  44. if [ $? -eq 0 ]; then
  45. emscripten_docker_build
  46. return $?
  47. fi
  48. echo "(Skipping Emscripten test)"
  49. }
  50. # Amalgamate the sources
  51. ./create_single_file_decoder.sh
  52. # Did combining work?
  53. if [ $? -ne 0 ]; then
  54. echo "Single file decoder creation script: FAILED"
  55. exit 1
  56. fi
  57. echo "Single file decoder creation script: PASSED"
  58. # Compile the generated output
  59. cc -Wall -Wextra -Wshadow -Werror -Os -g0 -o $OUT_FILE examples/simple.c
  60. # Did compilation work?
  61. if [ $? -ne 0 ]; then
  62. echo "Compiling simple.c: FAILED"
  63. exit 1
  64. fi
  65. echo "Compiling simple.c: PASSED"
  66. # Run then delete the compiled output
  67. ./$OUT_FILE
  68. retVal=$?
  69. rm -f $OUT_FILE
  70. # Did the test work?
  71. if [ $retVal -ne 0 ]; then
  72. echo "Running simple.c: FAILED"
  73. exit 1
  74. fi
  75. echo "Running simple.c: PASSED"
  76. # Try Emscripten build if emcc or docker command is available.
  77. try_emscripten_build
  78. exit 0