Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions utils/build_swift/build_swift/driver_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,9 @@ def create_argument_parser():
option(['--swiftsyntax'], toggle_true('build_swiftsyntax'),
help='build swiftSyntax')

option(['--early-swiftsyntax'], toggle_true('build_early_swiftsyntax'),
help='build early SwiftSyntax')

option(['--skstresstester'], toggle_true('build_skstresstester'),
help='build the SourceKit stress tester')

Expand Down
2 changes: 2 additions & 0 deletions utils/build_swift/tests/expected_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
'build_swiftpm': False,
'build_swift_driver': False,
'build_early_swift_driver': True,
'build_early_swiftsyntax': False,
'build_swiftsyntax': False,
'build_libparser_only': False,
'build_skstresstester': False,
Expand Down Expand Up @@ -516,6 +517,7 @@ class BuildScriptImplOption(_BaseOption):
SetTrueOption('--skip-build'),
SetTrueOption('--swiftpm', dest='build_swiftpm'),
SetTrueOption('--swift-driver', dest='build_swift_driver'),
SetTrueOption('--early-swiftsyntax', dest='build_early_swiftsyntax'),
SetTrueOption('--swiftsyntax', dest='build_swiftsyntax'),
SetTrueOption('--build-libparser-only', dest='build_libparser_only'),
SetTrueOption('--skstresstester', dest='build_skstresstester'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,10 @@ def compute_product_pipelines(self):
builder = ProductPipelineListBuilder(self.args)

builder.begin_pipeline()

builder.add_product(products.EarlySwiftSyntax,
is_enabled=self.args.build_early_swiftsyntax)

# If --skip-early-swift-driver is passed in, swift will be built
# as usual, but relying on its own C++-based (Legacy) driver.
# Otherwise, we build an "early" swift-driver using the host
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from .cmark import CMark
from .curl import LibCurl
from .earlyswiftdriver import EarlySwiftDriver
from .earlyswiftsyntax import EarlySwiftSyntax
from .foundation import Foundation
from .indexstoredb import IndexStoreDB
from .libcxx import LibCXX
Expand Down Expand Up @@ -63,6 +64,7 @@
'SwiftPM',
'SwiftDriver',
'EarlySwiftDriver',
'EarlySwiftSyntax',
'XCTest',
'SwiftSyntax',
'SKStressTester',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# swift_build_support/products/earlyswiftsyntax.py --------------*- python -*-
#
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See https://swift.org/LICENSE.txt for license information
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
#
# ----------------------------------------------------------------------------

from . import cmake_product
from .. import toolchain


# SwiftSyntax is a Swift module used to parse and manipulate Swift syntax. This
# build product is a "Special" SwiftSyntax that gets built with the host
# toolchain that can be linked into the Swift compiler itself, hence it does not
# depend on any other build product of `build-script`.
class EarlySwiftSyntax(cmake_product.CMakeProduct):
@classmethod
def product_source_name(cls):
return "swift-syntax"

@classmethod
def is_build_script_impl_product(cls):
return False

@classmethod
def is_before_build_script_impl_product(cls):
return True

def should_build(self, host_target):
if self.args.build_early_swiftsyntax:
if toolchain.host_toolchain().find_tool("swift") is None:
warn_msg = 'Host toolchain could not locate a '\
'compiler to build early swift-syntax.'
print('-- Warning: {}', warn_msg)
return False
else:
return True
return False

@classmethod
def get_dependencies(cls):
return []

def build(self, host_target):
self.cmake_options.define('CMAKE_BUILD_TYPE:STRING',
self.args.swift_build_variant)
self.cmake_options.define('BUILD_SHARED_LIBS:STRING', 'NO')

(platform, arch) = host_target.split('-')

common_c_flags = ' '.join(self.common_cross_c_flags(platform, arch))
self.cmake_options.define('CMAKE_C_FLAGS', common_c_flags)
self.cmake_options.define('CMAKE_CXX_FLAGS', common_c_flags)

if host_target.startswith("macosx") or \
host_target.startswith("iphone") or \
host_target.startswith("appletv") or \
host_target.startswith("watch"):
toolchain_file = self.generate_darwin_toolchain_file(platform, arch)
self.cmake_options.define('CMAKE_TOOLCHAIN_FILE:PATH', toolchain_file)
elif platform == "linux":
toolchain_file = self.generate_linux_toolchain_file(platform, arch)
self.cmake_options.define('CMAKE_TOOLCHAIN_FILE:PATH', toolchain_file)

self.build_with_cmake(["all"], self.args.swift_build_variant, [])

def should_test(self, host_target):
# The normal SwiftSyntax target runs tests through SwiftPM.
return False

def test(self, host_target):
pass

def should_install(self, host_target):
# This product is for the swift-syntax used with the build-directory compiler.
# If a toolchain install is required, please use the SwiftSyntax (no 'Early')
# product with `--swift-syntax --install-swift-syntax`.
return False

@classmethod
def is_ignore_install_all_product(cls):
# Ensures that `install_all` setting triggered by `--infer` does not
# affect products which specify `is_ignore_install_all_product` as
# True. This is useful for products which should not be installed into the
# toolchain (corresponding build products that use the just-built
# toolchain are the products that get installed, e.g. `swiftsyntax` to
# `earlyswiftsyntax`).
return True