@@ -44,6 +44,10 @@ def should_install(self, host_target):
44
44
return False
45
45
46
46
def build (self , host_target ):
47
+ self ._build (host_target )
48
+ self ._build (host_target , thread_model = 'posix' , target_triple = 'wasm32-wasip1-threads' )
49
+
50
+ def _build (self , host_target , thread_model = 'single' , target_triple = 'wasm32-wasi' ):
47
51
build_root = os .path .dirname (self .build_dir )
48
52
llvm_build_bin_dir = os .path .join (
49
53
'..' , build_root , '%s-%s' % ('llvm' , host_target ), 'bin' )
@@ -66,12 +70,14 @@ def build(self, host_target):
66
70
# https://github.com/llvm/llvm-project/commit/7dd387d2971d7759cadfffeb2082439f6c7ddd49
67
71
'--old-file=check-symbols' ,
68
72
'-C' , self .source_dir ,
69
- 'OBJDIR=' + os .path .join (self .build_dir , 'obj' ),
73
+ 'OBJDIR=' + os .path .join (self .build_dir , 'obj-' + thread_model ),
70
74
'SYSROOT=' + sysroot_build_dir ,
71
75
'INSTALL_DIR=' + WASILibc .sysroot_install_path (build_root ),
72
76
'CC=' + os .path .join (clang_tools_path , 'clang' ),
73
77
'AR=' + os .path .join (llvm_tools_path , 'llvm-ar' ),
74
78
'NM=' + os .path .join (llvm_tools_path , 'llvm-nm' ),
79
+ 'THREAD_MODEL=' + thread_model ,
80
+ 'TARGET_TRIPLE=' + target_triple ,
75
81
])
76
82
77
83
@classmethod
@@ -121,18 +127,30 @@ def should_install(self, host_target):
121
127
return False
122
128
123
129
def build (self , host_target ):
130
+ self ._build (host_target )
131
+
132
+ def _build (self , host_target , enable_wasi_threads = False ):
124
133
build_root = os .path .dirname (self .build_dir )
125
134
llvm_build_bin_dir = os .path .join (
126
135
'..' , build_root , '%s-%s' % ('llvm' , host_target ), 'bin' )
127
136
llvm_tools_path = self .args .native_llvm_tools_path or llvm_build_bin_dir
128
137
clang_tools_path = self .args .native_clang_tools_path or llvm_build_bin_dir
129
138
139
+ cmake_has_threads = 'TRUE' if enable_wasi_threads else 'FALSE'
140
+
130
141
self .cmake_options .define ('CMAKE_SYSROOT:PATH' ,
131
142
WASILibc .sysroot_build_path (build_root , host_target ))
132
- self .cmake_options .define ('LLVM_ENABLE_RUNTIMES:STRING' ,
133
- 'libcxx;libcxxabi;compiler-rt' )
134
- self .cmake_options .define ('LIBCXX_LIBDIR_SUFFIX:STRING' , '/wasm32-wasi' )
135
- self .cmake_options .define ('LIBCXXABI_LIBDIR_SUFFIX:STRING' , '/wasm32-wasi' )
143
+ enable_runtimes = ['libcxx' , 'libcxxabi' ]
144
+ if not enable_wasi_threads :
145
+ # compiler-rt can be shared between wasi and wasip1-threads
146
+ enable_runtimes .append ('compiler-rt' )
147
+ self .cmake_options .define ('LLVM_ENABLE_RUNTIMES:STRING' , ';' .join (enable_runtimes ))
148
+
149
+ libdir_suffix = '/wasm32-wasi'
150
+ if enable_wasi_threads :
151
+ libdir_suffix = '/wasm32-wasi-threads'
152
+ self .cmake_options .define ('LIBCXX_LIBDIR_SUFFIX:STRING' , libdir_suffix )
153
+ self .cmake_options .define ('LIBCXXABI_LIBDIR_SUFFIX:STRING' , libdir_suffix )
136
154
self .cmake_options .define ('CMAKE_STAGING_PREFIX:PATH' , '/' )
137
155
138
156
self .cmake_options .define ('COMPILER_RT_DEFAULT_TARGET_ARCH:STRING' , 'wasm32' )
@@ -157,19 +175,27 @@ def build(self, host_target):
157
175
os .path .join (clang_tools_path , 'clang' ))
158
176
self .cmake_options .define ('CMAKE_CXX_COMPILER:STRING' ,
159
177
os .path .join (clang_tools_path , 'clang++' ))
178
+
179
+ c_flags = []
160
180
# Explicitly disable exceptions even though it's usually implicitly disabled by
161
181
# LIBCXX_ENABLE_EXCEPTIONS because the CMake feature check fails to detect
162
182
# -fno-exceptions support in clang due to missing compiler-rt while configuring
163
183
# as mono project.
164
- self .cmake_options .define ('CMAKE_CXX_FLAGS:STRING' , '-fno-exceptions' )
184
+ cxx_flags = ['-fno-exceptions' ]
185
+ if enable_wasi_threads :
186
+ c_flags .append ('-pthread' )
187
+ cxx_flags .append ('-pthread' )
188
+ self .cmake_options .define ('CMAKE_C_FLAGS:STRING' , ' ' .join (c_flags ))
189
+ self .cmake_options .define ('CMAKE_CXX_FLAGS:STRING' , ' ' .join (cxx_flags ))
165
190
166
- self .cmake_options .define ('CMAKE_C_COMPILER_TARGET:STRING' , 'wasm32-wasi' )
167
- self .cmake_options .define ('CMAKE_CXX_COMPILER_TARGET:STRING' , 'wasm32-wasi' )
191
+ target_triple = 'wasm32-wasi-threads' if enable_wasi_threads else 'wasm32-wasi'
192
+ self .cmake_options .define ('CMAKE_C_COMPILER_TARGET:STRING' , target_triple )
193
+ self .cmake_options .define ('CMAKE_CXX_COMPILER_TARGET:STRING' , target_triple )
168
194
169
195
self .cmake_options .define ('CXX_SUPPORTS_CXX11:BOOL' , 'TRUE' )
170
196
171
- self .cmake_options .define ('LIBCXX_ENABLE_THREADS:BOOL' , 'FALSE' )
172
- self .cmake_options .define ('LIBCXX_HAS_PTHREAD_API:BOOL' , 'FALSE' )
197
+ self .cmake_options .define ('LIBCXX_ENABLE_THREADS:BOOL' , cmake_has_threads )
198
+ self .cmake_options .define ('LIBCXX_HAS_PTHREAD_API:BOOL' , cmake_has_threads )
173
199
self .cmake_options .define ('LIBCXX_HAS_EXTERNAL_THREAD_API:BOOL' , 'FALSE' )
174
200
self .cmake_options .define ('LIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY:BOOL' , 'FALSE' )
175
201
self .cmake_options .define ('LIBCXX_HAS_WIN32_THREAD_API:BOOL' , 'FALSE' )
@@ -184,8 +210,8 @@ def build(self, host_target):
184
210
self .cmake_options .define ('LIBCXXABI_ENABLE_EXCEPTIONS:BOOL' , 'FALSE' )
185
211
self .cmake_options .define ('LIBCXXABI_ENABLE_SHARED:BOOL' , 'FALSE' )
186
212
self .cmake_options .define ('LIBCXXABI_SILENT_TERMINATE:BOOL' , 'TRUE' )
187
- self .cmake_options .define ('LIBCXXABI_ENABLE_THREADS:BOOL' , 'FALSE' )
188
- self .cmake_options .define ('LIBCXXABI_HAS_PTHREAD_API:BOOL' , 'FALSE' )
213
+ self .cmake_options .define ('LIBCXXABI_ENABLE_THREADS:BOOL' , cmake_has_threads )
214
+ self .cmake_options .define ('LIBCXXABI_HAS_PTHREAD_API:BOOL' , cmake_has_threads )
189
215
self .cmake_options .define ('LIBCXXABI_HAS_EXTERNAL_THREAD_API:BOOL' , 'FALSE' )
190
216
self .cmake_options .define ('LIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY:BOOL' ,
191
217
'FALSE' )
@@ -201,3 +227,15 @@ def build(self, host_target):
201
227
@classmethod
202
228
def get_dependencies (cls ):
203
229
return [WASILibc , llvm .LLVM ]
230
+
231
+ class WasmThreadsLLVMRuntimeLibs (WasmLLVMRuntimeLibs ):
232
+ def build (self , host_target ):
233
+ self ._build (host_target , enable_wasi_threads = True )
234
+
235
+ build_root = os .path .dirname (self .build_dir )
236
+ wasi_sysroot = WASILibc .sysroot_install_path (build_root )
237
+ # Copy compiler-rt os dirs to the WASI variant
238
+ os_dir = os .path .join (wasi_sysroot , 'lib' , 'wasip1' )
239
+ if os .path .exists (os_dir ):
240
+ shell .rmtree (os_dir )
241
+ shell .copytree (os .path .join (wasi_sysroot , 'lib' , 'wasi' ), os_dir )
0 commit comments