Skip to content

Commit f12a132

Browse files
committed
[SR-1738] Allow *only* static libraries to be built
This splits the `--build-swift-stdlib` and `--build-swift-sdk-overlay` arguments into `dynamic` and `static` variants, which makes the following build command possible: ``` utils/build-script -- \ --build-swift-dynamic-stdlib=0 --build-swift-dynamic-sdk-overlay=0 \ --build-swift-static-stdlib=1 --build-swift-static-sdk-overlay=0 ``` This command produces *only* static libraries for the stdlib, and no SDK overlay libraries at all. Many other finely-grained build options are now possible.
1 parent 104a72f commit f12a132

File tree

7 files changed

+122
-27
lines changed

7 files changed

+122
-27
lines changed

CMakeLists.txt

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,40 @@ option(SWIFT_BUILD_TOOLS
4848
"Build the Swift compiler and other tools"
4949
TRUE)
5050

51-
option(SWIFT_BUILD_STDLIB
52-
"Build the Swift standard library (independent of the SDK headers)"
51+
option(SWIFT_BUILD_DYNAMIC_STDLIB
52+
"Build dynamic variants of the Swift standard library"
5353
TRUE)
5454

55-
option(SWIFT_BUILD_SDK_OVERLAY
56-
"Build Swift SDK overlay"
55+
option(SWIFT_BUILD_STATIC_STDLIB
56+
"Build static variants of the Swift standard library"
57+
FALSE)
58+
59+
option(SWIFT_BUILD_DYNAMIC_SDK_OVERLAY
60+
"Build dynamic variants of the Swift SDK overlay"
5761
TRUE)
5862

59-
option(SWIFT_BUILD_STATIC_STDLIB
60-
"Build static variants of the Swift standard library and SDK overlay"
63+
option(SWIFT_BUILD_STATIC_SDK_OVERLAY
64+
"Build static variants of the Swift SDK overlay"
6165
FALSE)
6266

67+
# In many cases, the CMake build system needs to determine whether to include
68+
# a directory, or perform other actions, based on whether the stdlib or SDK is
69+
# being built at all -- statically or dynamically. Please note that these
70+
# flags are not related to the deprecated build-script-impl arguments
71+
# 'build-swift-stdlib' and 'build-swift-sdk-overlay'. These are not flags that
72+
# the build script should be able to set.
73+
if(SWIFT_BUILD_DYNAMIC_STDLIB OR SWIFT_BUILD_STATIC_STDLIB)
74+
set(SWIFT_BUILD_STDLIB TRUE)
75+
else()
76+
set(SWIFT_BUILD_STDLIB FALSE)
77+
endif()
78+
79+
if(SWIFT_BUILD_DYNAMIC_SDK_OVERLAY OR SWIFT_BUILD_STATIC_SDK_OVERLAY)
80+
set(SWIFT_BUILD_SDK_OVERLAY TRUE)
81+
else()
82+
set(SWIFT_BUILD_SDK_OVERLAY FALSE)
83+
endif()
84+
6385
option(SWIFT_BUILD_PERF_TESTSUITE
6486
"Create targets for swift performance benchmarks."
6587
FALSE)
@@ -798,7 +820,7 @@ endif()
798820
add_subdirectory(utils)
799821
add_subdirectory(stdlib)
800822

801-
if(SWIFT_BUILD_STDLIB AND SWIFT_INCLUDE_TESTS)
823+
if(SWIFT_BUILD_DYNAMIC_STDLIB AND SWIFT_INCLUDE_TESTS)
802824
add_subdirectory(tools/swift-reflection-test)
803825
endif()
804826

cmake/modules/AddSwift.cmake

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,10 +557,15 @@ function(_add_swift_library_single target name)
557557
set(libkind MODULE)
558558
elseif(SWIFTLIB_SINGLE_OBJECT_LIBRARY)
559559
set(libkind OBJECT)
560+
# If both SHARED and STATIC are specified, we add the SHARED library first.
561+
# The STATIC library is handled further below.
560562
elseif(SWIFTLIB_SINGLE_SHARED)
561563
set(libkind SHARED)
564+
elseif(SWIFTLIB_SINGLE_STATIC)
565+
set(libkind STATIC)
562566
else()
563-
set(libkind)
567+
message(FATAL_ERROR
568+
"Either SHARED, STATIC, or OBJECT_LIBRARY must be specified")
564569
endif()
565570

566571
handle_gyb_sources(
@@ -721,7 +726,6 @@ function(_add_swift_library_single target name)
721726
# Configure the static library target.
722727
# Set compile and link flags for the non-static target.
723728
# Do these LAST.
724-
725729
set(target_static)
726730
if(SWIFTLIB_SINGLE_IS_STDLIB AND SWIFTLIB_SINGLE_STATIC)
727731
set(target_static "${target}-static")

stdlib/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ else()
1010
set(CMAKE_C_COMPILER_ARG1 "")
1111
endif()
1212

13-
# FIXME: Make it possible to build *only* static libraries for the stdlib.
14-
set(SWIFT_STDLIB_LIBRARY_BUILD_TYPES SHARED)
13+
set(SWIFT_STDLIB_LIBRARY_BUILD_TYPES)
14+
if(SWIFT_BUILD_DYNAMIC_STDLIB)
15+
list(APPEND SWIFT_STDLIB_LIBRARY_BUILD_TYPES SHARED)
16+
endif()
1517
if(SWIFT_BUILD_STATIC_STDLIB)
1618
list(APPEND SWIFT_STDLIB_LIBRARY_BUILD_TYPES STATIC)
1719
endif()

stdlib/public/SDK/CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# All libraries in this directory tree are overlays that depend on Darwin SDK.
22

3-
# FIXME: Make it possible to build *only* static libraries for the SDK overlays.
4-
set(SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES SHARED)
5-
if(SWIFT_BUILD_STATIC_STDLIB)
3+
set(SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES)
4+
if(SWIFT_BUILD_DYNAMIC_SDK_OVERLAY)
5+
list(APPEND SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES SHARED)
6+
endif()
7+
if(SWIFT_BUILD_STATIC_SDK_OVERLAY)
68
list(APPEND SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES STATIC)
79
endif()
810

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# libswiftRemoteMirror.dylib should not have runtime dependencies; it's
22
# always built as a shared library.
3-
add_swift_library(swiftRemoteMirror SHARED TARGET_LIBRARY DONT_EMBED_BITCODE
4-
SwiftRemoteMirror.cpp
5-
LINK_LIBRARIES swiftReflection
6-
INSTALL_IN_COMPONENT stdlib)
3+
if(SWIFT_BUILD_DYNAMIC_STDLIB)
4+
add_swift_library(swiftRemoteMirror SHARED TARGET_LIBRARY DONT_EMBED_BITCODE
5+
SwiftRemoteMirror.cpp
6+
LINK_LIBRARIES swiftReflection
7+
INSTALL_IN_COMPONENT stdlib)
8+
endif()

utils/build-script

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,27 @@ class BuildScriptInvocation(object):
364364
args.skip_test_tvos = True
365365
args.skip_test_watchos = True
366366

367+
# --build-swift-stdlib and --build-swift-sdk-overlay are deprecated
368+
# aliases for --build-swift-{dynamic,static}-stdlib and
369+
# --build-swift-{dynamic,static}-sdk-overlay. The deprecated options
370+
# are None by default, but if specified they take precedence over the
371+
# new, more granular options.
372+
if args.build_swift_stdlib is not None:
373+
if args.build_swift_stdlib:
374+
args.build_swift_dynamic_stdlib = True
375+
args.build_swift_static_stdlib = False
376+
else:
377+
args.build_swift_dynamic_stdlib = False
378+
args.build_swift_static_stdlib = False
379+
380+
if args.build_swift_sdk_overlay is not None:
381+
if args.build_swift_sdk_overlay:
382+
args.build_swift_dynamic_sdk_overlay = True
383+
args.build_swift_static_sdk_overlay = False
384+
else:
385+
args.build_swift_dynamic_sdk_overlay = False
386+
args.build_swift_static_sdk_overlay = False
387+
367388
# --skip-test-ios is merely a shorthand for host and simulator tests.
368389
if args.skip_test_ios:
369390
args.skip_test_ios_host = True
@@ -636,8 +657,16 @@ class BuildScriptInvocation(object):
636657
impl_args += ["--skip-build-libdispatch"]
637658
if not args.build_swiftpm:
638659
impl_args += ["--skip-build-swiftpm"]
660+
if args.build_swift_dynamic_stdlib:
661+
impl_args += ["--build-swift-dynamic-stdlib"]
662+
if args.build_swift_static_stdlib:
663+
impl_args += ["--build-swift-static-stdlib"]
639664
if args.build_swift_stdlib_unittest_extra:
640665
impl_args += ["--build-swift-stdlib-unittest-extra"]
666+
if args.build_swift_dynamic_sdk_overlay:
667+
impl_args += ["--build-swift-dynamic-sdk-overlay"]
668+
if args.build_swift_static_sdk_overlay:
669+
impl_args += ["--build-swift-static-sdk-overlay"]
641670

642671
if args.skip_build_linux:
643672
impl_args += ["--skip-build-linux"]
@@ -1507,13 +1536,45 @@ details of the setups of other systems or automated environments.""")
15071536
help="Use the host compiler, not the self-built one to compile the "
15081537
"Swift runtime",
15091538
action=arguments.action.optional_bool)
1510-
parser.add_argument(
1511-
"--build-swift-stdlib-unittest-extra",
1512-
help="Build optional StdlibUnittest components",
1513-
action=arguments.action.optional_bool)
15141539

15151540
run_build_group = parser.add_argument_group(
15161541
title="Run build")
1542+
run_build_group.add_argument(
1543+
"--build-swift-stdlib",
1544+
help="a deprecated alias for '--build-swift-dynamic-stdlib=1 "
1545+
"--build-swift-static-stdlib=0'. When specified, this takes "
1546+
"precedence over those options",
1547+
action=arguments.action.optional_bool,
1548+
default=None)
1549+
run_build_group.add_argument(
1550+
"--build-swift-dynamic-stdlib",
1551+
help="build dynamic variants of the Swift standard library",
1552+
action=arguments.action.optional_bool,
1553+
default=True)
1554+
run_build_group.add_argument(
1555+
"--build-swift-static-stdlib",
1556+
help="build static variants of the Swift standard library",
1557+
action=arguments.action.optional_bool)
1558+
run_build_group.add_argument(
1559+
"--build-swift-sdk-overlay",
1560+
help="a deprecated alias for '--build-swift-dynamic-sdk-overlay=1 "
1561+
"--build-swift-static-sdk-overlay=0'. When specified, this takes "
1562+
"precedence over those options",
1563+
action=arguments.action.optional_bool,
1564+
default=None)
1565+
run_build_group.add_argument(
1566+
"--build-swift-dynamic-sdk-overlay",
1567+
help="build dynamic variants of the Swift SDK overlay",
1568+
action=arguments.action.optional_bool,
1569+
default=True)
1570+
run_build_group.add_argument(
1571+
"--build-swift-static-sdk-overlay",
1572+
help="build static variants of the Swift SDK overlay",
1573+
action=arguments.action.optional_bool)
1574+
run_build_group.add_argument(
1575+
"--build-swift-stdlib-unittest-extra",
1576+
help="Build optional StdlibUnittest components",
1577+
action=arguments.action.optional_bool)
15171578
run_build_group.add_argument(
15181579
"-S", "--skip-build",
15191580
help="generate build directory only without building",

utils/build-script-impl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,11 @@ KNOWN_SETTINGS=(
154154
enable-llvm-assertions "1" "set to enable llvm assertions"
155155
build-llvm "1" "set to 1 to build LLVM and Clang"
156156
build-swift-tools "1" "set to 1 to build Swift host tools"
157-
build-swift-stdlib "1" "set to 1 to build the Swift standard library"
157+
build-swift-dynamic-stdlib "" "set to 1 to build dynamic variants of the Swift standard library"
158+
build-swift-static-stdlib "" "set to 1 to build static variants of the Swift standard library"
158159
build-swift-stdlib-unittest-extra "0" "set to 1 to build optional StdlibUnittest components"
159-
build-swift-sdk-overlay "1" "set to 1 to build the Swift SDK overlay"
160-
build-swift-static-stdlib "0" "set to 1 to build static versions of the Swift standard library and SDK overlay"
160+
build-swift-dynamic-sdk-overlay "" "set to 1 to build dynamic variants of the Swift SDK overlay"
161+
build-swift-static-sdk-overlay "" "set to 1 to build static variants of the Swift SDK overlay"
161162
build-swift-examples "1" "set to 1 to build examples"
162163
build-serialized-stdlib-unittest "0" "set to 1 to build the StdlibUnittest module with -sil-serialize-all"
163164
build-sil-debugging-stdlib "0" "set to 1 to build the Swift standard library with -gsil to enable debugging and profiling on SIL level"
@@ -1871,12 +1872,13 @@ for host in "${ALL_HOSTS[@]}"; do
18711872
-DSWIFT_NATIVE_CLANG_TOOLS_PATH:STRING="${native_clang_tools_path}"
18721873
-DSWIFT_NATIVE_SWIFT_TOOLS_PATH:STRING="${native_swift_tools_path}"
18731874
-DSWIFT_BUILD_TOOLS:BOOL=$(true_false "${BUILD_SWIFT_TOOLS}")
1874-
-DSWIFT_BUILD_STDLIB:BOOL=$(true_false "${BUILD_SWIFT_STDLIB}")
18751875
-DSWIFT_SERIALIZE_STDLIB_UNITTEST:BOOL=$(true_false "${BUILD_SERIALIZED_STDLIB_UNITTEST}")
18761876
-DSWIFT_STDLIB_SIL_DEBUGGING:BOOL=$(true_false "${BUILD_SIL_DEBUGGING_STDLIB}")
18771877
-DSWIFT_CHECK_INCREMENTAL_COMPILATION:BOOL=$(true_false "${CHECK_INCREMENTAL_COMPILATION}")
1878-
-DSWIFT_BUILD_SDK_OVERLAY:BOOL=$(true_false "${BUILD_SWIFT_SDK_OVERLAY}")
1878+
-DSWIFT_BUILD_DYNAMIC_STDLIB:BOOL=$(true_false "${BUILD_SWIFT_DYNAMIC_STDLIB}")
18791879
-DSWIFT_BUILD_STATIC_STDLIB:BOOL=$(true_false "${BUILD_SWIFT_STATIC_STDLIB}")
1880+
-DSWIFT_BUILD_DYNAMIC_SDK_OVERLAY:BOOL=$(true_false "${BUILD_SWIFT_DYNAMIC_SDK_OVERLAY}")
1881+
-DSWIFT_BUILD_STATIC_SDK_OVERLAY:BOOL=$(true_false "${BUILD_SWIFT_STATIC_SDK_OVERLAY}")
18801882
-DSWIFT_BUILD_PERF_TESTSUITE:BOOL=$(true_false "${build_perf_testsuite_this_time}")
18811883
-DSWIFT_BUILD_EXAMPLES:BOOL=$(true_false "${BUILD_SWIFT_EXAMPLES}")
18821884
-DSWIFT_INCLUDE_TESTS:BOOL=$(true_false "${build_tests_this_time}")

0 commit comments

Comments
 (0)