build_aot.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/bash
  2. #
  3. # Copyright (C) 2019 Intel Corporation. All rights reserved.
  4. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  5. #
  6. # Define a list of .wasm files
  7. file_names=("mem_grow_out_of_bounds_01" "mem_grow_out_of_bounds_02"
  8. "mem_page_01" "mem_page_02" "mem_page_03" "mem_page_05"
  9. "mem_page_07" "mem_page_08" "mem_page_09" "mem_page_10"
  10. "mem_page_12" "mem_page_14" "mem_page_16" "mem_page_20" "out_of_bounds")
  11. WORKDIR="$PWD"
  12. WAMRC_ROOT_DIR="${WORKDIR}/../../../wamr-compiler"
  13. WAMRC="${WAMRC_ROOT_DIR}/build/wamrc"
  14. WAST2WASM="/opt/wabt/bin/wat2wasm"
  15. # build wamrc if not exist
  16. if [ ! -s "$WAMRC" ]; then
  17. cd $WAMRC_ROOT_DIR
  18. if [ -d "$WAMRC/build" ]; then
  19. rm -r build
  20. fi
  21. cmake -B build && cmake --build build -j $(nproc)
  22. cd $WORKDIR
  23. fi
  24. # error if not exist
  25. if [ ! -s "$WAST2WASM" ]; then
  26. echo "please install wabt first" && exit -1
  27. fi
  28. # Detect host architecture
  29. HOST_ARCH=$(uname -m)
  30. echo "Detected host architecture: $HOST_ARCH"
  31. # Iterate over the files array
  32. rm -r build 2>/dev/null
  33. mkdir build
  34. for file_name in "${file_names[@]}"; do
  35. # wast to wasm
  36. $WAST2WASM "${file_name}.wast" -o "build/${file_name}.wasm"
  37. # Determine compilation configurations based on host architecture
  38. case "$HOST_ARCH" in
  39. x86_64)
  40. # x86-64 host: compile both x86-64 and x86-32
  41. $WAMRC -o "build/${file_name}.aot" "build/${file_name}.wasm"
  42. $WAMRC --target=i386 -o "build/${file_name}_32.aot" "build/${file_name}.wasm"
  43. $WAMRC --bounds-checks=1 -o "build/${file_name}_no_hw_bounds.aot" "build/${file_name}.wasm"
  44. $WAMRC --bounds-checks=1 --target=i386 -o "build/${file_name}_no_hw_bounds_32.aot" "build/${file_name}.wasm"
  45. ;;
  46. i386|i686)
  47. # x86-32 host: compile only x86-32
  48. $WAMRC -o "build/${file_name}.aot" "build/${file_name}.wasm"
  49. $WAMRC --bounds-checks=1 -o "build/${file_name}_no_hw_bounds.aot" "build/${file_name}.wasm"
  50. ;;
  51. aarch64|arm64)
  52. # ARM64 host: compile only aarch64
  53. $WAMRC -o "build/${file_name}.aot" "build/${file_name}.wasm"
  54. $WAMRC --bounds-checks=1 -o "build/${file_name}_no_hw_bounds.aot" "build/${file_name}.wasm"
  55. ;;
  56. *)
  57. echo "Warning: Unsupported architecture '$HOST_ARCH'. Using default target."
  58. $WAMRC -o "build/${file_name}.aot" "build/${file_name}.wasm"
  59. $WAMRC --bounds-checks=1 -o "build/${file_name}_no_hw_bounds.aot" "build/${file_name}.wasm"
  60. ;;
  61. esac
  62. done
  63. echo "AOT compilation completed for architecture: $HOST_ARCH"