Skip to content

Commit 71d0fa0

Browse files
author
Eugene Burmako
authored
Merge pull request #26562 from apple/tensorflow-merge
Merge tag 'swift-DEVELOPMENT-SNAPSHOT-2019-08-05-a' into tensorflow
2 parents da03d99 + 10645b0 commit 71d0fa0

File tree

344 files changed

+5724
-3110
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

344 files changed

+5724
-3110
lines changed

CMakeLists.txt

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,13 @@ if(SWIFT_HOST_VARIANT_SDK)
620620
set(SWIFT_HOST_VARIANT_SDK_default "${SWIFT_HOST_VARIANT_SDK}")
621621
else()
622622
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
623-
set(SWIFT_HOST_VARIANT_SDK_default "LINUX")
623+
# CMake on an Android host sets this to Linux, so check for the ANDROID_DATA
624+
# environment variable to see if we're building on Android.
625+
if(NOT "$ENV{ANDROID_DATA}" STREQUAL "")
626+
set(SWIFT_HOST_VARIANT_SDK_default "ANDROID")
627+
else()
628+
set(SWIFT_HOST_VARIANT_SDK_default "LINUX")
629+
endif()
624630
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD")
625631
set(SWIFT_HOST_VARIANT_SDK_default "FREEBSD")
626632
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "CYGWIN")
@@ -630,6 +636,7 @@ else()
630636
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Haiku")
631637
set(SWIFT_HOST_VARIANT_SDK_default "HAIKU")
632638
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Android")
639+
# CMAKE_SYSTEM_NAME might be set this way when cross-compiling to Android.
633640
set(SWIFT_HOST_VARIANT_SDK_default "ANDROID")
634641
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
635642
set(SWIFT_HOST_VARIANT_SDK_default "OSX")
@@ -694,7 +701,7 @@ endif()
694701

695702
# FIXME: the parameters we specify in SWIFT_SDKS are lacking architecture specifics,
696703
# so we need to hard-code it. For example, the SDK for Android is just 'ANDROID',
697-
# which we assume below to be armv7.
704+
# and we have to specify SWIFT_SDK_ANDROID_ARCHITECTURES separately.
698705
# The iOS SDKs all have their architectures hardcoded because they are just specified by name (e.g. 'IOS' or 'WATCHOS').
699706
# We can't cross-compile the standard library for another linux architecture,
700707
# because the SDK list would just be 'LINUX' and we couldn't disambiguate it from the host.
@@ -756,9 +763,16 @@ elseif("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "HAIKU")
756763
elseif("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "ANDROID")
757764

758765
set(SWIFT_HOST_VARIANT "android" CACHE STRING
759-
"Deployment OS for Swift host tools (the compiler) [android].")
766+
"Deployment OS for Swift host tools (the compiler) [android]")
760767

761-
configure_sdk_unix("Android" "${SWIFT_HOST_VARIANT_ARCH}")
768+
set(SWIFT_ANDROID_NATIVE_SYSROOT "/data/data/com.termux/files" CACHE STRING
769+
"Path to Android sysroot, default initialized to the Termux app's layout")
770+
771+
if("${SWIFT_SDK_ANDROID_ARCHITECTURES}" STREQUAL "")
772+
set(SWIFT_SDK_ANDROID_ARCHITECTURES ${SWIFT_HOST_VARIANT_ARCH})
773+
endif()
774+
775+
configure_sdk_unix("Android" "${SWIFT_SDK_ANDROID_ARCHITECTURES}")
762776
set(SWIFT_PRIMARY_VARIANT_SDK_default "${SWIFT_HOST_VARIANT_SDK}")
763777
set(SWIFT_PRIMARY_VARIANT_ARCH_default "${SWIFT_HOST_VARIANT_ARCH}")
764778

@@ -1091,8 +1105,7 @@ endif()
10911105
#
10921106
# We must include stdlib/ before tools/ because stdlib/CMakeLists.txt
10931107
# declares the swift-stdlib-* set of targets. These targets will then
1094-
# implicitly depend on any targets declared with IS_STDLIB or
1095-
# TARGET_LIBRARY.
1108+
# implicitly depend on any targets declared with IS_STDLIB.
10961109
#
10971110
# One such library that declares IS_STDLIB is SwiftSyntax, living in
10981111
# tools/SwiftSyntax. If we include stdlib/ after tools/,

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Please make sure you use Python 2.x. Python 3.x is not supported currently.
3030

3131
#### macOS
3232

33-
To build for macOS, you need [Xcode 11 beta 4](https://developer.apple.com/xcode/downloads/).
33+
To build for macOS, you need [Xcode 11 beta 5](https://developer.apple.com/xcode/downloads/).
3434
The required version of Xcode changes frequently, and is often a beta release.
3535
Check this document for the current required version.
3636

@@ -68,7 +68,7 @@ First, create a directory for all of the Swift sources:
6868
**Note:** This is important since update-checkout (see below) checks out
6969
repositories next to the Swift source directory. This means that if one clones
7070
Swift and has other unrelated repositories, update-checkout may not clone those
71-
repositories and will update them instead. Additionally, ensure Python 2.7 is being
71+
repositories and will update them instead. Additionally, ensure Python 2.7 is being
7272
used for this step, whether via conda environment or other means.
7373

7474
**TensorFlow Support:** To build with TensorFlow support, the `tensorflow`

benchmark/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ set(SWIFT_BENCH_MODULES
166166
single-source/StringInterpolation
167167
single-source/StringMatch
168168
single-source/StringRemoveDupes
169+
single-source/StringReplaceSubrange
169170
single-source/StringTests
170171
single-source/StringWalk
171172
single-source/Substring
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
//===--- StringReplaceSubrange.swift -------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import TestsUtils
14+
15+
let tags: [BenchmarkCategory] = [.validation, .api, .String]
16+
17+
public let StringReplaceSubrange = [
18+
BenchmarkInfo(
19+
name: "String.replaceSubrange.String.Small",
20+
runFunction: { replaceSubrange($0, smallString, with: "t") },
21+
tags: tags
22+
),
23+
BenchmarkInfo(
24+
name: "String.replaceSubrange.String",
25+
runFunction: { replaceSubrange($0, largeString, with: "t") },
26+
tags: tags
27+
),
28+
BenchmarkInfo(
29+
name: "String.replaceSubrange.Substring.Small",
30+
runFunction: { replaceSubrange($0, smallString, with: "t"[...]) },
31+
tags: tags
32+
),
33+
BenchmarkInfo(
34+
name: "String.replaceSubrange.Substring",
35+
runFunction: { replaceSubrange($0, largeString, with: "t"[...]) },
36+
tags: tags
37+
),
38+
BenchmarkInfo(
39+
name: "String.replaceSubrange.ArrChar.Small",
40+
runFunction: { replaceSubrange($0, smallString, with: arrayCharacter) },
41+
tags: tags
42+
),
43+
BenchmarkInfo(
44+
name: "String.replaceSubrange.ArrChar",
45+
runFunction: { replaceSubrange($0, largeString, with: arrayCharacter) },
46+
tags: tags
47+
),
48+
BenchmarkInfo(
49+
name: "String.replaceSubrange.RepChar.Small",
50+
runFunction: { replaceSubrange($0, smallString, with: repeatedCharacter) },
51+
tags: tags
52+
),
53+
BenchmarkInfo(
54+
name: "String.replaceSubrange.RepChar",
55+
runFunction: { replaceSubrange($0, largeString, with: repeatedCharacter) },
56+
tags: tags
57+
),
58+
]
59+
60+
let smallString = "coffee"
61+
let largeString = "coffee\u{301}coffeecoffeecoffeecoffee"
62+
63+
let arrayCharacter = Array<Character>(["t"])
64+
let repeatedCharacter = repeatElement(Character("t"), count: 1)
65+
66+
@inline(never)
67+
private func replaceSubrange<C: Collection>(
68+
_ N: Int, _ string: String, with newElements: C
69+
) where C.Element == Character {
70+
var copy = getString(string)
71+
let range = string.startIndex..<string.index(after: string.startIndex)
72+
for _ in 0 ..< 500 * N {
73+
copy.replaceSubrange(range, with: newElements)
74+
}
75+
}

benchmark/utils/main.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ import StringEnum
161161
import StringInterpolation
162162
import StringMatch
163163
import StringRemoveDupes
164+
import StringReplaceSubrange
164165
import StringTests
165166
import StringWalk
166167
import Substring
@@ -343,6 +344,7 @@ registerBenchmark(StringInterpolationManySmallSegments)
343344
registerBenchmark(StringMatch)
344345
registerBenchmark(StringNormalization)
345346
registerBenchmark(StringRemoveDupes)
347+
registerBenchmark(StringReplaceSubrange)
346348
registerBenchmark(StringTests)
347349
registerBenchmark(StringWalk)
348350
registerBenchmark(SubstringTest)

cmake/modules/AddSwift.cmake

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ function(_add_variant_c_compile_link_flags)
140140
# lld can handle targeting the android build. However, if lld is not
141141
# enabled, then fallback to the linker included in the android NDK.
142142
if(NOT SWIFT_ENABLE_LLD_LINKER)
143-
list(APPEND result "-B" "${SWIFT_SDK_ANDROID_ARCH_${CFLAGS_ARCH}_NDK_PREBUILT_PATH}/${SWIFT_SDK_ANDROID_ARCH_${CFLAGS_ARCH}_NDK_TRIPLE}/bin")
143+
swift_android_tools_path(${CFLAGS_ARCH} tools_path)
144+
list(APPEND result "-B" "${tools_path}")
144145
endif()
145146
endif()
146147

@@ -482,22 +483,9 @@ function(_add_variant_link_flags)
482483
# We need to add the math library, which is linked implicitly by libc++
483484
list(APPEND result "-lm")
484485

485-
if("${LFLAGS_ARCH}" MATCHES armv7)
486-
set(android_libcxx_path "${SWIFT_ANDROID_NDK_PATH}/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a")
487-
elseif("${LFLAGS_ARCH}" MATCHES aarch64)
488-
set(android_libcxx_path "${SWIFT_ANDROID_NDK_PATH}/sources/cxx-stl/llvm-libc++/libs/arm64-v8a")
489-
elseif("${LFLAGS_ARCH}" MATCHES i686)
490-
set(android_libcxx_path "${SWIFT_ANDROID_NDK_PATH}/sources/cxx-stl/llvm-libc++/libs/x86")
491-
elseif("${LFLAGS_ARCH}" MATCHES x86_64)
492-
set(android_libcxx_path "${SWIFT_ANDROID_NDK_PATH}/sources/cxx-stl/llvm-libc++/libs/x86_64")
493-
else()
494-
message(SEND_ERROR "unknown architecture (${LFLAGS_ARCH}) for android")
495-
endif()
496-
497486
# link against the custom C++ library
498-
list(APPEND link_libraries
499-
${android_libcxx_path}/libc++abi.a
500-
${android_libcxx_path}/libc++_shared.so)
487+
swift_android_cxx_libraries_for_arch(${LFLAGS_ARCH} cxx_link_libraries)
488+
list(APPEND link_libraries ${cxx_link_libraries})
501489

502490
# link against the ICU libraries
503491
list(APPEND link_libraries
@@ -1016,7 +1004,7 @@ function(_add_swift_library_single target name)
10161004
${SWIFTLIB_SINGLE_XCODE_WORKAROUND_SOURCES})
10171005
if(("${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_OBJECT_FORMAT}" STREQUAL "ELF" OR
10181006
"${SWIFT_SDK_${SWIFTLIB_SINGLE_SDK}_OBJECT_FORMAT}" STREQUAL "COFF") AND
1019-
SWIFTLIB_TARGET_LIBRARY)
1007+
SWIFTLIB_SINGLE_TARGET_LIBRARY)
10201008
if("${libkind}" STREQUAL "SHARED" AND NOT SWIFTLIB_SINGLE_NOSWIFTRT)
10211009
# TODO(compnerd) switch to the generator expression when cmake is upgraded
10221010
# to a version which supports it.
@@ -1115,7 +1103,7 @@ function(_add_swift_library_single target name)
11151103
set_target_properties("${target}"
11161104
PROPERTIES
11171105
INSTALL_NAME_DIR "${install_name_dir}")
1118-
elseif("${SWIFTLIB_SINGLE_SDK}" STREQUAL "LINUX" AND NOT "${SWIFTLIB_SINGLE_SDK}" STREQUAL "ANDROID")
1106+
elseif("${SWIFTLIB_SINGLE_SDK}" STREQUAL "LINUX")
11191107
set_target_properties("${target}"
11201108
PROPERTIES
11211109
INSTALL_RPATH "$ORIGIN:/usr/lib/swift/linux")
@@ -1127,6 +1115,14 @@ function(_add_swift_library_single target name)
11271115
# CMake generates incorrect rule `$SONAME_FLAG $INSTALLNAME_DIR$SONAME` for Android build on macOS cross-compile host.
11281116
# Proper linker flags constructed manually. See below variable `swiftlib_link_flags_all`.
11291117
set_target_properties("${target}" PROPERTIES NO_SONAME TRUE)
1118+
# Only set the install RPATH if cross-compiling the host tools, in which
1119+
# case both the NDK and Sysroot paths must be set.
1120+
if(NOT "${SWIFT_ANDROID_NDK_PATH}" STREQUAL "" AND
1121+
NOT "${SWIFT_ANDROID_NATIVE_SYSROOT}" STREQUAL "")
1122+
set_target_properties("${target}"
1123+
PROPERTIES
1124+
INSTALL_RPATH "$ORIGIN")
1125+
endif()
11301126
endif()
11311127

11321128
# SWIFT_ENABLE_TENSORFLOW
@@ -1582,7 +1578,6 @@ endfunction()
15821578
# [INSTALL]
15831579
# [IS_STDLIB]
15841580
# [IS_STDLIB_CORE]
1585-
# [TARGET_LIBRARY]
15861581
# [INSTALL_WITH_SHARED]
15871582
# INSTALL_IN_COMPONENT comp
15881583
# DEPLOYMENT_VERSION_OSX version
@@ -1663,17 +1658,13 @@ endfunction()
16631658
#
16641659
# IS_STDLIB
16651660
# Treat the library as a part of the Swift standard library.
1666-
# IS_STDLIB implies TARGET_LIBRARY.
16671661
#
16681662
# IS_STDLIB_CORE
16691663
# Compile as the Swift standard library core.
16701664
#
16711665
# IS_SDK_OVERLAY
16721666
# Treat the library as a part of the Swift SDK overlay.
1673-
# IS_SDK_OVERLAY implies TARGET_LIBRARY and IS_STDLIB.
1674-
#
1675-
# TARGET_LIBRARY
1676-
# Build library for the target SDKs.
1667+
# IS_SDK_OVERLAY implies IS_STDLIB.
16771668
#
16781669
# INSTALL_IN_COMPONENT comp
16791670
# The Swift installation component that this library belongs to.
@@ -1707,7 +1698,6 @@ function(add_swift_target_library name)
17071698
OBJECT_LIBRARY
17081699
SHARED
17091700
STATIC
1710-
TARGET_LIBRARY
17111701
INSTALL_WITH_SHARED)
17121702
set(SWIFTLIB_single_parameter_options
17131703
DEPLOYMENT_VERSION_IOS
@@ -1736,6 +1726,7 @@ function(add_swift_target_library name)
17361726
SWIFT_COMPILE_FLAGS_OSX
17371727
SWIFT_COMPILE_FLAGS_TVOS
17381728
SWIFT_COMPILE_FLAGS_WATCHOS
1729+
SWIFT_COMPILE_FLAGS_LINUX
17391730
SWIFT_MODULE_DEPENDS
17401731
SWIFT_MODULE_DEPENDS_CYGWIN
17411732
SWIFT_MODULE_DEPENDS_FREEBSD
@@ -1760,18 +1751,11 @@ function(add_swift_target_library name)
17601751
if(SWIFTLIB_IS_SDK_OVERLAY)
17611752
set(SWIFTLIB_HAS_SWIFT_CONTENT TRUE)
17621753
set(SWIFTLIB_IS_STDLIB TRUE)
1763-
set(SWIFTLIB_TARGET_LIBRARY TRUE)
1764-
1765-
# Install to sdk-overlay by default, but don't hardcode it
1766-
if(NOT SWIFTLIB_INSTALL_IN_COMPONENT)
1767-
set(SWIFTLIB_INSTALL_IN_COMPONENT sdk-overlay)
1768-
endif()
17691754
endif()
17701755

17711756
# Standard library is always a target library.
17721757
if(SWIFTLIB_IS_STDLIB)
17731758
set(SWIFTLIB_HAS_SWIFT_CONTENT TRUE)
1774-
set(SWIFTLIB_TARGET_LIBRARY TRUE)
17751759
endif()
17761760

17771761
# If target SDKs are not specified, build for all known SDKs.
@@ -1811,9 +1795,6 @@ function(add_swift_target_library name)
18111795
"Either SHARED, STATIC, or OBJECT_LIBRARY must be specified")
18121796
endif()
18131797

1814-
precondition(SWIFTLIB_TARGET_LIBRARY
1815-
MESSAGE "TARGET_LIBRARY not inferred in add_swift_target_library?!")
1816-
18171798
# In the standard library and overlays, warn about implicit overrides
18181799
# as a reminder to consider when inherited protocols need different
18191800
# behavior for their requirements.
@@ -1894,6 +1875,9 @@ function(add_swift_target_library name)
18941875
elseif(${sdk} STREQUAL WATCHOS OR ${sdk} STREQUAL WATCHOS_SIMULATOR)
18951876
list(APPEND swiftlib_swift_compile_flags_all
18961877
${SWIFTLIB_SWIFT_COMPILE_FLAGS_WATCHOS})
1878+
elseif(${sdk} STREQUAL LINUX)
1879+
list(APPEND swiftlib_swift_compile_flags_all
1880+
${SWIFTLIB_SWIFT_COMPILE_FLAGS_LINUX})
18971881
elseif(${sdk} STREQUAL WINDOWS)
18981882
# FIXME(SR2005) static and shared are not mutually exclusive; however
18991883
# since we do a single build of the sources, this doesn't work for
@@ -2005,6 +1989,7 @@ function(add_swift_target_library name)
20051989
${SWIFTLIB_OBJECT_LIBRARY_keyword}
20061990
${SWIFTLIB_INSTALL_WITH_SHARED_keyword}
20071991
${SWIFTLIB_SOURCES}
1992+
TARGET_LIBRARY
20081993
MODULE_TARGET ${MODULE_VARIANT_NAME}
20091994
SDK ${sdk}
20101995
ARCHITECTURE ${arch}
@@ -2024,7 +2009,6 @@ function(add_swift_target_library name)
20242009
${SWIFTLIB_IS_STDLIB_keyword}
20252010
${SWIFTLIB_IS_STDLIB_CORE_keyword}
20262011
${SWIFTLIB_IS_SDK_OVERLAY_keyword}
2027-
${SWIFTLIB_TARGET_LIBRARY_keyword}
20282012
${SWIFTLIB_FORCE_BUILD_OPTIMIZED_keyword}
20292013
${SWIFTLIB_NOSWIFTRT_keyword}
20302014
DARWIN_INSTALL_NAME_DIR "${SWIFTLIB_DARWIN_INSTALL_NAME_DIR}"

cmake/modules/AddSwiftUnittests.cmake

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,14 @@ function(add_swift_unittest test_dirname)
4242
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
4343
set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY
4444
LINK_FLAGS " -Xlinker -rpath -Xlinker ${SWIFT_LIBRARY_OUTPUT_INTDIR}/swift/macosx")
45+
elseif("${SWIFT_HOST_VARIANT}" STREQUAL "android")
46+
swift_android_lib_for_arch(${SWIFT_HOST_VARIANT_ARCH} android_system_libs)
47+
set_property(TARGET "${test_dirname}" APPEND PROPERTY LINK_DIRECTORIES
48+
"${android_system_libs}")
49+
set_property(TARGET "${test_dirname}" APPEND PROPERTY LINK_LIBRARIES "log")
4550
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
46-
set_property(TARGET "${test_dirname}" APPEND_STRING PROPERTY
47-
LINK_FLAGS " -latomic")
51+
set_property(TARGET "${test_dirname}" APPEND PROPERTY LINK_LIBRARIES
52+
"atomic")
4853
endif()
4954

5055
find_program(LDLLD_PATH "ld.lld")

0 commit comments

Comments
 (0)