@@ -79,6 +79,10 @@ KNOWN_SETTINGS=(
79
79
playgroundsupport-build-type " Debug" " the build variant for PlaygroundSupport"
80
80
xctest-build-type " Debug" " the build variant for xctest"
81
81
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"
82
86
llbuild-enable-assertions " 1" " enable assertions in llbuild"
83
87
enable-asan " " " enable Address Sanitizer"
84
88
enable-ubsan " " " enable Undefined Behavior Sanitizer"
@@ -97,6 +101,8 @@ KNOWN_SETTINGS=(
97
101
installable-package " " " the path to the archive of the installation directory"
98
102
test-installable-package " " " whether to run post-packaging tests on the produced package"
99
103
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"
100
106
skip-reconfigure " " " set to skip reconfigure"
101
107
swift-primary-variant-sdk " " " default SDK for target binaries"
102
108
swift-primary-variant-arch " " " default arch for target binaries"
@@ -120,6 +126,7 @@ KNOWN_SETTINGS=(
120
126
skip-build-llbuild " " " set to skip building llbuild"
121
127
skip-build-libcxx " " " set to skip building libcxx"
122
128
skip-build-swiftpm " " " set to skip building swiftpm"
129
+ skip-build-swiftsyntax " " " set to skip building swiftSyntax"
123
130
skip-build-xctest " " " set to skip building xctest"
124
131
skip-build-foundation " " " set to skip building foundation"
125
132
skip-build-libdispatch " " " set to skip building libdispatch"
@@ -133,6 +140,7 @@ KNOWN_SETTINGS=(
133
140
skip-test-swift " " " set to skip testing Swift"
134
141
skip-test-llbuild " " " set to skip testing llbuild"
135
142
skip-test-swiftpm " " " set to skip testing swiftpm"
143
+ skip-test-swiftsyntax " " " set to skip testing swiftSyntax"
136
144
skip-test-xctest " " " set to skip testing xctest"
137
145
skip-test-foundation " " " set to skip testing foundation"
138
146
skip-test-libdispatch " " " set to skip testing libdispatch"
@@ -190,6 +198,9 @@ KNOWN_SETTINGS=(
190
198
install-lldb " " " whether to install LLDB"
191
199
install-llbuild " " " whether to install llbuild"
192
200
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"
193
204
install-xctest " " " whether to install xctest"
194
205
install-foundation " " " whether to install foundation"
195
206
install-libcxx " " " whether to install libc++"
@@ -1180,6 +1191,7 @@ CMARK_SOURCE_DIR="${WORKSPACE}/cmark"
1180
1191
LLDB_SOURCE_DIR=" ${WORKSPACE} /lldb"
1181
1192
LLBUILD_SOURCE_DIR=" ${WORKSPACE} /llbuild"
1182
1193
SWIFTPM_SOURCE_DIR=" ${WORKSPACE} /swiftpm"
1194
+ SWIFTSYNTAX_SOURCE_DIR=" ${WORKSPACE} /swift-syntax"
1183
1195
STRESSTEST_PACKAGE_DIR=" ${WORKSPACE} /swift-stress-tester"
1184
1196
XCTEST_SOURCE_DIR=" ${WORKSPACE} /swift-corelibs-xctest"
1185
1197
FOUNDATION_SOURCE_DIR=" ${WORKSPACE} /swift-corelibs-foundation"
@@ -1233,8 +1245,8 @@ PRODUCTS=("${PRODUCTS[@]}" swift)
1233
1245
if [[ ! " ${SKIP_BUILD_LLDB} " ]] ; then
1234
1246
PRODUCTS=(" ${PRODUCTS[@]} " lldb)
1235
1247
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.
1238
1250
if [[ ! " ${SKIP_BUILD_LIBDISPATCH} " ]] ; then
1239
1251
PRODUCTS=(" ${PRODUCTS[@]} " libdispatch)
1240
1252
if [[ -z " ${SKIP_BUILD_SWIFT_STATIC_LIBDISPATCH} " ]] ; then
@@ -1253,14 +1265,19 @@ fi
1253
1265
if [[ ! " ${SKIP_BUILD_PLAYGROUNDSUPPORT} " ]] ; then
1254
1266
PRODUCTS=(" ${PRODUCTS[@]} " playgroundsupport)
1255
1267
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.
1258
1270
if [[ ! " ${SKIP_BUILD_XCTEST} " ]] ; then
1259
1271
PRODUCTS=(" ${PRODUCTS[@]} " xctest)
1260
1272
fi
1273
+ # SwiftSyntax is dependent on SwiftPM, so SwiftPM must be added to the list of
1274
+ # build products first.
1261
1275
if [[ ! " ${SKIP_BUILD_SWIFTPM} " ]] ; then
1262
1276
PRODUCTS=(" ${PRODUCTS[@]} " swiftpm)
1263
1277
fi
1278
+ if [[ ! " ${SKIP_BUILD_SWIFTSYNTAX} " ]] ; then
1279
+ PRODUCTS=(" ${PRODUCTS[@]} " swiftsyntax)
1280
+ fi
1264
1281
1265
1282
# Checks if a given product is enabled (i.e. part of $PRODUCTS array)
1266
1283
function contains_product() {
@@ -1566,6 +1583,9 @@ function build_directory_bin() {
1566
1583
swiftpm)
1567
1584
echo " ${root} /${SWIFTPM_BUILD_TYPE} /bin"
1568
1585
;;
1586
+ swiftsyntax)
1587
+ echo " ${root} /${SWIFTSYNTAX_BUILD_TYPE} /bin"
1588
+ ;;
1569
1589
xctest)
1570
1590
echo " ${root} /${XCTEST_BUILD_TYPE} /bin"
1571
1591
;;
@@ -1708,6 +1728,9 @@ function cmake_config_opt() {
1708
1728
swiftpm)
1709
1729
echo " --config ${SWIFTPM_BUILD_TYPE} "
1710
1730
;;
1731
+ swiftsyntax)
1732
+ echo " --config ${SWIFTSYNTAX_BUILD_TYPE} "
1733
+ ;;
1711
1734
xctest)
1712
1735
echo " --config ${XCTEST_BUILD_TYPE} "
1713
1736
;;
@@ -1798,13 +1821,43 @@ function set_swiftpm_bootstrap_command() {
1798
1821
1799
1822
function swiftpm_find_tool() {
1800
1823
tool=$1
1801
- if [[ " ${SKIP_BUILD_SWIFTPM} " ]]; then
1824
+ if [[ " ${SKIP_BUILD_SWIFTPM} " || " ${BUILD_LIBPARSER_ONLY} " ]]; then
1802
1825
echo " $( xcrun_find_tool ${tool} ) "
1803
1826
else
1804
1827
echo " $( build_directory_bin ${LOCAL_HOST} swiftpm) /${tool} "
1805
1828
fi
1806
1829
}
1807
1830
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
+
1808
1861
#
1809
1862
# Configure and build each product
1810
1863
#
@@ -2305,6 +2358,15 @@ for host in "${ALL_HOSTS[@]}"; do
2305
2358
build_targets=(" ${build_targets[@]} "
2306
2359
" ${SWIFT_BENCHMARK_TARGETS[@]} " )
2307
2360
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
2308
2370
skip_build=${SKIP_BUILD_SWIFT}
2309
2371
;;
2310
2372
lldb)
@@ -2441,6 +2503,15 @@ for host in "${ALL_HOSTS[@]}"; do
2441
2503
call " ${swiftpm_bootstrap_command[@]} "
2442
2504
2443
2505
# 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
+
2444
2515
continue
2445
2516
;;
2446
2517
xctest)
@@ -2945,6 +3016,16 @@ for host in "${ALL_HOSTS[@]}"; do
2945
3016
# As swiftpm tests itself, we break early here.
2946
3017
continue
2947
3018
;;
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
+ ;;
2948
3029
xctest)
2949
3030
if [[ " ${SKIP_TEST_XCTEST} " ]]; then
2950
3031
continue
@@ -3229,6 +3310,11 @@ for host in "${ALL_HOSTS[@]}"; do
3229
3310
continue
3230
3311
fi
3231
3312
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
3232
3318
;;
3233
3319
llbuild)
3234
3320
if [[ -z " ${INSTALL_LLBUILD} " ]] ; then
@@ -3259,6 +3345,43 @@ for host in "${ALL_HOSTS[@]}"; do
3259
3345
set_swiftpm_bootstrap_command
3260
3346
call " ${swiftpm_bootstrap_command[@]} " --prefix=" ${host_install_destdir}${host_install_prefix} " install
3261
3347
# 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
+
3262
3385
continue
3263
3386
;;
3264
3387
xctest)
0 commit comments