Rewrite the CMake build system

Swift SVN r24124
This commit is contained in:
Dmitri Hrybenko
2014-12-23 22:15:30 +00:00
parent 44eec49842
commit 6670bb76ec
86 changed files with 3308 additions and 2685 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,30 +0,0 @@
# Minimal CMake toolchain file for iOS builds.
include(CMakeForceCompiler)
set(CMAKE_SYSTEM_NAME Darwin)
set(CMAKE_SYSTEM_VERSION 13.0) # Pretend to be OS X 10.9
execute_process(COMMAND xcrun -sdk iphoneos -toolchain XcodeDefault -find clang
OUTPUT_VARIABLE cc_path
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND xcrun -sdk iphoneos -toolchain XcodeDefault -find clang++
OUTPUT_VARIABLE cxx_path
OUTPUT_STRIP_TRAILING_WHITESPACE)
if (SWIFT_DISTCC)
set(CMAKE_C_COMPILER_ARG1 "${cc_path}")
set(CMAKE_CXX_COMPILER_ARG1 "${cxx_path}")
# These two calls don't have any effect other than to bypass the
# check for a working compiler (since we're cross-compiling)
CMAKE_FORCE_C_COMPILER("${SWIFT_DISTCC}" Clang)
CMAKE_FORCE_CXX_COMPILER("${SWIFT_DISTCC}" Clang)
else()
CMAKE_FORCE_C_COMPILER("${cc_path}" Clang)
CMAKE_FORCE_CXX_COMPILER("${cxx_path}" Clang)
endif()
set(CXX_SUPPORTS_CXX11 ON FORCE)
# Compiler forcing leaves the compiler version unset, which the llvm
# build machinery doesn't like. Pacify it.
set(LLVM_FORCE_USE_OLD_TOOLCHAIN ON)

View File

@@ -1,30 +0,0 @@
# Minimal CMake toolchain file for iOS simulator builds.
include(CMakeForceCompiler)
set(CMAKE_SYSTEM_NAME Darwin)
set(CMAKE_SYSTEM_VERSION 13.0) # Pretend to be OS X 10.9
execute_process(COMMAND xcrun -sdk iphonesimulator -toolchain XcodeDefault -find clang
OUTPUT_VARIABLE cc_path
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND xcrun -sdk iphonesimulator -toolchain XcodeDefault -find clang++
OUTPUT_VARIABLE cxx_path
OUTPUT_STRIP_TRAILING_WHITESPACE)
if (SWIFT_DISTCC)
set(CMAKE_C_COMPILER_ARG1 "${cc_path}")
set(CMAKE_CXX_COMPILER_ARG1 "${cxx_path}")
# These two calls don't have any effect other than to bypass the
# check for a working compiler (since we're cross-compiling)
CMAKE_FORCE_C_COMPILER("${SWIFT_DISTCC}" Clang)
CMAKE_FORCE_CXX_COMPILER("${SWIFT_DISTCC}" Clang)
else()
CMAKE_FORCE_C_COMPILER("${cc_path}" Clang)
CMAKE_FORCE_CXX_COMPILER("${cxx_path}" Clang)
endif()
set(CXX_SUPPORTS_CXX11 ON FORCE)
# Compiler forcing leaves the compiler version unset, which the llvm
# build machinery doesn't like. Pacify it.
set(LLVM_FORCE_USE_OLD_TOOLCHAIN ON)

View File

@@ -1,18 +0,0 @@
# Minimal CMake toolchain file for OS X builds.
include(CMakeForceCompiler)
set(CMAKE_SYSTEM_NAME Darwin)
execute_process(COMMAND xcrun -sdk macosx -toolchain XcodeDefault -find clang
OUTPUT_VARIABLE cc_path
OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND xcrun -sdk macosx -toolchain XcodeDefault -find clang++
OUTPUT_VARIABLE cxx_path
OUTPUT_STRIP_TRAILING_WHITESPACE)
CMAKE_FORCE_C_COMPILER("${cc_path}" Clang)
CMAKE_FORCE_CXX_COMPILER("${cxx_path}" Clang)
# Compiler forcing leaves the compiler version unset, which the llvm
# build machinery doesn't like. Pacify it.
set(LLVM_FORCE_USE_OLD_TOOLCHAIN ON)

1574
cmake/modules/AddSwift.cmake Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,162 @@
include(CMakeParseArguments)
include(SwiftTranslateFlag)
# Populate the variable 'args' in the parent scope with a keyword
# argument list. We read the variables options, ${k}_keyword, and
# ACCT_${k} from the parent scope, for each ${k} in the list of
# keyword names other than COMMAND accepted by
# add_custom_command_target.
#
# ${k}_keyword must expand to ${k} if ${k} was passed to
# add_custom_command_target, and be empty otherwise.
#
# ACCT_${k} must expand to the list of arguments to
# add_custom_command_target marked by ${k}, and be empty otherwise.
#
function(_make_acct_argument_list)
set(args)
foreach(k ${ARGN})
list(FIND options ${k} option_index)
if(${option_index} EQUAL -1)
list(APPEND args ${${k}_keyword} ${ACCT_${k}})
else()
list(APPEND args ${${k}_keyword})
endif()
endforeach()
set(args ${args} PARENT_SCOPE)
endfunction()
# Add a custom command/target pair. Use this instead of
# add_custom_command because it provides proper dependency tracking
# when used with parallel builds and the 'Unix Makefiles' generator.
# See https://www.cmake.org/Bug/view.php?id=10082
#
# The CMake documentation for add_custom_command quoth,
#
# "Do not list the output in more than one independent target that
# may build in parallel or the two instances of the rule may
# conflict (instead use add_custom_target to drive the command and
# make the other targets depend on that one)."
#
# This function implements the suggested pattern.
#
# add_custom_command_target(
# dependency_out_var_name
#
# COMMAND command1 [ARGS] [args1...]
# [COMMAND command2 [ARGS] [args2...] ...]
#
# OUTPUT output1 [output2 ...]
# [MAIN_DEPENDENCY depend]
# [DEPENDS [depends...]]
# [IMPLICIT_DEPENDS <lang1> depend1
# [<lang2> depend2] ...]
# [WORKING_DIRECTORY dir]
# [COMMENT comment] [VERBATIM] [APPEND]
# [ALL]
# [SOURCES src1 [src2...]])
#
# dependency_out_var_name is the name of a variable, to be set in the
# parent scope with the name of a target that all targets using the
# OUTPUT should depend on. For example:
#
# add_custom_command_target(
# TheDependency
# COMMAND echo "int main() {}" ">" z.c
# OUTPUT z.c
# VERBATIM
# DEPENDS z.c.gyb)
#
# add_executable(exe1 z.c)
# add_dependencies(exe1 ${TheDependency})
# add_executable(exe2 z.c)
# add_dependencies(exe2 ${TheDependency})
#
# **Note1**: all COMMAND arguments must immediately follow
# dependency_out_var_name or this function will misbehave.
#
# **Note2**: any subdirectories that define targets dependent on
# OUTPUT ${o} should invoke:
#
# set_source_files_properties(${o} PROPERTIES GENERATED true)
#
# All arguments other than ALL, SOURCES, and dependency_out_var_name
# are forwarded to add_custom_command; arguments ALL, SOURCES, and
# WORKING_DIRECTORY are forwarded to add_custom_target. See the
# documentation of those functions for a description of all arguments.
#
# How This Function Works
#
# CMake offers one way to add new build rules: add_custom_command.
# Most people, however, overlook its actual semantics.
# add_custom_command does *not* create a target. The CMake
# documentation declareth,
#
# "A target created in the same directory (CMakeLists.txt file) that
# specifies any output of the custom command as a source file is
# given a rule to generate the file using the command at build
# time."
#
# Therefore, when two targets built in parallel depend on an output of
# the same custom command, they may race to rebuild that output.
# Hilarity ensues. You might not notice this effect depending on the
# generator you use, but it happens with 'Unix Makefiles'.
#
# By injecting a target into the dependency graph between the custom
# command output and any targets that depend on that output, we force
# the output to be built before starting on any of its dependent
# targets.
function(add_custom_command_target dependency_out_var_name)
# Parse the arguments. We don't look for COMMAND arguments because
# they don't follow the pattern supported by cmake_parse_arguments.
# As a result, they end up in ACCT_UNPARSED_ARGUMENTS and are
# forwarded verbatim.
set(options ALL VERBATIM APPEND IDEMPOTENT)
set(single_value_args
MAIN_DEPENDENCY WORKING_DIRECTORY COMMENT CUSTOM_TARGET_NAME)
set(multi_value_args OUTPUT DEPENDS IMPLICIT_DEPENDS SOURCES)
cmake_parse_arguments(
ACCT # prefix
"${options}" "${single_value_args}" "${multi_value_args}" ${ARGN})
set(ACCT_COMMANDS ${ACCT_UNPARSED_ARGUMENTS})
if("${ACCT_CUSTOM_TARGET_NAME}" STREQUAL "")
# Construct a unique name for the custom target.
# Use a hash so that the file name does not push the OS limits for filename
# length.
list(GET ACCT_OUTPUT 0 output_filename)
string(MD5 ACCT_CUSTOM_TARGET_NAME
"add_custom_command_target${CMAKE_CURRENT_BINARY_DIR}/${output_filename}")
get_filename_component(output_filename_basename "${output_filename}" NAME)
set(ACCT_CUSTOM_TARGET_NAME
"add_custom_command_target-${ACCT_CUSTOM_TARGET_NAME}-${output_filename_basename}")
endif()
if((NOT ACCT_IDEMPOTENT) OR
(ACCT_IDEMPOTENT AND NOT TARGET "${ACCT_CUSTOM_TARGET_NAME}"))
# For each keyword argument k that was passed to this function, set
# ${k}_keyword to ${k}. That will allow us to use the incantation
# '${${k}_keyword} ${ACCT_${k}}' to forward the arguments on.
foreach(var ${options} ${single_value_args} ${multi_value_args})
translate_flag(ACCT_${var} ${var} ${var}_keyword)
endforeach()
_make_acct_argument_list(
OUTPUT MAIN_DEPENDENCY DEPENDS
IMPLICIT_DEPENDS WORKING_DIRECTORY COMMENT VERBATIM APPEND)
add_custom_command(${ACCT_COMMANDS} ${args})
_make_acct_argument_list(ALL WORKING_DIRECTORY SOURCES)
add_custom_target(
"${ACCT_CUSTOM_TARGET_NAME}" ${args}
DEPENDS ${ACCT_OUTPUT}
COMMENT "${ACCT_OUTPUT}")
set_target_properties(
"${ACCT_CUSTOM_TARGET_NAME}" PROPERTIES
FOLDER "add_custom_command_target artifacts")
endif()
# "Return" the name of the custom target
set("${dependency_out_var_name}" "${ACCT_CUSTOM_TARGET_NAME}" PARENT_SCOPE)
endfunction()

View File

@@ -0,0 +1,9 @@
function(apply_xcode_substitutions config path result_var_name)
# Hack to deal with the fact that paths contain the build-time
# variables. Note that this fix is Xcode-specific.
string(REPLACE "$(CONFIGURATION)" "${config}" result "${path}")
string(REPLACE "$(EFFECTIVE_PLATFORM_NAME)" "" result "${result}")
set("${result_var_name}" "${result}" PARENT_SCOPE)
endfunction()

View File

@@ -0,0 +1,25 @@
function(is_build_type_optimized build_type result_var_name)
if("${build_type}" STREQUAL "Debug")
set("${result_var_name}" FALSE PARENT_SCOPE)
elseif("${build_type}" STREQUAL "RelWithDebInfo" OR
"${build_type}" STREQUAL "Release" OR
"${build_type}" STREQUAL "MinSizeRel")
set("${result_var_name}" TRUE PARENT_SCOPE)
else()
message(FATAL_ERROR "Unknown build type: ${build_type}")
endif()
endfunction()
function(is_build_type_with_debuginfo build_type result_var_name)
if("${build_type}" STREQUAL "Debug" OR
"${build_type}" STREQUAL "RelWithDebInfo")
set("${result_var_name}" TRUE PARENT_SCOPE)
elseif("${build_type}" STREQUAL "Release" OR
"${build_type}" STREQUAL "MinSizeRel")
set("${result_var_name}" FALSE PARENT_SCOPE)
else()
message(FATAL_ERROR "Unknown build type: ${build_type}")
endif()
endfunction()

View File

@@ -0,0 +1,149 @@
# Variable that tracks the set of configured SDKs.
#
# Each element in this list is an SDK for which the various
# SWIFT_SDK_${name}_* variables are defined. Swift libraries will be
# built for each variant.
set(SWIFT_CONFIGURED_SDKS)
# Report the given SDK to the user.
function(_report_sdk prefix)
message(STATUS "${SWIFT_SDK_${prefix}_NAME} SDK:")
message(STATUS " Path: ${SWIFT_SDK_${prefix}_PATH}")
message(STATUS " Version: ${SWIFT_SDK_${prefix}_VERSION}")
message(STATUS " Deployment version: ${SWIFT_SDK_${prefix}_DEPLOYMENT_VERSION}")
message(STATUS " Library subdir: ${SWIFT_SDK_${prefix}_LIB_SUBDIR}")
message(STATUS " Version min name: ${SWIFT_SDK_${prefix}_VERSION_MIN_NAME}")
message(STATUS " Triple name: ${SWIFT_SDK_${prefix}_TRIPLE_NAME}")
message(STATUS " Architectures: ${SWIFT_SDK_${prefix}_ARCHITECTURES}")
foreach(arch ${SWIFT_SDK_${prefix}_ARCHITECTURES})
message(STATUS
" Triple for ${arch} is ${SWIFT_SDK_${prefix}_ARCH_${arch}_TRIPLE}")
endforeach()
message(STATUS "")
endfunction()
# Configure an SDK
#
# Usage:
# configure_sdk_darwin(
# prefix # Prefix to use for SDK variables (e.g., OSX)
# name # Display name for this SDK
# deployment_version # Deployment version
# xcrun_name # SDK name to use with xcrun
# version_min_name # The name used in the -mOS-version-min flag
# triple_name # The name used in Swift's -triple
# architectures # A list of architectures this SDK supports
# internal # Whether the prefer the internal SDK, if present
# )
#
# Sadly there are three OS naming conventions.
# xcrun SDK name: macosx iphoneos iphonesimulator (+ "internal" or version)
# -mOS-version-min: macosx ios ios-simulator
# swift -triple: macosx ios ios
#
# This macro attempts to configure a given SDK. When successful, it
# defines a number of variables:
#
# SWIFT_SDK_${prefix}_NAME Display name for the SDK
# SWIFT_SDK_${prefix}_PATH Path to the SDK
# SWIFT_SDK_${prefix}_VERSION SDK version number (e.g., 10.9, 7.0)
# SWIFT_SDK_${prefix}_DEPLOYMENT_VERSION Deployment version (e.g., 10.9, 7.0)
# SWIFT_SDK_${prefix}_LIB_SUBDIR Library subdir for this SDK
# SWIFT_SDK_${prefix}_VERSION_MIN_NAME Version min name for this SDK
# SWIFT_SDK_${prefix}_TRIPLE_NAME Triple name for this SDK
# SWIFT_SDK_${prefix}_ARCHITECTURES Architectures (as a list)
# SWIFT_SDK_${prefix}_ARCH_${ARCH}_TRIPLE Triple name
macro(configure_sdk_darwin
prefix name deployment_version xcrun_name
version_min_name triple_name architectures internal)
# Note: this has to be implemented as a macro because it sets global
# variables.
# Find the SDK
set(SWIFT_SDK_${prefix}_PATH "" CACHE PATH "Path to the ${name} SDK")
if(NOT SWIFT_SDK_${prefix}_PATH)
if(${internal})
execute_process(
COMMAND "xcrun" "--sdk" "${xcrun_name}.internal" "--show-sdk-path"
OUTPUT_VARIABLE SWIFT_SDK_${prefix}_PATH
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
endif()
if(NOT SWIFT_SDK_${prefix}_PATH)
execute_process(
COMMAND "xcrun" "--sdk" "${xcrun_name}" "--show-sdk-path"
OUTPUT_VARIABLE SWIFT_SDK_${prefix}_PATH
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
if(NOT EXISTS "${SWIFT_SDK_${prefix}_PATH}/System/Library/Frameworks/module.map")
message(FATAL_ERROR "${name} SDK not found at SWIFT_SDK_${prefix}_PATH.")
endif()
# Determine the SDK version we found.
string(REGEX MATCH "/[A-Za-z]+[0-9]+\\.[0-9]+(\\.Internal)?\\.sdk"
SCRATCH ${SWIFT_SDK_${prefix}_PATH})
string(REGEX MATCH "[0-9]+\\.[0-9]+"
SWIFT_SDK_${prefix}_VERSION ${SCRATCH})
# Set other variables.
set(SWIFT_SDK_${prefix}_NAME "${name}")
set(SWIFT_SDK_${prefix}_DEPLOYMENT_VERSION "${deployment_version}")
set(SWIFT_SDK_${prefix}_LIB_SUBDIR "${xcrun_name}")
set(SWIFT_SDK_${prefix}_VERSION_MIN_NAME "${version_min_name}")
set(SWIFT_SDK_${prefix}_TRIPLE_NAME "${triple_name}")
set(SWIFT_SDK_${prefix}_ARCHITECTURES "${architectures}")
foreach(arch ${architectures})
set(SWIFT_SDK_${prefix}_ARCH_${arch}_TRIPLE
"${arch}-apple-${SWIFT_SDK_${prefix}_TRIPLE_NAME}${SWIFT_SDK_${prefix}_DEPLOYMENT_VERSION}")
endforeach()
# Add this to the list of known SDKs.
list(APPEND SWIFT_CONFIGURED_SDKS "${prefix}")
_report_sdk("${prefix}")
endmacro()
macro(configure_sdk_unix
prefix name lib_subdir triple_name arch triple)
# Note: this has to be implemented as a macro because it sets global
# variables.
set(SWIFT_SDK_${prefix}_NAME "${name}")
set(SWIFT_SDK_${prefix}_PATH "/")
set(SWIFT_SDK_${prefix}_VERSION "don't use")
set(SWIFT_SDK_${prefix}_DEPLOYMENT_VERSION "don't use")
set(SWIFT_SDK_${prefix}_LIB_SUBDIR "${lib_subdir}")
set(SWIFT_SDK_${prefix}_VERSION_MIN_NAME "")
set(SWIFT_SDK_${prefix}_TRIPLE_NAME "${triple_name}")
set(SWIFT_SDK_${prefix}_ARCHITECTURES "${arch}")
set(SWIFT_SDK_${prefix}_ARCH_${arch}_TRIPLE "${triple}")
# Add this to the list of known SDKs.
list(APPEND SWIFT_CONFIGURED_SDKS "${prefix}")
_report_sdk("${prefix}")
endmacro()
# Configure a variant of a certain SDK
#
# In addition to the SDK and architecture, a variant determines build settings.
#
# FIXME: this is not wired up with anything yet.
function(configure_target_variant prefix name sdk build_config lib_subdir)
set(SWIFT_VARIANT_${prefix}_NAME ${name})
set(SWIFT_VARIANT_${prefix}_SDK_PATH ${SWIFT_SDK_${sdk}_PATH})
set(SWIFT_VARIANT_${prefix}_VERSION ${SWIFT_SDK_${sdk}_VERSION})
set(SWIFT_VARIANT_${prefix}_DEPLOYMENT_VERSION ${SWIFT_SDK_${sdk}_DEPLOYMENT_VERSION})
set(SWIFT_VARIANT_${prefix}_LIB_SUBDIR "${lib_subdir}/${SWIFT_SDK_${sdk}_LIB_SUBDIR}")
set(SWIFT_VARIANT_${prefix}_VERSION_MIN_NAME ${SWIFT_SDK_${sdk}_VERSION_MIN_NAME})
set(SWIFT_VARIANT_${prefix}_TRIPLE_NAME ${SWIFT_SDK_${sdk}_TRIPLE_NAME})
set(SWIFT_VARIANT_${prefix}_ARCHITECTURES ${SWIFT_SDK_${sdk}_ARCHITECTURES})
endfunction()

View File

@@ -0,0 +1,13 @@
# On Darwin platforms that have xcrun, returns the path to the
# default toolchain directory.
function(get_default_toolchain_dir result_var_name)
execute_process(
COMMAND "xcrun" "--toolchain" "default" "--find" "clang"
OUTPUT_VARIABLE toolchain_dir
OUTPUT_STRIP_TRAILING_WHITESPACE)
get_filename_component(toolchain_dir "${toolchain_dir}" PATH)
get_filename_component(toolchain_dir "${toolchain_dir}" PATH)
get_filename_component(toolchain_dir "${toolchain_dir}" PATH)
set("${result_var_name}" "${toolchain_dir}" PARENT_SCOPE)
endfunction()

View File

@@ -0,0 +1,8 @@
function(swift_get_configuration_types result_var_name)
if(CMAKE_CONFIGURATION_TYPES)
set("${result_var_name}" "${CMAKE_CONFIGURATION_TYPES}" PARENT_SCOPE)
else()
set("${result_var_name}" "." PARENT_SCOPE)
endif()
endfunction()

View File

@@ -0,0 +1,69 @@
include(SwiftAddCustomCommandTarget)
include(SwiftSetIfArchBitness)
# Create a target to process .gyb files with the 'gyb' tool.
#
# handle_gyb_sources(
# dependency_out_var_name
# sources_var_name
# arch)
#
# Replace, in ${sources_var_name}, the given .gyb-suffixed sources with
# their un-suffixed intermediate files, which will be generated by processing
# the .gyb files with gyb.
#
# dependency_out_var_name
# The name of a variable, to be set in the parent scope to the list of
# targets that invoke gyb. Every target that depends on the generated
# sources should depend on ${dependency_out_var_name} targets.
#
# arch
# The architecture that the files will be compiled for.
function(handle_gyb_sources dependency_out_var_name sources_var_name arch)
set_if_arch_bitness(ptr_size
ARCH "${arch}"
CASE_32_BIT "4"
CASE_64_BIT "8")
set(gyb_flags
"--test" # Run gyb's self-tests whenever we use it. They're cheap
# enough and it keeps us honest.
${SWIFT_GYB_FLAGS}
"-DCMAKE_SIZEOF_VOID_P=${ptr_size}")
set(dependency_targets)
set(de_gybbed_sources)
set(gyb_sources)
set(gyb_tool "${SWIFT_SOURCE_DIR}/utils/gyb")
set(gyb_extra_sources "${SWIFT_SOURCE_DIR}/utils/GYBUnicodeDataUtils.py")
foreach (src ${${sources_var_name}})
string(REGEX REPLACE "[.]gyb$" "" src_sans_gyb "${src}")
if(src STREQUAL src_sans_gyb)
list(APPEND de_gybbed_sources "${src}")
else()
set(dir "${CMAKE_CURRENT_BINARY_DIR}/${ptr_size}")
set(output_file_name "${dir}/${src_sans_gyb}")
list(APPEND de_gybbed_sources "${output_file_name}")
string(MD5 output_file_name_hash "${output_file_name}")
add_custom_command_target(
dependency_target
COMMAND
"${CMAKE_COMMAND}" -E make_directory "${dir}"
COMMAND
"${gyb_tool}" "${gyb_flags}" -o "${output_file_name}.tmp" "${src}"
COMMAND
"${CMAKE_COMMAND}" -E copy_if_different "${output_file_name}.tmp" "${output_file_name}"
COMMAND
"${CMAKE_COMMAND}" -E remove "${output_file_name}.tmp"
OUTPUT "${output_file_name}"
DEPENDS "${gyb_tool}" "${src}" "${gyb_extra_sources}"
COMMENT "Generating ${src_sans_gyb} from ${src} with ptr size = ${ptr_size}"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
IDEMPOTENT)
list(APPEND dependency_targets "${dependency_target}")
endif()
endforeach()
set("${dependency_out_var_name}" "${dependency_targets}" PARENT_SCOPE)
set("${sources_var_name}" "${de_gybbed_sources}" PARENT_SCOPE)
endfunction()

View File

@@ -0,0 +1,54 @@
function(swift_is_installing_component component result_var_name)
if("${component}" STREQUAL "")
message(FATAL_ERROR "Component name is required")
endif()
if("${component}" STREQUAL "never_install")
set("${result_var_name}" FALSE PARENT_SCOPE)
else()
list(FIND _SWIFT_KNOWN_INSTALL_COMPONENTS "${component}" index)
if(${index} EQUAL -1)
message(FATAL_ERROR "unknown install component: ${component}")
endif()
string(TOUPPER "${component}" var_name_piece)
string(REPLACE "-" "_" var_name_piece "${var_name_piece}")
set("${result_var_name}" "${SWIFT_INSTALL_${var_name_piece}}" PARENT_SCOPE)
endif()
endfunction()
# swift_install_in_component(<COMPONENT NAME>
# <same parameters as install()>)
#
# Executes the specified installation actions if the named component is
# requested to be installed.
#
# This function accepts the same parameters as install().
function(swift_install_in_component component)
if("${component}" STREQUAL "")
message(FATAL_ERROR "Component name is required")
endif()
swift_is_installing_component("${component}" is_installing)
if(is_installing)
install(${ARGN})
endif()
endfunction()
macro(swift_configure_install_components install_components)
foreach(component ${_SWIFT_KNOWN_INSTALL_COMPONENTS})
string(TOUPPER "${component}" var_name_piece)
string(REPLACE "-" "_" var_name_piece "${var_name_piece}")
set(SWIFT_INSTALL_${var_name_piece} FALSE)
endforeach()
foreach(component ${install_components})
list(FIND _SWIFT_KNOWN_INSTALL_COMPONENTS "${component}" index)
if(${index} EQUAL -1)
message(FATAL_ERROR "unknown install component: ${component}")
endif()
string(TOUPPER "${component}" var_name_piece)
string(REPLACE "-" "_" var_name_piece "${var_name_piece}")
set(SWIFT_INSTALL_${var_name_piece} TRUE)
endforeach()
endmacro()

View File

@@ -0,0 +1,22 @@
function(list_subtract lhs rhs result_var_name)
set(result)
foreach(item IN LISTS lhs)
list(FIND rhs "${item}" index)
if(${index} EQUAL -1)
list(APPEND result "${item}")
endif()
endforeach()
set("${result_var_name}" "${result}" PARENT_SCOPE)
endfunction()
function(list_intersect lhs rhs result_var_name)
set(result)
foreach(item IN LISTS lhs)
list(FIND rhs "${item}" index)
if(NOT ${index} EQUAL -1)
list(APPEND result "${item}")
endif()
endforeach()
set("${result_var_name}" "${result}" PARENT_SCOPE)
endfunction()

View File

@@ -0,0 +1,45 @@
include(CMakeParseArguments)
find_program(POD2MAN pod2man)
# Create a target to create a man page from a pod file.
#
# manpage(
# SOURCE foobar.pod
# PAGE_HEADER "text"
# MAN_FILE_BASENAME foobar
# MAN_SECTION N
# INSTALL_IN_COMPONENT comp
# )
function(manpage)
cmake_parse_arguments(
MP # prefix
"" # options
"SOURCE;PAGE_HEADER;MAN_FILE_BASENAME;MAN_SECTION;INSTALL_IN_COMPONENT" # single-value args
"" # multi-value args
${ARGN})
if(NOT POD2MAN)
message(FATAL_ERROR "Need pod2man installed to generate man page")
endif()
set(output_file_name
"${CMAKE_CURRENT_BINARY_DIR}/${MP_MAN_FILE_BASENAME}.${MP_MAN_SECTION}")
add_custom_command_target(
unused_var
COMMAND
"${POD2MAN}" "--section" "${MP_MAN_SECTION}"
"--center" "${MP_PAGE_HEADER}" "--release"
"--name" "${MP_MAN_FILE_BASENAME}"
"--stderr"
"${MP_SOURCE}" > "${output_file_name}"
OUTPUT "${output_file_name}"
DEPENDS "${MP_SOURCE}"
ALL)
swift_install_in_component("${MP_INSTALL_IN_COMPONENT}"
FILES "${output_file_name}"
DESTINATION "share/man/man${MP_MAN_SECTION}")
endfunction()

View File

@@ -0,0 +1,19 @@
function(set_if_arch_bitness var_name)
cmake_parse_arguments(
SIA # prefix
"" # options
"ARCH;CASE_32_BIT;CASE_64_BIT" # single-value args
"" # multi-value args
${ARGN})
if("${SIA_ARCH}" STREQUAL "i386" OR
"${SIA_ARCH}" STREQUAL "armv7")
set("${var_name}" "${SIA_CASE_32_BIT}" PARENT_SCOPE)
elseif("${SIA_ARCH}" STREQUAL "x86_64" OR
"${SIA_ARCH}" STREQUAL "arm64")
set("${var_name}" "${SIA_CASE_64_BIT}" PARENT_SCOPE)
else()
message(FATAL_ERROR "Unknown architecture: ${SIA_ARCH}")
endif()
endfunction()

View File

@@ -0,0 +1,22 @@
# Translate a yes/no variable to the presence of a given string in a
# variable.
#
# Usage:
# translate_flag(is_set flag_name var_name)
#
# If is_set is true, sets ${var_name} to ${flag_name}. Otherwise,
# unsets ${var_name}.
function(translate_flag is_set flag_name var_name)
if(${is_set})
set("${var_name}" "${flag_name}" PARENT_SCOPE)
else()
set("${var_name}" "" PARENT_SCOPE)
endif()
endfunction()
macro(translate_flags prefix options)
foreach(var ${options})
translate_flag("${${prefix}_${var}}" "${var}" "${prefix}_${var}_keyword")
endforeach()
endmacro()

View File

@@ -22,20 +22,18 @@ if(SPHINX_EXECUTABLE)
COMMENT "Building HTML documentation") COMMENT "Building HTML documentation")
# Selectively install docs intended for general consumption. # Selectively install docs intended for general consumption.
install( swift_install_in_component(lang-docs
FILES FILES "${CMAKE_BINARY_DIR}/docs/html/LangRef.html"
${CMAKE_BINARY_DIR}/docs/html/LangRef.html DESTINATION "share/swift/docs/html")
DESTINATION share/swift/docs/html)
install( swift_install_in_component(lang-docs
DIRECTORY DIRECTORY
${CMAKE_BINARY_DIR}/docs/html/_static "${CMAKE_BINARY_DIR}/docs/html/_static"
${CMAKE_BINARY_DIR}/docs/html/whitepaper "${CMAKE_BINARY_DIR}/docs/html/whitepaper"
DESTINATION share/swift/docs/html) DESTINATION "share/swift/docs/html")
else()
else(SPHINX_EXECUTABLE)
message(WARNING "Unable to find sphinx-build program. Not building docs") message(WARNING "Unable to find sphinx-build program. Not building docs")
endif(SPHINX_EXECUTABLE) endif()
## Example testing ## Example testing
@@ -98,21 +96,20 @@ if(LITRE_EXECUTABLE)
# Only update the real top-level CMakeLists.txt if something changed # Only update the real top-level CMakeLists.txt if something changed
add_custom_command( add_custom_command(
OUTPUT OUTPUT
litre-tests/CMakeLists.txt "litre-tests/CMakeLists.txt"
COMMAND COMMAND
${CMAKE_COMMAND} -E copy_if_different litre-top-CMakeLists.cmake litre-tests/CMakeLists.txt "${CMAKE_COMMAND}" "-E" "copy_if_different"
"litre-top-CMakeLists.cmake" "litre-tests/CMakeLists.txt"
DEPENDS DEPENDS
litre-top-CMakeLists.cmake "litre-top-CMakeLists.cmake"
COMMENT COMMENT
"Updating top-level LitRe CMakeLists.txt" "Updating top-level LitRe CMakeLists.txt"
VERBATIM VERBATIM)
)
# Create a build directory # Create a build directory
add_custom_command( add_custom_command(
OUTPUT litre-tests/build OUTPUT "litre-tests/build"
COMMAND ${CMAKE_COMMAND} -E make_directory litre-tests/build COMMAND "${CMAKE_COMMAND}" "-E" "make_directory" "litre-tests/build")
)
# Run CMake itself to configure/build the tests # Run CMake itself to configure/build the tests
add_custom_command( add_custom_command(
@@ -184,13 +181,12 @@ if (DOXYGEN_FOUND)
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating swift doxygen documentation." VERBATIM) COMMENT "Generating swift doxygen documentation." VERBATIM)
if (LLVM_BUILD_DOCS) if(LLVM_BUILD_DOCS)
add_dependencies(doxygen doxygen-swift) add_dependencies(doxygen doxygen-swift)
endif() endif()
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) swift_install_in_component(dev
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/doxygen/html DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/doxygen/html"
DESTINATION docs/html) DESTINATION "docs/html")
endif()
endif() endif()
endif() endif()

View File

@@ -1 +1,9 @@
manpage("${CMAKE_CURRENT_SOURCE_DIR}/swift.pod" "Swift Documentation" swift 1) include(SwiftManpage)
manpage(
SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/swift.pod"
PAGE_HEADER "Swift Documentation"
MAN_FILE_BASENAME swift
MAN_SECTION 1
INSTALL_IN_COMPONENT compiler)

View File

@@ -34,13 +34,34 @@ add_swift_library(swiftAST
TypeWalker.cpp TypeWalker.cpp
USRGeneration.cpp USRGeneration.cpp
Verifier.cpp Verifier.cpp
DEPENDS swiftBasic swiftReST LINK_LIBRARIES
clangIndex swiftReST
clangFormat swiftBasic
clangToolingCore
LLVMCore
)
if( NOT SWIFT_BUILT_STANDALONE ) # Clang dependencies.
# FIXME: Clang should really export these in some reasonable manner.
clangIndex
clangFormat
clangToolingCore
clangFrontendTool
clangFrontend
clangDriver
clangSerialization
clangParse
clangSema
clangAnalysis
clangEdit
clangRewriteFrontend
clangRewrite
clangAST
clangLex
clangAPINotes
clangBasic)
llvm_config(swiftAST
profiledata object mc mcparser bitreader option core support)
if(NOT SWIFT_BUILT_STANDALONE)
add_dependencies(swiftAST intrinsics_gen) add_dependencies(swiftAST intrinsics_gen)
endif() endif()

View File

@@ -1,4 +1,4 @@
add_swift_library(swiftASTSectionImporter add_swift_library(swiftASTSectionImporter
ASTSectionImporter.cpp ASTSectionImporter.cpp
DEPENDS swiftBasic LLVMCore) LINK_LIBRARIES swiftBasic LLVMCore)

View File

@@ -1,7 +1,5 @@
find_package(UUID REQUIRED) find_package(UUID REQUIRED)
set(UNICODE_TABLES UnicodeExtendedGraphemeClusters.cpp.gyb)
add_swift_library(swiftBasic add_swift_library(swiftBasic
Cache.cpp Cache.cpp
Demangle.cpp Demangle.cpp
@@ -31,11 +29,10 @@ add_swift_library(swiftBasic
# Platform-agnostic fallback TaskQueue implementation # Platform-agnostic fallback TaskQueue implementation
Default/TaskQueue.inc Default/TaskQueue.inc
${UNICODE_TABLES} UnicodeExtendedGraphemeClusters.cpp.gyb
C_COMPILE_FLAGS "-I${UUID_INCLUDE_DIRS}" C_COMPILE_FLAGS "-I${UUID_INCLUDE_DIRS}"
DEPENDS ${UUID_LIBRARIES} LINK_LIBRARIES ${UUID_LIBRARIES})
)
set(SWIFT_VERSION "1.1") set(SWIFT_VERSION "1.1")
message(STATUS "Swift version: ${SWIFT_VERSION}") message(STATUS "Swift version: ${SWIFT_VERSION}")

View File

@@ -31,5 +31,8 @@ StringRef swift::getPlatformNameForTriple(const llvm::Triple &triple) {
if (triple.isMacOSX()) if (triple.isMacOSX())
return "macosx"; return "macosx";
if (triple.isOSLinux())
return "linux";
return ""; return "";
} }

View File

@@ -4,31 +4,6 @@ add_swift_library(swiftClangImporter
ImportDecl.cpp ImportDecl.cpp
ImportMacro.cpp ImportMacro.cpp
ImportType.cpp ImportType.cpp
DEPENDS swiftAST) LINK_LIBRARIES
swiftAST)
# Clang dependencies.
# FIXME: Clang should really export these in some reasonable manner.
target_link_libraries(swiftClangImporter
clangIndex
clangFormat
clangToolingCore
clangFrontendTool
clangFrontend
clangDriver
clangSerialization
clangParse
clangSema
clangAnalysis
clangEdit
clangRewriteFrontend
clangRewrite
clangAST
clangLex
clangAPINotes
clangBasic
LLVMBitReader
LLVMMC
LLVMMCParser
LLVMOption
LLVMTransformUtils
LLVMSupport)

View File

@@ -13,4 +13,5 @@ add_swift_library(swiftDriver
ToolChains.cpp ToolChains.cpp
Types.cpp Types.cpp
Util.cpp Util.cpp
DEPENDS swiftAST swiftBasic swiftFrontend swiftOption) DEPENDS SwiftOptions
LINK_LIBRARIES swiftAST swiftBasic swiftFrontend swiftOption)

View File

@@ -684,7 +684,9 @@ Job *linux::Linker::constructJob(const JobAction &JA,
// Add the linker script that coalesces protocol conformance sections. // Add the linker script that coalesces protocol conformance sections.
Arguments.push_back("-Xlinker"); Arguments.push_back("-Xlinker");
Arguments.push_back("-Tswift.ld"); Arguments.push_back("-T");
Arguments.push_back(
Args.MakeArgString(Twine(RuntimeLibPath) + "/linux/x86_64/swift.ld"));
// This should be the last option, for convenience in checking output. // This should be the last option, for convenience in checking output.
Arguments.push_back("-o"); Arguments.push_back("-o");

View File

@@ -6,4 +6,11 @@ add_swift_library(swiftFrontend
FrontendOptions.cpp FrontendOptions.cpp
PrintingDiagnosticConsumer.cpp PrintingDiagnosticConsumer.cpp
SerializedDiagnosticConsumer.cpp SerializedDiagnosticConsumer.cpp
DEPENDS swiftAST swiftOption swiftParse swiftSema swiftSerialization swiftSIL) DEPENDS SwiftOptions
LINK_LIBRARIES
swiftSIL
swiftOption
swiftParse
swiftSema
swiftSerialization)

View File

@@ -1,9 +1,11 @@
add_swift_library(functionNameDemangle SHARED add_swift_library(functionNameDemangle SHARED
FunctionNameDemangle.cpp FunctionNameDemangle.cpp
MangleHack.cpp MangleHack.cpp
DEPENDS swiftBasic LINK_LIBRARIES swiftBasic
COMPONENT_DEPENDS support) COMPONENT_DEPENDS support)
install(TARGETS functionNameDemangle swift_install_in_component(compiler
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX} TARGETS functionNameDemangle
ARCHIVE DESTINATION lib${LLVM_LIBDIR_SUFFIX}) LIBRARY DESTINATION "lib${LLVM_LIBDIR_SUFFIX}"
ARCHIVE DESTINATION "lib${LLVM_LIBDIR_SUFFIX}")

View File

@@ -6,7 +6,9 @@ add_swift_library(swiftIDE
SourceEntityWalker.cpp SourceEntityWalker.cpp
SyntaxModel.cpp SyntaxModel.cpp
Utils.cpp Utils.cpp
DEPENDS LINK_LIBRARIES
swiftAST swiftParse swiftSema swiftClangImporter swiftClangImporter
) swiftParse
swiftSema
swiftAST)

View File

@@ -27,11 +27,14 @@ add_swift_library(swiftIRGen
SwiftTargetInfo.cpp SwiftTargetInfo.cpp
StructLayout.cpp StructLayout.cpp
UnimplementedTypeInfo.cpp UnimplementedTypeInfo.cpp
DEPENDS LLVMMC LLVMProfileData LLVMSupport LLVMCore LLVMObjCARCOpts LINK_LIBRARIES
swiftAST swiftLLVMPasses) swiftAST
swiftLLVMPasses
# Clang dependencies. # Clang dependencies.
# FIXME: Clang should really export these in some reasonable manner. # FIXME: Clang should really export these in some reasonable manner.
target_link_libraries(swiftIRGen clangCodeGen)
clangCodeGen)
llvm_config(swiftIRGen
profiledata)

View File

@@ -1,5 +1,7 @@
add_swift_library(swiftImmediate add_swift_library(swiftImmediate
Helpers.cpp Helpers.cpp
Immediate.cpp Immediate.cpp
DEPENDS swiftBasic swiftAST swiftFrontend swiftParse swiftIDE swiftSIL LINK_LIBRARIES
swiftSILPasses swiftIRGen) swiftFrontend swiftParse swiftIDE swiftSILGen
swiftSILPasses swiftIRGen)

View File

@@ -1,5 +1,6 @@
add_swift_library(swiftOption add_swift_library(swiftOption
Options.cpp Options.cpp
DEPENDS swiftBasic) DEPENDS SwiftOptions
LINK_LIBRARIES swiftBasic
FILE_DEPENDS SwiftOptions)
add_dependencies(swiftOption SwiftOptions)

View File

@@ -10,4 +10,7 @@ add_swift_library(swiftParse
ParseType.cpp ParseType.cpp
PersistentParserState.cpp PersistentParserState.cpp
Scope.cpp Scope.cpp
DEPENDS clangBasic swiftAST swiftSIL) LINK_LIBRARIES
swiftSIL
swiftAST)

View File

@@ -1,8 +1,9 @@
add_swift_library(swiftPrintAsObjC add_swift_library(swiftPrintAsObjC
PrintAsObjC.cpp PrintAsObjC.cpp
DEPENDS swiftAST)
# Clang dependencies. LINK_LIBRARIES
# FIXME: Clang should really export these in some reasonable manner. swiftIDE
target_link_libraries(swiftPrintAsObjC swiftFrontend
clangAST) swiftClangImporter
swiftAST)

View File

@@ -3,5 +3,5 @@ add_swift_library(swiftReST
BriefParser.cpp BriefParser.cpp
LineList.cpp LineList.cpp
Parser.cpp Parser.cpp
DEPENDS clangBasic LINK_LIBRARIES clangBasic)
)

View File

@@ -25,13 +25,7 @@ add_swift_library(swiftSIL
LoopInfo.cpp LoopInfo.cpp
Projection.cpp Projection.cpp
Mangle.cpp Mangle.cpp
DEPENDS swiftAST swiftSerialization) LINK_LIBRARIES
swiftSerialization
swiftSema)
# Clang dependencies.
# FIXME: remove this. SIL should not depend on Clang.
target_link_libraries(swiftSIL
clangAnalysis
clangAST
clangLex
clangBasic
LLVMSupport)

View File

@@ -13,4 +13,4 @@ add_swift_library(swiftSILAnalysis
SimplifyInstruction.cpp SimplifyInstruction.cpp
RCIdentityAnalysis.cpp RCIdentityAnalysis.cpp
DestructorAnalysis.cpp DestructorAnalysis.cpp
DEPENDS swiftSILPassesUtils) LINK_LIBRARIES swiftSILPassesUtils)

View File

@@ -12,5 +12,5 @@ add_swift_library(swiftSILGen
SILGenPattern.cpp SILGenPattern.cpp
SILGenPoly.cpp SILGenPoly.cpp
SILGenStmt.cpp SILGenStmt.cpp
DEPENDS swiftSIL) LINK_LIBRARIES swiftSIL)

View File

@@ -45,4 +45,4 @@ add_swift_library(swiftSILPasses
ArrayBoundsCheckOpts.cpp ArrayBoundsCheckOpts.cpp
ClosureSpecializer.cpp ClosureSpecializer.cpp
SILCombinerVisitors.cpp SILCombinerVisitors.cpp
DEPENDS swiftSILPassesUtils swiftSILAnalysis) LINK_LIBRARIES swiftSILPassesUtils swiftSILAnalysis)

View File

@@ -3,5 +3,5 @@ add_swift_library(swiftSILPassesUtils
Local.cpp Local.cpp
SILInliner.cpp SILInliner.cpp
SILSSAUpdater.cpp SILSSAUpdater.cpp
DEPENDS swiftSIL) LINK_LIBRARIES swiftSIL)

View File

@@ -29,4 +29,7 @@ add_swift_library(swiftSema
TypeCheckREPL.cpp TypeCheckREPL.cpp
TypeCheckStmt.cpp TypeCheckStmt.cpp
TypeCheckType.cpp TypeCheckType.cpp
DEPENDS swiftAST swiftParse) LINK_LIBRARIES
swiftParse
swiftAST)

View File

@@ -6,4 +6,6 @@ add_swift_library(swiftSerialization
SerializedModuleLoader.cpp SerializedModuleLoader.cpp
SerializedSILLoader.cpp SerializedSILLoader.cpp
SerializeSIL.cpp SerializeSIL.cpp
DEPENDS swiftAST swiftClangImporter LLVMBitReader LLVMBitWriter LLVMCore) LINK_LIBRARIES
swiftClangImporter)

View File

@@ -114,46 +114,54 @@ set(SWIFTLIB_SOURCES
Zip.swift Zip.swift
) )
set(swift_core_link_flags)
set(swift_core_framework_depends)
set(swift_core_private_link_libraries)
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(LINK_FLAGS "-all_load -Xlinker -reexport-lobjc") list(APPEND swift_core_link_flags
set(RUNTIME_DEPENDENCY swiftRuntime) "-all_load" "-Xlinker" "-reexport-lobjc")
list(APPEND swift_core_private_link_libraries swiftRuntime)
list(APPEND swift_core_framework_depends Foundation)
else() else()
set(LINK_FLAGS)
# With the GNU linker the equivalent of -all_load is to tell the linker # With the GNU linker the equivalent of -all_load is to tell the linker
# --whole-archive before the archive and --no-whole-archive after (without # --whole-archive before the archive and --no-whole-archive after (without
# the second, it causes errors when the system libraries are told to # the second, it causes errors when the system libraries are told to
# include everything). The best way to get it in there, according to the # include everything). The best way to get it in there, according to the
# documentation, is to put the flags in the target_link_Libraries setting. # documentation, is to put the flags in the target_link_libraries setting.
# TODO: However, for the moment this actually makes things explode with an # TODO: However, for the moment this actually makes things explode with an
# incomplete runtime. This should be turned back on when more of the porting # incomplete runtime. This should be turned back on when more of the porting
# effort has been completed. # effort has been completed.
#set(LINK_FLAGS #set(LINK_FLAGS
# -Wl,--whole-archive swiftRuntime -Wl,--no-whole-archive) # -Wl,--whole-archive swiftRuntime -Wl,--no-whole-archive)
set(RUNTIME_DEPENDENCY swiftRuntime) list(APPEND swift_core_private_link_libraries swiftRuntime)
endif() endif()
set(SWIFT_CHECK_ESSENTIAL_STDLIB NO CACHE BOOL if(SWIFT_HAVE_CRASH_REPORTER_CLIENT)
"Check core standard library layering by linking its essential subset") list(APPEND swift_core_private_link_libraries "CrashReporterClient")
endif()
option(SWIFT_CHECK_ESSENTIAL_STDLIB
"Check core standard library layering by linking its essential subset"
FALSE)
if(SWIFT_CHECK_ESSENTIAL_STDLIB) if(SWIFT_CHECK_ESSENTIAL_STDLIB)
add_swift_library(swift_stdlib_essential IS_STDLIB_CORE TARGET_LIBRARY add_swift_library(swift_stdlib_essential SHARED IS_STDLIB IS_STDLIB_CORE
${SWIFTLIB_ESSENTIAL} ${SWIFTLIB_ESSENTIAL})
)
target_link_libraries(swift_stdlib_essential ${RUNTIME_DEPENDENCY}) target_link_libraries(swift_stdlib_essential ${RUNTIME_DEPENDENCY})
endif() endif()
set(SHARED_LIBRARY ON) add_swift_library(swiftCore SHARED IS_STDLIB IS_STDLIB_CORE
add_swift_library(swiftCore INSTALL IS_STDLIB_CORE TARGET_LIBRARY
${SWIFTLIB_SOURCES} ${SWIFTLIB_SOURCES}
# The copy_shim_headers target dependency is required to let the # The copy_shim_headers target dependency is required to let the
# Makefile build know that there's a rule to produce the shims # build system know that there's a rule to produce the shims
# directory, but is not sufficient to cause Swift.o to be rebuilt # directory, but is not sufficient to cause the object file to be rebuilt
# when the shim header changes. Therefore, we pass both the target # when the shim header changes. Therefore, we pass both the target
# and the generated directory as dependencies # and the generated directory as dependencies.
FILE_DEPENDS FILE_DEPENDS
copy_shim_headers ${SWIFT_LIBRARY_OUTPUT_INTDIR}/swift/shims copy_shim_headers "${SWIFTLIB_DIR}/shims"
LINK_FLAGS ${LINK_FLAGS} LINK_FLAGS ${swift_core_link_flags}
DEPENDS ${RUNTIME_DEPENDENCY} PRIVATE_LINK_LIBRARIES ${swift_core_private_link_libraries}
) FRAMEWORK_DEPENDS ${swift_core_framework_depends}
add_dependencies(swiftCore swift) INSTALL_IN_COMPONENT stdlib)

View File

@@ -74,7 +74,7 @@ struct _SliceBuffer<T> : _ArrayBufferType {
) { ) {
_invariantCheck() _invariantCheck()
// FIXME: <rdar://problem/17464946> with // FIXME: <rdar://problem/17464946> with
// -DSWIFT_STDLIB_INTERNAL_CHECKS=OFF, enabling this sanityCheck // -DSWIFT_STDLIB_ASSERTIONS=FALSE, enabling this sanityCheck
// actually causes leaks in the stdlib/NewArray.swift.gyb test // actually causes leaks in the stdlib/NewArray.swift.gyb test
/* _sanityCheck(insertCount <= numericCast(count(newValues))) */ /* _sanityCheck(insertCount <= numericCast(count(newValues))) */

View File

@@ -1,11 +1,8 @@
set(SHARED_LIBRARY ON) add_swift_library(swiftSwiftExperimental SHARED IS_STDLIB
add_swift_library(swiftSwiftExperimental INSTALL TARGET_LIBRARY
# This file should be listed the first. Module name is inferred from the # This file should be listed the first. Module name is inferred from the
# filename. # filename.
SwiftExperimental.swift SwiftExperimental.swift
SWIFT_COMPILE_FLAGS -Xfrontend -sil-serialize-all SWIFT_COMPILE_FLAGS -Xfrontend -sil-serialize-all
INSTALL_IN_COMPONENT stdlib-experimental)
DEPENDS swiftCore)

View File

@@ -1,6 +1,6 @@
set(SHARED_LIBRARY ON) add_swift_library(swiftAppKit IS_SDK_OVERLAY
add_swift_library(swiftAppKit INSTALL TARGET_LIBRARY
AppKit.swift AppKit.swift
TARGET_SDKS "OSX" TARGET_SDKS OSX
DEPENDS swiftCore swiftObjectiveC swiftFoundation swiftQuartzCore SWIFT_MODULE_DEPENDS ObjectiveC Foundation QuartzCore
FRAMEWORK_DEPENDS AppKit QuartzCore) FRAMEWORK_DEPENDS AppKit QuartzCore)

View File

@@ -1,8 +1,6 @@
set(SHARED_LIBRARY ON) add_swift_library(swiftAssetsLibrary IS_SDK_OVERLAY
add_swift_library(swiftAssetsLibrary INSTALL TARGET_LIBRARY
AssetsLibrary.swift AssetsLibrary.swift
TARGET_SDKS IOS IOS_SIMULATOR TARGET_SDKS IOS IOS_SIMULATOR
DEPENDS swiftCore swiftObjectiveC swiftFoundation swiftCoreGraphics SWIFT_MODULE_DEPENDS ObjectiveC Foundation CoreGraphics
FRAMEWORK_DEPENDS AssetsLibrary) FRAMEWORK_DEPENDS AssetsLibrary)

View File

@@ -1,31 +1,16 @@
# All libraries in this directory tree are overlays. # All libraries in this directory tree are overlays.
list(APPEND SWIFT_EXTRA_FLAGS add_subdirectory(AppKit)
"-autolink-force-load") add_subdirectory(AssetsLibrary)
add_subdirectory(CoreGraphics)
add_subdirectory(CoreImage)
add_subdirectory(Darwin) add_subdirectory(Darwin)
add_subdirectory(Dispatch) add_subdirectory(Dispatch)
add_subdirectory(CoreGraphics)
add_subdirectory(Foundation) add_subdirectory(Foundation)
add_subdirectory(ObjectiveC) add_subdirectory(ObjectiveC)
add_subdirectory(QuartzCore)
add_subdirectory(Security) add_subdirectory(Security)
add_subdirectory(SpriteKit) add_subdirectory(SpriteKit)
add_subdirectory(UIKit)
add_subdirectory(XCTest) add_subdirectory(XCTest)
add_subdirectory(GLKit) add_subdirectory(GLKit)
if (SWIFT_SDKS)
add_subdirectory(AppKit)
add_subdirectory(AssetsLibrary)
add_subdirectory(CoreImage)
add_subdirectory(QuartzCore)
add_subdirectory(UIKit)
else()
if (SWIFT_DEPLOYMENT_OS MATCHES "^macosx")
add_subdirectory(AppKit)
add_subdirectory(QuartzCore)
else()
add_subdirectory(AssetsLibrary)
add_subdirectory(CoreImage)
add_subdirectory(UIKit)
endif()
endif()

View File

@@ -1,9 +1,7 @@
set(SHARED_LIBRARY ON) add_swift_library(swiftCoreGraphics IS_SDK_OVERLAY
add_swift_library(swiftCoreGraphics
CoreGraphics.swift CoreGraphics.swift
CGFloat.swift.gyb CGFloat.swift.gyb
CoreGraphicsMirrors.swift.gyb CoreGraphicsMirrors.swift.gyb
INSTALL TARGET_LIBRARY SWIFT_MODULE_DEPENDS ObjectiveC Dispatch Darwin
DEPENDS swiftCore swiftObjectiveC swiftDispatch swiftDarwin
FRAMEWORK_DEPENDS CoreGraphics) FRAMEWORK_DEPENDS CoreGraphics)

View File

@@ -1,6 +1,6 @@
set(SHARED_LIBRARY ON) add_swift_library(swiftCoreImage IS_SDK_OVERLAY
add_swift_library(swiftCoreImage INSTALL TARGET_LIBRARY
CoreImage.swift CoreImage.swift
TARGET_SDKS IOS IOS_SIMULATOR TARGET_SDKS IOS IOS_SIMULATOR
DEPENDS swiftCore swiftFoundation swiftObjectiveC SWIFT_MODULE_DEPENDS Foundation ObjectiveC
FRAMEWORK_DEPENDS CoreImage) FRAMEWORK_DEPENDS CoreImage)

View File

@@ -1,8 +1,6 @@
set(SHARED_LIBRARY ON) add_swift_library(swiftDarwin IS_SDK_OVERLAY
add_swift_library(swiftDarwin INSTALL TARGET_LIBRARY
Darwin.swift Darwin.swift
Misc.mm Misc.mm
tgmath.swift.gyb tgmath.swift.gyb
DEPENDS swiftCore
API_NOTES_NON_OVERLAY) API_NOTES_NON_OVERLAY)

View File

@@ -1,7 +1,5 @@
set(SHARED_LIBRARY ON) add_swift_library(swiftDispatch IS_SDK_OVERLAY
add_swift_library(swiftDispatch
Dispatch.swift Dispatch.swift
Dispatch.mm Dispatch.mm
INSTALL TARGET_LIBRARY SWIFT_MODULE_DEPENDS ObjectiveC)
DEPENDS swiftCore swiftObjectiveC)

View File

@@ -1,6 +1,4 @@
set(SHARED_LIBRARY ON) add_swift_library(swiftFoundation IS_SDK_OVERLAY
add_swift_library(swiftFoundation INSTALL TARGET_LIBRARY
Foundation.swift Foundation.swift
FoundationMirrors.swift.gyb FoundationMirrors.swift.gyb
ExtraStringAPIs.swift ExtraStringAPIs.swift
@@ -8,5 +6,6 @@ add_swift_library(swiftFoundation INSTALL TARGET_LIBRARY
MixedStringNSStringOperations.swift.gyb MixedStringNSStringOperations.swift.gyb
NSStringAPI.swift NSStringAPI.swift
NSValue.swift NSValue.swift
DEPENDS swiftCore swiftObjectiveC swiftCoreGraphics swiftDispatch swiftSecurity SWIFT_MODULE_DEPENDS ObjectiveC CoreGraphics Dispatch Security
FRAMEWORK_DEPENDS Foundation) FRAMEWORK_DEPENDS Foundation)

View File

@@ -1,20 +1,8 @@
set(SHARED_LIBRARY ON) add_swift_library(swiftGLKit IS_SDK_OVERLAY
if (SWIFT_DEPLOYMENT_OS MATCHES "^macosx")
set(SWIFTGLKIT_UI swiftAppKit)
else()
set(SWIFTGLKIT_UI swiftUIKit)
endif()
add_swift_library(swiftGLKit INSTALL
GLKit.swift.gyb GLKit.swift.gyb
DEPENDS ${SWIFTGLKIT_UI}
SWIFT_MODULE_DEPENDS Foundation
SWIFT_MODULE_DEPENDS_OSX AppKit
SWIFT_MODULE_DEPENDS_IOS UIKit
FRAMEWORK_DEPENDS GLKit) FRAMEWORK_DEPENDS GLKit)
if (SWIFT_SDKS)
add_swift_library(swiftGLKit INSTALL TARGET_LIBRARY
GLKit.swift.gyb
TARGET_SDKS IOS IOS_SIMULATOR
DEPENDS swiftUIKit
FRAMEWORK_DEPENDS GLKit)
endif()

View File

@@ -1,5 +1,4 @@
set(SHARED_LIBRARY ON) add_swift_library(swiftObjectiveC IS_SDK_OVERLAY
add_swift_library(swiftObjectiveC INSTALL TARGET_LIBRARY
ObjectiveC.swift ObjectiveC.swift
DEPENDS swiftCore swiftDarwin) SWIFT_MODULE_DEPENDS Darwin)

View File

@@ -1,6 +1,6 @@
set(SHARED_LIBRARY ON) add_swift_library(swiftQuartzCore IS_SDK_OVERLAY
add_swift_library(swiftQuartzCore INSTALL TARGET_LIBRARY
QuartzCore.swift QuartzCore.swift
TARGET_SDKS OSX TARGET_SDKS OSX
DEPENDS swiftCore swiftFoundation swiftObjectiveC SWIFT_MODULE_DEPENDS Foundation ObjectiveC
FRAMEWORK_DEPENDS QuartzCore) FRAMEWORK_DEPENDS QuartzCore)

View File

@@ -1,8 +1,5 @@
set(SHARED_LIBRARY ON) add_swift_library(swiftSecurity IS_SDK_OVERLAY
add_swift_library(swiftSecurity
Security.swift Security.swift
INSTALL TARGET_LIBRARY SWIFT_MODULE_DEPENDS ObjectiveC Dispatch Darwin
FRAMEWORK_DEPENDS Security FRAMEWORK_DEPENDS Security)
DEPENDS swiftCore swiftObjectiveC swiftDispatch swiftDarwin)

View File

@@ -1,21 +1,9 @@
set(SHARED_LIBRARY ON) add_swift_library(swiftSpriteKit IS_SDK_OVERLAY
if (SWIFT_DEPLOYMENT_OS MATCHES "^macosx")
set(SWIFTSPRITEKIT_UI swiftAppKit)
else()
set(SWIFTSPRITEKIT_UI swiftUIKit)
endif()
add_swift_library(swiftSpriteKit INSTALL
SpriteKit.swift SpriteKit.swift
SpriteKitMirrors.swift.gyb SpriteKitMirrors.swift.gyb
DEPENDS ${SWIFTSPRITEKIT_UI} swiftGLKit
SWIFT_MODULE_DEPENDS Foundation GLKit
SWIFT_MODULE_DEPENDS_OSX AppKit
SWIFT_MODULE_DEPENDS_IOS UIKit
FRAMEWORK_DEPENDS SpriteKit) FRAMEWORK_DEPENDS SpriteKit)
if (SWIFT_SDKS)
add_swift_library(swiftSpriteKit INSTALL TARGET_LIBRARY
SpriteKit.swift
SpriteKitMirrors.swift.gyb
TARGET_SDKS IOS IOS_SIMULATOR
DEPENDS swiftUIKit swiftGLKit
FRAMEWORK_DEPENDS SpriteKit)
endif()

View File

@@ -1,7 +1,7 @@
set(SHARED_LIBRARY ON) add_swift_library(swiftUIKit IS_SDK_OVERLAY
add_swift_library(swiftUIKit INSTALL TARGET_LIBRARY
DesignatedInitializers.mm DesignatedInitializers.mm
UIKit.swift UIKit.swift
TARGET_SDKS IOS IOS_SIMULATOR TARGET_SDKS IOS IOS_SIMULATOR
DEPENDS swiftCore swiftObjectiveC swiftFoundation swiftCoreImage SWIFT_MODULE_DEPENDS ObjectiveC Foundation CoreImage
FRAMEWORK_DEPENDS UIKit) FRAMEWORK_DEPENDS UIKit)

View File

@@ -1,26 +1,8 @@
set(SHARED_LIBRARY ON)
set(DISABLE_APPLICATION_EXTENSION ON) set(DISABLE_APPLICATION_EXTENSION ON)
# XCTest.framework is not in the default search paths, add a search path for it add_swift_library(swiftXCTest IS_SDK_OVERLAY
# both when building and when linking. For compiling, that's accomplished by
# modifying SWIFT_EXTRA_FLAGS before invoking add_swift_library. For linking,
# that's accomplished by adding the extra flag to target_link_libraries since
# that will just pass through to the linker invocation.
set(XCTEST_FRAMEWORK_LOCATION "${MODULES_SDK}/../../../Developer/Library/Frameworks")
list(APPEND SWIFT_EXTRA_FLAGS
"-F${XCTEST_FRAMEWORK_LOCATION}"
"-framework" "XCTest")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -F${XCTEST_FRAMEWORK_LOCATION}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -framework XCTest")
add_swift_library(swiftXCTest INSTALL
XCTestCaseAdditions.mm XCTestCaseAdditions.mm
XCTest.swift XCTest.swift
DEPENDS swiftCore swiftObjectiveC swiftFoundation) SWIFT_MODULE_DEPENDS ObjectiveC Foundation
FRAMEWORK_DEPENDS Foundation XCTest)
target_link_libraries(swiftXCTest
"-F${XCTEST_FRAMEWORK_LOCATION}"
"-framework Foundation" "-framework XCTest")

View File

@@ -1,32 +1,25 @@
if (SWIFT_OPTIMIZED) set(swift_runtime_compile_flags)
set(SWIFT_RUNTIME_CLOBBER_FREED_OBJECTS_DEFAULT OFF)
else()
set(SWIFT_RUNTIME_CLOBBER_FREED_OBJECTS_DEFAULT ON)
endif()
set(SWIFT_RUNTIME_CLOBBER_FREED_OBJECTS
${SWIFT_RUNTIME_CLOBBER_FREED_OBJECTS_DEFAULT}
CACHE BOOL "Overwrite memory for deallocated Swift objects")
set(SWIFT_RUNTIME_COMPILE_FLAGS)
if(SWIFT_RUNTIME_CLOBBER_FREED_OBJECTS) if(SWIFT_RUNTIME_CLOBBER_FREED_OBJECTS)
list(APPEND SWIFT_RUNTIME_COMPILE_FLAGS "-DSWIFT_RUNTIME_CLOBBER_FREED_OBJECTS=1") list(APPEND swift_runtime_compile_flags
"-DSWIFT_RUNTIME_CLOBBER_FREED_OBJECTS=1")
endif() endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") if(SWIFT_HAVE_CRASH_REPORTER_CLIENT)
set(SWIFT_RUNTIME_OBJC_SOURCES list(APPEND swift_runtime_compile_flags
Availability.mm "-DSWIFT_HAVE_CRASHREPORTERCLIENT=1")
SwiftObject.mm
SwiftNativeNSXXXBase.mm.gyb
Reflection.mm)
set(FRAMEWORKS Foundation)
else()
set(SWIFT_RUNTIME_OBJC_SOURCES)
set(FRAMEWORKS)
endif() endif()
add_swift_library(swiftRuntime set(swift_runtime_objc_sources)
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
set(swift_runtime_objc_sources
Availability.mm
SwiftObject.mm
SwiftNativeNSXXXBase.mm.gyb
Reflection.mm)
endif()
add_swift_library(swiftRuntime IS_STDLIB IS_STDLIB_CORE
Casting.cpp Casting.cpp
Demangle.cpp Demangle.cpp
GlobalObjects.cpp GlobalObjects.cpp
@@ -41,24 +34,18 @@ add_swift_library(swiftRuntime
Heap.cpp Heap.cpp
Errors.cpp Errors.cpp
UnicodeExtendedGraphemeClusters.cpp.gyb UnicodeExtendedGraphemeClusters.cpp.gyb
${SWIFT_RUNTIME_OBJC_SOURCES} ${swift_runtime_objc_sources}
C_COMPILE_FLAGS ${SWIFT_RUNTIME_COMPILE_FLAGS} C_COMPILE_FLAGS ${swift_runtime_compile_flags}
TARGET_LIBRARY INSTALL INSTALL_IN_COMPONENT stdlib)
FRAMEWORK_DEPENDS ${FRAMEWORKS})
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") foreach(sdk ${SWIFTLIB_TARGET_SDKS})
# FIXME: This is probably not flexible enough to deal with 32bit builds, if("${sdk}" STREQUAL "LINUX")
# but SWIFTLIB_DIR isn't available in this cmake file and duplicating foreach(arch ${SWIFT_SDK_${sdk}_ARCHITECTURES})
# the logic seems wrong. rdar://problem/19035586 set(arch_subdir "${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${arch}")
configure_file(swift.ld ${CMAKE_BINARY_DIR}/lib/swift/swift.ld COPYONLY)
target_link_libraries(swiftRuntime "-lpthread" "-ldl")
endif()
list(APPEND CMAKE_FIND_ROOT_PATH "${CMAKE_OSX_SYSROOT}") # FIXME: We will need a different linker script for 32-bit builds.
find_library(CRASHREPORTERCLIENT CrashReporterClient ONLY_CMAKE_FIND_ROOT_PATH) configure_file(
"swift.ld" "${SWIFTLIB_DIR}/${arch_subdir}/swift.ld" COPYONLY)
endforeach()
endforeach()
if (CRASHREPORTERCLIENT)
target_link_libraries(swiftRuntime "-lCrashReporterClient")
set_property(TARGET swiftRuntime APPEND_STRING PROPERTY
COMPILE_FLAGS " -DSWIFT_HAVE_CRASHREPORTERCLIENT=1")
endif()

View File

@@ -12,58 +12,68 @@ set(sources
) )
set(output_dir "${SWIFTLIB_DIR}/shims") set(output_dir "${SWIFTLIB_DIR}/shims")
set(commands) set(commands
set(outputs) COMMAND ${CMAKE_COMMAND} "-E" "make_directory" "${output_dir}")
set(outputs "${output_dir}")
foreach(input ${sources}) foreach(input ${sources})
list(APPEND outputs "${output_dir}/${input}")
list(APPEND commands list(APPEND commands
COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${input}" COMMAND
"${output_dir}/${input}") "${CMAKE_COMMAND}" "-E" "copy_if_different"
"${CMAKE_CURRENT_SOURCE_DIR}/${input}"
"${output_dir}/${input}")
list(APPEND outputs "${output_dir}/${input}")
endforeach() endforeach()
add_custom_command(OUTPUT "${output_dir}" ${outputs} add_custom_command_target(unused_var
COMMAND ${CMAKE_COMMAND} -E make_directory "${output_dir}" ${commands}
${commands} CUSTOM_TARGET_NAME "copy_shim_headers"
DEPENDS ${sources} OUTPUT "${outputs}"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" DEPENDS "${sources}"
COMMENT "Copying SwiftShims module to ${output_dir}" COMMENT "Copying SwiftShims module to ${output_dir}")
)
add_custom_target(
copy_shim_headers
DEPENDS "${output_dir}" ${outputs}
SOURCES ${sources}
)
# Symlink in the Clang headers. # Symlink in the Clang headers.
add_custom_command(TARGET copy_shim_headers POST_BUILD add_custom_command_target(unused_var
COMMAND ${CMAKE_COMMAND} -E create_symlink COMMAND
"${SWIFT_PATH_TO_CLANG_BUILD}/${CMAKE_CFG_INTDIR}/lib/clang" "${CMAKE_COMMAND}" "-E" "make_directory" "${SWIFTLIB_DIR}"
"${SWIFTLIB_DIR}/clang" COMMAND
COMMENT "Symlinking Clang resource headers into ${SWIFTLIB_DIR}/clang") "${CMAKE_COMMAND}" "-E" "create_symlink"
"${SWIFT_PATH_TO_CLANG_BUILD}/${CMAKE_CFG_INTDIR}/lib/clang"
"${SWIFTLIB_DIR}/clang"
CUSTOM_TARGET_NAME "symlink_clang_headers"
OUTPUT "${SWIFTLIB_DIR}/clang"
COMMENT "Symlinking Clang resource headers into ${SWIFTLIB_DIR}/clang")
add_dependencies(copy_shim_headers symlink_clang_headers)
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") include(SwiftDarwin)
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
# Symlink in arclite from the XcodeDefault toolchain. # Symlink in arclite from the XcodeDefault toolchain.
execute_process(COMMAND xcrun --toolchain XcodeDefault -find clang get_default_toolchain_dir(toolchain_dir)
OUTPUT_VARIABLE toolchain_dir add_custom_command_target(unused_var
OUTPUT_STRIP_TRAILING_WHITESPACE) COMMAND
string(LENGTH "${toolchain_dir}" len) "${CMAKE_COMMAND}" "-E" "make_directory"
math(EXPR len "${len} - 14") # "/usr/bin/clang" "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib"
string(SUBSTRING "${toolchain_dir}" 0 ${len} toolchain_dir) COMMAND
"${CMAKE_COMMAND}" "-E" "create_symlink"
"${toolchain_dir}/usr/lib/arc"
"${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib/arc"
CUSTOM_TARGET_NAME "symlink_arclite"
OUTPUT "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib/arc"
COMMENT "Symlinking toolchain's arclite into ${SWIFTLIB_DIR}/arc")
add_dependencies(copy_shim_headers symlink_arclite)
add_custom_command(TARGET copy_shim_headers POST_BUILD swift_install_in_component(arclite-symlink
COMMAND ${CMAKE_COMMAND} -E create_symlink DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib/arc"
"${toolchain_dir}/usr/lib/arc" DESTINATION "lib")
"${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib/arc"
COMMENT "Symlinking toolchain's arclite into ${SWIFTLIB_DIR}/arc")
endif() endif()
install(FILES ${sources} DESTINATION "lib/swift/shims") swift_install_in_component(compiler
FILES ${sources}
DESTINATION "lib/swift/shims")
# Install Clang headers under the Swift library so that an installed swift's # Install Clang headers under the Swift library so that an installed swift's
# module importer can find the compiler headers corresponding to its clang. # module importer can find the compiler headers corresponding to its clang.
install( swift_install_in_component(clang-builtin-headers
DIRECTORY "${SWIFT_PATH_TO_CLANG_BUILD}/lib/clang" DIRECTORY "${SWIFT_PATH_TO_CLANG_BUILD}/lib/clang"
DESTINATION "lib/swift" DESTINATION "lib/swift"
PATTERN "*.h") PATTERN "*.h")

View File

@@ -1,5 +1,4 @@
set(SHARED_LIBRARY ON) add_swift_library(swiftStdlibUnittest SHARED IS_STDLIB
set(SWIFTUNITTEST_SOURCES
# This file should be listed the first. Module name is inferred from the # This file should be listed the first. Module name is inferred from the
# filename. # filename.
StdlibUnittest.swift.gyb StdlibUnittest.swift.gyb
@@ -16,10 +15,6 @@ set(SWIFTUNITTEST_SOURCES
StdlibCoreExtras.swift StdlibCoreExtras.swift
SwiftBlockToCFunctionThunks.cpp SwiftBlockToCFunctionThunks.cpp
LifetimeTracked.swift LifetimeTracked.swift
)
add_swift_library(swiftStdlibUnittest INSTALL TARGET_LIBRARY
${SWIFTUNITTEST_SOURCES}
# Can not serialize StdlibUnittest because of: # Can not serialize StdlibUnittest because of:
# <rdar://problem/18917405> Compiling StdlibUnittest with -sil-serialize-all # <rdar://problem/18917405> Compiling StdlibUnittest with -sil-serialize-all
@@ -27,6 +22,7 @@ add_swift_library(swiftStdlibUnittest INSTALL TARGET_LIBRARY
# #
# SWIFT_COMPILE_FLAGS -Xfrontend -sil-serialize-all # SWIFT_COMPILE_FLAGS -Xfrontend -sil-serialize-all
SWIFT_MODULE_DEPENDS Darwin Foundation
FRAMEWORK_DEPENDS Foundation FRAMEWORK_DEPENDS Foundation
DEPENDS swiftCore swiftDarwin swiftFoundation) INSTALL_IN_COMPONENT stdlib-experimental)

View File

@@ -63,7 +63,7 @@
// LINUX-DAG: -lswiftCore // LINUX-DAG: -lswiftCore
// LINUX-DAG: -L [[STDLIB_PATH:[^ ]+/lib/swift]] // LINUX-DAG: -L [[STDLIB_PATH:[^ ]+/lib/swift]]
// LINUX-DAG: -Xlinker -rpath -Xlinker [[STDLIB_PATH]] // LINUX-DAG: -Xlinker -rpath -Xlinker [[STDLIB_PATH]]
// LINUX-DAG: -Xlinker -Tswift.ld // LINUX-DAG: -Xlinker -T /{{[^ ]+}}/linux/x86_64/swift.ld
// LINUX-DAG: -F foo // LINUX-DAG: -F foo
// LINUX-DAG: -framework bar // LINUX-DAG: -framework bar
// LINUX-DAG: -L baz // LINUX-DAG: -L baz

View File

@@ -1,5 +1,6 @@
import sys import os
import platform import platform
import sys
## Autogenerated by Swift configuration. ## Autogenerated by Swift configuration.
# Do not edit! # Do not edit!
@@ -8,7 +9,7 @@ config.llvm_obj_root = "@LLVM_BINARY_DIR@"
config.llvm_tools_dir = "@LLVM_TOOLS_DIR@" config.llvm_tools_dir = "@LLVM_TOOLS_DIR@"
config.llvm_libs_dir = "@LLVM_LIBS_DIR@" config.llvm_libs_dir = "@LLVM_LIBS_DIR@"
config.lit_tools_dir = "@LLVM_LIT_TOOLS_DIR@" config.lit_tools_dir = "@LLVM_LIT_TOOLS_DIR@"
config.swift_src_root = "@SWIFT_SOURCE_DIR@" config.swift_src_root = lit_config.params.get("swift_src_root", "@SWIFT_SOURCE_DIR@")
config.swift_obj_root = "@SWIFT_BINARY_DIR@" config.swift_obj_root = "@SWIFT_BINARY_DIR@"
config.target_triple = "@TARGET_TRIPLE@" config.target_triple = "@TARGET_TRIPLE@"
config.targets_to_build = "@TARGETS_TO_BUILD@" config.targets_to_build = "@TARGETS_TO_BUILD@"
@@ -25,21 +26,24 @@ except KeyError:
key, = e.args key, = e.args
lit_config.fatal("unable to find %r parameter, use '--param=%s=VALUE'" % (key,key)) lit_config.fatal("unable to find %r parameter, use '--param=%s=VALUE'" % (key,key))
if "@SWIFT_RUN_LONG_TESTS@" != "OFF" and "@SWIFT_RUN_LONG_TESTS@" != "NO": if "@SWIFT_ASAN_BUILD@" == "TRUE":
config.available_features.add("long_tests") config.available_features.add("asan")
if "@SWIFT_ASAN_BUILD@" != "OFF" and "@SWIFT_ASAN_BUILD@" != "NO": if "@LLVM_ENABLE_ASSERTIONS@" == "TRUE":
config.available_features.add("asan") config.available_features.add('asserts')
if "@SWIFT_STDLIB_INTERNAL_CHECKS@" != "OFF" and "@SWIFT_STDLIB_INTERNAL_CHECKS@" != "NO":
config.available_features.add('swift_stdlib_asserts')
else: else:
config.available_features.add('swift_stdlib_no_asserts') config.available_features.add('no_asserts')
if "@SWIFT_OPTIMIZED@" == "ON" or "@SWIFT_OPTIMIZED@" == "YES": if "@SWIFT_STDLIB_ASSERTIONS@" == "TRUE":
config.available_features.add("optimized_stdlib") config.available_features.add('swift_stdlib_asserts')
else:
config.available_features.add('swift_stdlib_no_asserts')
if "@SWIFT_OPTIMIZED@" == "TRUE":
config.available_features.add("optimized_stdlib")
# Let the main config do the real work. # Let the main config do the real work.
if config.test_exec_root is None: if config.test_exec_root is None:
config.test_exec_root = os.path.dirname(os.path.realpath(__file__)) config.test_exec_root = os.path.dirname(os.path.realpath(__file__))
lit_config.load_config(config, "@SWIFT_SOURCE_DIR@/test/lit.cfg") lit_config.load_config(
config, os.path.join(config.swift_src_root, "test", "lit.cfg"))

View File

@@ -1,3 +1,7 @@
if(NOT SWIFT_INSTALL_TESTSUITE_TOOLS)
# Prevent SwiftLLVMPasses from being installed.
set(LLVM_INSTALL_TOOLCHAIN_ONLY TRUE)
endif()
add_llvm_loadable_module(SwiftLLVMPasses add_llvm_loadable_module(SwiftLLVMPasses
SwiftLLVMPasses.cpp SwiftLLVMPasses.cpp
@@ -9,15 +13,11 @@ set_target_properties(SwiftLLVMPasses PROPERTIES
foreach(config ${CMAKE_CONFIGURATION_TYPES}) foreach(config ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${config} config_upper) string(TOUPPER ${config} config_upper)
# Hack to deal with the fact that ${SWIFTLIB_DIR} contains the build-time apply_xcode_substitutions(
# variable $(CONFIGURATION). Note that this fix is Xcode-specific. "${config}"
# You might think you could just replace ${CMAKE_CFG_INTDIR} here, but "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib"
# that can actually have other things mangled into it besides just the config_lib_dir)
# configuration. This at least doesn't pretend to do the right thing
# outside of Xcode.
string(REPLACE "$(CONFIGURATION)" ${config} config_lib_dir
"${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib")
set_target_properties(SwiftLLVMPasses PROPERTIES set_target_properties(SwiftLLVMPasses PROPERTIES
LIBRARY_OUTPUT_DIRECTORY_${config_upper} ${config_lib_dir} LIBRARY_OUTPUT_DIRECTORY_${config_upper} ${config_lib_dir}
ARCHIVE_OUTPUT_DIRECTORY_${config_upper} ${config_lib_dir}) ARCHIVE_OUTPUT_DIRECTORY_${config_upper} ${config_lib_dir})
endforeach() endforeach()

View File

@@ -1,44 +1,49 @@
add_swift_executable(swift add_swift_executable(swift
driver.cpp driver.cpp
frontend_main.cpp frontend_main.cpp
DEPENDS swiftDriver swiftIRGen swiftSIL swiftSILGen swiftSILPasses swiftImmediate LINK_LIBRARIES
swiftSerialization swiftFrontend swiftClangImporter swiftPrintAsObjC swiftDriver swiftIRGen swiftSIL swiftSILGen swiftSILPasses
swiftIDE swiftOption swiftImmediate
COMPONENT_DEPENDS bitreader bitwriter codegen ipo linker mcjit asmparser swiftSerialization
selectiondag ${LLVM_TARGETS_TO_BUILD}) swiftPrintAsObjC
swiftFrontend
swiftClangImporter
swiftIDE
swiftOption
COMPONENT_DEPENDS
bitreader bitwriter codegen ipo linker mcjit asmparser selectiondag
objcarcopts option support ${LLVM_TARGETS_TO_BUILD})
target_link_libraries(swift edit) target_link_libraries(swift edit)
add_custom_command(TARGET swift POST_BUILD
COMMAND "${CMAKE_COMMAND}" "-E" "create_symlink" "swift" "swiftc"
WORKING_DIRECTORY "${SWIFT_RUNTIME_OUTPUT_INTDIR}")
# If building as part of clang, make sure the headers are installed. # If building as part of clang, make sure the headers are installed.
if(SWIFT_PATH_TO_CLANG_BUILD STREQUAL ${CMAKE_BINARY_DIR}) if(NOT SWIFT_BUILT_STANDALONE)
add_dependencies(swift clang-headers) add_dependencies(swift clang-headers)
endif() endif()
# Platforms that have a REPL need extra libraries to be linked into the 'swift' # Platforms that have a REPL need extra libraries to be linked into the 'swift'
# binary. # binary.
if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") include(SwiftDarwin)
if(SWIFT_HOST_VARIANT STREQUAL "macosx")
# Link in CoreFoundation on Darwin. # Link in CoreFoundation on Darwin.
find_library(CORE_FOUNDATION NAMES CoreFoundation) find_library(CORE_FOUNDATION NAMES CoreFoundation)
target_link_libraries(swift ${CORE_FOUNDATION}) target_link_libraries(swift ${CORE_FOUNDATION})
# Link in arclite on Darwin. # Link in arclite on Darwin.
execute_process( get_default_toolchain_dir(toolchain_dir)
COMMAND xcrun --toolchain default -f clang set(SWIFT_REPL_ARCLITE "${toolchain_dir}/usr/lib/arc/libarclite_${SWIFT_HOST_VARIANT}.a")
OUTPUT_VARIABLE default_toolchain_compiler) set_property(TARGET swift APPEND_STRING PROPERTY
get_filename_component(ARCLITE_BASE ${default_toolchain_compiler} PATH)
get_filename_component(ARCLITE_BASE ${ARCLITE_BASE} PATH)
set(SWIFT_REPL_ARCLITE "${ARCLITE_BASE}/lib/arc/libarclite_${SWIFT_DEPLOYMENT_OS}.a")
if (SWIFT_REPL_ARCLITE)
set_property(TARGET swift APPEND_STRING PROPERTY
LINK_FLAGS " -lobjc -Wl,-force_load,\"${SWIFT_REPL_ARCLITE}\"") LINK_FLAGS " -lobjc -Wl,-force_load,\"${SWIFT_REPL_ARCLITE}\"")
endif()
endif() endif()
install(TARGETS swift swift_install_in_component(compiler
RUNTIME DESTINATION bin) TARGETS swift
RUNTIME DESTINATION "bin")
swift_install_in_component(compiler
FILES "${SWIFT_RUNTIME_OUTPUT_INTDIR}/swiftc"
DESTINATION "bin")
add_custom_command(TARGET swift POST_BUILD
COMMAND ${CMAKE_COMMAND} -E create_symlink swift swiftc
WORKING_DIRECTORY ${SWIFT_RUNTIME_OUTPUT_INTDIR})
install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink swift swiftc WORKING_DIRECTORY ${CMAKE_INSTALL_PREFIX}/bin)")

View File

@@ -1,9 +1,11 @@
add_swift_executable(lldb-moduleimport-test add_swift_executable(lldb-moduleimport-test
lldb-moduleimport-test.cpp lldb-moduleimport-test.cpp
DEPENDS swiftASTSectionImporter swiftFrontend swiftClangImporter LINK_LIBRARIES
COMPONENT_DEPENDS bitreader bitwriter support ${LLVM_TARGETS_TO_BUILD}) swiftASTSectionImporter swiftFrontend swiftClangImporter
COMPONENT_DEPENDS
bitreader bitwriter option support ${LLVM_TARGETS_TO_BUILD})
target_link_libraries(swift) swift_install_in_component(testsuite-tools
TARGETS lldb-moduleimport-test
RUNTIME DESTINATION "bin")
install(TARGETS lldb-moduleimport-test
RUNTIME DESTINATION bin)

View File

@@ -1,8 +1,15 @@
add_swift_executable(sil-extract add_swift_executable(sil-extract
SILExtract.cpp SILExtract.cpp
DEPENDS swiftSIL swiftSILGen swiftSILPasses swiftSerialization LINK_LIBRARIES
swiftFrontend swiftClangImporter swiftFrontend
COMPONENT_DEPENDS option bitreader bitwriter support ${LLVM_TARGETS_TO_BUILD}) swiftSILGen
swiftSILPasses
swiftSerialization
swiftClangImporter
COMPONENT_DEPENDS
option bitreader bitwriter support ${LLVM_TARGETS_TO_BUILD})
swift_install_in_component(tools
TARGETS sil-extract
RUNTIME DESTINATION "bin")
install(TARGETS sil-extract
RUNTIME DESTINATION bin)

View File

@@ -1,8 +1,14 @@
add_swift_executable(sil-opt add_swift_executable(sil-opt
SILOpt.cpp SILOpt.cpp
DEPENDS swiftIRGen swiftSIL swiftSILGen swiftSILPasses swiftSerialization LINK_LIBRARIES
swiftFrontend swiftClangImporter swiftFrontend
COMPONENT_DEPENDS option bitreader bitwriter support ${LLVM_TARGETS_TO_BUILD}) swiftIRGen
swiftSILGen
swiftSILPasses
COMPONENT_DEPENDS
option bitreader bitwriter support ${LLVM_TARGETS_TO_BUILD})
swift_install_in_component(tools
TARGETS sil-opt
RUNTIME DESTINATION bin)
install(TARGETS sil-opt
RUNTIME DESTINATION bin)

View File

@@ -1,7 +1,9 @@
add_swift_executable(swift-demangle add_swift_executable(swift-demangle
swift-demangle.cpp swift-demangle.cpp
DEPENDS swiftBasic LINK_LIBRARIES swiftBasic
COMPONENT_DEPENDS support ${LLVM_TARGETS_TO_BUILD}) COMPONENT_DEPENDS support ${LLVM_TARGETS_TO_BUILD})
install(TARGETS swift-demangle swift_install_in_component(compiler
RUNTIME DESTINATION bin) TARGETS swift-demangle
RUNTIME DESTINATION "bin")

View File

@@ -2,16 +2,21 @@ add_swift_executable(swift-ide-test
swift-ide-test.cpp swift-ide-test.cpp
ModuleAPIDiff.cpp ModuleAPIDiff.cpp
XMLValidator.cpp XMLValidator.cpp
DEPENDS swiftDriver swiftFrontend swiftIDE LINK_LIBRARIES
COMPONENT_DEPENDS bitreader bitwriter support ${LLVM_TARGETS_TO_BUILD}) swiftDriver
swiftFrontend
swiftIDE
COMPONENT_DEPENDS
bitreader bitwriter option support ${LLVM_TARGETS_TO_BUILD})
# If libxml2 is available, make it available for swift-ide-test. # If libxml2 is available, make it available for swift-ide-test.
if (SWIFT_HAVE_LIBXML) if(SWIFT_HAVE_LIBXML)
include_directories(SYSTEM ${LIBXML2_INCLUDE_DIR}) include_directories(SYSTEM ${LIBXML2_INCLUDE_DIR})
target_link_libraries(swift-ide-test ${LIBXML2_LIBRARIES}) target_link_libraries(swift-ide-test ${LIBXML2_LIBRARIES})
add_definitions( -DSWIFT_HAVE_LIBXML="1" ) add_definitions(-DSWIFT_HAVE_LIBXML="1")
endif() endif()
install(TARGETS swift-ide-test swift_install_in_component(tools
RUNTIME DESTINATION bin) TARGETS swift-ide-test
RUNTIME DESTINATION bin)

View File

@@ -1,6 +1,9 @@
set(GENERATED_TESTS UnicodeGraphemeBreakTest.cpp.gyb) set(generated_tests UnicodeGraphemeBreakTest.cpp.gyb)
handle_gyb_sources(${CMAKE_SIZEOF_VOID_P} GENERATED_TESTS) handle_gyb_sources(
gyb_dependency_targets
generated_tests
${SWIFT_HOST_VARIANT_ARCH})
add_swift_unittest(SwiftBasicTests add_swift_unittest(SwiftBasicTests
Demangle.cpp Demangle.cpp
@@ -10,9 +13,11 @@ add_swift_unittest(SwiftBasicTests
SuccessorMapTest.cpp SuccessorMapTest.cpp
Unicode.cpp Unicode.cpp
${GENERATED_TESTS} ${generated_tests}
) )
add_dependencies(SwiftBasicTests "${gyb_dependency_targets}")
target_link_libraries(SwiftBasicTests target_link_libraries(SwiftBasicTests
swiftBasic swiftBasic
clangBasic clangBasic

View File

@@ -1,23 +1,21 @@
add_custom_target(SwiftUnitTests) add_custom_target(SwiftUnitTests)
if (NOT SWIFT_BUILD_TOOLS) set_target_properties(SwiftUnitTests PROPERTIES FOLDER "Tests")
# These tests are not properly configured for stdlib-only builds.
else()
set_target_properties(SwiftUnitTests PROPERTIES FOLDER "Tests")
function(add_swift_unittest test_dirname) function(add_swift_unittest test_dirname)
add_unittest(SwiftUnitTests ${test_dirname} ${ARGN}) add_unittest(SwiftUnitTests ${test_dirname} ${ARGN})
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
set_property(TARGET ${test_dirname} APPEND_STRING PROPERTY set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY
LINK_FLAGS " -Xlinker -rpath -Xlinker ${SWIFT_LIBRARY_OUTPUT_INTDIR}/swift/${SWIFTLIB_SUBDIR}") LINK_FLAGS " -Xlinker -rpath -Xlinker ${SWIFT_LIBRARY_OUTPUT_INTDIR}/swift/macosx")
endif() endif()
endfunction() endfunction()
# FIXME: cross-compile runtime unittests.
file(GLOB entries *)
foreach(entry ${entries})
if(IS_DIRECTORY ${entry} AND EXISTS ${entry}/CMakeLists.txt)
add_subdirectory(${entry})
endif()
endforeach()
file(GLOB entries *)
foreach(entry ${entries})
if(IS_DIRECTORY ${entry} AND EXISTS ${entry}/CMakeLists.txt)
add_subdirectory(${entry})
endif()
endforeach(entry)
endif()

View File

@@ -1,9 +1,11 @@
set(LLVM_LINK_COMPONENTS
core)
add_swift_unittest(SwiftParseTests add_swift_unittest(SwiftParseTests
LexerTests.cpp LexerTests.cpp
) )
target_link_libraries(SwiftParseTests target_link_libraries(SwiftParseTests
swiftParse swiftSIL swiftSema swiftClangImporter swiftClangImporter
) swiftSIL
swiftSema
swiftParse
swiftAST)

View File

@@ -1,13 +1,18 @@
add_swift_unittest(SwiftRuntimeTests if(("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "${SWIFT_PRIMARY_VARIANT_SDK}") AND
Metadata.cpp ("${SWIFT_HOST_VARIANT_ARCH}" STREQUAL "${SWIFT_PRIMARY_VARIANT_ARCH}"))
Enum.cpp
)
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") add_swift_unittest(SwiftRuntimeTests
find_library(FOUNDATION_LIBRARY Foundation) Metadata.cpp
target_link_libraries(SwiftRuntimeTests ${FOUNDATION_LIBRARY}) Enum.cpp
)
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
find_library(FOUNDATION_LIBRARY Foundation)
target_link_libraries(SwiftRuntimeTests ${FOUNDATION_LIBRARY})
endif()
# FIXME: cross-compile for all variants.
target_link_libraries(SwiftRuntimeTests
swiftCore${SWIFT_PRIMARY_VARIANT_SUFFIX})
endif() endif()
target_link_libraries(SwiftRuntimeTests
swiftCore
)

126
utils/SwiftBuildSupport.py Normal file
View File

@@ -0,0 +1,126 @@
#===--- SwiftBuildSupport.py - Utilities for Swift build scripts -----------===#
#
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
#
#===------------------------------------------------------------------------===#
from __future__ import print_function
import ConfigParser
import os
import pipes
import subprocess
import sys
HOME = os.environ["HOME"]
# Set SWIFT_SOURCE_ROOT in your environment to control where the sources
# are found.
SWIFT_SOURCE_ROOT = os.environ.get(
"SWIFT_SOURCE_ROOT", os.path.join(HOME, "src", "s"))
# Set SWIFT_BUILD_ROOT to a directory that will contain a subdirectory
# for each build configuration
SWIFT_BUILD_ROOT = os.environ.get(
"SWIFT_BUILD_ROOT", os.path.join(HOME, "build", "swift"))
def print_with_argv0(message):
print(sys.argv[0] + ": " + message)
def bad_usage(message):
print_with_argv0(message)
print("Run '" + pipes.quote(sys.argv[0]) + " --help' for more information.")
sys.exit(1)
def quote_shell_command(args):
return " ".join([ pipes.quote(a) for a in args ])
def check_call(args, verbose=False):
try:
return subprocess.check_call(args)
except:
if verbose:
print_with_argv0("failed command: " + quote_shell_command(args))
else:
print_with_argv0("command terminated with a non-zero exit status, aborting build")
sys.stdout.flush()
sys.exit(1)
def check_output(args, verbose=False):
try:
return subprocess.check_output(args)
except:
if verbose:
print_with_argv0("failed command: " + quote_shell_command(args))
else:
print_with_argv0("command terminated with a non-zero exit status, aborting build")
sys.stdout.flush()
sys.exit(1)
def get_preset_options_impl(config, substitutions, preset_name):
section_name = "preset: " + preset_name
if section_name not in config.sections():
return (None, None)
build_script_opts = []
build_script_impl_opts = []
dash_dash_seen = False
for o, a in config.items(section_name):
if o in substitutions:
continue
opt = None
if o == "mixin-preset":
# Split on newlines and filter out empty lines.
mixins = filter(None, [m.strip() for m in a.splitlines()])
for mixin in mixins:
(base_build_script_opts, base_build_script_impl_opts) = \
get_preset_options_impl(config, substitutions, mixin)
build_script_opts += base_build_script_opts
build_script_impl_opts += base_build_script_impl_opts
elif o == "dash-dash":
dash_dash_seen = True
elif a == "":
opt = "--" + o
else:
opt = "--" + o + "=" + a
if opt:
if not dash_dash_seen:
build_script_opts.append(opt)
else:
build_script_impl_opts.append(opt)
return (build_script_opts, build_script_impl_opts)
def get_preset_options(substitutions, preset_file_names, preset_name):
config = ConfigParser.SafeConfigParser(substitutions, allow_no_value=True)
if config.read(preset_file_names) == []:
print_with_argv0(
"preset file not found (tried " + str(preset_file_names) + ")")
sys.exit(1)
(build_script_opts, build_script_impl_opts) = \
get_preset_options_impl(config, substitutions, preset_name)
if build_script_opts is None:
print_with_argv0("preset '" + preset_name + "'not found")
sys.exit(1)
return build_script_opts + [ "--" ] + build_script_impl_opts

View File

@@ -1,627 +0,0 @@
#!/bin/bash
set -o pipefail
set -e
#
# Note: Jenkins is set up to restore the repositories to pristine
# state before building, so we rebuild from scratch every time. If
# you use this script yourself, it will NOT auto-clean before building
# Set up the default path to cmake
CMAKE_DEFAULT="$(which cmake || echo /usr/local/bin/cmake)"
# Declare the set of known settings along with each one's description
#
# If you add a user-settable variable, add it to this list.
#
# a default value of "" indicates that the corresponding variable
# will remain unset unless set explicitly
KNOWN_SETTINGS=(
# name default description
build-args "" "arguments to the build tool; defaults to -j8 when CMake generator is \"Unix Makefiles\""
build-dir "" "out-of-tree build directory; default is in-tree. **This argument is required**"
build-type Debug "the CMake build variant: Debug, RelWithDebInfo, Release, etc."
llvm-build-dir "" "out-of-tree build directory for llvm; default is BUILD_DIR/llvm, where BUILD_DIR is given by --build-dir"
llvm-build-type "$BUILD_TYPE" "the CMake build variant for clang and llvm: Debug, RelWithDebInfo, Release, etc. defaults to BUILD_TYPE, where BUILD_TYPE is given by --build-type"
cmake "$CMAKE_DEFAULT" "path to the cmake binary"
distcc "" "use distcc in pump mode"
config-args "" "User-supplied arguments to cmake when used to do configuration"
cmake-generator "Unix Makefiles" "kind of build system to generate; see output of cmake --help for choices"
prefix "/usr" "installation prefix"
show-sdks "" "print installed Xcode and SDK versions"
reconfigure "" "force a CMake configuration run even if CMakeCache.txt already exists"
skip-ios "" "set to skip everything iOS-related"
skip-build-llvm "" "set to skip building LLVM/Clang"
skip-build-swift "" "set to skip building Swift"
skip-build-ios "" "set to skip building Swift stdlibs for iOS"
skip-build-ios-device "" "set to skip building Swift stdlibs for iOS devices (i.e. build simulators only)"
skip-build-ios-simulator "" "set to skip building Swift stdlibs for iOS simulators (i.e. build devices only)"
skip-build-sourcekit "" "set to skip building SourceKit"
skip-test-swift "" "set to skip testing Swift"
skip-test-ios "" "set to skip testing Swift stdlibs for iOS"
skip-test-ios-device "" "set to skip testing Swift stdlibs for iOS devices (i.e. test simulators only)"
skip-test-ios-simulator "" "set to skip testing Swift stdlibs for iOS simulators (i.e. test devices only)"
skip-test-sourcekit "" "set to skip testing SourceKit"
skip-test-swift-performance "" "set to skip testing Swift performance"
skip-test-validation "" "set to skip validation test suite"
stress-test-sourcekit "" "set to run the stress-SourceKit target"
workspace "${HOME}/src" "source directory containing llvm, clang, swift, and SourceKit"
run-with-asan-compiler "" "the AddressSanitizer compiler to use (non-asan build if empty string is passed)"
disable-assertions "" "set to disable assertions"
)
function toupper() {
echo "$@" | tr '[:lower:]' '[:upper:]'
}
function to_varname() {
toupper "${1//-/_}"
}
# Set up an "associative array" of settings for error checking, and set
# (or unset) each corresponding variable to its default value
# If the Mac's bash were not stuck in the past, we could "declare -A" an
# associative array, but instead we have to hack it by defining variables
# declare -A IS_KNOWN_SETTING
for ((i = 0; i < ${#KNOWN_SETTINGS[@]}; i += 3)); do
setting="${KNOWN_SETTINGS[i]}"
default_value="${KNOWN_SETTINGS[$((i+1))]}"
varname="$(to_varname "${setting}")" # upcase the setting name to get the variable
eval "${varname}_IS_KNOWN_SETTING=1"
if [[ "${default_value}" ]] ; then
# For an explanation of the backslash see http://stackoverflow.com/a/9715377
eval ${varname}=$\default_value
else
unset ${varname}
fi
done
COMMAND_NAME="$(basename "$0")"
# Print instructions for using this script to stdout
usage() {
echo "Usage: ${COMMAND_NAME} [--help|-h] [ --SETTING=VALUE | --SETTING VALUE | --SETTING | --release ] *"
echo
echo " Available settings. Each setting corresponds to a variable,"
echo " obtained by upcasing its name, in this script. A variable"
echo " with no default listed here will be unset in the script if"
echo " not explicitly specified. A setting passed in the 3rd form"
echo " will set its corresponding variable to \"1\"."
echo
setting_list="
| |Setting| Default|Description
| |-------| -------|-----------
"
for ((i = 0; i < ${#KNOWN_SETTINGS[@]}; i += 3)); do
setting_list+="\
| |--${KNOWN_SETTINGS[i]}| ${KNOWN_SETTINGS[$((i+1))]}|${KNOWN_SETTINGS[$((i+2))]}
"
done
echo "${setting_list}" | column -x -s'|' -t
echo
echo "Note: when using the form --SETTING VALUE, VALUE must not begin "
echo " with a hyphen."
echo "Note: the \"--release\" option creates a pre-packaged combination"
echo " of settings used by the buildbot."
}
# Scan all command-line arguments
while [[ "$1" ]] ; do
case "$1" in
-h | --help )
usage
exit
;;
--release)
BUILD_TYPE=RelWithDebInfo
# Include a custom name to avoid picking up stale module files.
CUSTOM_VERSION_NAME="release $(date -j '+%Y-%m-%d %H-%M-%S')"
;;
--* )
dashless="${1:2}"
# drop suffix beginning with the first "="
setting="${dashless%%=*}"
# compute the variable to set
varname="$(to_varname "${setting}")"
# check to see if this is a known option
known_var_name="${varname}_IS_KNOWN_SETTING"
if [[ ! "${!known_var_name}" ]] ; then
echo "Error: Unknown setting: ${setting}" 1>&2
usage 1>&2
exit 1
fi
# find the intended value
if [[ "${dashless}" == *=* ]] ; then # if there's an '=', the value
value="${dashless#*=}" # is everything after the first '='
elif [[ "$2" ]] && [[ "${2:0:1}" != "-" ]] ; then # else if the next parameter exists
value="$2" # but isn't an option, use that
shift
else # otherwise, the value is 1
value=1
fi
# For explanation of backslash see http://stackoverflow.com/a/9715377
eval ${varname}=$\value
;;
*)
usage
exit 1
esac
shift
done
# Set this to the install prefix for release builds.
INSTALL_PREFIX="${PREFIX}"
# Set these to the paths of the OS X SDK and toolchain.
if [[ "$(uname -s)" == "Darwin" ]] ; then
SYSROOT="$(xcrun --show-sdk-path --sdk macosx10.10internal)"
TOOLCHAIN="$(xcode-select -p)/Toolchains/XcodeDefault.xctoolchain"
else
SYSROOT="/"
TOOLCHAIN="/"
fi
# WORKSPACE and BUILD_DIR must be absolute paths
case "${WORKSPACE}" in
/*) ;;
*) echo "workspace must be an absolute path (was '${WORKSPACE}')" ; exit 1 ;;
esac
case "${BUILD_DIR}" in
/*) ;;
"") echo "the --build-dir option is required"
usage
exit 1
;;
*) echo "build-dir must be an absolute path (was '${BUILD_DIR}')" ; exit 1 ;;
esac
# WORKSPACE must exist
if [ ! -e "$WORKSPACE" ]; then
echo "Workspace does not exist (tried $WORKSPACE)"
exit 1
fi
# Swift-project products, in the order they must be built
SWIFT_BUILD_PRODUCTS=(swift)
if [[ ! "$SKIP_BUILD_SOURCEKIT" ]]; then
SWIFT_BUILD_PRODUCTS=("${SWIFT_BUILD_PRODUCTS[@]}" SourceKit)
fi
SWIFT_TEST_PRODUCTS=("${SWIFT_BUILD_PRODUCTS[@]}")
LLVM_TARGETS_TO_BUILD="X86;ARM;AArch64"
# Swift stdlib build products
# macosx-x86_64 stdlib is part of the swift product itself
if [[ ! "$SKIP_IOS" ]]; then
IOS_SIMULATOR_PRODUCTS=(swift_stdlib_ios_simulator_x86_64 swift_stdlib_ios_simulator_i386)
IOS_DEVICE_PRODUCTS=(swift_stdlib_ios_arm64 swift_stdlib_ios_armv7)
if [[ ! "$SKIP_BUILD_IOS" ]]; then
if [[ ! "$SKIP_BUILD_IOS_SIMULATOR" ]]; then
IOS_BUILD_PRODUCTS=("${IOS_BUILD_PRODUCTS[@]}" "${IOS_SIMULATOR_PRODUCTS[@]}")
fi
if [[ ! "$SKIP_BUILD_IOS_DEVICE" ]]; then
IOS_BUILD_PRODUCTS=("${IOS_BUILD_PRODUCTS[@]}" "${IOS_DEVICE_PRODUCTS[@]}")
fi
SWIFT_BUILD_PRODUCTS=("${SWIFT_BUILD_PRODUCTS[@]}" "${IOS_BUILD_PRODUCTS[@]}")
fi
if [[ ! "$SKIP_TEST_IOS" ]]; then
if [[ ! "$SKIP_TEST_IOS_SIMULATOR" ]]; then
IOS_TEST_PRODUCTS=("${IOS_TEST_PRODUCTS[@]}" "${IOS_SIMULATOR_PRODUCTS[@]}")
fi
if [[ ! "$SKIP_TEST_IOS_DEVICE" ]]; then
IOS_TEST_PRODUCTS=("${IOS_TEST_PRODUCTS[@]}" "${IOS_DEVICE_PRODUCTS[@]}")
fi
SWIFT_TEST_PRODUCTS=("${SWIFT_TEST_PRODUCTS[@]}" "${IOS_TEST_PRODUCTS[@]}")
fi
fi
# All build products, in the order they must be built
ALL_BUILD_PRODUCTS=(llvm "${SWIFT_BUILD_PRODUCTS[@]}")
#
# Calculate source directories for each product.
#
# iOS build products use the same source directory as swift itself.
# Default to $WORKSPACE/swift if SWIFT_SOURCE_DIR if not set above.
for product in "${IOS_BUILD_PRODUCTS[@]}" "${IOS_TEST_PRODUCTS[@]}" ; do
varname="$(toupper "${product}")"_SOURCE_DIR
eval $varname=${SWIFT_SOURCE_DIR:-$WORKSPACE/swift}
done
# Default source directory is $WORKSPACE/$product if not set above.
for product in "${ALL_BUILD_PRODUCTS[@]}" ; do
_PRODUCT_SOURCE_DIR="$(toupper "${product}")"_SOURCE_DIR
eval dir=\${$_PRODUCT_SOURCE_DIR:=$WORKSPACE/$product}
if [ ! -e "${dir}" ] ; then
echo "Can't find source directory for $product (tried $dir)"
exit 1
fi
done
#
# Calculate build directories for each product
#
# Build directories are $BUILD_DIR/$product or $PRODUCT_SOURCE_DIR/build
for product in "${ALL_BUILD_PRODUCTS[@]}" ; do
PRODUCT=$(toupper "${product}")
product_build_dir_var="${PRODUCT}_BUILD_DIR"
eval "product_build_dir=\${${product_build_dir_var}}"
if [[ ! "${product_build_dir}" ]] ; then
eval "${PRODUCT}_BUILD_DIR=\"\${BUILD_DIR}/${product}\""
fi
done
# iOS build products use their own build directories, which are
# subdirectories of swift's build directory if BUILD_DIR is not set.
for product in "${IOS_BUILD_PRODUCTS[@]}" "${IOS_TEST_PRODUCTS[@]}" ; do
_PRODUCT_BUILD_DIR="$(toupper "${product}")"_BUILD_DIR
eval ${_PRODUCT_BUILD_DIR}="${BUILD_DIR}/${product}"
done
# Symlink clang into the llvm tree.
CLANG_SOURCE_DIR="${LLVM_SOURCE_DIR}/tools/clang"
CLANG_BUILD_DIR="${LLVM_BUILD_DIR}"
if [ ! -e "${WORKSPACE}/clang" ]; then
# If llvm/tools/clang is already a directory, use that and skip the symlink.
if [ ! -d "${CLANG_SOURCE_DIR}" ]; then
echo "Can't find source directory for clang (tried ${WORKSPACE}/clang and ${CLANG_SOURCE_DIR})"
exit 1
fi
fi
if [ ! -d "${CLANG_SOURCE_DIR}" ]; then
ln -sf "${WORKSPACE}/clang" "${CLANG_SOURCE_DIR}"
fi
if [[ "$(uname -s)" == "Darwin" ]] ; then
HOST_CC="$TOOLCHAIN/usr/bin/clang"
HOST_CXX="$TOOLCHAIN/usr/bin/clang++"
else
HOST_CC="clang"
HOST_CXX="clang++"
fi
if [[ "$DISTCC" ]] ; then
# On some platforms, pump may be unrelated to distcc, in which case it's
# called distcc-pump.
DISTCC_PUMP="$(which distcc-pump || which pump)"
CMAKE_COMPILER_OPTIONS=(
-DSWIFT_DISTCC="$(which distcc)"
-DCMAKE_C_COMPILER="$(which distcc)"
-DCMAKE_C_COMPILER_ARG1="${HOST_CC}"
-DCMAKE_CXX_COMPILER="$(which distcc)"
-DCMAKE_CXX_COMPILER_ARG1="${HOST_CXX}"
)
else
CMAKE_COMPILER_OPTIONS=(
-DCMAKE_C_COMPILER="${HOST_CC}"
-DCMAKE_CXX_COMPILER="${HOST_CXX}"
)
fi
CMAKE_C_FLAGS=""
CMAKE_CXX_FLAGS=""
CMAKE_EXE_LINKER_FLAGS=""
CMAKE_SHARED_LINKER_FLAGS=""
if [[ "${RUN_WITH_ASAN_COMPILER}" ]]; then
CMAKE_COMPILER_OPTIONS=(
-DCMAKE_C_COMPILER="${RUN_WITH_ASAN_COMPILER}"
-DCMAKE_CXX_COMPILER="${RUN_WITH_ASAN_COMPILER}++"
)
CMAKE_C_FLAGS="-fsanitize=address -O1 -g -fno-omit-frame-pointer -mllvm -asan-globals=0"
CMAKE_CXX_FLAGS="-fsanitize=address -O1 -g -fno-omit-frame-pointer -mllvm -asan-globals=0"
CMAKE_EXE_LINKER_FLAGS="-fsanitize=address"
CMAKE_SHARED_LINKER_FLAGS="-fsanitize=address"
fi
ENABLE_ASSERTIONS="ON"
if [[ "$DISABLE_ASSERTIONS" ]]; then
ENABLE_ASSERTIONS="OFF"
fi
# CMake options used for all targets, including LLVM/Clang
COMMON_CMAKE_OPTIONS=(
"${CMAKE_COMPILER_OPTIONS[@]}"
-DLLVM_ENABLE_ASSERTIONS="${ENABLE_ASSERTIONS}"
)
case "${CMAKE_GENERATOR}" in
'Unix Makefiles')
BUILD_ARGS="${BUILD_ARGS:--j8}"
;;
Xcode)
BUILD_TARGET_FLAG=-target
COMMON_CMAKE_OPTIONS=(
"${COMMON_CMAKE_OPTIONS[@]}"
-DCMAKE_XCODE_ATTRIBUTE_GCC_VERSION:STRING=com.apple.compilers.llvm.clang.1_0
-DCMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY:STRING=libc++
-DCMAKE_OSX_DEPLOYMENT_TARGET=10.8
-DCMAKE_CONFIGURATION_TYPES="Debug;Release"
)
;;
esac
# Record SDK and tools versions for posterity
if [[ "$SHOW_SDKS" ]]; then
echo "--- SDK versions ---"
xcodebuild -version || :
echo
xcodebuild -version -sdk macosx.internal || :
if [[ ! "$SKIP_IOS" ]]; then
xcodebuild -version -sdk iphoneos.internal || :
xcodebuild -version -sdk iphonesimulator || :
fi
fi
# Build LLVM and Clang (x86 target only).
if [ \! "$SKIP_BUILD_LLVM" ]; then
echo "--- Building LLVM and Clang ---"
if [[ "${RECONFIGURE}" || ! -f "${LLVM_BUILD_DIR}/CMakeCache.txt" ]] ; then
set -x
mkdir -p "${LLVM_BUILD_DIR}"
# Note: we set LLVM_IMPLICIT_PROJECT_IGNORE below because this
# script builds swift separately, and people often have reasons
# to symlink the swift directory into llvm/tools, e.g. to build
# LLDB
(cd "${LLVM_BUILD_DIR}" &&
"$CMAKE" -G "${CMAKE_GENERATOR}" "${COMMON_CMAKE_OPTIONS[@]}" \
-DCMAKE_BUILD_TYPE="${LLVM_BUILD_TYPE}" \
-DCMAKE_C_FLAGS="${CMAKE_C_FLAGS}" \
-DLLVM_IMPLICIT_PROJECT_IGNORE="${LLVM_SOURCE_DIR}/tools/swift" \
-DLLVM_TARGETS_TO_BUILD="${LLVM_TARGETS_TO_BUILD}" \
-DCLANG_REPOSITORY_STRING="$CUSTOM_VERSION_NAME" \
${CONFIG_ARGS} \
"${LLVM_SOURCE_DIR}" || exit 1)
{ set +x; } 2>/dev/null
fi
set -x
$DISTCC_PUMP "$CMAKE" --build "${LLVM_BUILD_DIR}" -- ${BUILD_ARGS}
{ set +x; } 2>/dev/null
fi
#
# Now build all the Swift products
#
if [[ "$(uname -s)" == "Darwin" ]] ; then
SWIFT_CMAKE_OPTIONS=(
-DCMAKE_OSX_SYSROOT="${SYSROOT}"
-DMODULES_SDK="${SYSROOT}"
-DCMAKE_C_FLAGS="-isysroot${SYSROOT} ${CMAKE_C_FLAGS}"
-DCMAKE_CXX_FLAGS="-isysroot${SYSROOT} ${CMAKE_CXX_FLAGS}"
)
else
SWIFT_CMAKE_OPTIONS=(
-DCMAKE_C_FLAGS="${CMAKE_C_FLAGS}"
-DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS}"
)
fi
SWIFT_CMAKE_OPTIONS=(
"${SWIFT_CMAKE_OPTIONS[@]}"
-DSWIFT_RUN_LONG_TESTS="ON"
-DLLVM_CONFIG="${LLVM_BUILD_DIR}/bin/llvm-config"
-DCMAKE_BUILD_TYPE="$BUILD_TYPE"
)
# set_ios_options options_var platform deployment_target internal_suffix arch
function set_ios_options {
local platform=$2
local deployment_target=$3
local internal_suffix=$4
local arch=$5
local sdkroot=$(xcrun -sdk ${platform}${internal_suffix} -show-sdk-path)
local opts=(
-DCMAKE_TOOLCHAIN_FILE="${SWIFT_SOURCE_DIR}/cmake/${platform}.cmake"
-DCMAKE_SYSTEM_PROCESSOR=${arch}
-DCMAKE_OSX_ARCHITECTURES=${arch}
-DCMAKE_OSX_SYSROOT="${sdkroot}"
-DMODULES_SDK="${sdkroot}"
-DCMAKE_C_FLAGS="-isysroot${sdkroot}"
-DCMAKE_CXX_FLAGS="-isysroot${sdkroot}"
-DSWIFT_DEPLOYMENT_OS=${platform}
-DSWIFT_DEPLOYMENT_TARGET=${deployment_target}
-DSWIFT_BUILD_TOOLS=OFF
-DSWIFT_RUN_LONG_TESTS="ON"
-DPATH_TO_SWIFT_BUILD="${SWIFT_BUILD_DIR}"
-DSWIFT_INCLUDE_DOCS=OFF
-DLLVM_CONFIG="${LLVM_BUILD_DIR}/bin/llvm-config"
)
eval $1=\(\${opts[@]}\)
}
if [[ ! "$SKIP_BUILD_IOS" ]]; then
set_ios_options SWIFT_STDLIB_IOS_ARM64_CMAKE_OPTIONS iphoneos 7.0 .internal arm64
set_ios_options SWIFT_STDLIB_IOS_SIMULATOR_X86_64_CMAKE_OPTIONS iphonesimulator 7.0 "" x86_64
set_ios_options SWIFT_STDLIB_IOS_ARMV7_CMAKE_OPTIONS iphoneos 7.0 .internal armv7
set_ios_options SWIFT_STDLIB_IOS_SIMULATOR_I386_CMAKE_OPTIONS iphonesimulator 7.0 "" i386
fi
SOURCEKIT_CMAKE_OPTIONS=(
-DSOURCEKIT_PATH_TO_SWIFT_SOURCE="${SWIFT_SOURCE_DIR}"
-DSOURCEKIT_PATH_TO_SWIFT_BUILD="${SWIFT_BUILD_DIR}"
-DLLVM_CONFIG="${LLVM_BUILD_DIR}/bin/llvm-config"
-DCMAKE_C_FLAGS="-isysroot${SYSROOT} ${CMAKE_C_FLAGS}"
-DCMAKE_CXX_FLAGS="-isysroot${SYSROOT} ${CMAKE_CXX_FLAGS}"
)
ASAN_CMAKE_OPTIONS=(
-DSOURCEKIT_USE_INPROC_LIBRARY="ON"
-DSWIFT_ASAN_BUILD="ON"
)
# Build each one. Note: in this block, names beginning with underscore
# are used indirectly to access product-specific variables.
for product in "${SWIFT_BUILD_PRODUCTS[@]}" ; do
PRODUCT=$(toupper "${product}")
_SKIP_BUILD_PRODUCT=SKIP_BUILD_${PRODUCT}
if [[ ! "${!_SKIP_BUILD_PRODUCT}" ]]; then
echo "--- Building ${product} ---"
_PRODUCT_SOURCE_DIR=${PRODUCT}_SOURCE_DIR
_PRODUCT_BUILD_DIR=${PRODUCT}_BUILD_DIR
# Clean product-local module cache.
swift_module_cache="${!_PRODUCT_BUILD_DIR}/swift-module-cache"
rm -rf "${swift_module_cache}"
mkdir -p "${swift_module_cache}"
# Configure if necessary.
if [[ "${RECONFIGURE}" || ! -f "${!_PRODUCT_BUILD_DIR}/CMakeCache.txt" ]] ; then
mkdir -p "${!_PRODUCT_BUILD_DIR}"
_PRODUCT_CMAKE_OPTIONS=${PRODUCT}_CMAKE_OPTIONS[@]
if [[ "${RUN_WITH_ASAN_COMPILER}" ]]; then
_ASAN_OPTIONS=ASAN_CMAKE_OPTIONS[@]
fi
case "${PRODUCT}" in
SWIFT_STDLIB*) var_prefix="SWIFT" ;;
*) var_prefix=${PRODUCT} ;;
esac
set -x
(cd "${!_PRODUCT_BUILD_DIR}" &&
"$CMAKE" -G "${CMAKE_GENERATOR}" "${COMMON_CMAKE_OPTIONS[@]}" \
"${!_PRODUCT_CMAKE_OPTIONS}" \
"${!_ASAN_OPTIONS}" \
-DSWIFT_MODULE_CACHE_PATH="${swift_module_cache}" \
-DCMAKE_INSTALL_PREFIX="$INSTALL_PREFIX" \
-D${var_prefix}_PATH_TO_CLANG_SOURCE="${CLANG_SOURCE_DIR}" \
-D${var_prefix}_PATH_TO_CLANG_BUILD="${CLANG_BUILD_DIR}" \
-D${var_prefix}_PATH_TO_LLVM_SOURCE="${LLVM_SOURCE_DIR}" \
-D${var_prefix}_PATH_TO_LLVM_BUILD="${LLVM_BUILD_DIR}" \
${CONFIG_ARGS} \
"${!_PRODUCT_SOURCE_DIR}" || exit 1)
{ set +x; } 2>/dev/null
fi
# Build.
set -x
$DISTCC_PUMP "$CMAKE" --build "${!_PRODUCT_BUILD_DIR}" -- ${BUILD_ARGS}
{ set +x; } 2>/dev/null
fi
done
# Trap function to print the current test configuration when tests fail.
# This is a function so the text is not unnecessarily displayed when running -x.
tests_busted ()
{
echo "*** Failed while running tests for $1"
}
# Run the tests for each product
for product in "${SWIFT_TEST_PRODUCTS[@]}" ; do
PRODUCT=$(toupper "${product}")
_SKIP_TEST_PRODUCT=SKIP_TEST_${PRODUCT}
if [[ ! "${!_SKIP_TEST_PRODUCT}" ]]; then
echo "--- Running tests for ${product} ---"
trap "tests_busted ${product}" ERR
_PRODUCT_SOURCE_DIR=${PRODUCT}_SOURCE_DIR
_PRODUCT_BUILD_DIR=${PRODUCT}_BUILD_DIR
build_cmd=("$CMAKE" --build "${!_PRODUCT_BUILD_DIR}" -- ${BUILD_ARGS})
if [[ "${product}" == SourceKit ]] ; then
test_target=SourceKitUnitTests
else
test_target=SwiftUnitTests
fi
set -x
$DISTCC_PUMP "${build_cmd[@]}" ${BUILD_TARGET_FLAG} "${test_target}"
{ set +x; } 2>/dev/null
if [[ "${product}" == SourceKit ]] ; then
test_target=check-${product}
if [[ "$STRESS_TEST_SOURCEKIT" ]]; then
test_target="${test_target} stress-SourceKit"
fi
else
test_target=check-${product}-all
if [[ "$SKIP_TEST_VALIDATION" ]]; then
test_target=check-${product}
fi
fi
if [[ "${CMAKE_GENERATOR}" == Ninja ]] ; then
# Ninja buffers command output to avoid scrambling the output
# of parallel jobs, which is awesome... except that it
# interferes with the progress meter when testing. Instead of
# executing ninja directly, have it dump the commands it would
# run, strip Ninja's progress prefix with sed, and tell the
# shell to execute that.
sh -c "set -x && $("${build_cmd[@]}" -n -v ${test_target} | sed -e 's/[^]]*] //')"
else
set -x
"${build_cmd[@]}" ${BUILD_TARGET_FLAG} ${test_target}
{ set +x; } 2>/dev/null
fi
trap - ERR
echo "--- Finished tests for ${product} ---"
fi
done
# Run the Swift performance tests.
if [ \! "$SKIP_TEST_SWIFT_PERFORMANCE" ]; then
# Currently we use the toolchain-specific Clang as our CC under test, because
# our locally built one might not end up invoking an LD that supports
# autolinking on older machines. We can reconsider this when it becomes useful
# to have the C/C++ tests be running using the same LLVM basis as the Swift we
# are testing.
echo "--- Running Swift Performance Tests ---"
export CLANG="$TOOLCHAIN/usr/bin/clang"
export SWIFT="${SWIFT_BUILD_DIR}/bin/swift"
set -x
if (cd "${SWIFT_BUILD_DIR}" &&
"${LLVM_BUILD_DIR}/bin/llvm-lit" -v benchmark \
-j1 --output benchmark/results.json); then
PERFORMANCE_TESTS_PASSED=1
else
PERFORMANCE_TESTS_PASSED=0
fi
{ set +x; } 2>/dev/null
echo "--- Submitting Swift Performance Tests ---"
swift_source_revision="$("${LLVM_SOURCE_DIR}/utils/GetSourceVersion" "${SWIFT_SOURCE_DIR}")"
set -x
(cd "${SWIFT_BUILD_DIR}" &&
"${SWIFT_SOURCE_DIR}/utils/submit-benchmark-results" benchmark/results.json \
--output benchmark/lnt_results.json \
--machine-name "matte.apple.com--${BUILD_TYPE}--x86_64--O3" \
--run-order "$swift_source_revision" \
--submit http://localhost:32169/submitRun) \
|| echo "*** Swift performance test results not submitted."
{ set +x; } 2>/dev/null
# If the performance tests failed, fail the build.
if [ "$PERFORMANCE_TESTS_PASSED" -ne 1 ]; then
echo "*** ERROR: Swift Performance Tests failed ***"
exit 1
fi
fi

View File

@@ -1,15 +1,21 @@
add_swift_library(LeaksDetector SHARED
leaksDetector.c)
if (APPLE) swift_get_configuration_types(configs)
set(SHARED_LIBRARY YES) foreach(config ${configs})
add_swift_library(LeaksDetector leaksDetector.c) set(LEAKS_DETECTOR_LIBRARY_PATH
get_property(LEAKS_DETECTOR_LIBRARY_PATH TARGET LeaksDetector PROPERTY LOCATION) "${CMAKE_BINARY_DIR}/${config}/lib/libLeaksDetector${CMAKE_SHARED_LIBRARY_SUFFIX}")
configure_file( configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/leaks-runner.in "${CMAKE_CURRENT_SOURCE_DIR}/leaks-runner.in"
${CMAKE_CURRENT_BINARY_DIR}/leaks-runner "${CMAKE_CURRENT_BINARY_DIR}/${config}/leaks-runner"
@ONLY @ONLY
NEWLINE_STYLE UNIX) NEWLINE_STYLE UNIX)
file(COPY ${CMAKE_CURRENT_BINARY_DIR}/leaks-runner file(COPY "${CMAKE_CURRENT_BINARY_DIR}/${config}/leaks-runner"
DESTINATION ${CMAKE_BINARY_DIR}/bin DESTINATION "${CMAKE_BINARY_DIR}/${config}/bin"
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ FILE_PERMISSIONS
GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) OWNER_READ OWNER_WRITE OWNER_EXECUTE
endif() GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE)
endforeach()

View File

@@ -1,9 +1,8 @@
#!/bin/bash #!/bin/bash
#
# This is a wrapper for running the leaks detector tool on a binary. # This is a wrapper for running the leaks detector tool on a binary.
#
LEAKS_DETECTOR_LIBRARY_PATH=@LEAKS_DETECTOR_LIBRARY_PATH@
set -e set -e
DYLD_INSERT_LIBRARIES=$LEAKS_DETECTOR_LIBRARY_PATH $@ DYLD_INSERT_LIBRARIES="@LEAKS_DETECTOR_LIBRARY_PATH@" "$@"
set +e

View File

@@ -1,31 +1,22 @@
if(CMAKE_CONFIGURATION_TYPES) swift_get_configuration_types(configs)
foreach(config ${CMAKE_CONFIGURATION_TYPES}) foreach(config ${configs})
# Xcode support. See the CMakeLists.txt for the SwiftLLVMPasses library. set(OPT "${PATH_TO_LLVM_BUILD}/${config}/bin/opt")
set(SWIFT_LLVM_DYLIB
set(OPT ${PATH_TO_LLVM_BUILD}/${config}/bin/opt) "${CMAKE_BINARY_DIR}/${config}/lib/SwiftLLVMPasses${CMAKE_SHARED_LIBRARY_SUFFIX}")
string(TOUPPER ${config} config_upper)
get_property(SWIFT_LLVM_DYLIB
TARGET SwiftLLVMPasses
PROPERTY "LOCATION_${config_upper}")
# Note: this won't work if the EFFECTIVE_PLATFORM_NAME isn't empty.
# Currently it always is on OS X.
string(REPLACE "$(EFFECTIVE_PLATFORM_NAME)" "" SWIFT_LLVM_DYLIB
"${SWIFT_LLVM_DYLIB}")
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/llvm-opt.in
${CMAKE_BINARY_DIR}/${config}/bin/llvm-opt
@ONLY)
endforeach()
else()
set(OPT ${PATH_TO_LLVM_BUILD}/bin/opt)
get_property(SWIFT_LLVM_DYLIB
TARGET SwiftLLVMPasses
PROPERTY LOCATION)
configure_file( configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/llvm-opt.in "${CMAKE_CURRENT_SOURCE_DIR}/llvm-opt.in"
${CMAKE_BINARY_DIR}/${config}/bin/llvm-opt "${CMAKE_CURRENT_BINARY_DIR}/${config}/llvm-opt"
@ONLY) @ONLY
endif() NEWLINE_STYLE UNIX)
file(COPY "${CMAKE_CURRENT_BINARY_DIR}/${config}/llvm-opt"
DESTINATION "${CMAKE_BINARY_DIR}/${config}/bin"
FILE_PERMISSIONS
OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE)
endforeach()
swift_install_in_component(testsuite-tools
FILES "${SWIFT_RUNTIME_OUTPUT_INTDIR}/llvm-opt"
DESTINATION "bin")

View File

@@ -1,6 +1,9 @@
#!/bin/bash #!/bin/bash
#
# This is a wrapper around llvm's opt command line tool that automatically # This is a wrapper around llvm's opt command line tool that automatically
# performs the necessary work to access swift's llvm passes. # performs the necessary work to access swift's llvm passes.
#
set -e
"@OPT@" -load "@SWIFT_LLVM_DYLIB@" "$@"
"@OPT@" -load "@SWIFT_LLVM_DYLIB@" $@

View File

@@ -61,7 +61,7 @@ def getWorkTreeSha():
def buildBenchmarks(cacheDir): def buildBenchmarks(cacheDir):
print('Building executables...') print('Building executables...')
configVars = {'SWIFT_INCLUDE_BENCHMARKS':'ON', 'SWIFT_INCLUDE_PERF_TESTSUITE':'ON', 'SWIFT_OPTIMIZED':'ON', 'SWIFT_STDLIB_INTERNAL_CHECKS':'OFF'} configVars = {'SWIFT_INCLUDE_BENCHMARKS':'TRUE', 'SWIFT_INCLUDE_PERF_TESTSUITE':'TRUE', 'SWIFT_STDLIB_BUILD_TYPE':'RelWithDebInfo', 'SWIFT_STDLIB_ASSERTIONS':'FALSE'}
cmakeCache = os.path.join(buildDir, 'CMakeCache.txt') cmakeCache = os.path.join(buildDir, 'CMakeCache.txt')

116
utils/update-checkout Executable file
View File

@@ -0,0 +1,116 @@
#!/usr/bin/python
#===--- update-checkout - Utility to update your local checkouts -----------===#
#
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
#
#===------------------------------------------------------------------------===#
from __future__ import print_function
import getopt
import os
import shutil
import string
import sys
sys.path.append(os.path.dirname(__file__))
from SwiftBuildSupport import *
def usage():
print("""
Usage:
update-checkout [options]
source repositories.
By default, updates your checkouts of Swift, SourceKit and LLDB.
Options:
-a, --all update your checkouts of LLVM, Clang and Swift,
SourceKit and LLDB
""")
class WorkingDirectory(object):
def __init__(self, new_cwd):
self.new_cwd = new_cwd
def __enter__(self):
self.old_cwd = os.getcwd()
os.chdir(self.new_cwd)
def __exit__(self, type, value, traceback):
os.chdir(self.old_cwd)
def update_git_svn(repo_path):
with WorkingDirectory(repo_path):
use_stash = (check_output([ "git", "status", "--porcelain" ]) != "")
if use_stash:
check_call([ "git", "stash", "save", "--all"])
# Try first to pull from an upstream Git repo, assuming there is one
if check_output([ "git", "remote" ]) != "":
check_call([ "git", "pull", "--rebase" ])
check_call([ "git", "svn", "rebase", "-l" ])
else:
check_call([ "git", "svn", "rebase" ])
if use_stash:
check_call([ "git", "stash", "pop" ])
def update_working_copy(repo_path):
if not os.path.isdir(repo_path):
return
with WorkingDirectory(repo_path):
if os.path.isdir(os.path.join(".git", "svn")):
update_git_svn(repo_path)
elif os.path.isdir(".git"):
check_call([ "git", "pull" ])
else:
check_call([ "svn", "update" ])
def main():
try:
opts, args = getopt.getopt(sys.argv[1:], "a",
[ "all" ])
except getopt.GetoptError as err:
bad_usage(str(err))
opt_update_all = False
for o, a in opts:
if o == "--all":
opt_update_all = True
else:
assert False, "unhandled option " + o
if args != []:
bad_usage("extra arguments: " + args)
if opt_update_all:
update_working_copy(os.path.join(SWIFT_SOURCE_ROOT, "llvm"))
update_working_copy(os.path.join(SWIFT_SOURCE_ROOT, "clang"))
update_working_copy(os.path.join(SWIFT_SOURCE_ROOT, "swift"))
update_working_copy(os.path.join(SWIFT_SOURCE_ROOT, "SourceKit"))
update_working_copy(os.path.join(SWIFT_SOURCE_ROOT, "lldb"))
return 0
if __name__ == "__main__":
sys.exit(main())

View File

@@ -1,6 +1,7 @@
install( swift_install_in_component(editor-integration
DIRECTORY DIRECTORY
ftdetect ftdetect
syntax syntax
DESTINATION share/vim/vim73 DESTINATION "share/vim/vim73"
PATTERN ".*" EXCLUDE) PATTERN ".*" EXCLUDE)

View File

@@ -25,19 +25,21 @@ except KeyError:
key, = e.args key, = e.args
lit_config.fatal("unable to find %r parameter, use '--param=%s=VALUE'" % (key,key)) lit_config.fatal("unable to find %r parameter, use '--param=%s=VALUE'" % (key,key))
if "@SWIFT_ASAN_BUILD@" != "OFF" and "@SWIFT_ASAN_BUILD@" != "NO": if "@SWIFT_ASAN_BUILD@" == "TRUE":
config.available_features.add("asan") config.available_features.add("asan")
if "@LLVM_ENABLE_ASSERTIONS@" == "TRUE" or "@LLVM_ENABLE_ASSERTIONS@" == "ON": if "@LLVM_ENABLE_ASSERTIONS@" == "TRUE":
config.available_features.add('asserts') config.available_features.add('asserts')
else: else:
config.available_features.add('no_asserts') config.available_features.add('no_asserts')
if "@SWIFT_STDLIB_INTERNAL_CHECKS@" != "OFF" and "@SWIFT_STDLIB_INTERNAL_CHECKS@" != "NO": if "@SWIFT_STDLIB_ASSERTIONS@" == "TRUE":
config.available_features.add('swift_stdlib_asserts') config.available_features.add('swift_stdlib_asserts')
else:
config.available_features.add('swift_stdlib_no_asserts')
if "@SWIFT_OPTIMIZED@" == "ON" or "@SWIFT_OPTIMIZED@" == "YES": if "@SWIFT_OPTIMIZED@" == "TRUE":
config.available_features.add("optimized_stdlib") config.available_features.add("optimized_stdlib")
# Let the main config do the real work. # Let the main config do the real work.
config.test_exec_root = os.path.dirname(os.path.realpath(__file__)) config.test_exec_root = os.path.dirname(os.path.realpath(__file__))