Skip to content

Commit 0fc3659

Browse files
authored
Merge pull request swiftlang#65795 from apple/maxd/fix-missing-cmake-value
CMake: fix missing `SWIFT_CONCURRENCY_GLOBAL_EXECUTOR` value `SWIFT_CONCURRENCY_GLOBAL_EXECUTOR` is defined in `stdlib/cmake/modules/StdlibOptions.cmake`, which is not included during the first pass of evaluation of the root `CMakeLists.txt`. It is available on subsequent evaluations after the value is stored in CMake cache. This led to subtle bugs, where `usr/lib/swift_static/linux/static-stdlib-args.lnk` didn't contain certain flags on clean toolchain builds, but did contain them in incremental builds. Not having these autolinking flags in toolchain builds leads to errors when statically linking executables on Linux. Additionally, since are trivial tests previously didn't link Dispatch statically, the didn't expose a bug where `%import-static-libdispatch` substitution had a missing value. To fix that I had to update `lit.cfg` and clean up some of the related path computations to infer a correct substitution value. Resolves some of the errors reported in swiftlang#65097.
2 parents fcdca08 + a25432d commit 0fc3659

File tree

6 files changed

+26
-23
lines changed

6 files changed

+26
-23
lines changed

Diff for: CMakeLists.txt

+2-9
Original file line numberDiff line numberDiff line change
@@ -691,13 +691,6 @@ if(NOT EXISTS "${SWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE}")
691691
message(SEND_ERROR "swift-syntax is required to build the Swift compiler. Please run update-checkout or specify SWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE")
692692
endif()
693693

694-
# Use dispatch as the system scheduler by default.
695-
# For convenience, we set this to false when concurrency is disabled.
696-
set(SWIFT_CONCURRENCY_USES_DISPATCH FALSE)
697-
if(SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY AND "${SWIFT_CONCURRENCY_GLOBAL_EXECUTOR}" STREQUAL "dispatch")
698-
set(SWIFT_CONCURRENCY_USES_DISPATCH TRUE)
699-
endif()
700-
701694
set(SWIFT_BUILD_HOST_DISPATCH FALSE)
702695
if(SWIFT_ENABLE_DISPATCH AND NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
703696
# Only build libdispatch for the host if the host tools are being built and
@@ -706,9 +699,9 @@ if(SWIFT_ENABLE_DISPATCH AND NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
706699
set(SWIFT_BUILD_HOST_DISPATCH TRUE)
707700
endif()
708701

709-
if(SWIFT_BUILD_HOST_DISPATCH OR SWIFT_CONCURRENCY_USES_DISPATCH)
702+
if(SWIFT_BUILD_HOST_DISPATCH)
710703
if(NOT EXISTS "${SWIFT_PATH_TO_LIBDISPATCH_SOURCE}")
711-
message(SEND_ERROR "SourceKit and concurrency require libdispatch on non-Darwin hosts. Please specify SWIFT_PATH_TO_LIBDISPATCH_SOURCE")
704+
message(SEND_ERROR "SourceKit requires libdispatch on non-Darwin hosts. Please specify SWIFT_PATH_TO_LIBDISPATCH_SOURCE")
712705
endif()
713706
endif()
714707
endif()

Diff for: stdlib/cmake/modules/StdlibOptions.cmake

+13
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,16 @@ set(SWIFT_RUNTIME_FIXED_BACKTRACER_PATH "" CACHE STRING
239239
"If set, provides a fixed path to the swift-backtrace binary. This
240240
will disable dynamic determination of the path and will also disable
241241
the setting in SWIFT_BACKTRACE.")
242+
243+
# Use dispatch as the system scheduler by default.
244+
# For convenience, we set this to false when concurrency is disabled.
245+
set(SWIFT_CONCURRENCY_USES_DISPATCH FALSE)
246+
if(SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY AND "${SWIFT_CONCURRENCY_GLOBAL_EXECUTOR}" STREQUAL "dispatch")
247+
set(SWIFT_CONCURRENCY_USES_DISPATCH TRUE)
248+
endif()
249+
250+
if(SWIFT_CONCURRENCY_USES_DISPATCH)
251+
if(NOT EXISTS "${SWIFT_PATH_TO_LIBDISPATCH_SOURCE}")
252+
message(SEND_ERROR "Concurrency require libdispatch on non-Darwin hosts. Please specify SWIFT_PATH_TO_LIBDISPATCH_SOURCE")
253+
endif()
254+
endif()

Diff for: test/Driver/static-stdlib-autolink-linux.swift

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
// RUN: echo 'public func asyncFunc() async { print("Hello") }' > %t/asyncModule.swift
88

99
// RUN: %target-swiftc_driver -emit-library -emit-module -module-name asyncModule -module-link-name asyncModule %t/asyncModule.swift -static -static-stdlib -o %t/libasyncModule.a
10-
// TODO: "-ldispatch -lBlocksRuntime" should be told by asyncModule.swiftmodule transitively
11-
// RUN: %target-swiftc_driver -parse-as-library -static -static-stdlib -module-name main %s %import-static-libdispatch -I%t -L%t -ldispatch -lBlocksRuntime -o %t/main
10+
// RUN: %target-swiftc_driver -parse-as-library -static -static-stdlib -module-name main %s %import-static-libdispatch -I%t -L%t -o %t/main
1211

1312
// RUN: %t/main | %FileCheck %s
1413
// CHECK: Hello

Diff for: test/Driver/static-stdlib-linux.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// REQUIRES: static_stdlib
44
print("hello world!")
55
// RUN: %empty-directory(%t)
6-
// RUN: %target-swiftc_driver -static-stdlib -o %t/static-stdlib %s
6+
// RUN: %target-swiftc_driver %import-static-libdispatch -static-stdlib -o %t/static-stdlib %s
77
// RUN: %t/static-stdlib | %FileCheck %s
88
// RUN: ldd %t/static-stdlib | %FileCheck %s --check-prefix=LDD
99
// CHECK: hello world!

Diff for: test/lit.cfg

+8-10
Original file line numberDiff line numberDiff line change
@@ -1613,19 +1613,13 @@ elif (run_os in ['linux-gnu', 'linux-gnueabihf', 'freebsd', 'openbsd', 'windows-
16131613
config.import_libdispatch = ('-I %s -I %s -L %s'
16141614
% (libdispatch_source_dir, libdispatch_swift_module_dir, libdispatch_artifact_dir))
16151615

1616-
libdispatch_static_artifact_dir = config.libdispatch_static_build_path
1617-
libdispatch_swift_static_module_dir = make_path(libdispatch_static_artifact_dir, 'src', 'swift', 'swift')
1616+
libdispatch_static_artifact_dir = os.path.join(config.libdispatch_static_build_path, 'lib')
16181617
libdispatch_static_artifacts = [
1619-
make_path(libdispatch_static_artifact_dir, 'src', 'libdispatch.a'),
1620-
make_path(libdispatch_static_artifact_dir, 'src', 'swift', 'libswiftDispatch.a'),
1621-
make_path(libdispatch_swift_static_module_dir, 'Dispatch.swiftmodule')]
1618+
make_path(libdispatch_static_artifact_dir, 'libdispatch.a'),
1619+
make_path(libdispatch_static_artifact_dir, 'libBlocksRuntime.a')]
16221620
if (all(os.path.exists(p) for p in libdispatch_static_artifacts)):
16231621
config.available_features.add('libdispatch_static')
1624-
config.import_libdispatch_static = ('-I %s -I %s -L %s -L %s -L %s'
1625-
% (libdispatch_source_dir, libdispatch_swift_static_module_dir,
1626-
make_path(libdispatch_static_artifact_dir, 'src'),
1627-
make_path(libdispatch_static_artifact_dir, 'src', 'BlocksRuntime'),
1628-
make_path(libdispatch_static_artifact_dir, 'src', 'swift')))
1622+
config.import_libdispatch_static = '-L %s' % libdispatch_static_artifact_dir
16291623

16301624
config.target_build_swift = (
16311625
'%s -target %s -toolchain-stdlib-rpath %s %s %s %s %s'
@@ -2669,6 +2663,10 @@ run_filecheck = '%s %s --allow-unused-prefixes --sanitize BUILD_DIR=%s --sanitiz
26692663
config.substitutions.append(('%FileCheck', run_filecheck))
26702664
config.substitutions.append(('%raw-FileCheck', shell_quote(config.filecheck)))
26712665
config.substitutions.append(('%import-libdispatch', getattr(config, 'import_libdispatch', '')))
2666+
# WARNING: the order of components in a substitution name has to be different from the previous one, as lit does
2667+
# a pure string substitution without understanding that these components are grouped together. That is, the following
2668+
# subsitution name can't be `%import-libdispatch-static`, otherwise the first two components will be substituted with
2669+
# the value of `%import-libdispatch` substitution with `-static` string appended to it.
26722670
config.substitutions.append(('%import-static-libdispatch', getattr(config, 'import_libdispatch_static', '')))
26732671

26742672
# Disable COW sanity checks in the swift runtime by default.

Diff for: utils/build-script-impl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1901,7 +1901,7 @@ for host in "${ALL_HOSTS[@]}"; do
19011901
-DSWIFT_PATH_TO_CMARK_BUILD:PATH="$(build_directory ${host} cmark)"
19021902
-DSWIFT_PATH_TO_LIBDISPATCH_SOURCE:PATH="${LIBDISPATCH_SOURCE_DIR}"
19031903
-DSWIFT_PATH_TO_LIBDISPATCH_BUILD:PATH="$(build_directory ${host} libdispatch)"
1904-
-DSWIFT_PATH_TO_LIBDISPATCH_STATIC_BUILD:PATH="$(build_directory ${host} libdispatch_static)"
1904+
-DSWIFT_PATH_TO_LIBDISPATCH_STATIC_BUILD:PATH="$(build_directory ${host} swift)/$(basename $(build_directory ${host} libdispatch))-static-prefix"
19051905
)
19061906

19071907
if [[ "${SWIFT_SDKS}" ]] ; then

0 commit comments

Comments
 (0)