Skip to content

Commit 446efe9

Browse files
committed
Use separate targets for wasi-libc with and without lto
A downside: this makes four more copies of wasi-libc source tree.
1 parent 6531c19 commit 446efe9

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

cmake/wasi-sdk-sysroot.cmake

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,27 @@ add_custom_target(compiler-rt DEPENDS compiler-rt-build compiler-rt-post-build)
9292
# wasi-libc build logic
9393
# =============================================================================
9494

95-
function(define_wasi_libc target)
96-
set(build_dir ${CMAKE_CURRENT_BINARY_DIR}/wasi-libc-${target})
95+
function(define_wasi_libc_sub target target_suffix lto)
96+
set(build_dir ${CMAKE_CURRENT_BINARY_DIR}/wasi-libc-${target}${target_suffix})
9797

9898
if(${target} MATCHES threads)
99-
set(extra_make_flags THREAD_MODEL=posix)
100-
set(extra_make_flags_lto LTO=full THREAD_MODEL=posix)
99+
if(lto)
100+
set(extra_make_flags LTO=full THREAD_MODEL=posix)
101+
else()
102+
set(extra_make_flags THREAD_MODEL=posix)
103+
endif()
101104
elseif(${target} MATCHES p2)
102-
set(extra_make_flags WASI_SNAPSHOT=p2 default libc_so)
103-
set(extra_make_flags_lto LTO=full WASI_SNAPSHOT=p2 default)
105+
if(lto)
106+
set(extra_make_flags LTO=full WASI_SNAPSHOT=p2 default)
107+
else()
108+
set(extra_make_flags WASI_SNAPSHOT=p2 default libc_so)
109+
endif()
104110
else()
105-
set(extra_make_flags default libc_so)
106-
set(extra_make_flags_lto LTO=full default)
111+
if(lto)
112+
set(extra_make_flags LTO=full default)
113+
else()
114+
set(extra_make_flags default libc_so)
115+
endif()
107116
endif()
108117

109118
string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPER)
@@ -112,7 +121,7 @@ function(define_wasi_libc target)
112121
"${CMAKE_C_FLAGS} ${directory_cflags} ${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPER}}")
113122
list(JOIN extra_cflags_list " " extra_cflags)
114123

115-
ExternalProject_Add(wasi-libc-${target}
124+
ExternalProject_Add(wasi-libc-${target}${target_suffix}-build
116125
# Currently wasi-libc doesn't support out-of-tree builds so feigh a
117126
# "download command" which copies the source tree to a different location
118127
# so out-of-tree builds are supported.
@@ -129,15 +138,6 @@ function(define_wasi_libc target)
129138
EXTRA_CFLAGS=${extra_cflags}
130139
TARGET_TRIPLE=${target}
131140
${extra_make_flags}
132-
COMMAND
133-
${MAKE} -j8 -C ${build_dir}
134-
CC=${CMAKE_C_COMPILER}
135-
AR=${CMAKE_AR}
136-
NM=${CMAKE_NM}
137-
SYSROOT=${wasi_sysroot}
138-
EXTRA_CFLAGS=${extra_cflags}
139-
TARGET_TRIPLE=${target}
140-
${extra_make_flags_lto}
141141
INSTALL_COMMAND ""
142142
DEPENDS compiler-rt
143143
EXCLUDE_FROM_ALL ON
@@ -147,6 +147,14 @@ function(define_wasi_libc target)
147147
)
148148
endfunction()
149149

150+
function(define_wasi_libc target)
151+
define_wasi_libc_sub (${target} "" OFF)
152+
define_wasi_libc_sub (${target} "-lto" ON)
153+
154+
add_custom_target(wasi-libc-${target}
155+
DEPENDS wasi-libc-${target}-build wasi-libc-${target}-lto-build)
156+
endfunction()
157+
150158
foreach(target IN LISTS WASI_SDK_TARGETS)
151159
define_wasi_libc(${target})
152160
endforeach()

0 commit comments

Comments
 (0)