build.sh 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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=("spawn_stress_test.wasm" "linear_memory_size_update.wasm" "stress_test_threads_creation.wasm")
  33. for test_c in *.c; do
  34. test_wasm="$(basename $test_c .c).wasm"
  35. if [[ " ${thread_start_file_exclusions[@]} " =~ " ${test_wasm} " ]] ; then
  36. thread_start_file=""
  37. else
  38. thread_start_file=$WAMR_DIR/samples/wasi-threads/wasm-apps/wasi_thread_start.S
  39. fi
  40. if [[ -n "$sysroot_path" ]]; then
  41. if [ ! -d "$sysroot_path" ]; then
  42. echo "Directory $sysroot_path doesn't exist. Aborting"
  43. exit 1
  44. fi
  45. sysroot_command="--sysroot $sysroot_path"
  46. fi
  47. echo "Compiling $test_c to $test_wasm"
  48. $CC \
  49. -target wasm32-wasi-threads \
  50. -O2 \
  51. -pthread -ftls-model=local-exec \
  52. -z stack-size=32768 \
  53. -Wl,--export=__heap_base \
  54. -Wl,--export=__data_end \
  55. -Wl,--shared-memory,--max-memory=1966080 \
  56. -Wl,--export=wasi_thread_start \
  57. -Wl,--export=malloc \
  58. -Wl,--export=free \
  59. -I $WAMR_DIR/samples/wasi-threads/wasm-apps \
  60. $sysroot_command \
  61. $thread_start_file \
  62. $test_c -o $test_wasm
  63. done