Skip to content

Commit 541b2ef

Browse files
authored
Merge branch 'master' into cxx-link-stdlib
2 parents de21a66 + 9591caf commit 541b2ef

File tree

2,910 files changed

+112604
-73535
lines changed

Some content is hidden

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

2,910 files changed

+112604
-73535
lines changed

CMakeLists.txt

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ if(POLICY CMP0067)
1212
cmake_policy(SET CMP0067 NEW)
1313
endif()
1414

15+
# Convert relative paths to absolute for subdirectory `target_sources`
16+
if(POLICY CMP0076)
17+
cmake_policy(SET CMP0076 NEW)
18+
endif()
19+
1520
# Add path for custom CMake modules.
1621
list(APPEND CMAKE_MODULE_PATH
1722
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
@@ -142,14 +147,20 @@ set(SWIFT_COMPILER_VERSION "" CACHE STRING
142147
set(CLANG_COMPILER_VERSION "" CACHE STRING
143148
"The internal version of the Clang compiler")
144149

145-
# Indicate whether Swift should attempt to use the lld linker.
146-
set(SWIFT_ENABLE_LLD_LINKER TRUE CACHE BOOL
147-
"Enable using the lld linker when available")
148-
149-
# Indicate whether Swift should attempt to use the gold linker.
150-
# This is not used on Darwin.
151-
set(SWIFT_ENABLE_GOLD_LINKER TRUE CACHE BOOL
152-
"Enable using the gold linker when available")
150+
# Which default linker to use. Prefer LLVM_USE_LINKER if it set, otherwise use
151+
# our own defaults. This should only be possible in a unified (not stand alone)
152+
# build environment.
153+
if(LLVM_USE_LINKER)
154+
set(SWIFT_USE_LINKER_default "${LLVM_USE_LINKER}")
155+
elseif(CMAKE_SYSTEM_NAME STREQUAL Windows AND NOT CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
156+
set(SWIFT_USE_LINKER_default "lld")
157+
elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin)
158+
set(SWIFT_USE_LINKER_default "")
159+
else()
160+
set(SWIFT_USE_LINKER_default "gold")
161+
endif()
162+
set(SWIFT_USE_LINKER ${SWIFT_USE_LINKER_default} CACHE STRING
163+
"Build Swift with a non-default linker")
153164

154165
set(SWIFT_TOOLS_ENABLE_LTO OFF CACHE STRING "Build Swift tools with LTO. One
155166
must specify the form of LTO by setting this to one of: 'full', 'thin'. This
@@ -402,6 +413,8 @@ endif()
402413

403414
if(MSVC OR "${CMAKE_SIMULATE_ID}" STREQUAL MSVC)
404415
include(ClangClCompileRules)
416+
elseif(UNIX)
417+
include(UnixCompileRules)
405418
endif()
406419

407420
if(CMAKE_C_COMPILER_ID MATCHES Clang)
@@ -421,19 +434,6 @@ if(SWIFT_BUILD_SYNTAXPARSERLIB OR SWIFT_BUILD_SOURCEKIT)
421434
endif()
422435
endif()
423436

424-
#
425-
# Assume a new enough ar to generate the index at construction time. This avoids
426-
# having to invoke ranlib as a secondary command.
427-
#
428-
429-
set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> crs <TARGET> <LINK_FLAGS> <OBJECTS>")
430-
set(CMAKE_C_ARCHIVE_APPEND "<CMAKE_AR> qs <TARGET> <LINK_FLAGS> <OBJECTS>")
431-
set(CMAKE_C_ARCHIVE_FINISH "")
432-
433-
set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> crs <TARGET> <LINK_FLAGS> <OBJECTS>")
434-
set(CMAKE_CXX_ARCHIVE_APPEND "<CMAKE_AR> qs <TARGET> <LINK_FLAGS> <OBJECTS>")
435-
set(CMAKE_CXX_ARCHIVE_FINISH "")
436-
437437
#
438438
# Include CMake modules
439439
#
@@ -458,6 +458,12 @@ if(SWIFT_PATH_TO_CMARK_BUILD)
458458
endif()
459459
message(STATUS "")
460460

461+
if("${SWIFT_NATIVE_LLVM_TOOLS_PATH}" STREQUAL "")
462+
set(SWIFT_CROSS_COMPILING FALSE)
463+
else()
464+
set(SWIFT_CROSS_COMPILING TRUE)
465+
endif()
466+
461467
include(SwiftSharedCMakeConfig)
462468

463469
# NOTE: We include this before SwiftComponents as it relies on some LLVM CMake
@@ -487,16 +493,6 @@ if(NOT SWIFT_LIPO)
487493
find_toolchain_tool(SWIFT_LIPO "${SWIFT_DARWIN_XCRUN_TOOLCHAIN}" lipo)
488494
endif()
489495

490-
# Reset CMAKE_SYSTEM_PROCESSOR if not cross-compiling.
491-
# CMake refuses to use `uname -m` on OS X
492-
# http://public.kitware.com/Bug/view.php?id=10326
493-
if(NOT CMAKE_CROSSCOMPILING AND CMAKE_SYSTEM_PROCESSOR STREQUAL "i386")
494-
execute_process(
495-
COMMAND "uname" "-m"
496-
OUTPUT_VARIABLE CMAKE_SYSTEM_PROCESSOR
497-
OUTPUT_STRIP_TRAILING_WHITESPACE)
498-
endif()
499-
500496
get_filename_component(SWIFT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} REALPATH)
501497
set(SWIFT_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
502498
set(SWIFT_CMAKE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
@@ -555,9 +551,6 @@ if(XCODE)
555551
swift_common_xcode_cxx_config()
556552
endif()
557553

558-
include(SwiftCheckCXXNativeRegex)
559-
check_cxx_native_regex(SWIFT_HAVE_WORKING_STD_REGEX)
560-
561554
# If SWIFT_HOST_VARIANT_SDK not given, try to detect from the CMAKE_SYSTEM_NAME.
562555
if(SWIFT_HOST_VARIANT_SDK)
563556
set(SWIFT_HOST_VARIANT_SDK_default "${SWIFT_HOST_VARIANT_SDK}")

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
| **Ubuntu 16.04** | x86_64 | [![Build Status](https://ci.swift.org/job/oss-swift-incremental-RA-linux-ubuntu-16_04/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-incremental-RA-linux-ubuntu-16_04)|[![Build Status](https://ci.swift.org/job/oss-swift-package-linux-ubuntu-16_04/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-linux-ubuntu-16_04)|
1010
| **Ubuntu 18.04** | x86_64 | [![Build Status](https://ci.swift.org/job/oss-swift-incremental-RA-linux-ubuntu-18_04/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-incremental-RA-linux-ubuntu-18_04)|[![Build Status](https://ci.swift.org/job/oss-swift-package-linux-ubuntu-18_04/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-linux-ubuntu-18_04)|
1111
| **Ubuntu 20.04** | x86_64 | [![Build Status](https://ci.swift.org/job/oss-swift-package-ubuntu-20_04/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-ubuntu-20_04)|[![Build Status](https://ci.swift.org/job/oss-swift-package-ubuntu-20_04/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-ubuntu-20_04)|
12-
| **CentOS 8** | x86_64 | [![Build Status](https://ci.swift.org/job/oss-swift-package-centos-8/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-centos-8)|[![Build Status](https://ci.swift.org/job/oss-swift-package-linux-ubuntu-18_04/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-centos-8)|
12+
| **CentOS 8** | x86_64 | [![Build Status](https://ci.swift.org/job/oss-swift-package-centos-8/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-centos-8)|[![Build Status](https://ci.swift.org/job/oss-swift-package-centos-8/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-centos-8)|
1313
| **Amazon Linux 2** | x86_64 | [![Build Status](https://ci.swift.org/job/oss-swift-package-amazon-linux-2/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-amazon-linux-2)|[![Build Status](https://ci.swift.org/job/oss-swift-package-amazon-linux-2/lastCompletedBuild/badge/icon)](https://ci.swift.org/job/oss-swift-package-amazon-linux-2)|
1414

1515
**Swift Community-Hosted CI Platforms**
@@ -85,6 +85,9 @@ Once you are able to build things successfully and have a compile-test-debug
8585
loop going, check out the [development tips](docs/DevelopmentTips.md) for
8686
better productivity while working on the compiler.
8787

88+
You can also skim [docs/README.md](/docs/README.md) to understand what
89+
high-level documentation is available.
90+
8891
### System Requirements
8992

9093
macOS, Ubuntu Linux LTS, and the latest Ubuntu Linux release are currently
@@ -94,7 +97,7 @@ Please make sure you use Python 2.x. Python 3.x is not supported currently.
9497

9598
#### macOS
9699

97-
To build for macOS, you need [Xcode 11.4](https://developer.apple.com/xcode/resources/).
100+
To build for macOS, you need [Xcode 12 beta](https://developer.apple.com/xcode/resources/).
98101
The required version of Xcode changes frequently, and is often a beta release.
99102
Check this document or the host information on <https://ci.swift.org> for the
100103
current required version.
@@ -151,8 +154,6 @@ with version 2 shipped with Ubuntu.
151154

152155
**Note:** For Ubuntu 20.04, use `libpython2-dev` in place of the libpython-dev package above.
153156

154-
Build instructions for Ubuntu 14.04 LTS can be found [here](docs/Ubuntu14.md).
155-
156157
### Getting Sources for Swift and Related Projects
157158

158159
First create a directory for all of the Swift sources:
@@ -240,7 +241,7 @@ various products. These incremental builds are a big timesaver when developing
240241
and debugging.
241242

242243
cd ${SWIFT_BUILD_DIR}
243-
ninja swift
244+
ninja swift-frontend
244245

245246
This will build the Swift compiler, but will not rebuild the standard library or
246247
any other target. Building the `swift-stdlib` target as an additional layer of
@@ -257,7 +258,7 @@ To open the Swift project in Xcode, open `${SWIFT_BUILD_DIR}/Swift.xcodeproj`.
257258
It will auto-create a *lot* of schemes for all of the available targets. A
258259
common debug flow would involve:
259260

260-
- Select the 'swift' scheme.
261+
- Select the 'swift-frontend' scheme.
261262
- Pull up the scheme editor (⌘⇧<).
262263
- Select the 'Arguments' tab and click the '+'.
263264
- Add the command line options.

benchmark/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ set(SWIFT_BENCH_MODULES
108108
single-source/LuhnAlgoLazy
109109
single-source/MapReduce
110110
single-source/Memset
111+
single-source/Mirror
111112
single-source/MonteCarloE
112113
single-source/MonteCarloPi
113114
single-source/NSDictionaryCastToSwift

benchmark/cmake/modules/AddSwiftBenchmarkSuite.cmake

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ macro(configure_build)
105105
endmacro()
106106

107107
macro(configure_sdks_darwin)
108-
set(macosx_arch "x86_64")
108+
set(macosx_arch "x86_64" "arm64")
109109
set(iphoneos_arch "arm64" "arm64e" "armv7")
110110
set(appletvos_arch "arm64")
111111
set(watchos_arch "armv7k")
@@ -609,11 +609,7 @@ function (swift_benchmark_compile_archopts)
609609

610610
if(is_darwin)
611611
# If host == target.
612-
if("${BENCH_COMPILE_ARCHOPTS_PLATFORM}" STREQUAL "macosx")
613-
set(OUTPUT_EXEC "${benchmark-bin-dir}/Benchmark_${BENCH_COMPILE_ARCHOPTS_OPT}")
614-
else()
615-
set(OUTPUT_EXEC "${benchmark-bin-dir}/Benchmark_${BENCH_COMPILE_ARCHOPTS_OPT}-${target}")
616-
endif()
612+
set(OUTPUT_EXEC "${benchmark-bin-dir}/Benchmark_${BENCH_COMPILE_ARCHOPTS_OPT}-${target}")
617613
else()
618614
# If we are on Linux, we do not support cross compiling.
619615
set(OUTPUT_EXEC "${benchmark-bin-dir}/Benchmark_${BENCH_COMPILE_ARCHOPTS_OPT}")
@@ -660,8 +656,11 @@ function (swift_benchmark_compile_archopts)
660656
"-m${triple_platform}-version-min=${ver}"
661657
"-lobjc"
662658
"-L${SWIFT_LIBRARY_PATH}/${BENCH_COMPILE_ARCHOPTS_PLATFORM}"
659+
"-L${sdk}/usr/lib/swift"
663660
"-Xlinker" "-rpath"
664661
"-Xlinker" "${SWIFT_LINK_RPATH}"
662+
"-Xlinker" "-rpath"
663+
"-Xlinker" "/usr/lib/swift"
665664
${bench_library_objects}
666665
${bench_driver_objects}
667666
${ld64_add_ast_path_opts}
@@ -694,7 +693,7 @@ function(swift_benchmark_compile)
694693
cmake_parse_arguments(SWIFT_BENCHMARK_COMPILE "" "PLATFORM" "" ${ARGN})
695694

696695
if(NOT SWIFT_BENCHMARK_BUILT_STANDALONE)
697-
set(stdlib_dependencies "swift")
696+
set(stdlib_dependencies "swift-frontend")
698697
foreach(stdlib_dependency ${UNIVERSAL_LIBRARY_NAMES_${SWIFT_BENCHMARK_COMPILE_PLATFORM}})
699698
string(FIND "${stdlib_dependency}" "Unittest" find_output)
700699
if("${find_output}" STREQUAL "-1")

benchmark/scripts/Benchmark_Driver

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,25 @@ class BenchmarkDriver(object):
7373
def test_harness(self):
7474
"""Full path to test harness binary."""
7575
suffix = self.args.optimization if hasattr(self.args, "optimization") else "O"
76-
return os.path.join(self.args.tests, "Benchmark_" + suffix)
76+
if hasattr(self.args, "architecture") and self.args.architecture:
77+
suffix += "-" + self.args.architecture + "*"
78+
pattern = os.path.join(self.args.tests, "Benchmark_" + suffix)
79+
executables = []
80+
if hasattr(self._subprocess, "test_mode") and self._subprocess.test_mode:
81+
executables = [pattern]
82+
else:
83+
executables = glob.glob(pattern)
84+
if len(executables) == 0:
85+
raise ValueError(
86+
"No benchmark executable for file name pattern " +
87+
pattern + " found")
88+
if len(executables) > 1:
89+
raise ValueError(
90+
"Multiple benchmark executables for file name pattern " +
91+
pattern + " found\n" +
92+
str(executables) +
93+
"\nSpecify the architecture to select the right benchmark executable")
94+
return executables[0]
7795

7896
def _git(self, cmd):
7997
"""Execute the Git command in the `swift-repo`."""

benchmark/scripts/run_smoke_bench

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,13 @@ VERBOSE = False
4848
class DriverArgs(object):
4949
"""Arguments for BenchmarkDriver."""
5050

51-
def __init__(self, tests, optimization="O"):
51+
def __init__(self, tests, optimization="O", architecture=None):
5252
"""Initialize with path to the build-dir and optimization level."""
5353
self.benchmarks = None
5454
self.filters = None
5555
self.tests = os.path.join(tests, "bin")
5656
self.optimization = optimization
57+
self.architecture = architecture
5758

5859

5960
def log(msg):
@@ -126,6 +127,12 @@ def main():
126127
help="The number of re-runs until it's assumed to be a real change",
127128
default=8,
128129
)
130+
argparser.add_argument(
131+
"-arch",
132+
type=str,
133+
help="The architecture. The default is x86_64",
134+
default="x86_64",
135+
)
129136
argparser.add_argument(
130137
"-platform", type=str, help="The benchmark build platform", default="macosx"
131138
)
@@ -158,6 +165,7 @@ def test_opt_levels(args):
158165
args.num_samples,
159166
args.num_reruns,
160167
output_file,
168+
args.arch
161169
):
162170
changes = True
163171

@@ -167,6 +175,7 @@ def test_opt_levels(args):
167175
opt_level,
168176
args.oldbuilddir[0],
169177
args.newbuilddir[0],
178+
args.arch,
170179
args.platform,
171180
output_file,
172181
):
@@ -177,6 +186,7 @@ def test_opt_levels(args):
177186
"swiftlibs",
178187
args.oldbuilddir[0],
179188
args.newbuilddir[0],
189+
args.arch,
180190
args.platform,
181191
output_file,
182192
):
@@ -221,7 +231,8 @@ def merge(results, other_results):
221231

222232

223233
def test_performance(
224-
opt_level, old_dir, new_dir, threshold, num_samples, num_reruns, output_file
234+
opt_level, old_dir, new_dir, threshold, num_samples, num_reruns,
235+
output_file, arch
225236
):
226237
"""Detect performance changes in benchmarks.
227238
@@ -231,7 +242,7 @@ def test_performance(
231242

232243
i, unchanged_length_count = 0, 0
233244
old, new = [
234-
BenchmarkDriver(DriverArgs(dir, optimization=opt_level))
245+
BenchmarkDriver(DriverArgs(dir, optimization=opt_level, architecture=arch))
235246
for dir in [old_dir, new_dir]
236247
]
237248
results = [measure(driver, driver.tests, i) for driver in [old, new]]
@@ -260,18 +271,20 @@ def test_performance(
260271
)
261272

262273

263-
def report_code_size(opt_level, old_dir, new_dir, platform, output_file):
274+
def report_code_size(opt_level, old_dir, new_dir, architecture, platform, output_file):
264275
if opt_level == "swiftlibs":
265276
files = glob.glob(os.path.join(old_dir, "lib", "swift", platform, "*.dylib"))
266277
else:
267278
files = glob.glob(
268-
os.path.join(old_dir, opt_level + "-*" + platform + "*", "*.o")
279+
os.path.join(old_dir, opt_level + "-" + architecture + "*" +
280+
platform + "*", "*.o")
269281
)
270282

271283
idx = 1
272284
old_lines = ""
273285
new_lines = ""
274286
for oldfile in files:
287+
new_dir = os.path.join(new_dir, '')
275288
newfile = oldfile.replace(old_dir, new_dir, 1)
276289
if os.path.isfile(newfile):
277290
oldsize = get_codesize(oldfile)
@@ -369,8 +382,8 @@ performance team (@eeckstein).
369382

370383

371384
def check_added(args, output_file=None):
372-
old = BenchmarkDriver(DriverArgs(args.oldbuilddir[0]))
373-
new = BenchmarkDriver(DriverArgs(args.newbuilddir[0]))
385+
old = BenchmarkDriver(DriverArgs(args.oldbuilddir[0], architecture=args.arch))
386+
new = BenchmarkDriver(DriverArgs(args.newbuilddir[0], architecture=args.arch))
374387
added = set(new.tests).difference(set(old.tests))
375388
new.tests = list(added)
376389
doctor = BenchmarkDoctor(args, driver=new)

benchmark/scripts/test_Benchmark_Driver.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ def record_and_respond(self, args, stdin, stdout, stderr, shell):
198198
self.calls.append(args)
199199
return self.respond.get(args, "")
200200

201+
def test_mode():
202+
return True
203+
201204

202205
class TestBenchmarkDriverInitialization(unittest.TestCase):
203206
def setUp(self):
@@ -206,13 +209,19 @@ def setUp(self):
206209

207210
def test_test_harness(self):
208211
self.assertEqual(
209-
BenchmarkDriver(self.args, tests=["ignored"]).test_harness,
212+
BenchmarkDriver(
213+
self.args,
214+
tests=["ignored"],
215+
_subprocess=self.subprocess_mock).test_harness,
210216
"/benchmarks/Benchmark_O",
211217
)
212218
self.args.tests = "/path"
213219
self.args.optimization = "Suffix"
214220
self.assertEqual(
215-
BenchmarkDriver(self.args, tests=["ignored"]).test_harness,
221+
BenchmarkDriver(
222+
self.args,
223+
tests=["ignored"],
224+
_subprocess=self.subprocess_mock).test_harness,
216225
"/path/Benchmark_Suffix",
217226
)
218227

@@ -271,6 +280,7 @@ def test_log_file(self):
271280
swift_repo=None,
272281
),
273282
tests=["ignored"],
283+
_subprocess=self.subprocess_mock
274284
)
275285
self.assertEqual(driver.log_file, "/path/Benchmark_Suffix-" + now + ".log")
276286

benchmark/single-source/DataBenchmarks.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import TestsUtils
1414
import Foundation
1515

16-
let d: [BenchmarkCategory] = [.validation, .api, .Data]
16+
let d: [BenchmarkCategory] = [.validation, .api, .Data, .cpubench]
1717

1818
public let DataBenchmarks = [
1919
BenchmarkInfo(name: "DataCreateEmpty",

0 commit comments

Comments
 (0)