Skip to content

Commit 5f85d24

Browse files
committed
Make LTO build optional
1 parent 446efe9 commit 5f85d24

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

cmake/wasi-sdk-sysroot.cmake

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ find_program(MAKE make REQUIRED)
99

1010
option(WASI_SDK_DEBUG_PREFIX_MAP "Pass `-fdebug-prefix-map` for built artifacts" ON)
1111
option(WASI_SDK_INCLUDE_TESTS "Whether or not to build tests by default" OFF)
12+
option(WASI_SDK_LTO "Whether or not to build LTO assets" ON)
1213

1314
set(wasi_sysroot ${CMAKE_INSTALL_PREFIX}/share/wasi-sysroot)
1415

@@ -149,10 +150,12 @@ endfunction()
149150

150151
function(define_wasi_libc target)
151152
define_wasi_libc_sub (${target} "" OFF)
152-
define_wasi_libc_sub (${target} "-lto" ON)
153+
if(WASI_SDK_LTO)
154+
define_wasi_libc_sub (${target} "-lto" ON)
155+
endif()
153156

154157
add_custom_target(wasi-libc-${target}
155-
DEPENDS wasi-libc-${target}-build wasi-libc-${target}-lto-build)
158+
DEPENDS wasi-libc-${target}-build $<$<BOOL:${WASI_SDK_LTO}>:wasi-libc-${target}-lto-build>)
156159
endfunction()
157160

158161
foreach(target IN LISTS WASI_SDK_TARGETS)
@@ -249,17 +252,19 @@ endfunction()
249252

250253
function(define_libcxx target)
251254
define_libcxx_sub(${target} "" "" "")
252-
# Note: clang knows this /llvm-lto/${llvm_version} convention.
253-
# https://github.com/llvm/llvm-project/blob/llvmorg-18.1.8/clang/lib/Driver/ToolChains/WebAssembly.cpp#L204-L210
254-
define_libcxx_sub(${target} "-lto" "-flto=full" "/llvm-lto/${llvm_version}")
255+
if(WASI_SDK_LTO)
256+
# Note: clang knows this /llvm-lto/${llvm_version} convention.
257+
# https://github.com/llvm/llvm-project/blob/llvmorg-18.1.8/clang/lib/Driver/ToolChains/WebAssembly.cpp#L204-L210
258+
define_libcxx_sub(${target} "-lto" "-flto=full" "/llvm-lto/${llvm_version}")
259+
endif()
255260

256261
# As of this writing, `clang++` will ignore the target-specific include dirs
257262
# unless this one also exists:
258263
add_custom_target(libcxx-${target}-extra-dir
259264
COMMAND ${CMAKE_COMMAND} -E make_directory ${wasi_sysroot}/include/c++/v1
260265
COMMENT "creating libcxx-specific header file folder")
261266
add_custom_target(libcxx-${target}
262-
DEPENDS libcxx-${target}-build libcxx-${target}-lto-build libcxx-${target}-extra-dir)
267+
DEPENDS libcxx-${target}-build $<$<BOOL:${WASI_SDK_LTO}>:libcxx-${target}-lto-build> libcxx-${target}-extra-dir)
263268
endfunction()
264269

265270
foreach(target IN LISTS WASI_SDK_TARGETS)

0 commit comments

Comments
 (0)