codeql_buildscript.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #!/usr/bin/env bash
  2. #
  3. # Copyright (C) 2019 Intel Corporation. All rights reserved.
  4. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  5. #
  6. # This script is used to build the WAMR project for CodeQL analysis.
  7. # Pre-requisites
  8. sudo apt -qq update
  9. sudo apt install -y -qq build-essential cmake g++-multilib libgcc-12-dev lib32gcc-12-dev ccache ninja-build
  10. LLVM_VER=18.1.8
  11. pushd /opt
  12. sudo wget --progress=dot:giga -O clang+llvm-x86_64-linux-gnu.tar.xz https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VER}/clang+llvm-${LLVM_VER}-x86_64-linux-gnu-ubuntu-18.04.tar.xz \
  13. && tar -xf clang+llvm-x86_64-linux-gnu.tar.xz \
  14. && mv clang+llvm-${LLVM_VER}-x86_64-linux-gnu-ubuntu-18.04 llvm-${LLVM_VER}
  15. popd
  16. # libtinfo.so.5 for /opt/llvm-18.1.8/lib/libomptarget.rtl.amdgpu.so.18.1
  17. sudo apt -qq update
  18. wget http://security.ubuntu.com/ubuntu/pool/universe/n/ncurses/libtinfo5_6.3-2ubuntu0.1_amd64.deb
  19. sudo apt install -y -qq ./libtinfo5_6.3-2ubuntu0.1_amd64.deb
  20. # Start the build process
  21. WAMR_DIR=${PWD}
  22. LLVM_DIR=/opt/llvm-${LLVM_VER}/lib/cmake/llvm
  23. # Function to build wamrc
  24. build_wamrc() {
  25. local options="$1"
  26. echo "Building wamrc with options: $options"
  27. pushd ${WAMR_DIR}/wamr-compiler
  28. rm -rf build
  29. cmake -S . -B build \
  30. -G Ninja \
  31. -DCMAKE_BUILD_TYPE=Debug \
  32. -DWAMR_BUILD_WITH_CUSTOM_LLVM=1 -DLLVM_DIR=${LLVM_DIR} \
  33. $options
  34. cmake --build build --target wamrc --parallel
  35. if [[ $? != 0 ]]; then
  36. echo "Failed to build wamrc with options: $options"
  37. exit 1
  38. fi
  39. popd
  40. }
  41. # Function to build iwasm
  42. build_iwasm() {
  43. local options="$1"
  44. echo "Building iwasm with options: $options"
  45. pushd ${WAMR_DIR}/product-mini/platforms/linux
  46. rm -rf build
  47. cmake -S . -B build \
  48. -G Ninja \
  49. -DCMAKE_BUILD_TYPE=Debug \
  50. -DLLVM_DIR=${LLVM_DIR} \
  51. $options
  52. cmake --build build --target iwasm --parallel
  53. if [[ $? != 0 ]]; then
  54. echo "Failed to build iwasm with options: $options"
  55. exit 1
  56. fi
  57. popd
  58. }
  59. # List of compilation options for wamrc
  60. wamrc_options_list=(
  61. #default
  62. ""
  63. )
  64. # List of compilation options for iwasm
  65. iwasm_options_list=(
  66. #default
  67. ""
  68. # +classic interp
  69. "-DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_SIMD=0"
  70. # fast jit
  71. "-DWAMR_BUILD_FAST_JIT=1 -DWAMR_BUILD_FAST_JIT_DUMP=1 -DWAMR_BUILD_SIMD=0"
  72. # +llvm jit
  73. "-DWAMR_BUILD_JIT=1"
  74. #
  75. "-DWAMR_BUILD_TARGET=X86_32"
  76. #
  77. # libraries
  78. "-DWAMR_BUILD_LIBC_BUILTIN=0 -DWAMR_BUILD_LIBC_UVWASI=1 -DWAMR_BUILD_LIBC_EMCC=1"
  79. "-DWAMR_BUILD_THREAD_MGR=1 -DWAMR_BUILD_LIB_PTHREAD=1 -DWAMR_BUILD_LIB_PTHREAD_SEMAPHORE=1"
  80. "-DWAMR_BUILD_THREAD_MGR=1 -DWAMR_BUILD_LIB_WASI_THREADS=1 -DWAMR_BUILD_LIB_PTHREAD_SEMAPHORE=1"
  81. "-DWAMR_BUILD_WASI_NN=1 -DWAMR_BUILD_WASI_NN_LLAMACPP=1"
  82. #
  83. # Wasm specs
  84. "-DWAMR_BUILD_GC=1 -DWAMR_BUILD_STRINGREF=1 -DWAMR_STRINGREF_IMPL_SOURCE=STUB"
  85. "-DWAMR_BUILD_EXCE_HANDLING=1 -DWAMR_BUILD_AOT=0 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_SIMD=0"
  86. "-DWAMR_BUILD_MEMORY64=1 -DWAMR_BUILD_MULTI_MEMORY=1 -DWAMR_BUILD_SHARED_MEMORY=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_SIMD=0 -DWAMR_BUILD_AOT=0"
  87. #
  88. # WARM features
  89. "-DWAMR_BUILD_MULTI_MODULE=1 -DWAMR_BUILD_MINI_LOADER=1 -DWAMR_BUILD_SHARED_HEAP=1"
  90. "-DWAMR_DISABLE_HW_BOUND_CHECK=1"
  91. "-DWAMR_CONFIGURABLE_BOUNDS_CHECKS=1"
  92. "-DWAMR_BUILD_EXTENDED_CONST_EXPR=1"
  93. # - Debug
  94. "-DWAMR_BUILD_DEBUG_INTERP=1 -DWAMR_BUILD_DEBUG_AOT=1 -DWAMR_BUILD_DYNAMIC_AOT_DEBUG=1"
  95. # - developer options
  96. "-DWAMR_BUILD_CUSTOM_NAME_SECTION=1 -DWAMR_BUILD_LOAD_CUSTOM_SECTION=1 -DWAMR_BUILD_DUMP_CALL_STACK=1 -DWAMR_BUILD_LINUX_PERF=1 -DWAMR_BUILD_AOT_VALIDATOR=1 -DWAMR_BUILD_MEMORY_PROFILING=1 -DWAMR_BUILD_PERF_PROFILING=1"
  97. # - global heap
  98. "-DWAMR_BUILD_ALLOC_WITH_USER_DATA=1 -DWAMR_BUILD_GLOBAL_HEAP_POOL=1 -DWAMR_BUILD_GLOBAL_HEAP_SIZE=131072"
  99. "-DWAMR_BUILD_QUICK_AOT_ENTRY=0 -DWAMR_DISABLE_WAKEUP_BLOCKING_OP=1 -DWAMR_BUILD_MODULE_INST_CONTEXT=0"
  100. # - pgo
  101. "-DWAMR_BUILD_STATIC_PGO=1"
  102. # TODO: SGX specifics.
  103. )
  104. # Loop through all iwasm options and build
  105. for options in "${iwasm_options_list[@]}"; do
  106. build_iwasm "$options"
  107. done
  108. # Loop through all wamrc options and build
  109. for options in "${wamrc_options_list[@]}"; do
  110. build_wamrc "$options"
  111. done