Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-1738] Allow *only* static libraries to be built #3027

Merged
merged 1 commit into from Jun 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 29 additions & 7 deletions CMakeLists.txt
Expand Up @@ -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)
Expand Down Expand Up @@ -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()

Expand Down
8 changes: 6 additions & 2 deletions cmake/modules/AddSwift.cmake
Expand Up @@ -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(
Expand Down Expand Up @@ -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")
Expand Down
6 changes: 4 additions & 2 deletions stdlib/CMakeLists.txt
Expand Up @@ -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()
Expand Down
8 changes: 5 additions & 3 deletions 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()

Expand Down
10 changes: 6 additions & 4 deletions 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()
69 changes: 65 additions & 4 deletions utils/build-script
Expand Up @@ -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
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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",
Expand Down
12 changes: 7 additions & 5 deletions utils/build-script-impl
Expand Up @@ -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"
Expand Down Expand Up @@ -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}")
Expand Down