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