Skip to content

Commit 38a10bb

Browse files
authored
Merge pull request #62159 from edymtt/use-libcxx-from-darwin-sdks-llvm-product
Use libcxx from Darwin SDKs when building LLVM and Swift (LLVM product) Those are present since Xcode 12.5, so we don't need to copy them anymore from the toolchain In this scenario, clean up any existing symlink in incremental builds to avoid masking or causing errors in the future. Took the chance to extract this logic to a different function in an attempt to improve readability To ease review, the PR has two commits -- the first to extract the logic as is (showing that I did not alter the existing logic) and the second one to change its behaviour for Darwin (and address a minor issue when printing about the creation of symlinks) Addresses rdar://102387542
2 parents d27e08e + 6add3c0 commit 38a10bb

File tree

2 files changed

+38
-15
lines changed

2 files changed

+38
-15
lines changed

utils/swift_build_support/swift_build_support/products/llvm.py

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -346,19 +346,42 @@ def build(self, host_target):
346346
self.cmake_options.extend(host_config.cmake_options)
347347
self.cmake_options.extend(llvm_cmake_options)
348348

349+
self._handle_cxx_headers(host_target, platform)
350+
351+
self.build_with_cmake(build_targets, self.args.llvm_build_variant, [])
352+
353+
# copy over the compiler-rt builtins for iOS/tvOS/watchOS to ensure
354+
# that Swift's stdlib can use compiler-rt builtins when targeting
355+
# iOS/tvOS/watchOS.
356+
if self.args.build_llvm and system() == 'Darwin':
357+
self.copy_embedded_compiler_rt_builtins_from_darwin_host_toolchain(
358+
self.build_dir)
359+
360+
def _handle_cxx_headers(self, host_target, platform):
349361
# When we are building LLVM create symlinks to the c++ headers. We need
350362
# to do this before building LLVM since compiler-rt depends on being
351363
# built with the just built clang compiler. These are normally put into
352364
# place during the cmake step of LLVM's build when libcxx is in
353365
# tree... but we are not building llvm with libcxx in tree when we build
354366
# swift. So we need to do configure's work here.
355-
host_cxx_headers_dir = None
356367
if system() == 'Darwin':
357-
host_cxx_dir = os.path.dirname(self.toolchain.cxx)
358-
host_cxx_headers_dir = os.path.join(host_cxx_dir, os.pardir, os.pardir,
359-
'usr', 'include', 'c++')
368+
# We don't need this for Darwin since libcxx is present in SDKs present
369+
# in Xcode 12.5 and onward (build-script requires Xcode 13.0 at a minimum),
370+
# and clang knows how to find it there
371+
# However, we should take care of removing the symlink
372+
# laid down by a previous invocation, so to avoid failures
373+
# finding c++ headers should the target folder become invalid
374+
cxx_include_symlink = os.path.join(self.build_dir, 'include', 'c++')
375+
if os.path.islink(cxx_include_symlink):
376+
print('removing the symlink to system headers in the local '
377+
f'clang build directory {cxx_include_symlink} .',
378+
flush=True)
379+
shell.remove(cxx_include_symlink)
380+
381+
return
360382

361-
elif system() == 'Haiku':
383+
host_cxx_headers_dir = None
384+
if system() == 'Haiku':
362385
host_cxx_headers_dir = '/boot/system/develop/headers/c++'
363386

364387
# This means we're building natively on Android in the Termux
@@ -384,18 +407,9 @@ def build(self, host_target):
384407
os.makedirs(built_cxx_include_dir)
385408
print('symlinking the system headers ({}) into the local '
386409
'clang build directory ({}).'.format(
387-
host_cxx_headers_dir, built_cxx_include_dir))
410+
host_cxx_headers_dir, built_cxx_include_dir), flush=True)
388411
shell.call(['ln', '-s', '-f', host_cxx_headers_dir, built_cxx_include_dir])
389412

390-
self.build_with_cmake(build_targets, self.args.llvm_build_variant, [])
391-
392-
# copy over the compiler-rt builtins for iOS/tvOS/watchOS to ensure
393-
# that Swift's stdlib can use compiler-rt builtins when targeting
394-
# iOS/tvOS/watchOS.
395-
if self.args.build_llvm and system() == 'Darwin':
396-
self.copy_embedded_compiler_rt_builtins_from_darwin_host_toolchain(
397-
self.build_dir)
398-
399413
def should_test(self, host_target):
400414
"""should_test() -> Bool
401415

utils/swift_build_support/swift_build_support/shell.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,15 @@ def symlink(source, dest, dry_run=None, echo=True):
202202
os.symlink(source, dest)
203203

204204

205+
def remove(path, dry_run=None, echo=True):
206+
dry_run = _coerce_dry_run(dry_run)
207+
if dry_run or echo:
208+
_echo_command(dry_run, ['rm', path])
209+
if dry_run:
210+
return
211+
os.remove(path)
212+
213+
205214
# Initialized later
206215
lock = None
207216

0 commit comments

Comments
 (0)