Skip to content

Commit 957d8cc

Browse files
committed
[build-script][tests] Add infrastucture to build/run tests on multiple targets.
Updates the build script, update checkout script, and lit config to support cross compiling uswift, then using uswift to cross compile and run tests on multiple targets locally.
1 parent 4b44ac5 commit 957d8cc

File tree

11 files changed

+159
-24
lines changed

11 files changed

+159
-24
lines changed

Swift.swiftdoc

400 Bytes
Binary file not shown.

Swift.swiftmodule

64.8 KB
Binary file not shown.

Swift.swiftsourceinfo

18.9 KB
Binary file not shown.

test/lit.cfg

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2203,6 +2203,16 @@ if platform.system() != 'Darwin' or swift_test_mode == 'optimize_none_with_impli
22032203
#
22042204

22052205
config.substitutions.append(('%target-clangxx', '%s -std=c++11' % config.target_clang))
2206+
config.substitutions.append(('%cxx-all-targets\(([^)]+)\)',
2207+
SubstituteCaptures(r"%s -disable-legacy-type-info -enable-cxx-interop -I %s/uswift-macos-arm64/swift -target arm64-apple-macosx10.9 \1 && "
2208+
r"%s -disable-legacy-type-info -enable-cxx-interop -I %s/uswift-macos-x86_64/swift -target x86_64-apple-macosx10.9 \1 && "
2209+
r"%s -enable-cxx-interop -I %s/uswift-linux-armv7/swift -target armv7-unknown-linux-androideabi \1 &&"
2210+
r"%s -enable-cxx-interop -I %s/uswift-windows-x86_64/swift -target x86_64-unknown-windows-msvc \1 "
2211+
% (config.swift_frontend, shell_quote(os.path.realpath(swift_obj_root).replace("\\", "/")),
2212+
config.swift_frontend, shell_quote(os.path.realpath(swift_obj_root).replace("\\", "/")),
2213+
config.swift_frontend, shell_quote(os.path.realpath(swift_obj_root).replace("\\", "/")),
2214+
config.swift_frontend, shell_quote(os.path.realpath(swift_obj_root).replace("\\", "/"))) )
2215+
))
22062216
config.substitutions.append(('%target-swiftxx-frontend', '%s -enable-cxx-interop' % config.target_swift_frontend))
22072217

22082218
config.substitutions.append(('%target-runtime', config.target_runtime))

utils/build-script-impl

Lines changed: 96 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,6 +1245,7 @@ NINJA_SOURCE_DIR="${WORKSPACE}/ninja"
12451245
SWIFT_SOURCE_DIR="${WORKSPACE}/swift"
12461246
LLVM_SOURCE_DIR="${WORKSPACE}/llvm-project/llvm"
12471247
CMARK_SOURCE_DIR="${WORKSPACE}/cmark"
1248+
USWIFT_SOURCE_DIR="${WORKSPACE}/uswift"
12481249
LLDB_SOURCE_DIR="${WORKSPACE}/llvm-project/lldb"
12491250
LLBUILD_SOURCE_DIR="${WORKSPACE}/llbuild"
12501251
STRESSTEST_PACKAGE_DIR="${WORKSPACE}/swift-stress-tester"
@@ -1266,6 +1267,7 @@ PRODUCTS=(llvm)
12661267
[[ "${SKIP_BUILD_LIBCXX}" ]] || PRODUCTS+=(libcxx)
12671268
[[ "${SKIP_BUILD_LIBICU}" ]] || PRODUCTS+=(libicu)
12681269
[[ "${SKIP_BUILD_SWIFT}" ]] || PRODUCTS+=(swift)
1270+
PRODUCTS+=(uswift)
12691271
[[ "${SKIP_BUILD_LLDB}" ]] || PRODUCTS+=(lldb)
12701272
[[ "${SKIP_BUILD_LIBDISPATCH}" ]] || PRODUCTS+=(libdispatch)
12711273
[[ "${SKIP_BUILD_STATIC_LIBDISPATCH}" ]] || PRODUCTS+=(libdispatch_static)
@@ -1356,6 +1358,8 @@ function build_directory_bin() {
13561358
;;
13571359
libicu)
13581360
;;
1361+
uswift)
1362+
;;
13591363
*)
13601364
echo "error: unknown product: ${product}"
13611365
exit 1
@@ -1759,6 +1763,91 @@ for host in "${ALL_HOSTS[@]}"; do
17591763
build_targets=(all)
17601764
;;
17611765

1766+
uswift)
1767+
uswift_targets=(
1768+
"macos-arm64" "arm64-apple-macosx10.9"
1769+
"macos-x86_64" "x86_64-apple-macosx10.9"
1770+
"linux-armv7" "armv7-unknown-linux-androideabi"
1771+
"windows-x86_64" "x86_64-unknown-windows-msvc"
1772+
)
1773+
uswift_targets_length=${#uswift_targets[@]}
1774+
1775+
cmake_options=(
1776+
"${cmake_options[@]}"
1777+
-D BUILD_SHARED_LIBS=NO
1778+
-D CMAKE_Swift_COMPILER_WORKS=YES
1779+
-D CMAKE_BUILD_TYPE=Release
1780+
-D CMAKE_Swift_COMPILER=$(build_directory ${host} swift)/bin/swiftc
1781+
)
1782+
1783+
# Build uswift for each target.
1784+
for (( i=1; i<${uswift_targets_length}+1; i+=2 ));
1785+
do
1786+
uswift_target_name=${uswift_targets[$i-1]}
1787+
uswift_target=${uswift_targets[$i]}
1788+
all_cmake_options=(
1789+
"${cmake_options[@]}"
1790+
-D CMAKE_Swift_COMPILER_TARGET=${uswift_target}
1791+
)
1792+
1793+
if [[ "$uswift_target_name" == "windows-x86_64" ]] ; then
1794+
all_cmake_options=(
1795+
"${all_cmake_options[@]}"
1796+
-D CMAKE_Swift_FLAGS="-use-ld=$(build_directory ${LOCAL_HOST} llvm)/bin/lld-link"
1797+
)
1798+
else
1799+
all_cmake_options=(
1800+
"${all_cmake_options[@]}"
1801+
-D CMAKE_Swift_FLAGS="-Xfrontend -disable-legacy-type-info"
1802+
)
1803+
fi
1804+
1805+
build_dir=$(build_directory ${uswift_target_name} ${product})
1806+
1807+
generator_output_path=""
1808+
if [[ "${CMAKE_GENERATOR}" == "Ninja" ]] ; then
1809+
generator_output_path="${build_dir}/build.ninja"
1810+
fi
1811+
1812+
# Configure if necessary.
1813+
cmake_cache_path="${build_dir}/CMakeCache.txt"
1814+
if [[ "${RECONFIGURE}" || ! -f "${cmake_cache_path}" || \
1815+
( ! -z "${generator_output_path}" && ! -f "${generator_output_path}" ) ]] ; then
1816+
call mkdir -p "${build_dir}"
1817+
1818+
# Use `cmake-file-api` in case it is available.
1819+
call mkdir -p "${build_dir}/.cmake/api/v1/query"
1820+
call touch "${build_dir}/.cmake/api/v1/query/codemodel-v2" "${build_dir}/.cmake/api/v1/query/cache-v2"
1821+
1822+
if [[ -n "${DISTCC}" ]]; then
1823+
EXTRA_DISTCC_OPTIONS=("DISTCC_HOSTS=localhost,lzo,cpp")
1824+
fi
1825+
with_pushd "${build_dir}" \
1826+
call env "${EXTRA_DISTCC_OPTIONS[@]}" "${CMAKE}" "${all_cmake_options[@]}" "${EXTRA_CMAKE_OPTIONS[@]}" "${source_dir}"
1827+
fi
1828+
1829+
# Note: unconditionally build uswift because it is required for running some tests.
1830+
if [[ "${CMAKE_GENERATOR}" == "Xcode" ]] ; then
1831+
# Xcode generator uses "ALL_BUILD" instead of "all".
1832+
# Also, xcodebuild uses -target instead of bare names.
1833+
build_targets=("${build_targets[@]/all/ALL_BUILD}")
1834+
build_targets=("${build_targets[@]/#/${BUILD_TARGET_FLAG} }")
1835+
1836+
# Xcode can't restart itself if it turns out we need to reconfigure.
1837+
# Do an advance build to handle that.
1838+
call "${CMAKE_BUILD[@]}" "${build_dir}" $(cmake_config_opt ${product})
1839+
fi
1840+
1841+
call "${CMAKE_BUILD[@]}" "${build_dir}" $(cmake_config_opt ${product}) -- "${BUILD_ARGS[@]}" ${build_targets[@]}
1842+
1843+
# Copy over the uswift build.
1844+
cp -a $(build_directory ${uswift_target_name} uswift) $(build_directory ${host} swift)
1845+
done
1846+
1847+
# We've already run cmake/build so we can just break out here.
1848+
continue
1849+
;;
1850+
17621851
llvm)
17631852
if [[ -n "${LLVM_NINJA_TARGETS_FOR_CROSS_COMPILE_HOSTS}" && $(is_cross_tools_host ${host}) ]] ; then
17641853
build_targets=("${LLVM_NINJA_TARGETS_FOR_CROSS_COMPILE_HOSTS[@]}")
@@ -1817,7 +1906,7 @@ for host in "${ALL_HOSTS[@]}"; do
18171906
"${llvm_cmake_options[@]}"
18181907
)
18191908

1820-
llvm_enable_projects=("clang")
1909+
llvm_enable_projects=("clang" "lld")
18211910

18221911
if [[ ! "${SKIP_BUILD_COMPILER_RT}" && ! $(is_cross_tools_host ${host}) ]]; then
18231912
llvm_enable_projects+=("compiler-rt")
@@ -1827,18 +1916,6 @@ for host in "${ALL_HOSTS[@]}"; do
18271916
llvm_enable_projects+=("clang-tools-extra")
18281917
fi
18291918

1830-
# On non-Darwin platforms, build lld so we can always have a
1831-
# linker that is compatible with the swift we are using to
1832-
# compile the stdlib.
1833-
#
1834-
# This makes it easier to build target stdlibs on systems that
1835-
# have old toolchains without more modern linker features.
1836-
if [[ "$(uname -s)" != "Darwin" ]] ; then
1837-
if [[ ! "${SKIP_BUILD_LLD}" ]]; then
1838-
llvm_enable_projects+=("lld")
1839-
fi
1840-
fi
1841-
18421919
cmake_options+=(
18431920
-DLLVM_ENABLE_PROJECTS="$(join ";" ${llvm_enable_projects[@]})"
18441921
)
@@ -1898,7 +1975,6 @@ for host in "${ALL_HOSTS[@]}"; do
18981975
;;
18991976

19001977
swift)
1901-
19021978
if [[ "${ANDROID_API_LEVEL}" ]]; then
19031979
cmake_options=(
19041980
"${cmake_options[@]}"
@@ -2808,6 +2884,9 @@ for host in "${ALL_HOSTS[@]}"; do
28082884
libcxx)
28092885
continue # We don't test libc++
28102886
;;
2887+
uswift)
2888+
continue # We don't test uswift
2889+
;;
28112890
swift)
28122891
executable_target=
28132892
results_targets=
@@ -3159,6 +3238,9 @@ for host in "${ALL_HOSTS[@]}"; do
31593238
fi
31603239
INSTALL_TARGETS=install-swift-components
31613240
;;
3241+
uswift)
3242+
continue
3243+
;;
31623244
llbuild)
31633245
if [[ -z "${INSTALL_LLBUILD}" ]] ; then
31643246
continue

utils/build_swift/build_swift/driver_arguments.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ def create_argument_parser():
346346
help='enable code coverage analysis in Swift (false, not-merged, '
347347
'merged).')
348348

349-
option('--swift-disable-dead-stripping', toggle_true,
349+
option('--swift-disable-dead-stripping', toggle_true,
350350
help="Turn off Darwin-specific dead stripping for Swift host tools")
351351

352352
option('--build-subdir', store,
@@ -1252,6 +1252,8 @@ def create_argument_parser():
12521252
help='skip building llvm')
12531253
option('--skip-build-swift', toggle_false('build_swift'),
12541254
help='skip building swift')
1255+
option('--skip-build-uswift', toggle_false('build_uswift'),
1256+
help='skip building uswift')
12551257

12561258
# We need to list --skip-test-swift explicitly because otherwise argparse
12571259
# will auto-expand arguments like --skip-test-swift to the only known

utils/build_swift/tests/expected_options.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
'build_foundation': False,
5959
'build_cmark': True,
6060
'build_swift': True,
61+
'build_uswift': True,
6162
'build_llvm': True,
6263
'build_freebsd': True,
6364
'build_ios': True,
@@ -597,6 +598,7 @@ class BuildScriptImplOption(_BaseOption):
597598
DisableOption('--skip-build-cmark', dest='build_cmark'),
598599
DisableOption('--skip-build-llvm', dest='build_llvm'),
599600
DisableOption('--skip-build-swift', dest='build_swift'),
601+
DisableOption('--skip-build-uswift', dest='build_uswift'),
600602

601603
DisableOption('--skip-build-android', dest='build_android'),
602604
DisableOption('--skip-build-benchmarks', dest='build_benchmarks'),

utils/swift_build_support/swift_build_support/build_script_invocation.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ def convert_to_impl_arguments(self):
250250
(args.build_cmark, "cmark"),
251251
(args.build_llvm, "llvm"),
252252
(args.build_swift, "swift"),
253+
(args.build_uswift, "uswift"),
253254
(args.build_foundation, "foundation"),
254255
(args.build_xctest, "xctest"),
255256
(args.build_lldb, "lldb"),
@@ -562,6 +563,8 @@ def compute_product_pipelines(self):
562563
is_enabled=self.args.build_libicu)
563564
builder.add_impl_product(products.Swift,
564565
is_enabled=self.args.build_swift)
566+
builder.add_impl_product(products.USwift,
567+
is_enabled=self.args.build_uswift)
565568
builder.add_impl_product(products.LLDB,
566569
is_enabled=self.args.build_lldb)
567570

utils/swift_build_support/swift_build_support/products/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from .benchmarks import Benchmarks
1515
from .cmark import CMark
1616
from .earlyswiftdriver import EarlySwiftDriver
17+
from .uswift import USwift
1718
from .foundation import Foundation
1819
from .indexstoredb import IndexStoreDB
1920
from .libcxx import LibCXX
@@ -40,6 +41,7 @@
4041

4142
__all__ = [
4243
'BackDeployConcurrency',
44+
'USwift',
4345
'CMark',
4446
'Ninja',
4547
'Foundation',
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# swift_build_support/products/cmark.py -------------------------*- python -*-
2+
#
3+
# This source file is part of the Swift.org open source project
4+
#
5+
# Copyright (c) 2014 - 2017 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 product
14+
15+
16+
class USwift(product.Product):
17+
@classmethod
18+
def is_build_script_impl_product(cls):
19+
"""is_build_script_impl_product -> bool
20+
21+
Whether this product is produced by build-script-impl.
22+
"""
23+
return True
24+
25+
# This is the root of the build-graph, so it doesn't have any dependencies.
26+
@classmethod
27+
def get_dependencies(cls):
28+
return []

utils/update_checkout/update-checkout-config.json

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
"swift-argument-parser": {
1212
"remote": { "id": "apple/swift-argument-parser" } },
1313
"swift-atomics": {
14-
"remote": { "id": "apple/swift-atomics" } },
14+
"remote": { "id": "apple/swift-atomics" } },
1515
"swift-collections": {
1616
"remote": { "id": "apple/swift-collections" } },
1717
"swift-crypto": {
1818
"remote": { "id": "apple/swift-crypto" } },
1919
"swift-driver": {
2020
"remote": { "id": "apple/swift-driver" } },
2121
"swift-numerics": {
22-
"remote": { "id": "apple/swift-numerics" } },
22+
"remote": { "id": "apple/swift-numerics" } },
2323
"swift-tools-support-core": {
2424
"remote": { "id": "apple/swift-tools-support-core" } },
2525
"swiftpm": {
@@ -80,7 +80,9 @@
8080
"swift-experimental-string-processing": {
8181
"remote": { "id": "apple/swift-experimental-string-processing" } },
8282
"llvm-project": {
83-
"remote": { "id": "apple/llvm-project" } }
83+
"remote": { "id": "apple/llvm-project" } },
84+
"uswift": {
85+
"remote": { "id": "compnerd/uswift" } }
8486
},
8587
"default-branch-scheme": "main",
8688
"branch-schemes": {
@@ -123,7 +125,8 @@
123125
"swift-cmark-gfm": "gfm",
124126
"swift-nio": "2.31.2",
125127
"swift-nio-ssl": "2.15.0",
126-
"swift-experimental-string-processing": "dev/6"
128+
"swift-experimental-string-processing": "dev/6",
129+
"uswift": "main"
127130
}
128131
},
129132
"rebranch": {
@@ -157,6 +160,7 @@
157160
"sourcekit-lsp": "main",
158161
"swift-format": "main",
159162
"swift-installer-scripts": "main",
163+
<<<<<<< HEAD
160164
"swift-experimental-string-processing": "dev/6"
161165
}
162166
},
@@ -198,7 +202,8 @@
198202
"swift-markdown": "release/5.6",
199203
"swift-cmark-gfm": "release/5.6-gfm",
200204
"swift-nio": "2.31.2",
201-
"swift-nio-ssl": "2.15.0"
205+
"swift-nio-ssl": "2.15.0",
206+
"uswift": "main"
202207
}
203208
},
204209
"release/5.5": {
@@ -288,12 +293,12 @@
288293
"swiftpm": "main",
289294
"swift-argument-parser": "1.0.3",
290295
"swift-atomics": "1.0.2",
291-
"swift-collections": "1.0.1",
292-
"swift-crypto": "1.1.5",
296+
"swift-collections": "1.0.1",
297+
"swift-crypto": "1.1.5",
293298
"swift-driver": "main",
294299
"swift-numerics": "1.0.1",
295300
"swift-syntax": "main",
296-
"swift-system": "1.1.1",
301+
"swift-system": "1.1.1",
297302
"swift-stress-tester": "main",
298303
"swift-corelibs-xctest": "main",
299304
"swift-corelibs-foundation": "main",
@@ -308,7 +313,8 @@
308313
"sourcekit-lsp": "main",
309314
"swift-format": "main",
310315
"swift-installer-scripts": "main",
311-
"swift-experimental-string-processing": "dev/6"
316+
"swift-experimental-string-processing": "dev/6",
317+
"uswift": "main"
312318
}
313319
},
314320
"release/5.4": {

0 commit comments

Comments
 (0)