Skip to content

Commit 5a66841

Browse files
build: Respect native-*-tools-path when building Wasm stdlib
This change allows the Wasm stdlib to be built using the prebuilt Swift toolchain instead of just built from source.
1 parent 43cdee3 commit 5a66841

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

utils/swift_build_support/swift_build_support/cmake.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def common_options(self, product=None):
147147
define("CMAKE_CXX_COMPILER_LAUNCHER:PATH", args.cmake_cxx_launcher)
148148

149149
if self.prefer_just_built_toolchain and product:
150-
toolchain_path = product.install_toolchain_path(args.host_target)
150+
toolchain_path = product.native_toolchain_path(args.host_target)
151151
cmake_swiftc_path = os.getenv('CMAKE_Swift_COMPILER',
152152
os.path.join(toolchain_path, 'bin', 'swiftc'))
153153
define("CMAKE_C_COMPILER:PATH", os.path.join(toolchain_path,

utils/swift_build_support/swift_build_support/products/wasisysroot.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ def should_install(self, host_target):
4545

4646
def build(self, host_target):
4747
build_root = os.path.dirname(self.build_dir)
48-
llvm_build_dir = os.path.join('..', build_root, '%s-%s' % ('llvm', host_target))
48+
llvm_build_bin_dir = os.path.join(
49+
'..', build_root, '%s-%s' % ('llvm', host_target), 'bin')
50+
llvm_tools_path = self.args.native_llvm_tools_path or llvm_build_bin_dir
51+
clang_tools_path = self.args.native_clang_tools_path or llvm_build_bin_dir
4952
build_jobs = self.args.build_jobs or multiprocessing.cpu_count()
5053

5154
sysroot_build_dir = WASILibc.sysroot_build_path(build_root, host_target)
@@ -66,9 +69,9 @@ def build(self, host_target):
6669
'OBJDIR=' + os.path.join(self.build_dir, 'obj'),
6770
'SYSROOT=' + sysroot_build_dir,
6871
'INSTALL_DIR=' + WASILibc.sysroot_install_path(build_root),
69-
'CC=' + os.path.join(llvm_build_dir, 'bin', 'clang'),
70-
'AR=' + os.path.join(llvm_build_dir, 'bin', 'llvm-ar'),
71-
'NM=' + os.path.join(llvm_build_dir, 'bin', 'llvm-nm'),
72+
'CC=' + os.path.join(clang_tools_path, 'clang'),
73+
'AR=' + os.path.join(llvm_tools_path, 'llvm-ar'),
74+
'NM=' + os.path.join(llvm_tools_path, 'llvm-nm'),
7275
])
7376

7477
@classmethod
@@ -119,7 +122,10 @@ def should_install(self, host_target):
119122

120123
def build(self, host_target):
121124
build_root = os.path.dirname(self.build_dir)
122-
llvm_build_dir = os.path.join('..', build_root, '%s-%s' % ('llvm', host_target))
125+
llvm_build_bin_dir = os.path.join(
126+
'..', build_root, '%s-%s' % ('llvm', host_target), 'bin')
127+
llvm_tools_path = self.args.native_llvm_tools_path or llvm_build_bin_dir
128+
clang_tools_path = self.args.native_clang_tools_path or llvm_build_bin_dir
123129

124130
self.cmake_options.define('CMAKE_SYSROOT:PATH',
125131
WASILibc.sysroot_build_path(build_root, host_target))
@@ -144,13 +150,13 @@ def build(self, host_target):
144150
self.cmake_options.define('CMAKE_SYSTEM_NAME:STRING', 'WASI')
145151
self.cmake_options.define('CMAKE_SYSTEM_PROCESSOR:STRING', 'wasm32')
146152
self.cmake_options.define('CMAKE_AR:FILEPATH',
147-
os.path.join(llvm_build_dir, 'bin', 'llvm-ar'))
153+
os.path.join(llvm_tools_path, 'llvm-ar'))
148154
self.cmake_options.define('CMAKE_RANLIB:FILEPATH',
149-
os.path.join(llvm_build_dir, 'bin', 'llvm-ranlib'))
155+
os.path.join(llvm_tools_path, 'llvm-ranlib'))
150156
self.cmake_options.define('CMAKE_C_COMPILER:FILEPATH',
151-
os.path.join(llvm_build_dir, 'bin', 'clang'))
157+
os.path.join(clang_tools_path, 'clang'))
152158
self.cmake_options.define('CMAKE_CXX_COMPILER:STRING',
153-
os.path.join(llvm_build_dir, 'bin', 'clang++'))
159+
os.path.join(clang_tools_path, 'clang++'))
154160
# Explicitly disable exceptions even though it's usually implicitly disabled by
155161
# LIBCXX_ENABLE_EXCEPTIONS because the CMake feature check fails to detect
156162
# -fno-exceptions support in clang due to missing compiler-rt while configuring

utils/swift_build_support/swift_build_support/products/wasmstdlib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def build(self, host_target):
4444
'SWIFT_STDLIB_BUILD_TYPE:STRING', self._build_variant)
4545

4646
# Toolchain configuration
47-
toolchain_path = self.install_toolchain_path(host_target)
47+
toolchain_path = self.native_toolchain_path(host_target)
4848
# Explicitly set the CMake AR and RANLIB to force it to use llvm-ar/llvm-ranlib
4949
# instead of the system ar/ranlib, which usually don't support WebAssembly
5050
# object files.

0 commit comments

Comments
 (0)