Skip to content

Commit 8b8c72a

Browse files
committed
[stdlib] add a _math module overlay for Android for deprecated constants
1 parent 86ba251 commit 8b8c72a

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

stdlib/public/Platform/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,20 @@ add_custom_target(musl_modulemap DEPENDS ${musl_modulemap_target_list})
273273
set_property(TARGET musl_modulemap PROPERTY FOLDER "Miscellaneous")
274274
add_dependencies(sdk-overlay musl_modulemap)
275275

276+
# Add a system 'math' module overlay, that only applies only to platforms that
277+
# have a top level '_math' module.
278+
add_swift_target_library(swift_math ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
279+
Math.swift
280+
281+
SWIFT_COMPILE_FLAGS
282+
${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}
283+
${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
284+
${swift_platform_compile_flags}
285+
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
286+
TARGET_SDKS "ANDROID"
287+
INSTALL_IN_COMPONENT sdk-overlay
288+
DEPENDS android_modulemap)
289+
276290
add_swift_target_library(swiftAndroid ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
277291
Android.swift
278292
${swift_platform_sources}

stdlib/public/Platform/Math.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@_exported import _math
2+
3+
// Constants defined by <math.h>
4+
@available(swift, deprecated: 3.0, message: "Please use 'Double.pi' or '.pi' to get the value of correct type and avoid casting.")
5+
public let M_PI = Double.pi
6+
7+
@available(swift, deprecated: 3.0, message: "Please use 'Double.pi / 2' or '.pi / 2' to get the value of correct type and avoid casting.")
8+
public let M_PI_2 = Double.pi / 2
9+
10+
@available(swift, deprecated: 3.0, message: "Please use 'Double.pi / 4' or '.pi / 4' to get the value of correct type and avoid casting.")
11+
public let M_PI_4 = Double.pi / 4
12+
13+
@available(swift, deprecated: 3.0, message: "Please use '2.squareRoot()'.")
14+
public let M_SQRT2 = 2.squareRoot()
15+
16+
@available(swift, deprecated: 3.0, message: "Please use '0.5.squareRoot()'.")
17+
public let M_SQRT1_2 = 0.5.squareRoot()

0 commit comments

Comments
 (0)