From 8f8c5605e9239c3e5294300f34a5e4cee471b05b Mon Sep 17 00:00:00 2001 From: "liang.he" Date: Thu, 17 Apr 2025 16:41:47 +0800 Subject: [PATCH] Raise wasi-sdk to 25 and wabt to 1.0.37 (#4187) Raise wasi-sdk to 25 and wabt to 1.0.37. It includes - Refactor CI workflow to install WASI-SDK and WABT from a composite action - Use ExternalProject to bring wasm-apps for few samples. file/ wasi-threads/ - Refactor sample build and test steps in SGX compilation workflow for improved clarity and efficiency (workaround) Add CMake support for EMSCRIPTEN and WAMRC, update module paths --- .../actions/install-wasi-sdk-wabt/action.yml | 80 +++++++++++++++++ .../compilation_on_android_ubuntu.yml | 85 +++++------------- .github/workflows/compilation_on_macos.yml | 46 +++------- .github/workflows/compilation_on_sgx.yml | 47 +++------- .github/workflows/nightly_run.yml | 86 +++++++------------ .../platforms/linux-sgx/CMakeLists.txt | 5 ++ .../cmake/FindEMSCRIPTEN.cmake | 0 .../{debug-tools => }/cmake/FindWAMRC.cmake | 0 .../{debug-tools => }/cmake/FindWASISDK.cmake | 11 +-- samples/debug-tools/CMakeLists.txt | 2 +- samples/debug-tools/wasm-apps/CMakeLists.txt | 2 +- samples/file/CMakeLists.txt | 18 +++- samples/file/wasm-app/CMakeLists.txt | 25 ++---- samples/linux-perf/CMakeLists.txt | 2 +- samples/linux-perf/cmake/FindWASISDK.cmake | 23 ----- samples/wasi-threads/CMakeLists.txt | 19 +++- samples/wasi-threads/wasm-apps/CMakeLists.txt | 28 ++---- 17 files changed, 213 insertions(+), 266 deletions(-) create mode 100644 .github/actions/install-wasi-sdk-wabt/action.yml rename samples/{debug-tools => }/cmake/FindEMSCRIPTEN.cmake (100%) rename samples/{debug-tools => }/cmake/FindWAMRC.cmake (100%) rename samples/{debug-tools => }/cmake/FindWASISDK.cmake (58%) delete mode 100644 samples/linux-perf/cmake/FindWASISDK.cmake diff --git a/.github/actions/install-wasi-sdk-wabt/action.yml b/.github/actions/install-wasi-sdk-wabt/action.yml new file mode 100644 index 000000000..c872e4252 --- /dev/null +++ b/.github/actions/install-wasi-sdk-wabt/action.yml @@ -0,0 +1,80 @@ +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +# Get URLs from: +# - https://github.com/WebAssembly/wasi-sdk/releases +# - https://github.com/WebAssembly/wabt/releases + +# Install WASI-SDK and WABT at /opt +# /opt is the assumed location widely used in the project +name: Install WASI-SDK and WABT + +description: A composite action to download and install wasi-sdk and wabt on Ubuntu, macOS. + +inputs: + os: + description: "Operating system to install on (ubuntu, macos)" + required: true + +runs: + using: "composite" + steps: + - name: Check Runner OS + if: ${{ !startsWith(inputs.os, 'ubuntu') && !startsWith(inputs.os, 'windows') && !startsWith(inputs.os, 'macos') }} + shell: bash + run: | + echo "::error title=⛔ error hint::Support Ubuntu, Windows, and macOS Only" + exit 1 + + - name: Set up wasi-sdk and wabt on Ubuntu + if: ${{ startsWith(inputs.os, 'ubuntu') }} + shell: bash + run: | + sudo wget -O wasi-sdk.tar.gz --progress=dot:giga https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-25/wasi-sdk-25.0-x86_64-linux.tar.gz + sudo tar -xf wasi-sdk.tar.gz + sudo ln -sf wasi-sdk-25.0-x86_64-linux/ wasi-sdk + sudo wget -O wabt.tar.gz --progress=dot:giga https://github.com/WebAssembly/wabt/releases/download/1.0.37/wabt-1.0.37-ubuntu-20.04.tar.gz + sudo tar -xf wabt.tar.gz + sudo ln -sf wabt-1.0.37 wabt + /opt/wasi-sdk/bin/clang --version + /opt/wabt/bin/wasm-interp --version + echo "::notice::wasi-sdk-25 and wabt-1.0.37 installed on ubuntu" + working-directory: /opt + + - name: Set up wasi-sdk and wabt on macOS-13 (intel) + if: ${{ inputs.os == 'macos-13' }} + shell: bash + run: | + sudo wget -O wasi-sdk.tar.gz --progress=dot:giga https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-25/wasi-sdk-25.0-x86_64-macos.tar.gz + sudo tar -xf wasi-sdk.tar.gz + sudo ln -sf wasi-sdk-25.0-x86_64-macos wasi-sdk + sudo wget -O wabt.tar.gz --progress=dot:giga https://github.com/WebAssembly/wabt/releases/download/1.0.36/wabt-1.0.36-macos-12.tar.gz + sudo tar -xf wabt.tar.gz + sudo ln -sf wabt-1.0.36 wabt + /opt/wasi-sdk/bin/clang --version + /opt/wabt/bin/wasm-interp --version + echo "::notice::wasi-sdk-25 and wabt-1.0.36 installed on macos-13" + working-directory: /opt + + - name: Set up wasi-sdk and wabt on macOS-14 (arm64) + if: ${{ inputs.os == 'macos-14' }} + shell: bash + run: | + sudo wget -O wasi-sdk.tar.gz --progress=dot:giga https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-25/wasi-sdk-25.0-arm64-macos.tar.gz + sudo tar -xf wasi-sdk.tar.gz + sudo ln -sf wasi-sdk-25.0-arm64-macos wasi-sdk + sudo wget -O wabt.tar.gz --progress=dot:giga https://github.com/WebAssembly/wabt/releases/download/1.0.37/wabt-1.0.37-macos-14.tar.gz + sudo tar -xf wabt.tar.gz + sudo ln -sf wabt-1.0.37 wabt + /opt/wasi-sdk/bin/clang --version + /opt/wabt/bin/wasm-interp --version + echo "::notice::wasi-sdk-25 and wabt-1.0.37 installed on macos-14" + working-directory: /opt + + #TODO: Add support for Windows + - name: Set up wasi-sdk and wabt on Windows + if: ${{ startsWith(inputs.os, 'windows') }} + shell: powershell + run: | + echo "::notice::Support for Windows is not implemented yet" + exit 1 diff --git a/.github/workflows/compilation_on_android_ubuntu.yml b/.github/workflows/compilation_on_android_ubuntu.yml index 47f613ab2..dd6c096f1 100644 --- a/.github/workflows/compilation_on_android_ubuntu.yml +++ b/.github/workflows/compilation_on_android_ubuntu.yml @@ -315,17 +315,10 @@ jobs: fail-fast: false matrix: os: [ubuntu-22.04] - wasi_sdk_release: - [ - "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-25/wasi-sdk-25.0-x86_64-linux.tar.gz" - ] - wabt_release: - [ - "https://github.com/WebAssembly/wabt/releases/download/1.0.31/wabt-1.0.31-ubuntu.tar.gz", - ] include: - os: ubuntu-22.04 llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2204.outputs.cache_key }} + steps: - name: checkout uses: actions/checkout@v4 @@ -346,19 +339,10 @@ jobs: if: (steps.retrieve_llvm_libs.outputs.cache-hit != 'true') run: echo "::error::can not get prebuilt llvm libraries" && exit 1 - - name: download and install wasi-sdk - run: | - cd /opt - sudo wget ${{ matrix.wasi_sdk_release }} - sudo tar -xzf wasi-sdk-*.tar.gz - sudo ln -sf wasi-sdk-25.0-x86_64-linux wasi-sdk - - - name: download and install wabt - run: | - cd /opt - sudo wget ${{ matrix.wabt_release }} - sudo tar -xzf wabt-1.0.31-*.tar.gz - sudo mv wabt-1.0.31 wabt + - name: install-wasi-sdk-wabt + uses: ./.github/actions/install-wasi-sdk-wabt + with: + os: ${{ matrix.os }} - name: Build wamrc run: | @@ -397,14 +381,6 @@ jobs: $MULTI_TIER_JIT_BUILD_OPTIONS, ] os: [ubuntu-22.04] - wasi_sdk_release: - [ - "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-linux.tar.gz", - ] - wabt_release: - [ - "https://github.com/WebAssembly/wabt/releases/download/1.0.31/wabt-1.0.31-ubuntu.tar.gz", - ] include: - os: ubuntu-22.04 llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2204.outputs.cache_key }} @@ -430,12 +406,10 @@ jobs: if: (!endsWith(matrix.make_options, '_INTERP_BUILD_OPTIONS')) && (steps.retrieve_llvm_libs.outputs.cache-hit != 'true') run: echo "::error::can not get prebuilt llvm libraries" && exit 1 - - name: download and install wabt - run: | - cd /opt - sudo wget ${{ matrix.wabt_release }} - sudo tar -xzf wabt-1.0.31-*.tar.gz - sudo mv wabt-1.0.31 wabt + - name: install-wasi-sdk-wabt + uses: ./.github/actions/install-wasi-sdk-wabt + with: + os: ${{ matrix.os }} - name: Build wamrc if: (!endsWith(matrix.make_options, '_INTERP_BUILD_OPTIONS')) @@ -464,34 +438,14 @@ jobs: strategy: matrix: os: [ubuntu-22.04] - wasi_sdk_release: - [ - "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-25/wasi-sdk-25.0-x86_64-linux.tar.gz" - ] - wabt_release: - [ - "https://github.com/WebAssembly/wabt/releases/download/1.0.31/wabt-1.0.31-ubuntu.tar.gz", - ] include: - os: ubuntu-22.04 llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2204.outputs.cache_key }} + steps: - name: checkout uses: actions/checkout@v4 - - name: download and install wasi-sdk - run: | - cd /opt - sudo wget ${{ matrix.wasi_sdk_release }} - sudo tar -xzf wasi-sdk-*.tar.gz - sudo ln -sf wasi-sdk-25.0-x86_64-linux wasi-sdk - - - name: download and install wabt - run: | - cd /opt - sudo wget ${{ matrix.wabt_release }} - sudo tar -xzf wabt-1.0.31-*.tar.gz - sudo ln -sf wabt-1.0.31 wabt - name: Get LLVM libraries id: retrieve_llvm_libs uses: actions/cache@v4 @@ -503,12 +457,19 @@ jobs: ./core/deps/llvm/build/libexec ./core/deps/llvm/build/share key: ${{ matrix.llvm_cache_key }} + + - name: install-wasi-sdk-wabt + uses: ./.github/actions/install-wasi-sdk-wabt + with: + os: ${{ matrix.os }} + - name: Build wamrc run: | mkdir build && cd build cmake .. cmake --build . --config Release --parallel 4 working-directory: wamr-compiler + - name: Build Sample [basic] run: | cd samples/basic @@ -634,10 +595,6 @@ jobs: $MEMORY64_TEST_OPTIONS, $MULTI_MEMORY_TEST_OPTIONS, ] - wasi_sdk_release: - [ - "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-25/wasi-sdk-25.0-x86_64-linux.tar.gz" - ] include: - os: ubuntu-22.04 llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu_2204.outputs.cache_key }} @@ -706,11 +663,9 @@ jobs: - name: download and install wasi-sdk if: matrix.test_option == '$WASI_TEST_OPTIONS' - run: | - cd /opt - sudo wget ${{ matrix.wasi_sdk_release }} - sudo tar -xzf wasi-sdk-*.tar.gz - sudo ln -sf wasi-sdk-25.0-x86_64-linux wasi-sdk + uses: ./.github/actions/install-wasi-sdk-wabt + with: + os: ${{ matrix.os }} # It is a temporary solution until new wasi-sdk that includes bug fixes is released - name: build wasi-libc from source diff --git a/.github/workflows/compilation_on_macos.yml b/.github/workflows/compilation_on_macos.yml index 66938905c..cf5578cfb 100644 --- a/.github/workflows/compilation_on_macos.yml +++ b/.github/workflows/compilation_on_macos.yml @@ -228,24 +228,14 @@ jobs: #$AOT_BUILD_OPTIONS, ] os: [macos-13] - wasi_sdk_release: - [ - "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-macos.tar.gz", - ] - wabt_release: - [ - "https://github.com/WebAssembly/wabt/releases/download/1.0.31/wabt-1.0.31-macos-12.tar.gz", - ] steps: - name: checkout uses: actions/checkout@v4 - - name: download and install wabt - run: | - cd /opt - sudo wget ${{ matrix.wabt_release }} - sudo tar -xzf wabt-1.0.31-*.tar.gz - sudo mv wabt-1.0.31 wabt + - name: install-wasi-sdk-wabt + uses: ./.github/actions/install-wasi-sdk-wabt + with: + os: ${{ matrix.os }} - name: Build Sample [wasm-c-api] run: | @@ -260,14 +250,6 @@ jobs: strategy: matrix: os: [macos-13, macos-14] - wasi_sdk_release: - [ - "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-macos.tar.gz", - ] - wabt_release: - [ - "https://github.com/WebAssembly/wabt/releases/download/1.0.31/wabt-1.0.31-macos-12.tar.gz", - ] include: - os: macos-13 llvm_cache_key: ${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }} @@ -277,19 +259,10 @@ jobs: - name: checkout uses: actions/checkout@v4 - - name: download and install wasi-sdk - run: | - cd /opt - sudo wget ${{ matrix.wasi_sdk_release }} - sudo tar -xzf wasi-sdk-*.tar.gz - sudo ln -sf wasi-sdk-20.0 wasi-sdk - - - name: download and install wabt - run: | - cd /opt - sudo wget ${{ matrix.wabt_release }} - sudo tar -xzf wabt-1.0.31-*.tar.gz - sudo ln -sf wabt-1.0.31 wabt + - name: install-wasi-sdk-wabt + uses: ./.github/actions/install-wasi-sdk-wabt + with: + os: ${{ matrix.os }} - name: Build Sample [basic] run: | @@ -356,12 +329,13 @@ jobs: cmake --build . --config Release --parallel 4 working-directory: wamr-compiler + # cmake --build . --config Debug --parallel 4 - name: Build Sample [wasi-threads] run: | cd samples/wasi-threads mkdir build && cd build cmake .. - cmake --build . --config Debug --parallel 4 + cmake --build . --config Debug --verbose ./iwasm wasm-apps/no_pthread.wasm ../../../wamr-compiler/build/wamrc --size-level=0 --enable-multi-thread -o wasm-apps/no_pthread.aot wasm-apps/no_pthread.wasm diff --git a/.github/workflows/compilation_on_sgx.yml b/.github/workflows/compilation_on_sgx.yml index 836f5c747..541f7a284 100644 --- a/.github/workflows/compilation_on_sgx.yml +++ b/.github/workflows/compilation_on_sgx.yml @@ -147,14 +147,6 @@ jobs: #$LLVM_EAGER_JIT_BUILD_OPTIONS, ] os: [ubuntu-22.04] - wasi_sdk_release: - [ - "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-19/wasi-sdk-19.0-linux.tar.gz", - ] - wabt_release: - [ - "https://github.com/WebAssembly/wabt/releases/download/1.0.31/wabt-1.0.31-ubuntu.tar.gz", - ] iwasm_make_options_feature: [ # Features to be tested: IPFS "-DWAMR_BUILD_SGX_IPFS=1", @@ -168,19 +160,10 @@ jobs: - name: checkout uses: actions/checkout@v4 - - name: download and install wasi-sdk - run: | - cd /opt - sudo wget ${{ matrix.wasi_sdk_release }} - sudo tar -xzf wasi-sdk-*.tar.gz - sudo mv wasi-sdk-19.0 wasi-sdk - - - name: download and install wabt - run: | - cd /opt - sudo wget ${{ matrix.wabt_release }} - sudo tar -xzf wabt-1.0.31-*.tar.gz - sudo mv wabt-1.0.31 wabt + - name: install-wasi-sdk-wabt + uses: ./.github/actions/install-wasi-sdk-wabt + with: + os: ${{ matrix.os }} - name: install SGX SDK and necessary libraries uses: ./.github/actions/install-linux-sgx @@ -213,33 +196,31 @@ jobs: - name: Build wamrc only for testing samples in aot mode if: matrix.iwasm_make_options_run_mode == '$AOT_BUILD_OPTIONS' run: | - mkdir build && cd build - cmake .. - cmake --build . --config Release --parallel 4 - cp wamrc `pwd`/../../product-mini/platforms/${{ matrix.platform }}/enclave-sample + cmake -S . -B build + cmake --build build --config Release --parallel 4 + cp build/wamrc ../product-mini/platforms/${{ matrix.platform }}/enclave-sample working-directory: wamr-compiler - name: Build Sample [file] run: | - cd samples/file - mkdir build && cd build - cmake .. - cmake --build . --config Debug --parallel 4 - cp wasm-app/file.wasm `pwd`/../../../product-mini/platforms/${{ matrix.platform }}/enclave-sample + cmake -S . -B build + cmake --build build --config Debug --parallel 4 + cp build/wasm-app/file.wasm ../../product-mini/platforms/${{ matrix.platform }}/enclave-sample + working-directory: samples/file - name: Test Sample [file] in non-aot mode if: matrix.iwasm_make_options_run_mode != '$AOT_BUILD_OPTIONS' run: | source /opt/intel/sgxsdk/environment - ./iwasm --dir=. file.wasm + ./iwasm --dir=. ./file.wasm working-directory: product-mini/platforms/${{ matrix.platform }}/enclave-sample - name: Test Sample [file] in aot mode if: matrix.iwasm_make_options_run_mode == '$AOT_BUILD_OPTIONS' run: | source /opt/intel/sgxsdk/environment - ./wamrc -sgx -o file.aot file.wasm - ./iwasm --dir=. file.aot + ./wamrc -sgx -o ./file.aot ./file.wasm + ./iwasm --dir=. ./file.aot working-directory: product-mini/platforms/${{ matrix.platform }}/enclave-sample spec_test_default: diff --git a/.github/workflows/nightly_run.yml b/.github/workflows/nightly_run.yml index dec06e327..92b8f5519 100644 --- a/.github/workflows/nightly_run.yml +++ b/.github/workflows/nightly_run.yml @@ -378,14 +378,6 @@ jobs: $MULTI_TIER_JIT_BUILD_OPTIONS, ] os: [ubuntu-22.04] - wasi_sdk_release: - [ - "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-linux.tar.gz", - ] - wabt_release: - [ - "https://github.com/WebAssembly/wabt/releases/download/1.0.31/wabt-1.0.31-ubuntu.tar.gz", - ] include: - os: ubuntu-22.04 llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu.outputs.cache_key }} @@ -413,12 +405,11 @@ jobs: if: (!endsWith(matrix.make_options, '_INTERP_BUILD_OPTIONS')) && (steps.retrieve_llvm_libs.outputs.cache-hit != 'true') run: echo "::error::can not get prebuilt llvm libraries" && exit 1 - - name: download and install wabt - run: | - cd /opt - sudo wget ${{ matrix.wabt_release }} - sudo tar -xzf wabt-1.0.31-*.tar.gz - sudo mv wabt-1.0.31 wabt + - name: install-wasi-sdk-wabt + uses: ./.github/actions/install-wasi-sdk-wabt + with: + os: ${{ matrix.os }} + - name: Build wamrc if: (!endsWith(matrix.make_options, '_INTERP_BUILD_OPTIONS')) run: | @@ -443,14 +434,6 @@ jobs: strategy: matrix: os: [ubuntu-22.04] - wasi_sdk_release: - [ - "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-linux.tar.gz", - ] - wabt_release: - [ - "https://github.com/WebAssembly/wabt/releases/download/1.0.31/wabt-1.0.31-ubuntu.tar.gz", - ] include: - os: ubuntu-22.04 llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu.outputs.cache_key }} @@ -458,19 +441,11 @@ jobs: - name: checkout uses: actions/checkout@v4 - - name: download and install wasi-sdk - run: | - cd /opt - sudo wget ${{ matrix.wasi_sdk_release }} - sudo tar -xzf wasi-sdk-*.tar.gz - sudo ln -sf wasi-sdk-20.0 wasi-sdk - - name: download and install wabt - run: | - cd /opt - sudo wget ${{ matrix.wabt_release }} - sudo tar -xzf wabt-1.0.31-*.tar.gz - sudo ln -sf wabt-1.0.31 wabt - + - name: install-wasi-sdk-wabt + uses: ./.github/actions/install-wasi-sdk-wabt + with: + os: ${{ matrix.os }} + - name: Get LLVM libraries id: retrieve_llvm_libs uses: actions/cache@v4 @@ -567,17 +542,21 @@ jobs: ./iwasm --native-lib=./libtest_add.so --native-lib=./libtest_sqrt.so --native-lib=./libtest_hello.so --native-lib=./libtest_hello2.so wasm-app/test.wasm working-directory: ./samples/native-lib - - name: checkout wamr-app-framework - run: git clone https://github.com/bytecodealliance/wamr-app-framework.git - - name: download wamr-app-framework dependencies - run: LVGL=0 LV_DRIVERS=0 ./download.sh - working-directory: ./wamr-app-framework/deps - - name: Build Sample [simple] - run: | - ./build.sh -p host-interp - python3 ./sample_test_run.py $(pwd)/out - exit $? - working-directory: ./wamr-app-framework/samples/simple + # FIXME: un-comment me after fix cmake minimum issue + # https://github.com/bytecodealliance/wamr-app-framework/pull/11 + # - name: checkout wamr-app-framework + # run: git clone https://github.com/bytecodealliance/wamr-app-framework.git + + # - name: download wamr-app-framework dependencies + # run: LVGL=0 LV_DRIVERS=0 ./download.sh + # working-directory: ./wamr-app-framework/deps + + # - name: Build Sample [simple] + # run: | + # ./build.sh -p host-interp + # python3 ./sample_test_run.py $(pwd)/out + # exit $? + # working-directory: ./wamr-app-framework/samples/simple - name: Build Sample [shared-heap] run: | @@ -613,10 +592,6 @@ jobs: $THREADS_TEST_OPTIONS, $WASI_TEST_OPTIONS, ] - wasi_sdk_release: - [ - "https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-linux.tar.gz", - ] include: - os: ubuntu-22.04 llvm_cache_key: ${{ needs.build_llvm_libraries_on_ubuntu.outputs.cache_key }} @@ -664,13 +639,10 @@ jobs: - name: checkout uses: actions/checkout@v4 - - name: download and install wasi-sdk - if: matrix.test_option == '$WASI_TEST_OPTIONS' - run: | - cd /opt - sudo wget ${{ matrix.wasi_sdk_release }} - sudo tar -xzf wasi-sdk-*.tar.gz - sudo mv wasi-sdk-20.0 wasi-sdk + - name: install-wasi-sdk-wabt + uses: ./.github/actions/install-wasi-sdk-wabt + with: + os: ${{ matrix.os }} # It is a temporary solution until new wasi-sdk that includes bug fixes is released - name: build wasi-libc from source diff --git a/product-mini/platforms/linux-sgx/CMakeLists.txt b/product-mini/platforms/linux-sgx/CMakeLists.txt index bc3bde565..af911a0db 100644 --- a/product-mini/platforms/linux-sgx/CMakeLists.txt +++ b/product-mini/platforms/linux-sgx/CMakeLists.txt @@ -98,6 +98,11 @@ if (NOT DEFINED WAMR_BUILD_STATIC_PGO) set (WAMR_BUILD_STATIC_PGO 0) endif () +if (NOT DEFINED WAMR_BUILD_REF_TYPES) + # Enable reference types by default + set (WAMR_BUILD_REF_TYPES 1) +endif () + set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11 -ffunction-sections -fdata-sections \ -Wall -Wno-unused-parameter -Wno-pedantic \ diff --git a/samples/debug-tools/cmake/FindEMSCRIPTEN.cmake b/samples/cmake/FindEMSCRIPTEN.cmake similarity index 100% rename from samples/debug-tools/cmake/FindEMSCRIPTEN.cmake rename to samples/cmake/FindEMSCRIPTEN.cmake diff --git a/samples/debug-tools/cmake/FindWAMRC.cmake b/samples/cmake/FindWAMRC.cmake similarity index 100% rename from samples/debug-tools/cmake/FindWAMRC.cmake rename to samples/cmake/FindWAMRC.cmake diff --git a/samples/debug-tools/cmake/FindWASISDK.cmake b/samples/cmake/FindWASISDK.cmake similarity index 58% rename from samples/debug-tools/cmake/FindWASISDK.cmake rename to samples/cmake/FindWASISDK.cmake index 0caf374df..65b9647d9 100644 --- a/samples/debug-tools/cmake/FindWASISDK.cmake +++ b/samples/cmake/FindWASISDK.cmake @@ -16,9 +16,10 @@ string(REGEX MATCH [0-9]+\.[0-9]+\.*[0-9]* WASISDK_VERSION ${WASISDK_HOME}) find_package_handle_standard_args(WASISDK REQUIRED_VARS WASISDK_HOME VERSION_VAR WASISDK_VERSION) if(WASISDK_FOUND) - set(WASISDK_CC_COMMAND ${WASISDK_HOME}/bin/clang) - set(WASISDK_CXX_COMMAND ${WASISDK_HOME}/bin/clang++) - set(WASISDK_TOOLCHAIN ${WASISDK_HOME}/share/cmake/wasi-sdk.cmake) - set(WASISDK_SYSROOT ${WASISDK_HOME}/share/wasi-sysroot) + set(WASISDK_CC_COMMAND ${WASISDK_HOME}/bin/clang) + set(WASISDK_CXX_COMMAND ${WASISDK_HOME}/bin/clang++) + set(WASISDK_TOOLCHAIN ${WASISDK_HOME}/share/cmake/wasi-sdk.cmake) + set(WASISDK_PTHREAD_TOOLCHAIN ${WASISDK_HOME}/share/cmake/wasi-sdk-pthread.cmake) + set(WASISDK_SYSROOT ${WASISDK_HOME}/share/wasi-sysroot) endif() -mark_as_advanced(WASISDK_CC_COMMAND WASISDK_CXX_COMMAND WASISDK_TOOLCHAIN WASISDK_SYSROOT WASISDK_HOME) +mark_as_advanced(WASISDK_CC_COMMAND WASISDK_CXX_COMMAND WASISDK_TOOLCHAIN WASISDK_PTHREAD_TOOLCHAIN WASISDK_SYSROOT WASISDK_HOME) diff --git a/samples/debug-tools/CMakeLists.txt b/samples/debug-tools/CMakeLists.txt index 411106bb3..512507d6e 100644 --- a/samples/debug-tools/CMakeLists.txt +++ b/samples/debug-tools/CMakeLists.txt @@ -7,7 +7,7 @@ include(CheckPIESupported) project(debug_tools_sample) -list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) +list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../cmake) find_package(WASISDK REQUIRED) option(SOURCE_MAP_DEMO "Enable source map demo" OFF) diff --git a/samples/debug-tools/wasm-apps/CMakeLists.txt b/samples/debug-tools/wasm-apps/CMakeLists.txt index 527b5f37a..9858b98da 100644 --- a/samples/debug-tools/wasm-apps/CMakeLists.txt +++ b/samples/debug-tools/wasm-apps/CMakeLists.txt @@ -7,7 +7,7 @@ project (debut_tools_wasm) set (CMAKE_BUILD_TYPE Debug) # Otherwise no debug symbols (addr2line) -list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../cmake) +list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../../cmake) find_package (WAMRC REQUIRED) option(SOURCE_MAP_DEMO "Enable source map demo" OFF) diff --git a/samples/file/CMakeLists.txt b/samples/file/CMakeLists.txt index fca200376..a5184718b 100644 --- a/samples/file/CMakeLists.txt +++ b/samples/file/CMakeLists.txt @@ -6,4 +6,20 @@ project(file) ################ wasm application ############### add_subdirectory(src) -add_subdirectory(wasm-app) + +# Use ExternalProject to avoid incorporating WAMR library compilation flags into the +# compilation of the wasm application, which could lead to compatibility +# issues due to different targets. +# Like: clang: error: unsupported option '-arch' for target 'wasm32-wasi' +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../cmake) +find_package(WASISDK REQUIRED) + +include(ExternalProject) +ExternalProject_Add(wasm-app + SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/wasm-app" + CONFIGURE_COMMAND ${CMAKE_COMMAND} -S ${CMAKE_CURRENT_SOURCE_DIR}/wasm-app -B build + -DWASI_SDK_PREFIX=${WASISDK_HOME} + -DCMAKE_TOOLCHAIN_FILE=${WASISDK_TOOLCHAIN} + BUILD_COMMAND ${CMAKE_COMMAND} --build build + INSTALL_COMMAND ${CMAKE_COMMAND} --install build --prefix ${CMAKE_CURRENT_BINARY_DIR} +) diff --git a/samples/file/wasm-app/CMakeLists.txt b/samples/file/wasm-app/CMakeLists.txt index f63485ca0..a80f0c8f0 100644 --- a/samples/file/wasm-app/CMakeLists.txt +++ b/samples/file/wasm-app/CMakeLists.txt @@ -2,25 +2,10 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception cmake_minimum_required(VERSION 3.14) -project(wasm-app) +project(file_wasm) -set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..) +set (CMAKE_BUILD_TYPE Debug) # Otherwise no debug symbols (addr2line) -if (APPLE) - set (HAVE_FLAG_SEARCH_PATHS_FIRST 0) - set (CMAKE_C_LINK_FLAGS "") - set (CMAKE_CXX_LINK_FLAGS "") -endif () - -set (CMAKE_SYSTEM_PROCESSOR wasm32) - -if (NOT DEFINED WASI_SDK_DIR) - set (WASI_SDK_DIR "/opt/wasi-sdk") -endif () - -set (CMAKE_C_COMPILER_TARGET "wasm32-wasi") -set (CMAKE_C_COMPILER "${WASI_SDK_DIR}/bin/clang") -set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3 -Wno-unused-command-line-argument") - -add_executable(file.wasm main.c) -target_link_libraries(file.wasm) +add_executable(file main.c) +set_target_properties (file PROPERTIES SUFFIX .wasm) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/file.wasm DESTINATION wasm-app) diff --git a/samples/linux-perf/CMakeLists.txt b/samples/linux-perf/CMakeLists.txt index e9882c835..efcc8c07e 100644 --- a/samples/linux-perf/CMakeLists.txt +++ b/samples/linux-perf/CMakeLists.txt @@ -15,7 +15,7 @@ endif() set(CMAKE_CXX_STANDARD 17) -list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) +list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../cmake) find_package(WASISDK REQUIRED) ################ runtime settings ################ diff --git a/samples/linux-perf/cmake/FindWASISDK.cmake b/samples/linux-perf/cmake/FindWASISDK.cmake deleted file mode 100644 index 5cdfea41e..000000000 --- a/samples/linux-perf/cmake/FindWASISDK.cmake +++ /dev/null @@ -1,23 +0,0 @@ -# Copyright (C) 2019 Intel Corporation. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -include(FindPackageHandleStandardArgs) - -file(GLOB WASISDK_SEARCH_PATH "/opt/wasi-sdk-*") -find_path(WASISDK_HOME - NAMES share/wasi-sysroot - PATHS ${WASISDK_SEARCH_PATH} - NO_DEFAULT_PATH - REQUIRED -) - -string(REGEX MATCH [0-9]+\.[0-9]+\.*[0-9]* WASISDK_VERSION ${WASISDK_HOME}) - -find_package_handle_standard_args(WASISDK REQUIRED_VARS WASISDK_HOME VERSION_VAR WASISDK_VERSION) - -if(WASISDK_FOUND) - set(WASISDK_CC_COMMAND ${WASISDK_HOME}/bin/clang) - set(WASISDK_CXX_COMMAND ${WASISDK_HOME}/bin/clang++) - set(WASISDK_TOOLCHAIN ${WASISDK_HOME}/share/cmake/wasi-sdk.cmake) - set(WASISDK_SYSROOT ${WASISDK_HOME}/share/wasi-sysroot) -endif() diff --git a/samples/wasi-threads/CMakeLists.txt b/samples/wasi-threads/CMakeLists.txt index 11b58d2ea..08cc3a7ff 100644 --- a/samples/wasi-threads/CMakeLists.txt +++ b/samples/wasi-threads/CMakeLists.txt @@ -66,7 +66,24 @@ add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE}) ################ wasm application ################ -add_subdirectory(wasm-apps) +# Use ExternalProject to avoid incorporating WAMR library compilation flags into the +# compilation of the wasm application, which could lead to compatibility +# issues due to different targets. +# Like: clang: error: unsupported option '-arch' for target 'wasm32-wasi' + +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/../cmake) +find_package(WASISDK REQUIRED) + +include(ExternalProject) +ExternalProject_Add(wasm-apps + SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/wasm-apps" + CONFIGURE_COMMAND ${CMAKE_COMMAND} -S ${CMAKE_CURRENT_SOURCE_DIR}/wasm-apps -B build + -DWASI_SDK_PREFIX=${WASISDK_HOME} + -DCMAKE_TOOLCHAIN_FILE=${WASISDK_PTHREAD_TOOLCHAIN} + BUILD_COMMAND ${CMAKE_COMMAND} --build build + INSTALL_COMMAND ${CMAKE_COMMAND} --install build --prefix ${CMAKE_CURRENT_BINARY_DIR} +) + ################ wamr runtime ################ include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake) diff --git a/samples/wasi-threads/wasm-apps/CMakeLists.txt b/samples/wasi-threads/wasm-apps/CMakeLists.txt index 87f21e9fd..27e06b634 100644 --- a/samples/wasi-threads/wasm-apps/CMakeLists.txt +++ b/samples/wasi-threads/wasm-apps/CMakeLists.txt @@ -1,28 +1,10 @@ # Copyright (C) 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -if (APPLE) - set (HAVE_FLAG_SEARCH_PATHS_FIRST 0) - set (CMAKE_C_LINK_FLAGS "") - set (CMAKE_CXX_LINK_FLAGS "") -endif () +cmake_minimum_required (VERSION 3.14) +project (wasi_threads_wasm) -if (NOT DEFINED WASI_SDK_DIR) - set (WASI_SDK_DIR "/opt/wasi-sdk") -endif () - -if (DEFINED WASI_SYSROOT) - set (CMAKE_SYSROOT "${WASI_SYSROOT}") -endif () - -set (CMAKE_C_COMPILER "${WASI_SDK_DIR}/bin/clang") -set (CMAKE_ASM_COMPILER "${WASI_SDK_DIR}/bin/clang") -set (CMAKE_EXE_LINKER_FLAGS "-target wasm32-wasi-threads") - -if ("$ENV{COLLECT_CODE_COVERAGE}" STREQUAL "1" OR COLLECT_CODE_COVERAGE EQUAL 1) - set (CMAKE_C_FLAGS "") - set (CMAKE_CXX_FLAGS "") -endif () +set (CMAKE_BUILD_TYPE Debug) # Otherwise no debug symbols (addr2line) function (compile_sample SOURCE_FILE) get_filename_component (FILE_NAME ${SOURCE_FILE} NAME_WLE) @@ -41,6 +23,8 @@ function (compile_sample SOURCE_FILE) LINKER:--export=malloc LINKER:--export=free ) + + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${WASM_MODULE} DESTINATION wasm-apps) endfunction () -compile_sample(no_pthread.c wasi_thread_start.S) \ No newline at end of file +compile_sample(no_pthread.c wasi_thread_start.S)