Skip to content

Commit 5c05feb

Browse files
authored
Merge pull request #27930 from apple/revert-27871-swiftsyntax_build_support
Revert "Migrate building SwiftSyntax to swift_build_support"
2 parents b00bc82 + 776e2c0 commit 5c05feb

File tree

16 files changed

+154
-140
lines changed

16 files changed

+154
-140
lines changed

CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,12 @@ endif()
10961096
# declares the swift-stdlib-* set of targets. These targets will then
10971097
# implicitly depend on any targets declared with IS_STDLIB.
10981098
#
1099+
# One such library that declares IS_STDLIB is SwiftSyntax, living in
1100+
# tools/SwiftSyntax. If we include stdlib/ after tools/,
1101+
# the swift-stdlib-* set of targets will not have been generated yet,
1102+
# causing the implicit dependency for SwiftSyntax to silently not be
1103+
# created. This then will cause SwiftSyntax to fail to build.
1104+
#
10991105
# https://bugs.swift.org/browse/SR-5975
11001106
if(SWIFT_BUILD_STDLIB)
11011107
add_subdirectory(stdlib)
@@ -1120,7 +1126,7 @@ add_subdirectory(include)
11201126

11211127
if(SWIFT_INCLUDE_TOOLS)
11221128
add_subdirectory(lib)
1123-
1129+
11241130
# Always include this after including stdlib/!
11251131
# Refer to the large comment above the add_subdirectory(stdlib) call.
11261132
# https://bugs.swift.org/browse/SR-5975

benchmark/scripts/test_Benchmark_Driver.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import os
1818
import time
1919
import unittest
20+
2021
from StringIO import StringIO
2122
from imp import load_source
2223

benchmark/scripts/test_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import logging
2626
import sys
27+
2728
from StringIO import StringIO
2829
from contextlib import contextmanager
2930

utils/build-script

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ class BuildScriptInvocation(object):
338338
"--libicu-build-type", args.libicu_build_variant,
339339
"--xctest-build-type", args.build_variant,
340340
"--swiftpm-build-type", args.build_variant,
341+
"--swiftsyntax-build-type", args.build_variant,
341342
"--llbuild-build-type", args.build_variant,
342343
"--swift-enable-assertions", str(args.swift_assertions).lower(),
343344
"--swift-stdlib-enable-assertions", str(
@@ -466,6 +467,8 @@ class BuildScriptInvocation(object):
466467
impl_args += ["--skip-build-libicu"]
467468
if not args.build_swiftpm:
468469
impl_args += ["--skip-build-swiftpm"]
470+
if not args.build_swiftsyntax:
471+
impl_args += ["--skip-build-swiftsyntax"]
469472
if not args.build_playgroundsupport:
470473
impl_args += ["--skip-build-playgroundsupport"]
471474
if args.build_swift_dynamic_stdlib:
@@ -509,6 +512,7 @@ class BuildScriptInvocation(object):
509512
"--skip-test-lldb",
510513
"--skip-test-llbuild",
511514
"--skip-test-swiftpm",
515+
"--skip-test-swiftsyntax",
512516
"--skip-test-xctest",
513517
"--skip-test-foundation",
514518
"--skip-test-libdispatch",
@@ -815,14 +819,10 @@ class BuildScriptInvocation(object):
815819
build_dir=self.workspace.build_dir(
816820
host_target, product_name))
817821
if product.should_build(host_target):
818-
print("--- Building %s ---" % product_name)
819822
product.build(host_target)
820823
if product.should_test(host_target):
821-
print("--- Running tests for %s ---" % product_name)
822824
product.test(host_target)
823-
print("--- Finished tests for %s ---" % product_name)
824825
if product.should_install(host_target):
825-
print("--- Installing %s ---" % product_name)
826826
product.install(host_target)
827827

828828
# Extract symbols...

utils/build-script-impl

Lines changed: 128 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ KNOWN_SETTINGS=(
7979
playgroundsupport-build-type "Debug" "the build variant for PlaygroundSupport"
8080
xctest-build-type "Debug" "the build variant for xctest"
8181
swiftpm-build-type "Debug" "the build variant for swiftpm"
82+
swiftsyntax-build-type "Debug" "the build variant for swiftSyntax"
83+
# When this flag is set, the build-script will only build/install the swift-syntax parser
84+
# This is a temporary workaround of having a separate build product for swift-syntax parser
85+
skip-swiftsyntax-swiftside "" "skip building/installing the swift side of swiftsyntax"
8286
llbuild-enable-assertions "1" "enable assertions in llbuild"
8387
enable-asan "" "enable Address Sanitizer"
8488
enable-ubsan "" "enable Undefined Behavior Sanitizer"
@@ -97,6 +101,8 @@ KNOWN_SETTINGS=(
97101
installable-package "" "the path to the archive of the installation directory"
98102
test-installable-package "" "whether to run post-packaging tests on the produced package"
99103
reconfigure "" "force a CMake configuration run even if CMakeCache.txt already exists"
104+
build-libparser-only "" "only build libSwiftSyntaxParser"
105+
libparser-ver "" "current version of libSwiftSyntaxParser"
100106
skip-reconfigure "" "set to skip reconfigure"
101107
swift-primary-variant-sdk "" "default SDK for target binaries"
102108
swift-primary-variant-arch "" "default arch for target binaries"
@@ -120,6 +126,7 @@ KNOWN_SETTINGS=(
120126
skip-build-llbuild "" "set to skip building llbuild"
121127
skip-build-libcxx "" "set to skip building libcxx"
122128
skip-build-swiftpm "" "set to skip building swiftpm"
129+
skip-build-swiftsyntax "" "set to skip building swiftSyntax"
123130
skip-build-xctest "" "set to skip building xctest"
124131
skip-build-foundation "" "set to skip building foundation"
125132
skip-build-libdispatch "" "set to skip building libdispatch"
@@ -133,6 +140,7 @@ KNOWN_SETTINGS=(
133140
skip-test-swift "" "set to skip testing Swift"
134141
skip-test-llbuild "" "set to skip testing llbuild"
135142
skip-test-swiftpm "" "set to skip testing swiftpm"
143+
skip-test-swiftsyntax "" "set to skip testing swiftSyntax"
136144
skip-test-xctest "" "set to skip testing xctest"
137145
skip-test-foundation "" "set to skip testing foundation"
138146
skip-test-libdispatch "" "set to skip testing libdispatch"
@@ -190,6 +198,9 @@ KNOWN_SETTINGS=(
190198
install-lldb "" "whether to install LLDB"
191199
install-llbuild "" "whether to install llbuild"
192200
install-swiftpm "" "whether to install swiftpm"
201+
install-swiftsyntax "" "whether to install swiftsyntax"
202+
skip-install-swiftsyntax-module "" "set to skip installing swiftsyntax modules"
203+
swiftsyntax-verify-generated-files "" "set to verify that the generated files in the source tree match the ones that would be generated from current master"
193204
install-xctest "" "whether to install xctest"
194205
install-foundation "" "whether to install foundation"
195206
install-libcxx "" "whether to install libc++"
@@ -1180,6 +1191,7 @@ CMARK_SOURCE_DIR="${WORKSPACE}/cmark"
11801191
LLDB_SOURCE_DIR="${WORKSPACE}/lldb"
11811192
LLBUILD_SOURCE_DIR="${WORKSPACE}/llbuild"
11821193
SWIFTPM_SOURCE_DIR="${WORKSPACE}/swiftpm"
1194+
SWIFTSYNTAX_SOURCE_DIR="${WORKSPACE}/swift-syntax"
11831195
STRESSTEST_PACKAGE_DIR="${WORKSPACE}/swift-stress-tester"
11841196
XCTEST_SOURCE_DIR="${WORKSPACE}/swift-corelibs-xctest"
11851197
FOUNDATION_SOURCE_DIR="${WORKSPACE}/swift-corelibs-foundation"
@@ -1233,8 +1245,8 @@ PRODUCTS=("${PRODUCTS[@]}" swift)
12331245
if [[ ! "${SKIP_BUILD_LLDB}" ]] ; then
12341246
PRODUCTS=("${PRODUCTS[@]}" lldb)
12351247
fi
1236-
# LLBuild, SwiftPM and XCTest are dependent on Foundation, so Foundation must
1237-
# be added to the list of build products first.
1248+
# LLBuild, SwiftPM, SwiftSyntax and XCTest are dependent on Foundation, so
1249+
# Foundation must be added to the list of build products first.
12381250
if [[ ! "${SKIP_BUILD_LIBDISPATCH}" ]] ; then
12391251
PRODUCTS=("${PRODUCTS[@]}" libdispatch)
12401252
if [[ -z "${SKIP_BUILD_SWIFT_STATIC_LIBDISPATCH}" ]] ; then
@@ -1253,14 +1265,19 @@ fi
12531265
if [[ ! "${SKIP_BUILD_PLAYGROUNDSUPPORT}" ]] ; then
12541266
PRODUCTS=("${PRODUCTS[@]}" playgroundsupport)
12551267
fi
1256-
# SwiftPM is dependent on XCTest, so XCTest must be added to the list of build
1257-
# products first.
1268+
# SwiftPM and SwiftSyntax are dependent on XCTest, so XCTest must be added to
1269+
# the list of build products first.
12581270
if [[ ! "${SKIP_BUILD_XCTEST}" ]] ; then
12591271
PRODUCTS=("${PRODUCTS[@]}" xctest)
12601272
fi
1273+
# SwiftSyntax is dependent on SwiftPM, so SwiftPM must be added to the list of
1274+
# build products first.
12611275
if [[ ! "${SKIP_BUILD_SWIFTPM}" ]] ; then
12621276
PRODUCTS=("${PRODUCTS[@]}" swiftpm)
12631277
fi
1278+
if [[ ! "${SKIP_BUILD_SWIFTSYNTAX}" ]] ; then
1279+
PRODUCTS=("${PRODUCTS[@]}" swiftsyntax)
1280+
fi
12641281

12651282
# Checks if a given product is enabled (i.e. part of $PRODUCTS array)
12661283
function contains_product() {
@@ -1566,6 +1583,9 @@ function build_directory_bin() {
15661583
swiftpm)
15671584
echo "${root}/${SWIFTPM_BUILD_TYPE}/bin"
15681585
;;
1586+
swiftsyntax)
1587+
echo "${root}/${SWIFTSYNTAX_BUILD_TYPE}/bin"
1588+
;;
15691589
xctest)
15701590
echo "${root}/${XCTEST_BUILD_TYPE}/bin"
15711591
;;
@@ -1708,6 +1728,9 @@ function cmake_config_opt() {
17081728
swiftpm)
17091729
echo "--config ${SWIFTPM_BUILD_TYPE}"
17101730
;;
1731+
swiftsyntax)
1732+
echo "--config ${SWIFTSYNTAX_BUILD_TYPE}"
1733+
;;
17111734
xctest)
17121735
echo "--config ${XCTEST_BUILD_TYPE}"
17131736
;;
@@ -1798,13 +1821,43 @@ function set_swiftpm_bootstrap_command() {
17981821

17991822
function swiftpm_find_tool() {
18001823
tool=$1
1801-
if [[ "${SKIP_BUILD_SWIFTPM}" ]]; then
1824+
if [[ "${SKIP_BUILD_SWIFTPM}" || "${BUILD_LIBPARSER_ONLY}" ]]; then
18021825
echo "$(xcrun_find_tool ${tool})"
18031826
else
18041827
echo "$(build_directory_bin ${LOCAL_HOST} swiftpm)/${tool}"
18051828
fi
18061829
}
18071830

1831+
function set_swiftsyntax_build_command() {
1832+
if [ "${BUILD_LIBPARSER_ONLY}" ]; then
1833+
# we don't have a compiler built so we have to use the one in the environment.
1834+
SWIFTC_BIN="$(xcrun_find_tool swiftc)"
1835+
else
1836+
SWIFTC_BIN="$(build_directory_bin ${LOCAL_HOST} swift)/swiftc"
1837+
fi
1838+
1839+
swiftsyntax_build_command=("${SWIFTSYNTAX_SOURCE_DIR}/build-script.py")
1840+
# Add --release if we have to build in release mode.
1841+
if [[ $(is_cmake_release_build_type "${SWIFTSYNTAX_BUILD_TYPE}") ]] ; then
1842+
swiftsyntax_build_command+=(--release)
1843+
fi
1844+
if [[ "${VERBOSE_BUILD}" ]] ; then
1845+
swiftsyntax_build_command+=(-v)
1846+
fi
1847+
swiftsyntax_build_command+=(
1848+
--build-dir="$(build_directory ${host} swiftsyntax)"
1849+
--swift-build-exec="$(swiftpm_find_tool swift-build)"
1850+
--swift-test-exec="$(swiftpm_find_tool swift-test)"
1851+
--swiftc-exec="${SWIFTC_BIN}"
1852+
--syntax-parser-header-dir="${SWIFT_SOURCE_DIR}/include/swift-c/SyntaxParser"
1853+
--syntax-parser-lib-dir="$(build_directory ${host} swift)/lib"
1854+
--swift-syntax-test-exec="$(build_directory_bin ${LOCAL_HOST} swift)/swift-syntax-test"
1855+
--filecheck-exec="$(build_directory_bin ${LOCAL_HOST} llvm)/FileCheck")
1856+
if [[ "${SWIFTSYNTAX_VERIFY_GENERATED_FILES}" ]] ; then
1857+
swiftsyntax_build_command+=(--verify-generated-files)
1858+
fi
1859+
}
1860+
18081861
#
18091862
# Configure and build each product
18101863
#
@@ -2305,6 +2358,15 @@ for host in "${ALL_HOSTS[@]}"; do
23052358
build_targets=("${build_targets[@]}"
23062359
"${SWIFT_BENCHMARK_TARGETS[@]}")
23072360
fi
2361+
if [ "${BUILD_LIBPARSER_ONLY}" ]; then
2362+
build_targets=(libSwiftSyntaxParser)
2363+
if [ "${LIBPARSER_VER}" ] ; then
2364+
cmake_options=(
2365+
"${cmake_options[@]}"
2366+
-DSWIFT_LIBPARSER_VER:STRING="${LIBPARSER_VER}"
2367+
)
2368+
fi
2369+
fi
23082370
skip_build=${SKIP_BUILD_SWIFT}
23092371
;;
23102372
lldb)
@@ -2441,6 +2503,15 @@ for host in "${ALL_HOSTS[@]}"; do
24412503
call "${swiftpm_bootstrap_command[@]}"
24422504

24432505
# swiftpm installs itself with a bootstrap method. No further cmake building is performed.
2506+
continue
2507+
;;
2508+
swiftsyntax)
2509+
if [[ "${SKIP_SWIFTSYNTAX_SWIFTSIDE}" ]]; then
2510+
continue
2511+
fi
2512+
set_swiftsyntax_build_command
2513+
call "${swiftsyntax_build_command[@]}"
2514+
24442515
continue
24452516
;;
24462517
xctest)
@@ -2945,6 +3016,16 @@ for host in "${ALL_HOSTS[@]}"; do
29453016
# As swiftpm tests itself, we break early here.
29463017
continue
29473018
;;
3019+
swiftsyntax)
3020+
if [[ "${SKIP_TEST_SWIFTSYNTAX}" ]]; then
3021+
continue
3022+
fi
3023+
echo "--- Running tests for ${product} ---"
3024+
set_swiftsyntax_build_command
3025+
call "${swiftsyntax_build_command[@]}" -t
3026+
# As swiftSyntax tests itself, we break early here.
3027+
continue
3028+
;;
29483029
xctest)
29493030
if [[ "${SKIP_TEST_XCTEST}" ]]; then
29503031
continue
@@ -3229,6 +3310,11 @@ for host in "${ALL_HOSTS[@]}"; do
32293310
continue
32303311
fi
32313312
INSTALL_TARGETS=install-swift-components
3313+
# Swift syntax parser is currently a sub-product of Swift;
3314+
# We need to specify the install target separately here.
3315+
if [ "${BUILD_LIBPARSER_ONLY}" ]; then
3316+
INSTALL_TARGETS=tools/libSwiftSyntaxParser/install
3317+
fi
32323318
;;
32333319
llbuild)
32343320
if [[ -z "${INSTALL_LLBUILD}" ]] ; then
@@ -3259,6 +3345,43 @@ for host in "${ALL_HOSTS[@]}"; do
32593345
set_swiftpm_bootstrap_command
32603346
call "${swiftpm_bootstrap_command[@]}" --prefix="${host_install_destdir}${host_install_prefix}" install
32613347
# As swiftpm bootstraps the installation itself, we break early here.
3348+
continue
3349+
;;
3350+
swiftsyntax)
3351+
if [[ -z "${INSTALL_SWIFTSYNTAX}" ]] ; then
3352+
continue
3353+
fi
3354+
if [[ -z "${INSTALL_DESTDIR}" ]] ; then
3355+
echo "--install-destdir is required to install products."
3356+
exit 1
3357+
fi
3358+
echo "--- Installing ${product} ---"
3359+
if [ "${BUILD_LIBPARSER_ONLY}" ]; then
3360+
# We don't have a toolchain so we should install to the specified dir
3361+
DYLIB_DIR="${INSTALL_DESTDIR}"
3362+
MODULE_DIR="${INSTALL_DESTDIR}/${product}.swiftmodule"
3363+
# Create the install dir if it doesn't exist
3364+
call mkdir -p "${INSTALL_DESTDIR}"
3365+
# Install libParser is necessary
3366+
rsync -a "$(build_directory ${host} swift)/lib/lib_InternalSwiftSyntaxParser.dylib" "${INSTALL_DESTDIR}"
3367+
# Install module map of libParser so client can import SwiftSyntax
3368+
rsync -a "${SWIFT_SOURCE_DIR}/include/swift-c/SyntaxParser" "${INSTALL_DESTDIR}"
3369+
else
3370+
# We have a toolchain so install to the toolchain
3371+
DYLIB_DIR="${host_install_destdir}${host_install_prefix}/lib/swift/${SWIFT_HOST_VARIANT}"
3372+
MODULE_DIR="${DYLIB_DIR}/${product}.swiftmodule"
3373+
fi
3374+
if [[ "${SKIP_SWIFTSYNTAX_SWIFTSIDE}" ]]; then
3375+
continue
3376+
fi
3377+
set_swiftsyntax_build_command
3378+
if [[ -z "${SKIP_INSTALL_SWIFTSYNTAX_MODULE}" ]] ; then
3379+
mkdir -p "${MODULE_DIR}"
3380+
call "${swiftsyntax_build_command[@]}" --dylib-dir="${DYLIB_DIR}" --swiftmodule-base-name "${MODULE_DIR}/${SWIFT_HOST_VARIANT_ARCH}" --install
3381+
else
3382+
call "${swiftsyntax_build_command[@]}" --dylib-dir="${DYLIB_DIR}" --install
3383+
fi
3384+
32623385
continue
32633386
;;
32643387
xctest)

utils/build_swift/driver_arguments.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ def _apply_default_arguments(args):
203203
args.test_tvos = False
204204
args.test_watchos = False
205205
args.test_android = False
206-
args.test_swiftsyntax = False
207206
args.test_indexstoredb = False
208207
args.test_sourcekitlsp = False
209208
args.test_skstresstester = False
@@ -569,15 +568,6 @@ def create_argument_parser():
569568
help='build IndexStoreDB')
570569
option(['--sourcekit-lsp'], toggle_true('build_sourcekitlsp'),
571570
help='build SourceKitLSP')
572-
option('--install-swiftsyntax', toggle_true('install_swiftsyntax'),
573-
help='install SwiftSyntax')
574-
option('--skip-install-swiftsyntax-module',
575-
toggle_true('skip_install_swiftsyntax_module'),
576-
help='skip installing the SwiftSyntax modules')
577-
option('--swiftsyntax-verify-generated-files',
578-
toggle_true('swiftsyntax_verify_generated_files'),
579-
help='set to verify that the generated files in the source tree '
580-
'match the ones that would be generated from current master')
581571
option(['--install-sourcekit-lsp'], toggle_true('install_sourcekitlsp'),
582572
help='install SourceKitLSP')
583573
option(['--install-skstresstester'], toggle_true('install_skstresstester'),
@@ -967,8 +957,6 @@ def create_argument_parser():
967957
help='skip testing Android device targets on the host machine (the '
968958
'phone itself)')
969959

970-
option('--skip-test-swiftsyntax', toggle_false('test_swiftsyntax'),
971-
help='skip testing SwiftSyntax')
972960
option('--skip-test-indexstore-db', toggle_false('test_indexstoredb'),
973961
help='skip testing indexstore-db')
974962
option('--skip-test-sourcekit-lsp', toggle_false('test_sourcekitlsp'),

0 commit comments

Comments
 (0)