Add a 'standalone_minimal' preset to build a minimal, static, OS independent, self-contained binaries of stdlib. (#33286)

This commit is contained in:
Kuba (Brecka) Mracek
2020-08-12 07:28:34 -07:00
committed by GitHub
parent 671be54f25
commit ef89b0dc51
10 changed files with 124 additions and 8 deletions

View File

@@ -131,7 +131,11 @@ function(_add_host_variant_c_compile_flags target)
is_build_type_optimized("${CMAKE_BUILD_TYPE}" optimized)
if(optimized)
if("${CMAKE_BUILD_TYPE}" STREQUAL "MinSizeRel")
target_compile_options(${target} PRIVATE -Os)
else()
target_compile_options(${target} PRIVATE -O2)
endif()
# Omit leaf frame pointers on x86 production builds (optimized, no debug
# info, and no asserts).

View File

@@ -26,6 +26,24 @@ if(swift_build_osx)
configure_target_variant(OSX-R "OS X Release" OSX R "Release")
endif()
is_sdk_requested(FREESTANDING swift_build_freestanding)
if(swift_build_freestanding)
set(SWIFT_FREESTANDING_SDK "" CACHE STRING
"Which SDK to use when building the FREESTANDING stdlib")
set(SWIFT_FREESTANDING_TRIPLE_NAME "" CACHE STRING
"Which triple name (e.g. 'none-macho') to use when building the FREESTANDING stdlib")
set(SWIFT_FREESTANDING_ARCHS "" CACHE STRING
"Which architectures to build when building the FREESTANDING stdlib")
configure_sdk_darwin(
FREESTANDING "FREESTANDING" ""
"${SWIFT_FREESTANDING_SDK}" freestanding "${SWIFT_FREESTANDING_TRIPLE_NAME}" freestanding "${SWIFT_FREESTANDING_ARCHS}")
set(SWIFT_SDK_FREESTANDING_LIB_SUBDIR "freestanding")
configure_target_variant(FREESTANDING-DA "FREESTANDING Debug+Asserts" FREESTANDING DA "Debug+Asserts")
configure_target_variant(FREESTANDING-RA "FREESTANDING Release+Asserts" FREESTANDING RA "Release+Asserts")
configure_target_variant(FREESTANDING-R "FREESTANDING Release" FREESTANDING R "Release")
configure_target_variant(FREESTANDING-S "FREESTANDING MinSizeRelease" FREESTANDING S "MinSizeRelease")
endif()
# Compatible cross-compile SDKS for Darwin OSes: IOS, IOS_SIMULATOR, TVOS,
# TVOS_SIMULATOR, WATCHOS, WATCHOS_SIMULATOR (archs hardcoded below).

View File

@@ -180,7 +180,11 @@ function(_add_target_variant_c_compile_flags)
is_build_type_optimized("${CFLAGS_BUILD_TYPE}" optimized)
if(optimized)
if("${CFLAGS_BUILD_TYPE}" STREQUAL "MinSizeRel")
list(APPEND result "-Os")
else()
list(APPEND result "-O2")
endif()
# Omit leaf frame pointers on x86 production builds (optimized, no debug
# info, and no asserts).

View File

@@ -11,6 +11,21 @@ function(compute_library_subdir result_var_name sdk arch)
endif()
endfunction()
# Return a swiftc flag (e.g. -O or -Onone) to control optimization level based
# on the build type.
function(swift_optimize_flag_for_build_type build_type result_var_name)
if("${build_type}" STREQUAL "Debug")
set("${result_var_name}" "-Onone" PARENT_SCOPE)
elseif("${build_type}" STREQUAL "RelWithDebInfo" OR
"${build_type}" STREQUAL "Release")
set("${result_var_name}" "-O" PARENT_SCOPE)
elseif("${build_type}" STREQUAL "MinSizeRel")
set("${result_var_name}" "-Osize" PARENT_SCOPE)
else()
message(FATAL_ERROR "Unknown build type: ${build_type}")
endif()
endfunction()
# Process the sources within the given variable, pulling out any Swift
# sources to be compiled with 'swift' directly. This updates
# ${sourcesvar} in place with the resulting list and ${externalvar} with the
@@ -230,12 +245,8 @@ function(_add_target_variant_swift_compile_flags
"-F${SWIFT_SDK_${sdk}_ARCH_${arch}_PATH}/../../../Developer/Library/Frameworks")
endif()
is_build_type_optimized("${build_type}" optimized)
if(optimized)
list(APPEND result "-O")
else()
list(APPEND result "-Onone")
endif()
swift_optimize_flag_for_build_type("${CMAKE_BUILD_TYPE}" optimize_flag)
list(APPEND result "${optimize_flag}")
is_build_type_with_debuginfo("${build_type}" debuginfo)
if(debuginfo)

View File

@@ -102,6 +102,7 @@ function(get_test_dependencies SDK result_var_name)
("${SDK}" STREQUAL "IOS_SIMULATOR") OR
("${SDK}" STREQUAL "TVOS_SIMULATOR") OR
("${SDK}" STREQUAL "WATCHOS_SIMULATOR") OR
("${SDK}" STREQUAL "FREESTANDING") OR
("${SDK}" STREQUAL "LINUX") OR
("${SDK}" STREQUAL "CYGWIN") OR
("${SDK}" STREQUAL "FREEBSD") OR

View File

@@ -2365,6 +2365,44 @@ mixin-preset=stdlib_DA_standalone,build
test
validation-test
[preset: stdlib_S_standalone,build]
mixin-preset=stdlib_base_standalone
build-subdir=stdlib_S_standalone
min-size-release
no-assertions
verbose-build
[preset: stdlib_SA_standalone,build]
mixin-preset=stdlib_base_standalone
build-subdir=stdlib_SA_standalone
min-size-release
assertions
verbose-build
[preset: mixin_stdlib_minimal]
enable-experimental-differentiable-programming=0
enable-experimental-concurrency=0
build-swift-dynamic-sdk-overlay=0
build-swift-dynamic-stdlib=0
build-swift-static-stdlib=1
[preset: stdlib_S_standalone_minimal_macho_x86_64,build]
mixin-preset=
stdlib_S_standalone,build
mixin_stdlib_minimal
stdlib-deployment-targets=freestanding-x86_64
swift-primary-variant-sdk=FREESTANDING
swift-primary-variant-arch=x86_64
swift-freestanding-sdk=macosx
# For now, until clang/swiftc works correctly with "none-macho" as the OS part of target triple.
swift-freestanding-triple-name=macosx11.0
swift-freestanding-archs=x86_64
#===----------------------------------------------------------------------===#
# Preset for Source Compatibility Suite
#===----------------------------------------------------------------------===#

View File

@@ -193,6 +193,11 @@ KNOWN_SETTINGS=(
sil-verify-all "0" "If enabled, run the SIL verifier after each transform when building Swift files during this build process"
stdlib-deployment-targets "" "space-separated list of targets to configure the Swift standard library to be compiled or cross-compiled for"
## FREESTANDING Stdlib Options
swift-freestanding-sdk "" "which SDK to use when building the FREESTANDING stdlib"
swift-freestanding-triple-name "" "which triple name (e.g. 'none-macho') to use when building the FREESTANDING stdlib"
swift-freestanding-archs "" "space-separated list of which architectures to build when building the FREESTANDING stdlib"
## Uncategorised
install-prefix "" "installation prefix"
toolchain-prefix "" "the path to the .xctoolchain directory that houses the install prefix path"
@@ -1832,6 +1837,27 @@ for host in "${ALL_HOSTS[@]}"; do
)
fi
if [ "${SWIFT_FREESTANDING_SDK}" ] ; then
cmake_options=(
"${cmake_options[@]}"
-DSWIFT_FREESTANDING_SDK:STRING="${SWIFT_FREESTANDING_SDK}"
)
fi
if [ "${SWIFT_FREESTANDING_TRIPLE_NAME}" ] ; then
cmake_options=(
"${cmake_options[@]}"
-DSWIFT_FREESTANDING_TRIPLE_NAME:STRING="${SWIFT_FREESTANDING_TRIPLE_NAME}"
)
fi
if [[ "${SWIFT_FREESTANDING_ARCHS}" ]] ; then
cmake_options=(
"${cmake_options[@]}"
-DSWIFT_FREESTANDING_ARCHS:STRING="$(join ";" ${SWIFT_FREESTANDING_ARCHS[@]})"
)
fi
if [[ ! "${SKIP_BUILD_LLDB}" ]] ; then
lldb_build_dir=$(build_directory ${host} lldb)
cmake_options=(

View File

@@ -680,6 +680,11 @@ def create_argument_parser():
help='build the Release variant of everything (default is '
'%(default)s)')
option(['--min-size-release'], store('build_variant'),
const='MinSizeRel',
help='build the MinSizeRel variant of everything (default is '
'%(default)s)')
# -------------------------------------------------------------------------
in_group('Override build variant for a specific project')

View File

@@ -412,6 +412,8 @@ EXPECTED_OPTIONS = [
SetOption('--release', dest='build_variant', value='Release'),
SetOption('--release-debuginfo',
dest='build_variant', value='RelWithDebInfo'),
SetOption('--min-size-release',
dest='build_variant', value='MinSizeRel'),
SetOption('--xcode', dest='cmake_generator', value='Xcode'),
SetOption('-R', dest='build_variant', value='Release'),
SetOption('-d', dest='build_variant', value='Debug'),

View File

@@ -179,6 +179,12 @@ class StdlibDeploymentTarget(object):
sdk_name="WATCHOS_SIMULATOR",
is_simulator=True)
# A platform that's not tied to any particular OS, and it meant to be used
# to build the stdlib as standalone and/or statically linked.
Freestanding = Platform("freestanding",
archs=["i386", "x86_64", "armv7", "armv7s", "armv7k",
"arm64", "arm64e"])
Linux = Platform("linux", archs=[
"x86_64",
"i686",
@@ -207,6 +213,7 @@ class StdlibDeploymentTarget(object):
iOS, iOSSimulator,
AppleTV, AppleTVSimulator,
AppleWatch, AppleWatchSimulator,
Freestanding,
Linux,
FreeBSD,
OpenBSD,