Skip to content

Commit 1cf426c

Browse files
authored
Plumb native-clang-tools-path to build support. (#81587)
The build support Python libraries assume by default that if we do not supply a Swift toolchain path, we can find clang in the installed toolchain path: i.e., the clang that we just built. However, possibly during bootstrap, we may not have a preexisting Swift compiler but still want to use the clang on the platform that is already installed. build-script already gives us native-clang-tools-path. Here, we plumb this through to the relevant Python modules. If the native-clang-tools-path is not specified, we use the install_toolchain_path, just like native_toolchain_path, and the existing behavior is effectively unchanged. If we do specify a native-clang-tools-path, then we return it to ensure that we properly refer to the clang that lives there instead of always defaulting to the just-built clang.
1 parent 529cc3c commit 1cf426c

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

utils/swift_build_support/swift_build_support/cmake.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,15 @@ def common_options(self, product=None):
150150
define("CMAKE_CXX_COMPILER_LAUNCHER:PATH", args.cmake_cxx_launcher)
151151

152152
if self.prefer_native_toolchain and product:
153+
clang_tools_path = product.native_clang_tools_path(args.host_target)
154+
define("CMAKE_C_COMPILER:PATH", os.path.join(clang_tools_path,
155+
'bin', 'clang'))
156+
define("CMAKE_CXX_COMPILER:PATH", os.path.join(clang_tools_path,
157+
'bin', 'clang++'))
158+
153159
toolchain_path = product.native_toolchain_path(args.host_target)
154160
cmake_swiftc_path = os.getenv('CMAKE_Swift_COMPILER',
155161
os.path.join(toolchain_path, 'bin', 'swiftc'))
156-
define("CMAKE_C_COMPILER:PATH", os.path.join(toolchain_path,
157-
'bin', 'clang'))
158-
define("CMAKE_CXX_COMPILER:PATH", os.path.join(toolchain_path,
159-
'bin', 'clang++'))
160162
define("CMAKE_Swift_COMPILER:PATH", cmake_swiftc_path)
161163
else:
162164
cmake_swiftc_path = os.getenv('CMAKE_Swift_COMPILER', toolchain.swiftc)

utils/swift_build_support/swift_build_support/products/product.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,12 @@ def install_toolchain_path(self, host_target):
217217
return targets.toolchain_path(install_destdir,
218218
self.args.install_prefix)
219219

220+
def native_clang_tools_path(self, host_target):
221+
if self.args.native_clang_tools_path is not None:
222+
return os.path.split(self.args.native_clang_tools_path)[0]
223+
else:
224+
return self.install_toolchain_path(host_target)
225+
220226
def native_toolchain_path(self, host_target):
221227
if self.args.native_swift_tools_path is not None:
222228
return os.path.split(self.args.native_swift_tools_path)[0]

utils/swift_build_support/swift_build_support/products/swiftpm.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ def run_bootstrap_script(
5454
self.source_dir, 'Utilities', 'bootstrap')
5555

5656
toolchain_path = self.native_toolchain_path(host_target)
57+
clang_tools_path = self.native_clang_tools_path(host_target)
5758
swiftc = os.path.join(toolchain_path, "bin", "swiftc")
58-
clang = os.path.join(toolchain_path, "bin", "clang")
59+
clang = os.path.join(clang_tools_path, "bin", "clang")
5960

6061
# FIXME: We require llbuild build directory in order to build. Is
6162
# there a better way to get this?

0 commit comments

Comments
 (0)