build.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #
  2. # Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #
  5. #!/bin/bash
  6. ####################################
  7. # build wasm-av1 sample #
  8. ####################################
  9. if [ ! -d "${EMSDK}" ]; then
  10. echo "can not find emsdk. "
  11. echo "please refer to https://emscripten.org/docs/getting_started/downloads.html "
  12. echo "to install it, or active it by 'source <emsdk_dir>emsdk_env.sh'"
  13. exit
  14. fi
  15. set -xe
  16. EMSDK_WASM_DIR="${EMSDK}/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten"
  17. BUILD_SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  18. OUT_DIR="${BUILD_SCRIPT_DIR}/out"
  19. WASM_AV1_DIR="${BUILD_SCRIPT_DIR}/wasm-av1"
  20. WAMR_PLATFORM_DIR="${BUILD_SCRIPT_DIR}/../../../product-mini/platforms"
  21. IWASM_CMD="${WAMR_PLATFORM_DIR}/linux/build/iwasm"
  22. WAMRC_DIR="${BUILD_SCRIPT_DIR}/../../../wamr-compiler"
  23. WAMRC_CMD="${WAMRC_DIR}/build/wamrc"
  24. function Clear_Before_Exit
  25. {
  26. [[ -f ${WASM_AV1_DIR}/wasm-av1.patch ]] &&
  27. rm -f ${WASM_AV1_DIR}/wasm-av1.patch
  28. # resume the libc.a under EMSDK_WASM_DIR
  29. cd ${EMSDK_WASM_DIR}
  30. mv libc.a.bak libc.a
  31. }
  32. # 1.hack emcc
  33. cd ${EMSDK_WASM_DIR}
  34. # back up libc.a
  35. cp libc.a libc.a.bak
  36. # delete some objects in libc.a
  37. emar d libc.a fopen.o
  38. emar d libc.a fread.o
  39. emar d libc.a feof.o
  40. emar d libc.a fclose.o
  41. # 2. build wasm-av1
  42. cd ${BUILD_SCRIPT_DIR}
  43. # 2.1 clone wasm-av1 repo from Github
  44. if [ ! -d "wasm-av1" ]; then
  45. git clone https://github.com/GoogleChromeLabs/wasm-av1.git
  46. fi
  47. # 2.2 copy the wasm-av1.patch to wasm-av1 and apply the patch
  48. cd ${WASM_AV1_DIR}
  49. cp -a ${BUILD_SCRIPT_DIR}/wasm-av1.patch .
  50. git checkout Makefile
  51. git checkout test.c
  52. git checkout third_party/aom
  53. if [[ $(git apply wasm-av1.patch 2>&1) =~ "error" ]]; then
  54. echo "git apply patch failed, please check wasm-av1 related changes..."
  55. Clear_Before_Exit
  56. exit 0
  57. fi
  58. make testavx -j 4
  59. # remove patch file and recover emcc libc.a after building
  60. Clear_Before_Exit
  61. # 2.3 copy /make/gen target files to out/
  62. rm -rf ${OUT_DIR} && mkdir ${OUT_DIR}
  63. cp -a ${WASM_AV1_DIR}/testavx.wasm ${OUT_DIR}/
  64. # 3. compile wasm-av1.wasm to wasm-av1.aot with wamrc
  65. # 3.1 build wamr-compiler
  66. cd ${WAMRC_DIR}
  67. ./build_llvm.sh
  68. rm -fr build && mkdir build
  69. cd build && cmake ..
  70. make
  71. # 3.2 compile wasm-av1.wasm to wasm-av1.aot
  72. cd ${OUT_DIR}
  73. ${WAMRC_CMD} -o testavx.aot testavx.wasm
  74. # 4. build iwasm with pthread and libc_emcc enable
  75. cd ${WAMR_PLATFORM_DIR}/linux
  76. rm -fr build && mkdir build
  77. cd build && cmake .. -DWAMR_BUILD_LIB_PTHREAD=1 -DWAMR_BUILD_LIBC_EMCC=1
  78. make
  79. # 5. run wasm-av1 with iwasm
  80. echo "---> run testav1.aot with iwasm"
  81. cd ${OUT_DIR}
  82. ${IWASM_CMD} testavx.aot ../wasm-av1/third_party/samples/elephants_dream_480p24.ivf