build.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. rm -rf *.wasm
  32. rm -rf *.aot
  33. for test_c in *.c; do
  34. test_wasm="$(basename $test_c .c).wasm"
  35. if [[ -n "$sysroot_path" ]]; then
  36. if [ ! -d "$sysroot_path" ]; then
  37. echo "Directory $sysroot_path doesn't exist. Aborting"
  38. exit 1
  39. fi
  40. sysroot_command="--sysroot $sysroot_path"
  41. fi
  42. echo "Compiling $test_c to $test_wasm"
  43. $CC \
  44. -target wasm32-wasi-threads \
  45. -O2 \
  46. -Wall \
  47. -pthread \
  48. -z stack-size=32768 \
  49. -Wl,--export=__heap_base \
  50. -Wl,--export=__data_end \
  51. -Wl,--shared-memory,--max-memory=1966080 \
  52. -Wl,--export=wasi_thread_start \
  53. -Wl,--export=malloc \
  54. -Wl,--export=free \
  55. -Wl,--export=test \
  56. $sysroot_command \
  57. $test_c -o $test_wasm
  58. done