wasm-micro-runtime: refractor build script (#3477)
* wasm-micro-runtime: refractor build script * fix patch * let cmake download dep on bsd/android * fix android * disable uvwasi * improve xmake.lua * fix uvwasi * add 1.3.2 * disable uvwasi * fix ntapi * Update xmake.luaautoupdate-seqan3-3.3.0
parent
35725bfc7e
commit
716e14d990
5 changed files with 270 additions and 33 deletions
@ -0,0 +1,86 @@ |
||||
diff --git a/CMakeLists.txt b/CMakeLists.txt
|
||||
index fbea2616..a1952ca8 100644
|
||||
--- a/CMakeLists.txt
|
||||
+++ b/CMakeLists.txt
|
||||
@@ -108,16 +108,12 @@ endif ()
|
||||
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
# Set the strip command based on the system (GNU or Clang)
|
||||
-if (CMAKE_STRIP)
|
||||
- set (CMAKE_STRIP_FLAGS "--strip-all")
|
||||
-endif ()
|
||||
+
|
||||
|
||||
include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
|
||||
|
||||
-set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security -Wshadow -Wno-unused-parameter")
|
||||
# set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wsign-conversion")
|
||||
|
||||
-set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wformat -Wformat-security -Wno-unused")
|
||||
|
||||
if (WAMR_BUILD_TARGET MATCHES "X86_.*" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
|
||||
if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang"))
|
||||
@@ -134,42 +130,37 @@ endif ()
|
||||
#set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-z,noexecstack,-z,relro,-z,now")
|
||||
|
||||
include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
|
||||
-
|
||||
+if (NOT BUILD_SHARED_LIBS)
|
||||
# STATIC LIBRARY
|
||||
add_library(iwasm_static STATIC ${WAMR_RUNTIME_LIB_SOURCE})
|
||||
set_target_properties (iwasm_static PROPERTIES OUTPUT_NAME vmlib)
|
||||
target_include_directories(iwasm_static INTERFACE ${WAMR_ROOT_DIR}/core/iwasm/include)
|
||||
-target_link_libraries (iwasm_static INTERFACE ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl -lpthread)
|
||||
+target_link_libraries (iwasm_static INTERFACE ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS})
|
||||
if (WAMR_BUILD_WASM_CACHE EQUAL 1)
|
||||
target_link_libraries(iwasm_static INTERFACE boringssl_crypto)
|
||||
endif ()
|
||||
|
||||
install (TARGETS iwasm_static ARCHIVE DESTINATION lib)
|
||||
|
||||
-# If it's a Release build, strip the static library
|
||||
-if (CMAKE_STRIP AND CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||
- # Strip static library
|
||||
- message (STATUS "Stripping static library after build!")
|
||||
- add_custom_command (TARGET iwasm_static POST_BUILD
|
||||
- COMMAND ${CMAKE_STRIP} ${CMAKE_STRIP_FLAGS} $<TARGET_FILE:iwasm_static>
|
||||
- )
|
||||
-endif ()
|
||||
+else ()
|
||||
|
||||
# SHARED LIBRARY
|
||||
add_library (iwasm_shared SHARED ${WAMR_RUNTIME_LIB_SOURCE})
|
||||
set_target_properties (iwasm_shared PROPERTIES OUTPUT_NAME iwasm)
|
||||
target_include_directories(iwasm_shared INTERFACE ${WAMR_ROOT_DIR}/core/iwasm/include)
|
||||
-target_link_libraries (iwasm_shared INTERFACE ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl -lpthread)
|
||||
+target_link_libraries (iwasm_shared INTERFACE ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS})
|
||||
if (WAMR_BUILD_WASM_CACHE EQUAL 1)
|
||||
target_link_libraries(iwasm_shared INTERFACE boringssl_crypto)
|
||||
endif ()
|
||||
-
|
||||
+if (WIN32)
|
||||
+target_link_libraries (iwasm_shared ntdll)
|
||||
+endif ()
|
||||
if (MINGW)
|
||||
target_link_libraries (iwasm_shared -lWs2_32)
|
||||
endif ()
|
||||
|
||||
install (TARGETS iwasm_shared LIBRARY DESTINATION lib)
|
||||
-
|
||||
+endif ()
|
||||
# HEADERS
|
||||
install (FILES
|
||||
${WAMR_ROOT_DIR}/core/iwasm/include/wasm_c_api.h
|
||||
@@ -177,11 +168,4 @@ install (FILES
|
||||
${WAMR_ROOT_DIR}/core/iwasm/include/lib_export.h
|
||||
DESTINATION include)
|
||||
|
||||
-# If it's a Release build, strip the shared library
|
||||
-if (CMAKE_STRIP AND CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||
- # Strip shared library
|
||||
- message (STATUS "Stripping shared library after build!")
|
||||
- add_custom_command (TARGET iwasm_shared POST_BUILD
|
||||
- COMMAND ${CMAKE_STRIP} ${CMAKE_STRIP_FLAGS} $<TARGET_FILE:iwasm_shared>
|
||||
- )
|
||||
-endif ()
|
||||
+
|
@ -0,0 +1,55 @@ |
||||
diff --git a/CMakeLists.txt b/CMakeLists.txt
|
||||
index 1c879949..8f8a73c7 100644
|
||||
--- a/CMakeLists.txt
|
||||
+++ b/CMakeLists.txt
|
||||
@@ -109,10 +109,8 @@ set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
|
||||
|
||||
-set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security -Wshadow -Wno-unused-parameter")
|
||||
# set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wconversion -Wsign-conversion")
|
||||
|
||||
-set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wformat -Wformat-security -Wno-unused")
|
||||
|
||||
if (WAMR_BUILD_TARGET MATCHES "X86_.*" OR WAMR_BUILD_TARGET STREQUAL "AMD_64")
|
||||
if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang"))
|
||||
@@ -131,31 +129,34 @@ endif ()
|
||||
include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
|
||||
|
||||
# STATIC LIBRARY
|
||||
+if (NOT BUILD_SHARED_LIBS)
|
||||
add_library(iwasm_static STATIC ${WAMR_RUNTIME_LIB_SOURCE})
|
||||
set_target_properties (iwasm_static PROPERTIES OUTPUT_NAME vmlib)
|
||||
target_include_directories(iwasm_static INTERFACE ${WAMR_ROOT_DIR}/core/iwasm/include)
|
||||
-target_link_libraries (iwasm_static INTERFACE ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl -lpthread)
|
||||
+target_link_libraries (iwasm_static INTERFACE ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS})
|
||||
if (WAMR_BUILD_WASM_CACHE EQUAL 1)
|
||||
target_link_libraries(iwasm_static INTERFACE boringssl_crypto)
|
||||
endif ()
|
||||
|
||||
install (TARGETS iwasm_static ARCHIVE DESTINATION lib)
|
||||
-
|
||||
+else ()
|
||||
# SHARED LIBRARY
|
||||
add_library (iwasm_shared SHARED ${WAMR_RUNTIME_LIB_SOURCE})
|
||||
set_target_properties (iwasm_shared PROPERTIES OUTPUT_NAME iwasm)
|
||||
target_include_directories(iwasm_shared INTERFACE ${WAMR_ROOT_DIR}/core/iwasm/include)
|
||||
-target_link_libraries (iwasm_shared INTERFACE ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS} -lm -ldl -lpthread)
|
||||
+target_link_libraries (iwasm_shared INTERFACE ${LLVM_AVAILABLE_LIBS} ${UV_A_LIBS})
|
||||
if (WAMR_BUILD_WASM_CACHE EQUAL 1)
|
||||
target_link_libraries(iwasm_shared INTERFACE boringssl_crypto)
|
||||
endif ()
|
||||
-
|
||||
+if (WIN32)
|
||||
+ target_link_libraries (iwasm_shared ntdll)
|
||||
+endif ()
|
||||
if (MINGW)
|
||||
target_link_libraries (iwasm_shared -lWs2_32)
|
||||
endif ()
|
||||
|
||||
install (TARGETS iwasm_shared LIBRARY DESTINATION lib)
|
||||
-
|
||||
+endif ()
|
||||
# HEADERS
|
||||
install (FILES
|
||||
${WAMR_ROOT_DIR}/core/iwasm/include/wasm_c_api.h
|
@ -0,0 +1,53 @@ |
||||
diff --git a/core/iwasm/libraries/libc-uvwasi/libc_uvwasi.cmake b/core/iwasm/libraries/libc-uvwasi/libc_uvwasi.cmake
|
||||
index 7a3bfbdc..3c8c4b19 100644
|
||||
--- a/core/iwasm/libraries/libc-uvwasi/libc_uvwasi.cmake
|
||||
+++ b/core/iwasm/libraries/libc-uvwasi/libc_uvwasi.cmake
|
||||
@@ -12,48 +12,6 @@ include(FetchContent)
|
||||
# Point CMake at the custom modules to find libuv and uvwasi
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
|
||||
|
||||
-## libuv
|
||||
-find_package(LIBUV QUIET)
|
||||
-if (LIBUV_FOUND)
|
||||
- include_directories(${LIBUV_INCLUDE_DIR})
|
||||
-else()
|
||||
- FetchContent_Declare(
|
||||
- libuv
|
||||
- GIT_REPOSITORY https://github.com/libuv/libuv.git
|
||||
- GIT_TAG ${LIBUV_VERSION}
|
||||
- )
|
||||
- FetchContent_GetProperties(libuv)
|
||||
- if (NOT libuv_POPULATED)
|
||||
- message("-- Fetching libuv ..")
|
||||
- FetchContent_Populate(libuv)
|
||||
- include_directories("${libuv_SOURCE_DIR}/include")
|
||||
- add_subdirectory(${libuv_SOURCE_DIR} ${libuv_BINARY_DIR} EXCLUDE_FROM_ALL)
|
||||
- set (LIBUV_LIBRARIES uv_a)
|
||||
- set_target_properties(uv_a PROPERTIES POSITION_INDEPENDENT_CODE 1)
|
||||
- endif()
|
||||
-endif()
|
||||
-
|
||||
-## uvwasi
|
||||
-find_package(UVWASI QUIET)
|
||||
-if (UVWASI_FOUND)
|
||||
- include_directories(${UVWASI_INCLUDE_DIR})
|
||||
-else()
|
||||
- FetchContent_Declare(
|
||||
- uvwasi
|
||||
- GIT_REPOSITORY https://github.com/nodejs/uvwasi.git
|
||||
- GIT_TAG main
|
||||
- )
|
||||
- FetchContent_GetProperties(uvwasi)
|
||||
- if (NOT uvwasi_POPULATED)
|
||||
- message("-- Fetching uvwasi ..")
|
||||
- FetchContent_Populate(uvwasi)
|
||||
- include_directories("${uvwasi_SOURCE_DIR}/include")
|
||||
- add_subdirectory(${uvwasi_SOURCE_DIR} ${uvwasi_BINARY_DIR} EXCLUDE_FROM_ALL)
|
||||
- set (UVWASI_LIBRARIES uvwasi_a)
|
||||
- set_target_properties(uvwasi_a PROPERTIES POSITION_INDEPENDENT_CODE 1)
|
||||
- endif()
|
||||
-endif()
|
||||
-
|
||||
set (UV_A_LIBS ${LIBUV_LIBRARIES} ${UVWASI_LIBRARIES})
|
||||
|
||||
file (GLOB_RECURSE source_all ${LIBC_WASI_DIR}/*.c)
|
@ -0,0 +1,36 @@ |
||||
diff --git a/core/shared/platform/windows/win_clock.c b/core/shared/platform/windows/win_clock.c
|
||||
index c96bdfb3..48e2c449 100644
|
||||
--- a/core/shared/platform/windows/win_clock.c
|
||||
+++ b/core/shared/platform/windows/win_clock.c
|
||||
@@ -55,14 +55,30 @@ os_clock_res_get(__wasi_clockid_t clock_id, __wasi_timestamp_t *resolution)
|
||||
case __WASI_CLOCK_THREAD_CPUTIME_ID:
|
||||
{
|
||||
#if WINAPI_PARTITION_DESKTOP
|
||||
+ HMODULE ntdll = LoadLibrary("ntdll.dll");
|
||||
+ if (!ntdll) {
|
||||
+ return __WASI_ENOTSUP;
|
||||
+ }
|
||||
+
|
||||
+ typedef NTSTATUS(NTAPI *LPFN_NtQueryTimerResolution)(
|
||||
+ OUT PULONG MinimumResolution,
|
||||
+ OUT PULONG MaximumResolution,
|
||||
+ OUT PULONG CurrentResolution
|
||||
+ );
|
||||
+ LPFN_NtQueryTimerResolution pNtQueryTimerResolution = (LPFN_NtQueryTimerResolution)GetProcAddress(ntdll, "NtQueryTimerResolution");
|
||||
+ if (!pNtQueryTimerResolution) {
|
||||
+ return __WASI_ENOTSUP;
|
||||
+ }
|
||||
+
|
||||
ULONG maximum_time;
|
||||
ULONG minimum_time;
|
||||
ULONG current_time;
|
||||
NTSTATUS
|
||||
- status = NtQueryTimerResolution(&maximum_time, &minimum_time,
|
||||
+ status = pNtQueryTimerResolution(&maximum_time, &minimum_time,
|
||||
¤t_time);
|
||||
uint64 result = (uint64)current_time * NANOSECONDS_PER_TICK;
|
||||
*resolution = result / (uint64)NANOSECONDS_PER_SECOND;
|
||||
+ FreeLibrary(ntdll);
|
||||
return error;
|
||||
#else
|
||||
return __WASI_ENOTSUP;
|
Loading…
Reference in new issue