diff --git a/CMakeLists.txt b/CMakeLists.txt index d04f27e560097..1c667fbd89146 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,18 +48,40 @@ option(SWIFT_BUILD_TOOLS "Build the Swift compiler and other tools" TRUE) -option(SWIFT_BUILD_STDLIB - "Build the Swift standard library (independent of the SDK headers)" +option(SWIFT_BUILD_DYNAMIC_STDLIB + "Build dynamic variants of the Swift standard library" TRUE) -option(SWIFT_BUILD_SDK_OVERLAY - "Build Swift SDK overlay" +option(SWIFT_BUILD_STATIC_STDLIB + "Build static variants of the Swift standard library" + FALSE) + +option(SWIFT_BUILD_DYNAMIC_SDK_OVERLAY + "Build dynamic variants of the Swift SDK overlay" TRUE) -option(SWIFT_BUILD_STATIC_STDLIB - "Build static variants of the Swift standard library and SDK overlay" +option(SWIFT_BUILD_STATIC_SDK_OVERLAY + "Build static variants of the Swift SDK overlay" FALSE) +# In many cases, the CMake build system needs to determine whether to include +# a directory, or perform other actions, based on whether the stdlib or SDK is +# being built at all -- statically or dynamically. Please note that these +# flags are not related to the deprecated build-script-impl arguments +# 'build-swift-stdlib' and 'build-swift-sdk-overlay'. These are not flags that +# the build script should be able to set. +if(SWIFT_BUILD_DYNAMIC_STDLIB OR SWIFT_BUILD_STATIC_STDLIB) + set(SWIFT_BUILD_STDLIB TRUE) +else() + set(SWIFT_BUILD_STDLIB FALSE) +endif() + +if(SWIFT_BUILD_DYNAMIC_SDK_OVERLAY OR SWIFT_BUILD_STATIC_SDK_OVERLAY) + set(SWIFT_BUILD_SDK_OVERLAY TRUE) +else() + set(SWIFT_BUILD_SDK_OVERLAY FALSE) +endif() + option(SWIFT_BUILD_PERF_TESTSUITE "Create targets for swift performance benchmarks." FALSE) @@ -798,7 +820,7 @@ endif() add_subdirectory(utils) add_subdirectory(stdlib) -if(SWIFT_BUILD_STDLIB AND SWIFT_INCLUDE_TESTS) +if(SWIFT_BUILD_DYNAMIC_STDLIB AND SWIFT_INCLUDE_TESTS) add_subdirectory(tools/swift-reflection-test) endif() diff --git a/cmake/modules/AddSwift.cmake b/cmake/modules/AddSwift.cmake index e205e18f40b73..53a93b8b2df07 100644 --- a/cmake/modules/AddSwift.cmake +++ b/cmake/modules/AddSwift.cmake @@ -557,10 +557,15 @@ function(_add_swift_library_single target name) set(libkind MODULE) elseif(SWIFTLIB_SINGLE_OBJECT_LIBRARY) set(libkind OBJECT) + # If both SHARED and STATIC are specified, we add the SHARED library first. + # The STATIC library is handled further below. elseif(SWIFTLIB_SINGLE_SHARED) set(libkind SHARED) + elseif(SWIFTLIB_SINGLE_STATIC) + set(libkind STATIC) else() - set(libkind) + message(FATAL_ERROR + "Either SHARED, STATIC, or OBJECT_LIBRARY must be specified") endif() handle_gyb_sources( @@ -721,7 +726,6 @@ function(_add_swift_library_single target name) # Configure the static library target. # Set compile and link flags for the non-static target. # Do these LAST. - set(target_static) if(SWIFTLIB_SINGLE_IS_STDLIB AND SWIFTLIB_SINGLE_STATIC) set(target_static "${target}-static") diff --git a/stdlib/CMakeLists.txt b/stdlib/CMakeLists.txt index d46e8f369fe45..937b3cc978782 100644 --- a/stdlib/CMakeLists.txt +++ b/stdlib/CMakeLists.txt @@ -10,8 +10,10 @@ else() set(CMAKE_C_COMPILER_ARG1 "") endif() -# FIXME: Make it possible to build *only* static libraries for the stdlib. -set(SWIFT_STDLIB_LIBRARY_BUILD_TYPES SHARED) +set(SWIFT_STDLIB_LIBRARY_BUILD_TYPES) +if(SWIFT_BUILD_DYNAMIC_STDLIB) + list(APPEND SWIFT_STDLIB_LIBRARY_BUILD_TYPES SHARED) +endif() if(SWIFT_BUILD_STATIC_STDLIB) list(APPEND SWIFT_STDLIB_LIBRARY_BUILD_TYPES STATIC) endif() diff --git a/stdlib/public/SDK/CMakeLists.txt b/stdlib/public/SDK/CMakeLists.txt index 29842cd6b2c54..a6f2da2ecbe25 100644 --- a/stdlib/public/SDK/CMakeLists.txt +++ b/stdlib/public/SDK/CMakeLists.txt @@ -1,8 +1,10 @@ # All libraries in this directory tree are overlays that depend on Darwin SDK. -# FIXME: Make it possible to build *only* static libraries for the SDK overlays. -set(SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES SHARED) -if(SWIFT_BUILD_STATIC_STDLIB) +set(SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES) +if(SWIFT_BUILD_DYNAMIC_SDK_OVERLAY) + list(APPEND SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES SHARED) +endif() +if(SWIFT_BUILD_STATIC_SDK_OVERLAY) list(APPEND SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES STATIC) endif() diff --git a/stdlib/public/SwiftRemoteMirror/CMakeLists.txt b/stdlib/public/SwiftRemoteMirror/CMakeLists.txt index dbd45d8fe3aa6..87a1d7d94717d 100644 --- a/stdlib/public/SwiftRemoteMirror/CMakeLists.txt +++ b/stdlib/public/SwiftRemoteMirror/CMakeLists.txt @@ -1,6 +1,8 @@ # libswiftRemoteMirror.dylib should not have runtime dependencies; it's # always built as a shared library. -add_swift_library(swiftRemoteMirror SHARED TARGET_LIBRARY DONT_EMBED_BITCODE - SwiftRemoteMirror.cpp - LINK_LIBRARIES swiftReflection - INSTALL_IN_COMPONENT stdlib) +if(SWIFT_BUILD_DYNAMIC_STDLIB) + add_swift_library(swiftRemoteMirror SHARED TARGET_LIBRARY DONT_EMBED_BITCODE + SwiftRemoteMirror.cpp + LINK_LIBRARIES swiftReflection + INSTALL_IN_COMPONENT stdlib) +endif() diff --git a/utils/build-script b/utils/build-script index a23b34bb35c06..26c2b3517061f 100755 --- a/utils/build-script +++ b/utils/build-script @@ -364,6 +364,27 @@ class BuildScriptInvocation(object): args.skip_test_tvos = True args.skip_test_watchos = True + # --build-swift-stdlib and --build-swift-sdk-overlay are deprecated + # aliases for --build-swift-{dynamic,static}-stdlib and + # --build-swift-{dynamic,static}-sdk-overlay. The deprecated options + # are None by default, but if specified they take precedence over the + # new, more granular options. + if args.build_swift_stdlib is not None: + if args.build_swift_stdlib: + args.build_swift_dynamic_stdlib = True + args.build_swift_static_stdlib = False + else: + args.build_swift_dynamic_stdlib = False + args.build_swift_static_stdlib = False + + if args.build_swift_sdk_overlay is not None: + if args.build_swift_sdk_overlay: + args.build_swift_dynamic_sdk_overlay = True + args.build_swift_static_sdk_overlay = False + else: + args.build_swift_dynamic_sdk_overlay = False + args.build_swift_static_sdk_overlay = False + # --skip-test-ios is merely a shorthand for host and simulator tests. if args.skip_test_ios: args.skip_test_ios_host = True @@ -636,8 +657,16 @@ class BuildScriptInvocation(object): impl_args += ["--skip-build-libdispatch"] if not args.build_swiftpm: impl_args += ["--skip-build-swiftpm"] + if args.build_swift_dynamic_stdlib: + impl_args += ["--build-swift-dynamic-stdlib"] + if args.build_swift_static_stdlib: + impl_args += ["--build-swift-static-stdlib"] if args.build_swift_stdlib_unittest_extra: impl_args += ["--build-swift-stdlib-unittest-extra"] + if args.build_swift_dynamic_sdk_overlay: + impl_args += ["--build-swift-dynamic-sdk-overlay"] + if args.build_swift_static_sdk_overlay: + impl_args += ["--build-swift-static-sdk-overlay"] if args.skip_build_linux: impl_args += ["--skip-build-linux"] @@ -1507,13 +1536,45 @@ details of the setups of other systems or automated environments.""") help="Use the host compiler, not the self-built one to compile the " "Swift runtime", action=arguments.action.optional_bool) - parser.add_argument( - "--build-swift-stdlib-unittest-extra", - help="Build optional StdlibUnittest components", - action=arguments.action.optional_bool) run_build_group = parser.add_argument_group( title="Run build") + run_build_group.add_argument( + "--build-swift-stdlib", + help="a deprecated alias for '--build-swift-dynamic-stdlib=1 " + "--build-swift-static-stdlib=0'. When specified, this takes " + "precedence over those options", + action=arguments.action.optional_bool, + default=None) + run_build_group.add_argument( + "--build-swift-dynamic-stdlib", + help="build dynamic variants of the Swift standard library", + action=arguments.action.optional_bool, + default=True) + run_build_group.add_argument( + "--build-swift-static-stdlib", + help="build static variants of the Swift standard library", + action=arguments.action.optional_bool) + run_build_group.add_argument( + "--build-swift-sdk-overlay", + help="a deprecated alias for '--build-swift-dynamic-sdk-overlay=1 " + "--build-swift-static-sdk-overlay=0'. When specified, this takes " + "precedence over those options", + action=arguments.action.optional_bool, + default=None) + run_build_group.add_argument( + "--build-swift-dynamic-sdk-overlay", + help="build dynamic variants of the Swift SDK overlay", + action=arguments.action.optional_bool, + default=True) + run_build_group.add_argument( + "--build-swift-static-sdk-overlay", + help="build static variants of the Swift SDK overlay", + action=arguments.action.optional_bool) + run_build_group.add_argument( + "--build-swift-stdlib-unittest-extra", + help="Build optional StdlibUnittest components", + action=arguments.action.optional_bool) run_build_group.add_argument( "-S", "--skip-build", help="generate build directory only without building", diff --git a/utils/build-script-impl b/utils/build-script-impl index 2543c7edce227..e5ab55e3fd2c1 100755 --- a/utils/build-script-impl +++ b/utils/build-script-impl @@ -154,10 +154,11 @@ KNOWN_SETTINGS=( enable-llvm-assertions "1" "set to enable llvm assertions" build-llvm "1" "set to 1 to build LLVM and Clang" build-swift-tools "1" "set to 1 to build Swift host tools" - build-swift-stdlib "1" "set to 1 to build the Swift standard library" + build-swift-dynamic-stdlib "" "set to 1 to build dynamic variants of the Swift standard library" + build-swift-static-stdlib "" "set to 1 to build static variants of the Swift standard library" build-swift-stdlib-unittest-extra "0" "set to 1 to build optional StdlibUnittest components" - build-swift-sdk-overlay "1" "set to 1 to build the Swift SDK overlay" - build-swift-static-stdlib "0" "set to 1 to build static versions of the Swift standard library and SDK overlay" + build-swift-dynamic-sdk-overlay "" "set to 1 to build dynamic variants of the Swift SDK overlay" + build-swift-static-sdk-overlay "" "set to 1 to build static variants of the Swift SDK overlay" build-swift-examples "1" "set to 1 to build examples" build-serialized-stdlib-unittest "0" "set to 1 to build the StdlibUnittest module with -sil-serialize-all" 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 -DSWIFT_NATIVE_CLANG_TOOLS_PATH:STRING="${native_clang_tools_path}" -DSWIFT_NATIVE_SWIFT_TOOLS_PATH:STRING="${native_swift_tools_path}" -DSWIFT_BUILD_TOOLS:BOOL=$(true_false "${BUILD_SWIFT_TOOLS}") - -DSWIFT_BUILD_STDLIB:BOOL=$(true_false "${BUILD_SWIFT_STDLIB}") -DSWIFT_SERIALIZE_STDLIB_UNITTEST:BOOL=$(true_false "${BUILD_SERIALIZED_STDLIB_UNITTEST}") -DSWIFT_STDLIB_SIL_DEBUGGING:BOOL=$(true_false "${BUILD_SIL_DEBUGGING_STDLIB}") -DSWIFT_CHECK_INCREMENTAL_COMPILATION:BOOL=$(true_false "${CHECK_INCREMENTAL_COMPILATION}") - -DSWIFT_BUILD_SDK_OVERLAY:BOOL=$(true_false "${BUILD_SWIFT_SDK_OVERLAY}") + -DSWIFT_BUILD_DYNAMIC_STDLIB:BOOL=$(true_false "${BUILD_SWIFT_DYNAMIC_STDLIB}") -DSWIFT_BUILD_STATIC_STDLIB:BOOL=$(true_false "${BUILD_SWIFT_STATIC_STDLIB}") + -DSWIFT_BUILD_DYNAMIC_SDK_OVERLAY:BOOL=$(true_false "${BUILD_SWIFT_DYNAMIC_SDK_OVERLAY}") + -DSWIFT_BUILD_STATIC_SDK_OVERLAY:BOOL=$(true_false "${BUILD_SWIFT_STATIC_SDK_OVERLAY}") -DSWIFT_BUILD_PERF_TESTSUITE:BOOL=$(true_false "${build_perf_testsuite_this_time}") -DSWIFT_BUILD_EXAMPLES:BOOL=$(true_false "${BUILD_SWIFT_EXAMPLES}") -DSWIFT_INCLUDE_TESTS:BOOL=$(true_false "${build_tests_this_time}")