Skip to content

Commit e4faae7

Browse files
committed
refactor: update CMake configurations for custom section tests and wasm-apps build process
1 parent 0d46878 commit e4faae7

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

tests/unit/custom-section/CMakeLists.txt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,23 @@
22
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
33

44
cmake_minimum_required(VERSION 3.14)
5-
65
project (test-custom-section)
76

7+
set(WASI_SDK_DIR "/opt/wasi-sdk")
8+
set(WASISDK_TOOLCHAIN "${WASI_SDK_DIR}/share/cmake/wasi-sdk.cmake")
9+
10+
include(ExternalProject)
11+
ExternalProject_Add(
12+
custom-section-test-wasm-apps
13+
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/wasm-apps
14+
BUILD_ALWAYS YES
15+
CONFIGURE_COMMAND ${CMAKE_COMMAND} -S ${CMAKE_CURRENT_SOURCE_DIR}/wasm-apps -B build
16+
-DWASI_SDK_PREFIX=${WASI_SDK_DIR}
17+
-DCMAKE_TOOLCHAIN_FILE=${WASISDK_TOOLCHAIN}
18+
BUILD_COMMAND ${CMAKE_COMMAND} --build build --verbose
19+
INSTALL_COMMAND ${CMAKE_COMMAND} --install build --prefix ${CMAKE_CURRENT_BINARY_DIR}/wasm-apps
20+
)
21+
822
add_definitions (-DRUN_ON_LINUX)
923

1024
set (WAMR_BUILD_LIBC_WASI 0)
@@ -37,9 +51,6 @@ set (unit_test_sources
3751
${IWASM_COMPL_SOURCE}
3852
)
3953

40-
# Automatically build wasm-apps for this test
41-
add_subdirectory(wasm-apps)
42-
4354
# Now simply link against gtest or gtest_main as needed. Eg
4455
add_executable (custom_section_test ${unit_test_sources})
4556

tests/unit/custom-section/wasm-apps/CMakeLists.txt

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@
22
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
33

44
cmake_minimum_required(VERSION 3.14)
5+
project(wasm-apps)
56

6-
project(wasm-apps-custom-section)
7+
add_executable(app.wasm app.c)
8+
target_compile_options(app.wasm PUBLIC -g -nostdlib)
9+
target_link_options(app.wasm PRIVATE
10+
-nostdlib
11+
LINKER:--allow-undefined
12+
LINKER:--export-all
13+
LINKER:--no-entry
14+
)
715

8-
# Add -g option so there will be debugger related custom sections
9-
add_custom_target(app.wasm ALL
10-
COMMAND /opt/wasi-sdk/bin/clang -g -nostdlib
11-
-Wl,--no-entry,--export-all
12-
-o ${CMAKE_CURRENT_BINARY_DIR}/app.wasm
13-
${CMAKE_CURRENT_LIST_DIR}/app.c
16+
# install .wasm
17+
set(
18+
WASM_FILES
19+
${CMAKE_CURRENT_BINARY_DIR}/app.wasm
1420
)
21+
install(FILES ${WASM_FILES} DESTINATION .)

0 commit comments

Comments
 (0)