Skip to content

Commit 1ce3935

Browse files
[overlay] Make an overlay for the clang _Builtin_float module
Clang's builtin float.h is no longer included in OS/SDK modules, and so it needs its own overlay. rdar://122351557
1 parent 2ded8ba commit 1ce3935

File tree

9 files changed

+109
-0
lines changed

9 files changed

+109
-0
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,10 @@ option(SWIFT_STDLIB_ENABLE_UNICODE_DATA
238238
NOTE: Disabling this will cause many String methods to crash."
239239
TRUE)
240240

241+
option(SWIFT_BUILD_CLANG_OVERLAYS
242+
"Build Swift overlays for the clang builtin modules"
243+
TRUE)
244+
241245
option(SWIFT_BUILD_DYNAMIC_SDK_OVERLAY
242246
"Build dynamic variants of the Swift SDK overlay"
243247
TRUE)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[
2+
{
3+
"module": "Darwin",
4+
"install_name": "/usr/lib/swift/libswiftDarwin.dylib"
5+
}
6+
]

stdlib/public/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,10 @@ if(SWIFT_BUILD_STDLIB AND NOT SWIFT_STDLIB_BUILD_ONLY_CORE_MODULES)
250250
# In some internal Apple configurations we have the need
251251
# to build Core and Onone separately from the rest
252252
# of the stdlib
253+
if(SWIFT_BUILD_CLANG_OVERLAYS)
254+
add_subdirectory(ClangOverlays)
255+
endif()
256+
253257
if(SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING)
254258
add_subdirectory(Differentiation)
255259
endif()
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
add_swift_target_library(swift_Builtin_float
2+
${SWIFT_STDLIB_LIBRARY_BUILD_TYPES}
3+
IS_SDK_OVERLAY
4+
5+
"${SWIFT_SOURCE_DIR}/stdlib/linker-support/magic-symbols-for-install-name.c"
6+
7+
GYB_SOURCES
8+
float.swift.gyb
9+
10+
SWIFT_COMPILE_FLAGS
11+
${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}
12+
${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
13+
-Xfrontend -previous-module-installname-map-file -Xfrontend "${SWIFT_SOURCE_DIR}/stdlib/linker-support/previous-module-installname.json"
14+
15+
LINK_FLAGS
16+
${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}
17+
18+
INSTALL_IN_COMPONENT stdlib
19+
MACCATALYST_BUILD_FLAVOR zippered)
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2018 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+
@_exported import _Builtin_float
14+
15+
@available(swift, deprecated: 3.0, message: "Please use 'T.radix' to get the radix of a FloatingPoint type 'T'.")
16+
public let FLT_RADIX = Double.radix
17+
18+
%for type, prefix in [('Float', 'FLT'), ('Double', 'DBL'), ('Float80', 'LDBL')]:
19+
% if type == "Float80":
20+
#if !os(Android) && !os(WASI) && !os(Windows) && (arch(i386) || arch(x86_64))
21+
% end
22+
// Where does the 1 come from? C counts the usually-implicit leading
23+
// significand bit, but Swift does not. Neither is really right or wrong.
24+
@available(swift, deprecated: 3.0, message: "Please use '${type}.significandBitCount + 1'.")
25+
@available(macOS 10.9, iOS 7.0, tvOS 7.0, watchOS 2.0, *)
26+
@_originallyDefinedIn(module: "Darwin", macOS 9999, iOS 9999, watchOS 9999, tvOS 9999)
27+
public let ${prefix}_MANT_DIG = ${type}.significandBitCount + 1
28+
29+
// Where does the 1 come from? C models floating-point numbers as having a
30+
// significand in [0.5, 1), but Swift (following IEEE 754) considers the
31+
// significand to be in [1, 2). This rationale applies to ${prefix}_MIN_EXP
32+
// as well.
33+
@available(swift, deprecated: 3.0, message: "Please use '${type}.greatestFiniteMagnitude.exponent + 1'.")
34+
@available(macOS 10.9, iOS 7.0, tvOS 7.0, watchOS 2.0, *)
35+
@_originallyDefinedIn(module: "Darwin", macOS 9999, iOS 9999, watchOS 9999, tvOS 9999)
36+
public let ${prefix}_MAX_EXP = ${type}.greatestFiniteMagnitude.exponent + 1
37+
38+
@available(swift, deprecated: 3.0, message: "Please use '${type}.leastNormalMagnitude.exponent + 1'.")
39+
@available(macOS 10.9, iOS 7.0, tvOS 7.0, watchOS 2.0, *)
40+
@_originallyDefinedIn(module: "Darwin", macOS 9999, iOS 9999, watchOS 9999, tvOS 9999)
41+
public let ${prefix}_MIN_EXP = ${type}.leastNormalMagnitude.exponent + 1
42+
43+
@available(swift, deprecated: 3.0, message: "Please use '${type}.greatestFiniteMagnitude' or '.greatestFiniteMagnitude'.")
44+
@available(macOS 10.9, iOS 7.0, tvOS 7.0, watchOS 2.0, *)
45+
@_originallyDefinedIn(module: "Darwin", macOS 9999, iOS 9999, watchOS 9999, tvOS 9999)
46+
public let ${prefix}_MAX = ${type}.greatestFiniteMagnitude
47+
48+
@available(swift, deprecated: 3.0, message: "Please use '${type}.ulpOfOne' or '.ulpOfOne'.")
49+
@available(macOS 10.9, iOS 7.0, tvOS 7.0, watchOS 2.0, *)
50+
@_originallyDefinedIn(module: "Darwin", macOS 9999, iOS 9999, watchOS 9999, tvOS 9999)
51+
public let ${prefix}_EPSILON = ${type}.ulpOfOne
52+
53+
@available(swift, deprecated: 3.0, message: "Please use '${type}.leastNormalMagnitude' or '.leastNormalMagnitude'.")
54+
@available(macOS 10.9, iOS 7.0, tvOS 7.0, watchOS 2.0, *)
55+
@_originallyDefinedIn(module: "Darwin", macOS 9999, iOS 9999, watchOS 9999, tvOS 9999)
56+
public let ${prefix}_MIN = ${type}.leastNormalMagnitude
57+
58+
@available(swift, deprecated: 3.0, message: "Please use '${type}.leastNonzeroMagnitude' or '.leastNonzeroMagnitude'.")
59+
@available(macOS 10.9, iOS 7.0, tvOS 7.0, watchOS 2.0, *)
60+
@_originallyDefinedIn(module: "Darwin", macOS 9999, iOS 9999, watchOS 9999, tvOS 9999)
61+
public let ${prefix}_TRUE_MIN = ${type}.leastNonzeroMagnitude
62+
63+
% if type == "Float80":
64+
#endif
65+
% end
66+
%end

utils/build-script-impl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ KNOWN_SETTINGS=(
146146
## Build ...
147147
build-llvm "1" "set to 1 to build LLVM and Clang"
148148
build-sil-debugging-stdlib "0" "set to 1 to build the Swift standard library with -sil-based-debuginfo to enable debugging and profiling on SIL level"
149+
build-swift-clang-overlays "1" "set to 1 to build the Swift overlays for the clang builtin modules"
149150
build-swift-dynamic-sdk-overlay "" "set to 1 to build dynamic variants of the Swift SDK overlay"
150151
build-swift-dynamic-stdlib "" "set to 1 to build dynamic variants of the Swift standard library"
151152
build-swift-examples "1" "set to 1 to build examples"
@@ -1870,6 +1871,7 @@ for host in "${ALL_HOSTS[@]}"; do
18701871
-DSWIFT_NATIVE_CLANG_TOOLS_PATH:STRING="${native_clang_tools_path}"
18711872
-DSWIFT_NATIVE_SWIFT_TOOLS_PATH:STRING="${native_swift_tools_path}"
18721873
-DSWIFT_INCLUDE_TOOLS:BOOL=$(true_false "${BUILD_SWIFT_TOOLS}")
1874+
-DSWIFT_BUILD_CLANG_OVERLAYS:BOOL=$(true_false "${BUILD_SWIFT_CLANG_OVERLAYS}")
18731875
-DSWIFT_BUILD_REMOTE_MIRROR:BOOL=$(true_false "${BUILD_SWIFT_REMOTE_MIRROR}")
18741876
-DSWIFT_BUILD_EXTERNAL_GENERIC_METADATA_BUILDER:BOOL=$(true_false "${BUILD_SWIFT_EXTERNAL_GENERIC_METADATA_BUILDER}")
18751877
-DSWIFT_STDLIB_SIL_DEBUGGING:BOOL=$(true_false "${BUILD_SIL_DEBUGGING_STDLIB}")

utils/build_swift/build_swift/driver_arguments.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,6 +1093,10 @@ def create_argument_parser():
10931093
help='Include Unicode data in the standard library.'
10941094
'Note: required for full String functionality')
10951095

1096+
option('--build-swift-clang-overlays', toggle_true,
1097+
default=True,
1098+
help='Build Swift overlays for the clang builtin modules')
1099+
10961100
option('--build-swift-remote-mirror', toggle_true,
10971101
default=True,
10981102
help='Build Remote Mirror')

utils/build_swift/tests/expected_options.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
'build_swift_stdlib_unittest_extra': False,
9090
'build_swift_stdlib_static_print': False,
9191
'build_swift_stdlib_unicode_data': True,
92+
'build_swift_clang_overlays': True,
9293
'build_swift_remote_mirror': True,
9394
'build_swiftpm': False,
9495
'build_swift_driver': False,
@@ -578,6 +579,7 @@ class BuildScriptImplOption(_BaseOption):
578579
EnableOption('--build-swift-private-stdlib'),
579580
EnableOption('--build-swift-stdlib-unicode-data'),
580581
EnableOption('--build-swift-libexec'),
582+
EnableOption('--build-swift-clang-overlays'),
581583
EnableOption('--build-swift-remote-mirror'),
582584
EnableOption('--build-swift-external-generic-metadata-builder'),
583585
EnableOption('--cross-compile-append-host-target-to-destdir'),

utils/swift_build_support/swift_build_support/build_script_invocation.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ def convert_to_impl_arguments(self):
134134
"--dsymutil-jobs", str(args.dsymutil_jobs),
135135
'--build-swift-libexec', str(args.build_swift_libexec).lower(),
136136
'--swift-enable-backtracing', str(args.swift_enable_backtracing).lower(),
137+
'--build-swift-clang-overlays', str(
138+
args.build_swift_clang_overlays).lower(),
137139
'--build-swift-remote-mirror', str(args.build_swift_remote_mirror).lower(),
138140
'--build-swift-external-generic-metadata-builder', str(
139141
args.build_swift_external_generic_metadata_builder).lower(),

0 commit comments

Comments
 (0)