build.sh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/bin/bash
  2. #
  3. # Copyright (C) 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  5. #
  6. set -eo pipefail
  7. CC=${CC:=/opt/wasi-sdk/bin/clang}
  8. WAMR_DIR=../../../../..
  9. show_usage() {
  10. echo "Usage: $0 [--sysroot PATH_TO_SYSROOT]"
  11. echo "--sysroot PATH_TO_SYSROOT specify to build with custom sysroot for wasi-libc"
  12. }
  13. while [[ $# -gt 0 ]]; do
  14. key="$1"
  15. case $key in
  16. --sysroot)
  17. sysroot_path="$2"
  18. shift
  19. shift
  20. ;;
  21. --help)
  22. show_usage
  23. exit
  24. ;;
  25. *)
  26. echo "Unknown option: $1"
  27. exit 1
  28. ;;
  29. esac
  30. done
  31. # Stress tests names
  32. thread_start_file_exclusions=("linear_memory_size_update.wasm")
  33. rm -rf *.wasm
  34. rm -rf *.aot
  35. for test_c in *.c; do
  36. test_wasm="$(basename $test_c .c).wasm"
  37. if [[ " ${thread_start_file_exclusions[@]} " =~ " ${test_wasm} " ]] ; then
  38. thread_start_file=""
  39. else
  40. thread_start_file=$WAMR_DIR/samples/wasi-threads/wasm-apps/wasi_thread_start.S
  41. fi
  42. if [[ -n "$sysroot_path" ]]; then
  43. if [ ! -d "$sysroot_path" ]; then
  44. echo "Directory $sysroot_path doesn't exist. Aborting"
  45. exit 1
  46. fi
  47. sysroot_command="--sysroot $sysroot_path"
  48. fi
  49. echo "Compiling $test_c to $test_wasm"
  50. $CC \
  51. -target wasm32-wasi-threads \
  52. -O2 \
  53. -pthread -ftls-model=local-exec \
  54. -z stack-size=32768 \
  55. -Wl,--export=__heap_base \
  56. -Wl,--export=__data_end \
  57. -Wl,--shared-memory,--max-memory=1966080 \
  58. -Wl,--export=wasi_thread_start \
  59. -Wl,--export=malloc \
  60. -Wl,--export=free \
  61. -I $WAMR_DIR/samples/wasi-threads/wasm-apps \
  62. $sysroot_command \
  63. $thread_start_file \
  64. $test_c -o $test_wasm
  65. done