Skip to content

Commit cf619e2

Browse files
Merge pull request #71977 from kateinoigakukun/pr-5ff3fb0d5bd5d000aa636f748af814d1607455e3
2 parents 4e62b21 + 82b1d9c commit cf619e2

File tree

5 files changed

+30
-21
lines changed

5 files changed

+30
-21
lines changed

utils/swift_build_support/swift_build_support/cmake.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,16 @@ def __iadd__(self, other):
9797

9898
class CMake(object):
9999

100-
def __init__(self, args, toolchain, prefer_just_built_toolchain=False):
101-
"""If prefer_just_built_toolchain is set to True, we set the clang, clang++,
102-
and Swift compilers from the installed toolchain.
100+
def __init__(self, args, toolchain, prefer_native_toolchain=False):
101+
"""If prefer_native_toolchain is set to True, we set the clang, clang++,
102+
and Swift compilers from the toolchain explicitly specified by the
103+
native-*-tools-path options or just installed toolchain if the options
104+
are not specified. If prefer_native_toolchain is set to False, we use
105+
system defaults.
103106
"""
104107
self.args = args
105108
self.toolchain = toolchain
106-
self.prefer_just_built_toolchain = prefer_just_built_toolchain
109+
self.prefer_native_toolchain = prefer_native_toolchain
107110

108111
def common_options(self, product=None):
109112
"""Return options used for all products, including LLVM/Clang
@@ -146,8 +149,8 @@ def common_options(self, product=None):
146149
if args.cmake_cxx_launcher:
147150
define("CMAKE_CXX_COMPILER_LAUNCHER:PATH", args.cmake_cxx_launcher)
148151

149-
if self.prefer_just_built_toolchain and product:
150-
toolchain_path = product.install_toolchain_path(args.host_target)
152+
if self.prefer_native_toolchain and product:
153+
toolchain_path = product.native_toolchain_path(args.host_target)
151154
cmake_swiftc_path = os.getenv('CMAKE_Swift_COMPILER',
152155
os.path.join(toolchain_path, 'bin', 'swiftc'))
153156
define("CMAKE_C_COMPILER:PATH", os.path.join(toolchain_path,

utils/swift_build_support/swift_build_support/products/cmake_product.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ def is_verbose(self):
2424
return self.args.verbose_build
2525

2626
def build_with_cmake(self, build_targets, build_type, build_args,
27-
prefer_just_built_toolchain=False):
27+
prefer_native_toolchain=False):
2828
assert self.toolchain.cmake is not None
2929
cmake_build = []
3030
_cmake = cmake.CMake(self.args, self.toolchain,
31-
prefer_just_built_toolchain)
31+
prefer_native_toolchain)
3232

3333
if self.toolchain.distcc_pump:
3434
cmake_build.append(self.toolchain.distcc_pump)

utils/swift_build_support/swift_build_support/products/minimalstdlib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def build(self, host_target):
174174

175175
# Build!
176176
self.build_with_cmake(["swift-stdlib-freestanding"], build_variant, [],
177-
prefer_just_built_toolchain=True)
177+
prefer_native_toolchain=True)
178178

179179
def should_test(self, host_target):
180180
return False

utils/swift_build_support/swift_build_support/products/wasisysroot.py

Lines changed: 16 additions & 10 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
@@ -188,7 +194,7 @@ def build(self, host_target):
188194
self.cmake_options.define('UNIX:BOOL', 'TRUE')
189195

190196
self.build_with_cmake([], self.args.build_variant, [],
191-
prefer_just_built_toolchain=True)
197+
prefer_native_toolchain=True)
192198
self.install_with_cmake(
193199
["install"], WASILibc.sysroot_install_path(build_root))
194200

utils/swift_build_support/swift_build_support/products/wasmstdlib.py

Lines changed: 2 additions & 2 deletions
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.
@@ -117,7 +117,7 @@ def build(self, host_target):
117117

118118
# Configure with WebAssembly target variant, and build with just-built toolchain
119119
self.build_with_cmake([], self._build_variant, [],
120-
prefer_just_built_toolchain=True)
120+
prefer_native_toolchain=True)
121121

122122
def test(self, host_target):
123123
build_root = os.path.dirname(self.build_dir)

0 commit comments

Comments
 (0)