Skip to content

Commit 8b74c09

Browse files
committed
utils: build static runtime with static dispatch and closure
Although we would like these to be dynamic, we currently cannot build them properly due to limitations of the build system. Adjust the build to pass in additional flags to properly build the runtimes for that environment as a temporary measure.
1 parent c33ce3f commit 8b74c09

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

stdlib/public/Concurrency/DispatchGlobalExecutor.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,13 @@ static void initializeDispatchEnqueueFunc(dispatch_queue_t queue, void *obj,
103103
if (SWIFT_RUNTIME_WEAK_CHECK(dispatch_async_swift_job))
104104
func = SWIFT_RUNTIME_WEAK_USE(dispatch_async_swift_job);
105105
#elif defined(_WIN32)
106+
#if defined(dispatch_STATIC)
107+
func = dispatch_async_swift_job;
108+
#else
106109
func = function_cast<dispatchEnqueueFuncType>(
107110
GetProcAddress(LoadLibraryW(L"dispatch.dll"),
108111
"dispatch_async_swift_job"));
112+
#endif
109113
#else
110114
func = function_cast<dispatchEnqueueFuncType>(
111115
dlsym(RTLD_NEXT, "dispatch_async_swift_job"));

utils/build.ps1

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2356,13 +2356,17 @@ function Build-ExperimentalRuntime {
23562356
CMAKE_FIND_PACKAGE_PREFER_CONFIG = "YES";
23572357
CMAKE_Swift_COMPILER_TARGET = (Get-ModuleTriple $Platform);
23582358
CMAKE_Swift_COMPILER_WORKS = "YES";
2359+
# TODO(compnerd) enforce dynamic linking of BlocksRuntime and dispatch.
2360+
CMAKE_Swift_FLAGS = $(if ($Static) { @("-Xcc", "-static-libclosure", "-Xcc", "-Ddispatch_STATIC") } else { @() });
23592361
CMAKE_STATIC_LIBRARY_PREFIX_Swift = "lib";
23602362
CMAKE_SYSTEM_NAME = $Platform.OS.ToString();
23612363
CMAKE_NINJA_FORCE_RESPONSE_FILE = "YES";
23622364

23632365
# NOTE(compnerd) we can get away with this currently because we only
2364-
# use the C portion of the dispatch build, which is always built
2365-
# dynamically.
2366+
# use the C portion of the dispatch build, which is supposed to always
2367+
# be built dynamically. Currently, we do not do this due to limitations
2368+
# of the build system, but because we are building statically, we do
2369+
# not link against the runtime and can get away with it.
23662370
dispatch_DIR = (Get-ProjectCMakeModules $Platform Dispatch);
23672371
SwiftCore_ENABLE_CONCURRENCY = "YES";
23682372
}
@@ -2758,7 +2762,8 @@ function Build-ExperimentalSDK([Hashtable] $Platform) {
27582762
CMAKE_FIND_PACKAGE_PREFER_CONFIG = "YES";
27592763
CMAKE_Swift_COMPILER_TARGET = (Get-ModuleTriple $Platform);
27602764
CMAKE_Swift_COMPILER_WORKS = "YES";
2761-
CMAKE_Swift_FLAGS = @("-static-stdlib", "-Xfrontend", "-use-static-resource-dir");
2765+
# TODO(compnerd) enforce dynamic linking of BlocksRuntime and dispatch.
2766+
CMAKE_Swift_FLAGS = @("-static-stdlib", "-Xfrontend", "-use-static-resource-dir", "-Xcc", "-Ddispatch_STATIC");
27622767
CMAKE_STATIC_LIBRARY_PREFIX_Swift = "lib";
27632768
CMAKE_SYSTEM_NAME = $Platform.OS.ToString();
27642769

0 commit comments

Comments
 (0)