Skip to content

Commit 98e5025

Browse files
authored
Merge pull request #60814 from DougGregor/build-early-swiftsyntax
[build-script] Support building "early" SwiftSyntax via `--early-swiftsyntax`
2 parents 150aca3 + 5ae31c0 commit 98e5025

File tree

5 files changed

+104
-0
lines changed

5 files changed

+104
-0
lines changed

utils/build_swift/build_swift/driver_arguments.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,9 @@ def create_argument_parser():
656656
option(['--swiftsyntax'], toggle_true('build_swiftsyntax'),
657657
help='build swiftSyntax')
658658

659+
option(['--early-swiftsyntax'], toggle_true('build_early_swiftsyntax'),
660+
help='build early SwiftSyntax')
661+
659662
option(['--skstresstester'], toggle_true('build_skstresstester'),
660663
help='build the SourceKit stress tester')
661664

utils/build_swift/tests/expected_options.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
'build_swiftpm': False,
9191
'build_swift_driver': False,
9292
'build_early_swift_driver': True,
93+
'build_early_swiftsyntax': False,
9394
'build_swiftsyntax': False,
9495
'build_libparser_only': False,
9596
'build_skstresstester': False,
@@ -517,6 +518,7 @@ class BuildScriptImplOption(_BaseOption):
517518
SetTrueOption('--skip-build'),
518519
SetTrueOption('--swiftpm', dest='build_swiftpm'),
519520
SetTrueOption('--swift-driver', dest='build_swift_driver'),
521+
SetTrueOption('--early-swiftsyntax', dest='build_early_swiftsyntax'),
520522
SetTrueOption('--swiftsyntax', dest='build_swiftsyntax'),
521523
SetTrueOption('--build-libparser-only', dest='build_libparser_only'),
522524
SetTrueOption('--skstresstester', dest='build_skstresstester'),

utils/swift_build_support/swift_build_support/build_script_invocation.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,10 @@ def compute_product_pipelines(self):
548548
builder = ProductPipelineListBuilder(self.args)
549549

550550
builder.begin_pipeline()
551+
552+
builder.add_product(products.EarlySwiftSyntax,
553+
is_enabled=self.args.build_early_swiftsyntax)
554+
551555
# If --skip-early-swift-driver is passed in, swift will be built
552556
# as usual, but relying on its own C++-based (Legacy) driver.
553557
# Otherwise, we build an "early" swift-driver using the host

utils/swift_build_support/swift_build_support/products/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from .cmark import CMark
1616
from .curl import LibCurl
1717
from .earlyswiftdriver import EarlySwiftDriver
18+
from .earlyswiftsyntax import EarlySwiftSyntax
1819
from .foundation import Foundation
1920
from .indexstoredb import IndexStoreDB
2021
from .libcxx import LibCXX
@@ -63,6 +64,7 @@
6364
'SwiftPM',
6465
'SwiftDriver',
6566
'EarlySwiftDriver',
67+
'EarlySwiftSyntax',
6668
'XCTest',
6769
'SwiftSyntax',
6870
'SKStressTester',
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# swift_build_support/products/earlyswiftsyntax.py --------------*- python -*-
2+
#
3+
# This source file is part of the Swift.org open source project
4+
#
5+
# Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors
6+
# Licensed under Apache License v2.0 with Runtime Library Exception
7+
#
8+
# See https://swift.org/LICENSE.txt for license information
9+
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
#
11+
# ----------------------------------------------------------------------------
12+
13+
from . import cmake_product
14+
from .. import toolchain
15+
16+
17+
# SwiftSyntax is a Swift module used to parse and manipulate Swift syntax. This
18+
# build product is a "Special" SwiftSyntax that gets built with the host
19+
# toolchain that can be linked into the Swift compiler itself, hence it does not
20+
# depend on any other build product of `build-script`.
21+
class EarlySwiftSyntax(cmake_product.CMakeProduct):
22+
@classmethod
23+
def product_source_name(cls):
24+
return "swift-syntax"
25+
26+
@classmethod
27+
def is_build_script_impl_product(cls):
28+
return False
29+
30+
@classmethod
31+
def is_before_build_script_impl_product(cls):
32+
return True
33+
34+
def should_build(self, host_target):
35+
if self.args.build_early_swiftsyntax:
36+
if toolchain.host_toolchain().find_tool("swift") is None:
37+
warn_msg = 'Host toolchain could not locate a '\
38+
'compiler to build early swift-syntax.'
39+
print('-- Warning: {}', warn_msg)
40+
return False
41+
else:
42+
return True
43+
return False
44+
45+
@classmethod
46+
def get_dependencies(cls):
47+
return []
48+
49+
def build(self, host_target):
50+
self.cmake_options.define('CMAKE_BUILD_TYPE:STRING',
51+
self.args.swift_build_variant)
52+
self.cmake_options.define('BUILD_SHARED_LIBS:STRING', 'NO')
53+
54+
(platform, arch) = host_target.split('-')
55+
56+
common_c_flags = ' '.join(self.common_cross_c_flags(platform, arch))
57+
self.cmake_options.define('CMAKE_C_FLAGS', common_c_flags)
58+
self.cmake_options.define('CMAKE_CXX_FLAGS', common_c_flags)
59+
60+
if host_target.startswith("macosx") or \
61+
host_target.startswith("iphone") or \
62+
host_target.startswith("appletv") or \
63+
host_target.startswith("watch"):
64+
toolchain_file = self.generate_darwin_toolchain_file(platform, arch)
65+
self.cmake_options.define('CMAKE_TOOLCHAIN_FILE:PATH', toolchain_file)
66+
elif platform == "linux":
67+
toolchain_file = self.generate_linux_toolchain_file(platform, arch)
68+
self.cmake_options.define('CMAKE_TOOLCHAIN_FILE:PATH', toolchain_file)
69+
70+
self.build_with_cmake(["all"], self.args.swift_build_variant, [])
71+
72+
def should_test(self, host_target):
73+
# The normal SwiftSyntax target runs tests through SwiftPM.
74+
return False
75+
76+
def test(self, host_target):
77+
pass
78+
79+
def should_install(self, host_target):
80+
# This product is for the swift-syntax used with the build-directory compiler.
81+
# If a toolchain install is required, please use the SwiftSyntax (no 'Early')
82+
# product with `--swift-syntax --install-swift-syntax`.
83+
return False
84+
85+
@classmethod
86+
def is_ignore_install_all_product(cls):
87+
# Ensures that `install_all` setting triggered by `--infer` does not
88+
# affect products which specify `is_ignore_install_all_product` as
89+
# True. This is useful for products which should not be installed into the
90+
# toolchain (corresponding build products that use the just-built
91+
# toolchain are the products that get installed, e.g. `swiftsyntax` to
92+
# `earlyswiftsyntax`).
93+
return True

0 commit comments

Comments
 (0)