@@ -92,18 +92,27 @@ add_custom_target(compiler-rt DEPENDS compiler-rt-build compiler-rt-post-build)
92
92
# wasi-libc build logic
93
93
# =============================================================================
94
94
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} )
97
97
98
98
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 ()
101
104
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 ()
104
110
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 ()
107
116
endif ()
108
117
109
118
string (TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPER)
@@ -112,7 +121,7 @@ function(define_wasi_libc target)
112
121
"${CMAKE_C_FLAGS} ${directory_cflags} ${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPER} }" )
113
122
list (JOIN extra_cflags_list " " extra_cflags)
114
123
115
- ExternalProject_Add(wasi-libc-${target}
124
+ ExternalProject_Add(wasi-libc-${target}${target_suffix} - build
116
125
# Currently wasi-libc doesn't support out-of-tree builds so feigh a
117
126
# "download command" which copies the source tree to a different location
118
127
# so out-of-tree builds are supported.
@@ -129,15 +138,6 @@ function(define_wasi_libc target)
129
138
EXTRA_CFLAGS=${extra_cflags}
130
139
TARGET_TRIPLE=${target}
131
140
${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}
141
141
INSTALL_COMMAND ""
142
142
DEPENDS compiler-rt
143
143
EXCLUDE_FROM_ALL ON
@@ -147,6 +147,14 @@ function(define_wasi_libc target)
147
147
)
148
148
endfunction ()
149
149
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
+
150
158
foreach (target IN LISTS WASI_SDK_TARGETS)
151
159
define_wasi_libc(${target} )
152
160
endforeach ()
0 commit comments