Skip to content

Commit 74e59ab

Browse files
authored
[Concurrency] Build C only libdispatch before Swift on non-Darwin pla… (swiftlang#35738)
* [Concurrency] Build C only libdispatch before Swift on non-Darwin platforms _Concurrency depends on libdispatch and since it is not available by default on non-Darwin platforms, it needs to be built before the Swift project, so that the dependency can be resolved. * Fix clibdispatch installation and BuildSystem tests * Fix build system tests on Darwin and formatting
1 parent d8502ac commit 74e59ab

16 files changed

+219
-15
lines changed

stdlib/public/Concurrency/CMakeLists.txt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@ set(LLVM_OPTIONAL_SOURCES
1919
set(swift_concurrency_link_libraries
2020
swiftCore)
2121

22+
set(swift_concurrency_link_flags "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}")
23+
2224
if(SWIFT_CONCURRENCY_USES_DISPATCH)
2325
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
2426
include_directories(AFTER
2527
${SWIFT_PATH_TO_LIBDISPATCH_SOURCE})
28+
link_directories(AFTER
29+
${SWIFT_PATH_TO_LIBDISPATCH_BUILD})
2630

27-
# FIXME: we can't rely on libdispatch having been built for the
28-
# target at this point in the process. Currently, we're relying
29-
# on soft-linking.
30-
#list(APPEND swift_concurrency_link_libraries
31-
# dispatch)
31+
list(APPEND swift_concurrency_link_flags
32+
"-ldispatch")
3233
endif()
3334
endif()
3435

@@ -67,6 +68,6 @@ add_swift_target_library(swift_Concurrency ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} I
6768
${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
6869
-parse-stdlib
6970
-Xfrontend -enable-experimental-concurrency
70-
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
71+
LINK_FLAGS "${swift_concurrency_link_flags}"
7172
INSTALL_IN_COMPONENT stdlib
7273
)

utils/build-presets.ini

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,7 @@ long-test
824824
stress-test
825825
test-optimized
826826
foundation
827+
clibdispatch
827828
libdispatch
828829
indexstore-db
829830
sourcekit-lsp
@@ -966,6 +967,7 @@ release
966967
test
967968
validation-test
968969
foundation
970+
clibdispatch
969971
libdispatch
970972
indexstore-db
971973
sourcekit-lsp
@@ -1065,6 +1067,7 @@ swiftpm
10651067
swift-driver
10661068
xctest
10671069
foundation
1070+
clibdispatch
10681071
libdispatch
10691072
swiftsyntax
10701073
indexstore-db
@@ -1593,6 +1596,7 @@ mixin-preset=
15931596
mixin_swiftpm_base
15941597
mixin_linux_install_components_with_clang
15951598

1599+
clibdispatch
15961600
libdispatch
15971601
libicu
15981602
foundation
@@ -1841,6 +1845,7 @@ llbuild
18411845
swiftpm
18421846
xctest
18431847
foundation
1848+
clibdispatch
18441849
libdispatch
18451850
indexstore-db
18461851
sourcekit-lsp
@@ -2456,6 +2461,7 @@ install-symroot=%(install_symroot)s
24562461
mixin-preset=source_compat_suite_base
24572462
build-subdir=compat_linux
24582463
foundation
2464+
clibdispatch
24592465
libdispatch
24602466
xctest
24612467
install-foundation
@@ -2511,6 +2517,7 @@ no-assertions
25112517
lldb
25122518
foundation
25132519
libicu
2520+
clibdispatch
25142521
libdispatch
25152522
build-ninja
25162523

utils/build-script

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,10 @@ def apply_default_arguments(toolchain, args):
318318
args.stdlib_deployment_targets = [
319319
target.name for target in stdlib_targets]
320320

321+
if (args.build_swift and
322+
platform.system() != "Darwin"):
323+
args.build_clibdispatch = True
324+
321325
# SwiftPM and XCTest have a dependency on Foundation.
322326
# On OS X, Foundation is built automatically using xcodebuild.
323327
# On Linux, we must ensure that it is built manually.
@@ -624,6 +628,7 @@ class BuildScriptInvocation(object):
624628
(args.build_llbuild, "llbuild"),
625629
(args.build_libcxx, "libcxx"),
626630
(args.build_libdispatch, "libdispatch"),
631+
(args.build_clibdispatch, "clibdispatch"),
627632
(args.build_libicu, "libicu")
628633
]
629634
for (should_build, string_name) in conditional_subproject_configs:
@@ -865,6 +870,8 @@ class BuildScriptInvocation(object):
865870
impl_product_classes.append(products.LibCXX)
866871
if self.args.build_libicu:
867872
impl_product_classes.append(products.LibICU)
873+
if self.args.build_clibdispatch:
874+
impl_product_classes.append(products.CLibDispatch)
868875
if self.args.build_swift:
869876
impl_product_classes.append(products.Swift)
870877
if self.args.build_lldb:

utils/build-script-impl

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ KNOWN_SETTINGS=(
230230
)
231231

232232
components=(
233+
clibdispatch
233234
cmark
234235
foundation
235236
libcxx
@@ -1162,6 +1163,7 @@ STRESSTEST_PACKAGE_DIR="${WORKSPACE}/swift-stress-tester"
11621163
XCTEST_SOURCE_DIR="${WORKSPACE}/swift-corelibs-xctest"
11631164
FOUNDATION_SOURCE_DIR="${WORKSPACE}/swift-corelibs-foundation"
11641165
FOUNDATION_STATIC_SOURCE_DIR="${WORKSPACE}/swift-corelibs-foundation"
1166+
CLIBDISPATCH_SOURCE_DIR="${WORKSPACE}/swift-corelibs-libdispatch"
11651167
LIBDISPATCH_SOURCE_DIR="${WORKSPACE}/swift-corelibs-libdispatch"
11661168
LIBDISPATCH_STATIC_SOURCE_DIR="${WORKSPACE}/swift-corelibs-libdispatch"
11671169
LIBICU_SOURCE_DIR="${WORKSPACE}/icu"
@@ -1175,6 +1177,7 @@ PRODUCTS=(llvm)
11751177
[[ "${SKIP_BUILD_CMARK}" ]] || PRODUCTS+=(cmark)
11761178
[[ "${SKIP_BUILD_LIBCXX}" ]] || PRODUCTS+=(libcxx)
11771179
[[ "${SKIP_BUILD_LIBICU}" ]] || PRODUCTS+=(libicu)
1180+
[[ "${SKIP_BUILD_CLIBDISPATCH}" ]] || PRODUCTS+=(clibdispatch)
11781181
[[ "${SKIP_BUILD_SWIFT}" ]] || PRODUCTS+=(swift)
11791182
[[ "${SKIP_BUILD_LLDB}" ]] || PRODUCTS+=(lldb)
11801183
[[ "${SKIP_BUILD_LIBDISPATCH}" ]] || PRODUCTS+=(libdispatch)
@@ -1259,7 +1262,7 @@ function build_directory_bin() {
12591262
foundation|foundation_static)
12601263
echo "${root}/${FOUNDATION_BUILD_TYPE}/bin"
12611264
;;
1262-
libdispatch|libdispatch_static)
1265+
clibdispatch|libdispatch|libdispatch_static)
12631266
echo "${root}/${LIBDISPATCH_BUILD_TYPE}/bin"
12641267
;;
12651268
libicu)
@@ -1377,7 +1380,7 @@ function cmake_config_opt() {
13771380
foundation|foundation_static)
13781381
echo "--config ${FOUNDATION_BUILD_TYPE}"
13791382
;;
1380-
libdispatch|libdispatch_static)
1383+
clibdispatch|libdispatch|libdispatch_static)
13811384
echo "--config ${LIBDISPATCH_BUILD_TYPE}"
13821385
;;
13831386
libicu)
@@ -1764,7 +1767,6 @@ for host in "${ALL_HOSTS[@]}"; do
17641767
;;
17651768

17661769
swift)
1767-
17681770
if [[ "${ANDROID_API_LEVEL}" ]]; then
17691771
cmake_options=(
17701772
"${cmake_options[@]}"
@@ -2320,9 +2322,18 @@ for host in "${ALL_HOSTS[@]}"; do
23202322
)
23212323

23222324
;;
2323-
libdispatch|libdispatch_static)
2325+
clibdispatch|libdispatch|libdispatch_static)
23242326
LIBDISPATCH_BUILD_DIR=$(build_directory ${host} ${product})
23252327
SWIFT_BUILD_PATH="$(build_directory ${host} swift)"
2328+
ENABLE_SWIFT=YES
2329+
if [[ "${product}" = "clibdispatch" ]]; then
2330+
if [[ "$(uname -s)" = "Darwin" ]]; then
2331+
continue # We don't build clibdispatch on Darwin
2332+
fi
2333+
ENABLE_SWIFT=NO
2334+
LIBDISPATCH_BUILD_DIR=$(build_directory ${host} libdispatch)
2335+
build_dir=${LIBDISPATCH_BUILD_DIR}
2336+
fi
23262337

23272338
case "${host}" in
23282339
macosx-*)
@@ -2338,7 +2349,7 @@ for host in "${ALL_HOSTS[@]}"; do
23382349
call rm -rf "${LIBDISPATCH_BUILD_DIR}"
23392350

23402351
cmake_options=(
2341-
-DENABLE_SWIFT=YES
2352+
-DENABLE_SWIFT="${ENABLE_SWIFT}"
23422353
${cmake_options[@]}
23432354
-DCMAKE_BUILD_TYPE:STRING="${LIBDISPATCH_BUILD_TYPE}"
23442355
-DCMAKE_C_COMPILER:PATH="${CLANG_BIN}/clang"
@@ -2506,6 +2517,13 @@ for host in "${ALL_HOSTS[@]}"; do
25062517
if [[ "${product}" = "llvm" ]] && [[ "${BUILD_LLVM}" = "1" ]] && [[ "$(uname -s)" = "Darwin" ]]; then
25072518
copy_embedded_compiler_rt_builtins_from_darwin_host_toolchain "$(build_directory_bin ${host} llvm)/.."
25082519
fi
2520+
2521+
# We need to copy libdispatch.so into the swift lib directory
2522+
# so the tests can find it
2523+
if [[ "${product}" = "clibdispatch" ]] && [[ "uname -s" != "Darwin" ]]; then
2524+
clibdispatch_libdir="$(build_directory ${host} swift)/lib/swift/${SWIFT_HOST_VARIANT}/${SWIFT_HOST_VARIANT_ARCH}"
2525+
call cp "${build_dir}/libdispatch.so" "${clibdispatch_libdir}"
2526+
fi
25092527
done
25102528
done
25112529
# END OF BUILD PHASE
@@ -2762,13 +2780,17 @@ for host in "${ALL_HOSTS[@]}"; do
27622780
foundation_static)
27632781
continue
27642782
;;
2765-
libdispatch)
2783+
clibdispatch|libdispatch)
27662784
if [[ "${SKIP_TEST_LIBDISPATCH}" ]]; then
27672785
continue
27682786
fi
27692787

27702788
case "${host}" in
27712789
macosx-*)
2790+
if [[ "${product}" = clibdispatch ]]; then
2791+
# we don't build clibdispatch on Darwin
2792+
continue
2793+
fi
27722794
LIBDISPATCH_BUILD_DIR=$(build_directory ${host} ${product})
27732795
echo "--- Running tests for ${product} ---"
27742796
with_pushd "${LIBDISPATCH_BUILD_DIR}" \
@@ -2777,6 +2799,9 @@ for host in "${ALL_HOSTS[@]}"; do
27772799
continue
27782800
;;
27792801
*)
2802+
if [[ "${product}" = clibdispatch ]]; then
2803+
product=libdispatch
2804+
fi
27802805
results_targets=( "test" )
27812806
executable_target=""
27822807
;;
@@ -2951,13 +2976,21 @@ for host in "${ALL_HOSTS[@]}"; do
29512976
fi
29522977

29532978
;;
2954-
libdispatch|libdispatch_static)
2955-
if [[ -z "${INSTALL_LIBDISPATCH}" ]] ; then
2979+
clibdispatch|libdispatch|libdispatch_static)
2980+
if [[ "${product}" = clibdispatch ]]; then
2981+
if [[ -z "${INSTALL_CLIBDISPATCH}" ]]; then
2982+
continue
2983+
fi
2984+
elif [[ -z "${INSTALL_LIBDISPATCH}" ]]; then
29562985
continue
29572986
fi
29582987

29592988
case "${host}" in
29602989
macosx-*)
2990+
if [[ "${product}" = clibdispatch ]]; then
2991+
# we don't build clibdispatch on Darwin
2992+
continue
2993+
fi
29612994
if [[ -z "${INSTALL_DESTDIR}" ]] ; then
29622995
echo "--install-destdir is required to install products."
29632996
exit 1
@@ -2976,6 +3009,9 @@ for host in "${ALL_HOSTS[@]}"; do
29763009
continue
29773010
;;
29783011
*)
3012+
if [[ "${product}" = clibdispatch ]]; then
3013+
product=libdispatch
3014+
fi
29793015
;;
29803016
esac
29813017
;;

utils/build_swift/build_swift/driver_arguments.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,9 @@ def create_argument_parser():
652652
option('--libdispatch', toggle_true('build_libdispatch'),
653653
help='build libdispatch')
654654

655+
option('--clibdispatch', toggle_true('build_clibdispatch'),
656+
help='build clibdispatch')
657+
655658
option('--libicu', toggle_true('build_libicu'),
656659
help='build libicu')
657660

utils/build_swift/tests/expected_options.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
'build_ios_simulator': False,
7171
'build_jobs': multiprocessing.cpu_count(),
7272
'build_libdispatch': False,
73+
'build_clibdispatch': False,
7374
'build_libicu': False,
7475
'build_linux': True,
7576
'build_llbuild': False,
@@ -522,6 +523,7 @@ class BuildScriptImplOption(_BaseOption):
522523
EnableOption('--only-executable-test'),
523524
EnableOption('--only-non-executable-test'),
524525
EnableOption('--libdispatch', dest='build_libdispatch'),
526+
EnableOption('--clibdispatch', dest='build_clibdispatch'),
525527
EnableOption('--libicu', dest='build_libicu'),
526528
EnableOption('--indexstore-db', dest='build_indexstoredb'),
527529
EnableOption('--test-indexstore-db-sanitize-all',

utils/swift_build_support/swift_build_support/products/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# ----------------------------------------------------------------------------
1212

1313
from .benchmarks import Benchmarks
14+
from .clibdispatch import CLibDispatch
1415
from .cmark import CMark
1516
from .foundation import Foundation
1617
from .indexstoredb import IndexStoreDB
@@ -39,6 +40,7 @@
3940
'Ninja',
4041
'Foundation',
4142
'LibCXX',
43+
'CLibDispatch',
4244
'LibDispatch',
4345
'LibICU',
4446
'LLBuild',
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# swift_build_support/products/clibdispatch.py -------------------*- python -*-
2+
#
3+
# This source file is part of the Swift.org open source project
4+
#
5+
# Copyright (c) 2014 - 2021 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 cmark
14+
from . import libcxx
15+
from . import llvm
16+
from . import product
17+
18+
19+
class CLibDispatch(product.Product):
20+
@classmethod
21+
def is_build_script_impl_product(cls):
22+
"""is_build_script_impl_product -> bool
23+
24+
Whether this product is produced by build-script-impl.
25+
"""
26+
return True
27+
28+
@classmethod
29+
def product_source_name(cls):
30+
"""product_source_name() -> str
31+
32+
The name of the source code directory of this product.
33+
"""
34+
return "swift-corelibs-libdispatch"
35+
36+
@classmethod
37+
def is_nondarwin_only_build_product(cls):
38+
return True
39+
40+
@classmethod
41+
def get_dependencies(cls):
42+
return [cmark.CMark,
43+
llvm.LLVM,
44+
libcxx.LibCXX]

utils/swift_build_support/swift_build_support/products/swift.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#
1111
# ----------------------------------------------------------------------------
1212

13+
from . import clibdispatch
1314
from . import cmark
1415
from . import libcxx
1516
from . import libicu
@@ -147,4 +148,5 @@ def get_dependencies(cls):
147148
return [cmark.CMark,
148149
llvm.LLVM,
149150
libcxx.LibCXX,
150-
libicu.LibICU]
151+
libicu.LibICU,
152+
clibdispatch.CLibDispatch]

0 commit comments

Comments
 (0)