Skip to content

Commit 615ea0a

Browse files
committed
Update wasi-libc to cmake-enabled build
1 parent 338aec5 commit 615ea0a

File tree

2 files changed

+19
-39
lines changed

2 files changed

+19
-39
lines changed

cmake/wasi-sdk-sysroot.cmake

Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -137,29 +137,11 @@ add_custom_target(compiler-rt DEPENDS compiler-rt-build compiler-rt-post-build)
137137
# =============================================================================
138138

139139
function(define_wasi_libc_sub target target_suffix lto)
140-
set(build_dir ${CMAKE_CURRENT_BINARY_DIR}/wasi-libc-${target}${target_suffix})
141-
142140
string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPER)
143141
get_property(directory_cflags DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY COMPILE_OPTIONS)
144-
list(APPEND directory_cflags -resource-dir ${wasi_resource_dir})
145-
set(extra_cflags_list
146-
"${WASI_SDK_CPU_CFLAGS} ${CMAKE_C_FLAGS} ${directory_cflags} ${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPER}}")
147-
148-
set(extra_make_flags default)
149-
150-
# If LTO is enabled then pass that on to wasi-libc, and otherwise make sure to
151-
# build a `libc.so` dynamic library where possible (not compatible with
152-
# threads though)
153-
if(lto)
154-
list(APPEND extra_make_flags LTO=full)
155-
elseif(NOT ${target} MATCHES threads)
156-
list(APPEND extra_make_flags libc_so)
157-
endif()
142+
set(extra_cflags_list "${WASI_SDK_CPU_CFLAGS} ${CMAKE_C_FLAGS} ${directory_cflags}")
158143

159-
if(${target} MATCHES threads)
160-
list(APPEND extra_make_flags THREAD_MODEL=posix)
161-
elseif(${target} MATCHES p2)
162-
list(APPEND extra_make_flags WASI_SNAPSHOT=p2)
144+
if(${target} MATCHES p2)
163145
# Always enable `-fPIC` for the `wasm32-wasip2` target. This makes `libc.a`
164146
# more flexible and usable in dynamic linking situations.
165147
list(APPEND extra_cflags_list -fPIC)
@@ -173,25 +155,23 @@ function(define_wasi_libc_sub target target_suffix lto)
173155
set(libcompiler_rt_a ${wasi_resource_dir}/lib/wasm32-unknown-wasip1/libclang_rt.builtins.a)
174156
endif()
175157

158+
set(extra_cmake_args)
159+
160+
# Configure LTO in wasi libc if it's enabled. Be sure to disable shared
161+
# libraries as well since that's not currently supported.
162+
if (lto)
163+
list(APPEND extra_cmake_args -DLTO=full -DBUILD_SHARED=OFF)
164+
endif()
165+
176166
ExternalProject_Add(wasi-libc-${target}${target_suffix}-build
177-
# Currently wasi-libc doesn't support out-of-tree builds so feign a
178-
# "download command" which copies the source tree to a different location
179-
# so out-of-tree builds are supported.
180-
DOWNLOAD_COMMAND
181-
${CMAKE_COMMAND} -E copy_directory ${wasi_libc} ${build_dir}
182-
SOURCE_DIR "${build_dir}"
183-
CONFIGURE_COMMAND ""
184-
BUILD_COMMAND
185-
${MAKE} -j8 -C ${build_dir}
186-
CC=${CMAKE_C_COMPILER}
187-
AR=${CMAKE_AR}
188-
NM=${CMAKE_NM}
189-
SYSROOT=${wasi_sysroot}
190-
EXTRA_CFLAGS=${extra_cflags}
191-
TARGET_TRIPLE=${target}
192-
BUILTINS_LIB=${libcompiler_rt_a}
193-
${extra_make_flags}
194-
INSTALL_COMMAND ""
167+
SOURCE_DIR ${wasi_libc}
168+
CMAKE_ARGS
169+
${default_cmake_args}
170+
${extra_cmake_args}
171+
-DTARGET_TRIPLE=${target}
172+
-DCMAKE_INSTALL_PREFIX=${wasi_sysroot}
173+
-DCMAKE_C_FLAGS=${extra_cflags}
174+
-DBUILTINS_LIB=${libcompiler_rt_a}
195175
DEPENDS compiler-rt
196176
EXCLUDE_FROM_ALL ON
197177
USES_TERMINAL_CONFIGURE ON

src/wasi-libc

Submodule wasi-libc updated 161 files

0 commit comments

Comments
 (0)