@@ -147,10 +147,21 @@ def _build(self, host_target, enable_wasi_threads, compiler_rt_os_dir, target_tr
147147 build_dir = os .path .join (self .build_dir , target_triple ))
148148
149149 build_root = os .path .dirname (self .build_dir )
150- llvm_build_bin_dir = os .path .join (
151- '..' , build_root , '%s-%s' % ('llvm' , host_target ), 'bin' )
152- llvm_tools_path = cmake .args .native_llvm_tools_path or llvm_build_bin_dir
153- clang_tools_path = cmake .args .native_clang_tools_path or llvm_build_bin_dir
150+
151+ if self .args .build_runtime_with_host_compiler :
152+ cc_path = self .toolchain .cc
153+ cxx_path = self .toolchain .cxx
154+ ar_path = self .toolchain .llvm_ar
155+ ranlib_path = self .toolchain .llvm_ranlib
156+ else :
157+ llvm_build_bin_dir = os .path .join (
158+ '..' , build_root , '%s-%s' % ('llvm' , host_target ), 'bin' )
159+ llvm_tools_path = cmake .args .native_llvm_tools_path or llvm_build_bin_dir
160+ clang_tools_path = cmake .args .native_clang_tools_path or llvm_build_bin_dir
161+ ar_path = os .path .join (llvm_tools_path , 'llvm-ar' )
162+ ranlib_path = os .path .join (llvm_tools_path , 'llvm-ranlib' )
163+ cc_path = os .path .join (clang_tools_path , 'clang' )
164+ cxx_path = os .path .join (clang_tools_path , 'clang++' )
154165
155166 cmake_has_threads = 'TRUE' if enable_wasi_threads else 'FALSE'
156167
@@ -181,14 +192,10 @@ def _build(self, host_target, enable_wasi_threads, compiler_rt_os_dir, target_tr
181192
182193 cmake .cmake_options .define ('CMAKE_SYSTEM_NAME:STRING' , 'WASI' )
183194 cmake .cmake_options .define ('CMAKE_SYSTEM_PROCESSOR:STRING' , 'wasm32' )
184- cmake .cmake_options .define ('CMAKE_AR:FILEPATH' ,
185- os .path .join (llvm_tools_path , 'llvm-ar' ))
186- cmake .cmake_options .define ('CMAKE_RANLIB:FILEPATH' ,
187- os .path .join (llvm_tools_path , 'llvm-ranlib' ))
188- cmake .cmake_options .define ('CMAKE_C_COMPILER:FILEPATH' ,
189- os .path .join (clang_tools_path , 'clang' ))
190- cmake .cmake_options .define ('CMAKE_CXX_COMPILER:STRING' ,
191- os .path .join (clang_tools_path , 'clang++' ))
195+ cmake .cmake_options .define ('CMAKE_AR:FILEPATH' , ar_path )
196+ cmake .cmake_options .define ('CMAKE_RANLIB:FILEPATH' , ranlib_path )
197+ cmake .cmake_options .define ('CMAKE_C_COMPILER:FILEPATH' , cc_path )
198+ cmake .cmake_options .define ('CMAKE_CXX_COMPILER:STRING' , cxx_path )
192199
193200 c_flags = []
194201 # Explicitly disable exceptions even though it's usually implicitly disabled by
@@ -234,7 +241,7 @@ def _build(self, host_target, enable_wasi_threads, compiler_rt_os_dir, target_tr
234241 cmake .cmake_options .define ('UNIX:BOOL' , 'TRUE' )
235242
236243 cmake .build_with_cmake ([], cmake .args .build_variant , [],
237- prefer_native_toolchain = True ,
244+ prefer_native_toolchain = not self . args . build_runtime_with_host_compiler ,
238245 ignore_extra_cmake_options = True )
239246 cmake .install_with_cmake (
240247 ["install" ], WASILibc .sysroot_install_path (build_root , target_triple ))
0 commit comments