Skip to content

Commit 6add3c0

Browse files
committed
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. Addresses rdar://102387542
1 parent cbfd7c2 commit 6add3c0

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

utils/swift_build_support/swift_build_support/products/llvm.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -363,13 +363,24 @@ def _handle_cxx_headers(self, host_target, platform):
363363
# place during the cmake step of LLVM's build when libcxx is in
364364
# tree... but we are not building llvm with libcxx in tree when we build
365365
# swift. So we need to do configure's work here.
366-
host_cxx_headers_dir = None
367366
if system() == 'Darwin':
368-
host_cxx_dir = os.path.dirname(self.toolchain.cxx)
369-
host_cxx_headers_dir = os.path.join(host_cxx_dir, os.pardir, os.pardir,
370-
'usr', 'include', 'c++')
367+
# We don't need this for Darwin since libcxx is present in SDKs present
368+
# in Xcode 12.5 and onward (build-script requires Xcode 13.0 at a minimum),
369+
# and clang knows how to find it there
370+
# However, we should take care of removing the symlink
371+
# laid down by a previous invocation, so to avoid failures
372+
# finding c++ headers should the target folder become invalid
373+
cxx_include_symlink = os.path.join(self.build_dir, 'include', 'c++')
374+
if os.path.islink(cxx_include_symlink):
375+
print('removing the symlink to system headers in the local '
376+
f'clang build directory {cxx_include_symlink} .',
377+
flush=True)
378+
shell.remove(cxx_include_symlink)
379+
380+
return
371381

372-
elif system() == 'Haiku':
382+
host_cxx_headers_dir = None
383+
if system() == 'Haiku':
373384
host_cxx_headers_dir = '/boot/system/develop/headers/c++'
374385

375386
# This means we're building natively on Android in the Termux
@@ -395,7 +406,7 @@ def _handle_cxx_headers(self, host_target, platform):
395406
os.makedirs(built_cxx_include_dir)
396407
print('symlinking the system headers ({}) into the local '
397408
'clang build directory ({}).'.format(
398-
host_cxx_headers_dir, built_cxx_include_dir))
409+
host_cxx_headers_dir, built_cxx_include_dir), flush=True)
399410
shell.call(['ln', '-s', '-f', host_cxx_headers_dir, built_cxx_include_dir])
400411

401412
def should_test(self, host_target):

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)