build.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/bin/bash
  2. set -e
  3. CURR_DIR=$PWD
  4. OUT_DIR=${PWD}/out
  5. WASM_APPS=${PWD}/wasm-apps
  6. WAMR_ROOT_DIR=${PWD}/../..
  7. WAMRC_CMD=${WAMR_ROOT_DIR}/wamr-compiler/build/wamrc
  8. BUILD_AOT=0
  9. if [ $# -gt 1 ]; then
  10. echo "Usage: $0 [--aot]"
  11. exit 1
  12. fi
  13. if [ $# -eq 1 ]; then
  14. if [ "$1" = "--aot" ]; then
  15. BUILD_AOT=1
  16. else
  17. echo "Usage: $0 [--aot]"
  18. exit 1
  19. fi
  20. fi
  21. rm -rf ${OUT_DIR}
  22. mkdir -p ${OUT_DIR}/wasm-apps
  23. printf '##################### build custom-section project\n'
  24. mkdir -p build
  25. cd build
  26. cmake .. -DCMAKE_BUILD_TYPE=Debug
  27. make -j 4
  28. cp -a custom_section ${OUT_DIR}
  29. printf '\n##################### build wasm app\n'
  30. cd ${WASM_APPS}
  31. /opt/wasi-sdk/bin/clang \
  32. --target=wasm32 \
  33. -O0 \
  34. -nostdlib \
  35. -Wl,--strip-all,--no-entry \
  36. -Wl,--allow-undefined \
  37. -Wl,--export=run_demo \
  38. -o ${OUT_DIR}/wasm-apps/custom_section.wasm \
  39. custom_section.c \
  40. custom_section_payload.s
  41. printf '\nbuild custom_section.wasm success\n'
  42. if [ ${BUILD_AOT} -eq 1 ]; then
  43. if [ ! -x ${WAMRC_CMD} ]; then
  44. echo "Error: wamrc not found at ${WAMRC_CMD}"
  45. echo "Please build wamrc first under ${WAMR_ROOT_DIR}/wamr-compiler"
  46. exit 1
  47. fi
  48. printf '\n##################### build aot app\n'
  49. ${WAMRC_CMD} --emit-custom-sections=demo -o ${OUT_DIR}/wasm-apps/custom_section.aot ${OUT_DIR}/wasm-apps/custom_section.wasm
  50. printf '\nbuild custom_section.aot success\n'
  51. fi
  52. cd ${CURR_DIR}