@@ -56,7 +56,8 @@ def _build(self, host_target, thread_model='single', target_triple='wasm32-wasi'
56
56
clang_tools_path = self .args .native_clang_tools_path or llvm_build_bin_dir
57
57
build_jobs = self .args .build_jobs or multiprocessing .cpu_count ()
58
58
59
- sysroot_build_dir = WASILibc .sysroot_build_path (build_root , host_target )
59
+ sysroot_build_dir = WASILibc .sysroot_build_path (
60
+ build_root , host_target , target_triple )
60
61
# FIXME: Manually create an empty dir that is usually created during
61
62
# check-symbols. The directory is required during sysroot installation step.
62
63
os .makedirs (os .path .join (sysroot_build_dir , "share" ), exist_ok = True )
@@ -73,7 +74,7 @@ def _build(self, host_target, thread_model='single', target_triple='wasm32-wasi'
73
74
'-C' , self .source_dir ,
74
75
'OBJDIR=' + os .path .join (self .build_dir , 'obj-' + thread_model ),
75
76
'SYSROOT=' + sysroot_build_dir ,
76
- 'INSTALL_DIR=' + WASILibc .sysroot_install_path (build_root ),
77
+ 'INSTALL_DIR=' + WASILibc .sysroot_install_path (build_root , target_triple ),
77
78
'CC=' + os .path .join (clang_tools_path , 'clang' ),
78
79
'AR=' + os .path .join (llvm_tools_path , 'llvm-ar' ),
79
80
'NM=' + os .path .join (llvm_tools_path , 'llvm-nm' ),
@@ -86,21 +87,22 @@ def get_dependencies(cls):
86
87
return [llvm .LLVM ]
87
88
88
89
@classmethod
89
- def sysroot_build_path (cls , build_root , host_target ):
90
+ def sysroot_build_path (cls , build_root , host_target , target_triple ):
90
91
"""
91
92
Returns the path to the sysroot build directory, which contains only the
92
93
artifacts of wasi-libc (Not including the artifacts of LLVM runtimes).
93
94
"""
94
95
return os .path .join (build_root ,
95
- '%s-%s' % (cls .product_name (), host_target ), 'sysroot' )
96
+ '%s-%s' % (cls .product_name (), host_target ),
97
+ 'sysroot' , target_triple )
96
98
97
99
@classmethod
98
- def sysroot_install_path (cls , build_root ):
100
+ def sysroot_install_path (cls , build_root , target_triple ):
99
101
"""
100
102
Returns the path to the sysroot install directory, which contains artifacts
101
103
of wasi-libc and LLVM runtimes.
102
104
"""
103
- return os .path .join (build_root , 'wasi-sysroot' )
105
+ return os .path .join (build_root , 'wasi-sysroot' , target_triple )
104
106
105
107
106
108
class WasmLLVMRuntimeLibs (cmake_product .CMakeProduct ):
@@ -130,7 +132,8 @@ def should_install(self, host_target):
130
132
def build (self , host_target ):
131
133
self ._build (host_target )
132
134
133
- def _build (self , host_target , enable_wasi_threads = False ):
135
+ def _build (self , host_target , enable_wasi_threads = False ,
136
+ compiler_rt_os_dir = 'wasi' , target_triple = 'wasm32-wasi' ):
134
137
build_root = os .path .dirname (self .build_dir )
135
138
llvm_build_bin_dir = os .path .join (
136
139
'..' , build_root , '%s-%s' % ('llvm' , host_target ), 'bin' )
@@ -139,18 +142,14 @@ def _build(self, host_target, enable_wasi_threads=False):
139
142
140
143
cmake_has_threads = 'TRUE' if enable_wasi_threads else 'FALSE'
141
144
142
- self .cmake_options .define ('CMAKE_SYSROOT:PATH' ,
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' )
145
+ self .cmake_options .define (
146
+ 'CMAKE_SYSROOT:PATH' ,
147
+ WASILibc .sysroot_build_path (build_root , host_target , target_triple ))
148
+ enable_runtimes = ['libcxx' , 'libcxxabi' , 'compiler-rt' ]
148
149
self .cmake_options .define ('LLVM_ENABLE_RUNTIMES:STRING' ,
149
150
';' .join (enable_runtimes ))
150
151
151
- libdir_suffix = '/wasm32-wasi'
152
- if enable_wasi_threads :
153
- libdir_suffix = '/wasm32-wasip1-threads'
152
+ libdir_suffix = '/' + target_triple
154
153
self .cmake_options .define ('LIBCXX_LIBDIR_SUFFIX:STRING' , libdir_suffix )
155
154
self .cmake_options .define ('LIBCXXABI_LIBDIR_SUFFIX:STRING' , libdir_suffix )
156
155
self .cmake_options .define ('CMAKE_STAGING_PREFIX:PATH' , '/' )
@@ -162,7 +161,7 @@ def _build(self, host_target, enable_wasi_threads=False):
162
161
self .cmake_options .define ('COMPILER_RT_INCLUDE_TESTS:BOOL' , 'FALSE' )
163
162
self .cmake_options .define ('COMPILER_RT_HAS_FPIC_FLAG:BOOL' , 'FALSE' )
164
163
self .cmake_options .define ('COMPILER_RT_EXCLUDE_ATOMIC_BUILTIN:BOOL' , 'FALSE' )
165
- self .cmake_options .define ('COMPILER_RT_OS_DIR:STRING' , 'wasi' )
164
+ self .cmake_options .define ('COMPILER_RT_OS_DIR:STRING' , compiler_rt_os_dir )
166
165
167
166
self .cmake_options .define ('CMAKE_C_COMPILER_WORKS:BOOL' , 'TRUE' )
168
167
self .cmake_options .define ('CMAKE_CXX_COMPILER_WORKS:BOOL' , 'TRUE' )
@@ -190,10 +189,6 @@ def _build(self, host_target, enable_wasi_threads=False):
190
189
self .cmake_options .define ('CMAKE_C_FLAGS:STRING' , ' ' .join (c_flags ))
191
190
self .cmake_options .define ('CMAKE_CXX_FLAGS:STRING' , ' ' .join (cxx_flags ))
192
191
193
- if enable_wasi_threads :
194
- target_triple = 'wasm32-wasip1-threads'
195
- else :
196
- target_triple = 'wasm32-wasi'
197
192
self .cmake_options .define ('CMAKE_C_COMPILER_TARGET:STRING' , target_triple )
198
193
self .cmake_options .define ('CMAKE_CXX_COMPILER_TARGET:STRING' , target_triple )
199
194
@@ -227,7 +222,7 @@ def _build(self, host_target, enable_wasi_threads=False):
227
222
self .build_with_cmake ([], self .args .build_variant , [],
228
223
prefer_native_toolchain = True )
229
224
self .install_with_cmake (
230
- ["install" ], WASILibc .sysroot_install_path (build_root ))
225
+ ["install" ], WASILibc .sysroot_install_path (build_root , target_triple ))
231
226
232
227
@classmethod
233
228
def get_dependencies (cls ):
@@ -236,12 +231,5 @@ def get_dependencies(cls):
236
231
237
232
class WasmThreadsLLVMRuntimeLibs (WasmLLVMRuntimeLibs ):
238
233
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 )
234
+ self ._build (host_target , enable_wasi_threads = True ,
235
+ compiler_rt_os_dir = 'wasip1' , target_triple = 'wasm32-wasip1-threads' )
0 commit comments