Skip to content

Commit f1a1bb0

Browse files
authored
WasmLLVMRuntimeLibs: respect args.build_runtime_with_host_compiler (#82949)
This allows quickly building `WasmLLVMRuntimeLibs` product with the host toolchain (usually Swift nightly development snapshot toolchain) when `--skip-build-llvm --skip-build-swift --build-runtime-with-host-compiler` combination of options is passed to `build-script`.
1 parent 47db5ad commit f1a1bb0

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

utils/swift_build_support/swift_build_support/products/wasisysroot.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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))

utils/swift_build_support/swift_build_support/toolchain.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ def _getter(self):
6868
else:
6969
_register("ranlib", "ranlib")
7070
_register("ar", "ar")
71+
_register("llvm_ar", "llvm-ar")
72+
_register("llvm_nm", "llvm-nm")
73+
_register("llvm_ranlib", "llvm-ranlib")
7174
_register("sccache", "sccache")
7275
_register("swiftc", "swiftc")
7376
_register("swift_build", "swift-build")

0 commit comments

Comments
 (0)