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
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
This is the start of the removal of the C++ implementation of libSyntax
in favor of the new Swift Parser and Swift Syntax libraries. Now that
the Swift Parser has switched the SwiftSyntaxParser library over to
being a thin wrapper around the Swift Parser, there is no longer any
reason we need to retain any libSyntax infrastructure in the swift
compiler.
As a first step, delete the infrastructure that builds
lib_InternalSwiftSyntaxParser and convert any scripts that mention
it to instead mention the static mirror libraries. The --swiftsyntax
build-script flag has been retained and will now just execute the
SwiftSyntax and Swift Parser builds with the just-built tools.
`build-script` invocations print a total duration summary at the end of the build, like this:
```
Total Duration: 4558.030000000001
```
With this change build duration summary is printed as
```
Total Duration: 487.93 seconds (8m 7s)
```
On both macOS and Linux `python` is not symlinked to `python3` by default. To avoid confusion, we should update our documentation that instructs users to run scripts with `python` to use `python3` instead.
Without this dependency, passing both `--swiftdocc` and `--install-swiftdocc` to `build-script` causes it to crash with this stack trace:
```
Traceback (most recent call last):
File "./swift/utils/build-script", line 789, in <module>
exit_code = main()
File "./swift/utils/build-script", line 784, in main
return main_normal()
File "./swift/utils/build-script", line 740, in main_normal
invocation.execute()
File "./swift/utils/swift_build_support/swift_build_support/build_script_invocation.py", line 670, in execute
(self.impl_env, self.impl_args) = self.convert_to_impl_arguments()
File "./swift/utils/swift_build_support/swift_build_support/build_script_invocation.py", line 147, in convert_to_impl_arguments
for product_class in sum(list(self.compute_product_pipelines()[0]), []):
File "./swift/utils/swift_build_support/swift_build_support/build_script_invocation.py", line 664, in compute_product_pipelines
return builder.finalize(shouldInfer=self.args.infer_dependencies)
File "./swift/utils/swift_build_support/swift_build_support/productpipeline_list_builder.py", line 198, in finalize
result = self.infer()
File "./swift/utils/swift_build_support/swift_build_support/productpipeline_list_builder.py", line 157, in infer
build_graph.produce_scheduled_build(enabled_pipeline)[0]
File "./swift/utils/swift_build_support/swift_build_support/build_graph.py", line 150, in produce_scheduled_build
dag.set_root(entry)
File "./swift/utils/swift_build_support/swift_build_support/build_graph.py", line 95, in set_root
assert self.root is None
AssertionError
```
Apparently, the absence of this explicit dependency makes `build_graph.py` code think that `SwiftDocCRender` and `SwiftDocC` are independent root targets, which it can't handle. Making one a dependency of the other resolves the issue.
Cross-compilation of the host depends on iteration over all of the host
architectures within build-script-impl itself, so the computation of
the build directory must occur in build-script-impl. Sink it down there
to fix builds for multiple host architectures.
Replace the correct Swift -> EarlySwiftSyntax dependency with an
EarlySwiftDriver -> EarlySwiftSyntax dependency, to keep a linear
dependency order in this part of the build graph.
When enabled, compile in support for round-trip testing the new
SwiftSyntax-provided Swift parser alongside the existing parser. Right
now, this means parsing every source file with the new parser and
ensuring that the resulting syntax tree can reproduce the input source
precisely. Over time, this is expected to grow.
Opt in to this behavior by passing the following to build-script:
build-script --early-swiftsyntax --extra-cmake-options=-DSWIFT_SWIFT_PARSER_MODE:STRING=ROUNDTRIP
With a properly prepared sysroot and toolchain file, these changes permit
cross-compilation of Swift as well as LLVM, CMark, and Dispatch (picking,
as usual, apple/swift-corelibs-libdispatch#556) from a Linux host
generating OpenBSD binaries.
The toolchain file must be specified as an environment variable to
`build-script` and discussion on how to properly set up the sysroot and
toolchain file will be handled later.
Similar to the way the early Swift Driver is built, introduce a
build-script option `--early-swiftsyntax` that uses the host Swift and
CMake to build the parts of the swift-syntax package that are expected
to become be used in the compiler.
Note that this does not obviate the need for the `--swiftsyntax`
option, because that build product uses the just-built Swift compiler
and SwiftPM to build, test, and install everything from the
swift-syntax package.
Running swift test with `--test-product SourceKitLSPPackageTest` fails when cross-compiling with an error message like the following (rdar://97876450)
```
error: Could not find target named 'SourceKitLSPPackageTests_-6F17C3BE20775DA1_PackageProduct'
```
Since we don’t run the test on the cross-compile host anyway, just disable cross-compilation during testing.
As part of the build the entire ninja source dir is copied to the build
dir and then built. When using git's fsmonitor feature the .git
directory contains a socket which causes the copytree to fail. With this
change .git is ignored entirely instead. Error:
```
Traceback (most recent call last):
...
File "/Users/ksmiley/dev/oss-swift/swift/utils/swift_build_support/swift_build_support/build_script_invocation.py", line 69, in build_ninja
ninja_build.build()
File "/Users/ksmiley/dev/oss-swift/swift/utils/swift_build_support/swift_build_support/products/ninja.py", line 80, in build
shell.copytree(self.source_dir, self.build_dir)
File "/Users/ksmiley/dev/oss-swift/swift/utils/swift_build_support/swift_build_support/shell.py", line 193, in copytree
shutil.copytree(src, dest)
File "/Users/ksmiley/.pyenv/versions/3.10.2/lib/python3.10/shutil.py", line 556, in copytree
return _copytree(entries=entries, src=src, dst=dst, symlinks=symlinks,
File "/Users/ksmiley/.pyenv/versions/3.10.2/lib/python3.10/shutil.py", line 512, in _copytree
raise Error(errors)
shutil.Error: [('/Users/ksmiley/dev/oss-swift/ninja/.git/fsmonitor--daemon.ipc', '/Users/ksmiley/dev/oss-swift/build/buildbot_osx/ninja-build/.git/fsmonitor--daemon.ipc', "[Errno 102] Operation not supported on socket: '/Users/ksmiley/dev/oss-swift/ninja/.git/fsmonitor--daemon.ipc'")]
```