Skip to content

Commit

Permalink
Revise WASI build
Browse files Browse the repository at this point in the history
* update to use v0.0.21 uvwasi instead of dangling commit
* revise cmake build for WASI

Signed-off-by: HyukWoo Park <[email protected]>
  • Loading branch information
clover2123 committed Jun 4, 2024
1 parent bc7b090 commit a7c581f
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 95 deletions.
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
path = third_party/wasm-c-api
url = https://github.com/WebAssembly/wasm-c-api
ignore = untracked
[submodule "third_party/uvwasi"]
path = third_party/uvwasi
url = https://github.com/nodejs/uvwasi.git
[submodule "third_party/uvwasi/uvwasi"]
path = third_party/uvwasi/uvwasi
url = https://github.com/nodejs/uvwasi
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,3 @@ PROCESSORCOUNT (NPROCS)
# INCLUDE CMAKE FILES
INCLUDE (${PROJECT_SOURCE_DIR}/build/config.cmake)
INCLUDE (${PROJECT_SOURCE_DIR}/build/walrus.cmake)
IF (WALRUS_WASI)
INCLUDE (${PROJECT_SOURCE_DIR}/build/wasi.cmake)
ENDIF()
6 changes: 4 additions & 2 deletions build/walrus.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ SET (WALRUS_LIBRARIES ${WALRUS_LIBRARIES} wabt)

IF (WALRUS_WASI)
# uvwasi
INCLUDE_DIRECTORIES (${WALRUS_INCDIRS} PRIVATE ${WALRUS_THIRD_PARTY_ROOT}/uvwasi/include)
INCLUDE_DIRECTORIES (${WALRUS_INCDIRS} PRIVATE ${CMAKE_BINARY_DIR}/_deps/libuv-src/include)
IF (${WALRUS_ARCH} STREQUAL "x86")
SET (UVWASI_BUILD_X86 ON)
ENDIF()
ADD_SUBDIRECTORY (third_party/uvwasi)
SET (WALRUS_DEFINITIONS ${WALRUS_DEFINITIONS} -DENABLE_WASI)
SET (WALRUS_LIBRARIES ${WALRUS_LIBRARIES} uvwasi_a)
ENDIF()
Expand Down
86 changes: 0 additions & 86 deletions build/wasi.cmake

This file was deleted.

1 change: 0 additions & 1 deletion third_party/uvwasi
Submodule uvwasi deleted from de39e5
105 changes: 105 additions & 0 deletions third_party/uvwasi/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
cmake_minimum_required(VERSION 3.11)
project (
uvwasi
DESCRIPTION "WASI syscall API built atop libuv"
VERSION 0.0.21
LANGUAGES C
)

set(UVWASI_DIR ${PROJECT_SOURCE_DIR}/uvwasi)

# Point CMake at any custom modules we may ship
list(APPEND CMAKE_MODULE_PATH "${UVWASI_DIR}/cmake")

# This can be a commit hash or tag
set(LIBUV_VERSION v1.44.2)

include(CMakeDependentOption)
cmake_dependent_option(UVWASI_BUILD_TESTS
"Build the unit tests when uvwasi is the root project" ON
"CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR" OFF)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/out)

if (UVWASI_BUILD_X86)
# set x86 build flag
set (CMAKE_C_FLAGS ${CMAKE_C_FLAGS} -m32)
endif()

if(CMAKE_C_COMPILER_ID MATCHES "AppleClang|Clang|GNU")
list(APPEND uvwasi_cflags -fvisibility=hidden --std=gnu89)
list(APPEND uvwasi_cflags -Wall -Wsign-compare -Wextra -Wstrict-prototypes)
list(APPEND uvwasi_cflags -Wno-unused-parameter)
endif()

if(APPLE)
set(CMAKE_MACOSX_RPATH ON)
endif()

if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
list(APPEND uvwasi_defines _GNU_SOURCE _POSIX_C_SOURCE=200112)
endif()

#find_package(LIBUV QUIET)
#if(LIBUV_FOUND)
# include_directories(${LIBUV_INCLUDE_DIR})
#else()
include(FetchContent)
## https://libuv.org
FetchContent_Declare(
libuv
GIT_REPOSITORY https://github.com/libuv/libuv.git
GIT_TAG ${LIBUV_VERSION})

FetchContent_GetProperties(libuv)
if(NOT libuv_POPULATED)
FetchContent_Populate(libuv)
include_directories("${libuv_SOURCE_DIR}/include")
add_subdirectory(${libuv_SOURCE_DIR} ${libuv_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()
set(LIBUV_INCLUDE_DIR ${libuv_SOURCE_DIR}/include)
set(LIBUV_LIBRARIES uv_a)
#endif()

## uvwasi source code files.
set(uvwasi_sources
${UVWASI_DIR}/src/clocks.c
${UVWASI_DIR}/src/fd_table.c
${UVWASI_DIR}/src/path_resolver.c
${UVWASI_DIR}/src/poll_oneoff.c
${UVWASI_DIR}/src/sync_helpers.c
${UVWASI_DIR}/src/uv_mapping.c
${UVWASI_DIR}/src/uvwasi.c
${UVWASI_DIR}/src/wasi_rights.c
${UVWASI_DIR}/src/wasi_serdes.c
)

# ASAN Support
option(ASAN "Enable code asan" OFF)
if(ASAN AND CMAKE_C_COMPILER_ID MATCHES "AppleClang|GNU|Clang")
set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")
set (CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")
endif()

## Static library target.
add_library(uvwasi_a STATIC ${uvwasi_sources})
target_compile_definitions(uvwasi_a PRIVATE ${uvwasi_defines})
target_compile_options(uvwasi_a PRIVATE ${uvwasi_cflags})
target_include_directories(uvwasi_a PUBLIC ${UVWASI_DIR}/include ${LIBUV_INCLUDE_DIR})
target_link_libraries(uvwasi_a PRIVATE ${LIBUV_LIBRARIES})

message(STATUS "summary of uvwasi build options:
Install prefix: ${CMAKE_INSTALL_PREFIX}
Target system: ${CMAKE_SYSTEM_NAME}
Compiler:
C compiler: ${CMAKE_C_COMPILER}
CFLAGS: ${CMAKE_C_FLAGS_${_build_type}} ${CMAKE_C_FLAGS}
LibUV libraries: ${LIBUV_LIBRARIES}
LibUV includes: ${LIBUV_INCLUDE_DIR}
Debug logging: ${UVWASI_DEBUG_LOG}
Code coverage: ${CODE_COVERAGE}
ASAN: ${ASAN}
Build tests: ${UVWASI_BUILD_TESTS}
")
1 change: 1 addition & 0 deletions third_party/uvwasi/uvwasi
Submodule uvwasi added at 83dd1f

0 comments on commit a7c581f

Please sign in to comment.