Skip to content

Commit e8b1a2b

Browse files
authored
Merge pull request #62248 from apple/maxd/alpine-musl-modulemap
stdlib: add modulemap for Musl, add Musl platform module
2 parents 40a7396 + 7581e72 commit e8b1a2b

File tree

3 files changed

+198
-0
lines changed

3 files changed

+198
-0
lines changed

stdlib/public/Platform/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,22 @@ add_swift_target_library(swiftGlibc ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_O
9898
INSTALL_IN_COMPONENT sdk-overlay
9999
DEPENDS glibc_modulemap)
100100

101+
add_swift_target_library(swiftMusl ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
102+
${swift_platform_sources}
103+
POSIXError.swift
104+
105+
GYB_SOURCES
106+
${swift_platform_gyb_sources}
107+
Musl.swift.gyb
108+
109+
SWIFT_COMPILE_FLAGS
110+
${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}
111+
${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
112+
${swift_platform_compile_flags}
113+
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
114+
TARGET_SDKS MUSL
115+
INSTALL_IN_COMPONENT sdk-overlay)
116+
101117
add_swift_target_library(swiftCRT ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
102118
ucrt.swift
103119
${swift_platform_sources}

stdlib/public/Platform/Musl.swift.gyb

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2022 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 SwiftMusl // Clang module
14+
15+
public let MAP_FAILED: UnsafeMutableRawPointer! = UnsafeMutableRawPointer(bitPattern: -1)
16+
17+
// Constants defined by <math.h>
18+
@available(swift, deprecated: 3.0, message: "Please use 'Double.pi' or '.pi' to get the value of correct type and avoid casting.")
19+
public let M_PI = Double.pi
20+
21+
@available(swift, deprecated: 3.0, message: "Please use 'Double.pi / 2' or '.pi / 2' to get the value of correct type and avoid casting.")
22+
public let M_PI_2 = Double.pi / 2
23+
24+
@available(swift, deprecated: 3.0, message: "Please use 'Double.pi / 4' or '.pi / 4' to get the value of correct type and avoid casting.")
25+
public let M_PI_4 = Double.pi / 4
26+
27+
@available(swift, deprecated: 3.0, message: "Please use '2.squareRoot()'.")
28+
public let M_SQRT2 = 2.squareRoot()
29+
30+
@available(swift, deprecated: 3.0, message: "Please use '0.5.squareRoot()'.")
31+
public let M_SQRT1_2 = 0.5.squareRoot()
32+
33+
// Constants defined by <float.h>
34+
@available(swift, deprecated: 3.0, message: "Please use 'T.radix' to get the radix of a FloatingPoint type 'T'.")
35+
public let FLT_RADIX = Double.radix
36+
37+
%for type, prefix in [('Float', 'FLT'), ('Double', 'DBL'), ('Float80', 'LDBL')]:
38+
% if type == "Float80":
39+
#if !os(Android) && (arch(i386) || arch(x86_64))
40+
% end
41+
// Where does the 1 come from? C counts the usually-implicit leading
42+
// significand bit, but Swift does not. Neither is really right or wrong.
43+
@available(swift, deprecated: 3.0, message: "Please use '${type}.significandBitCount + 1'.")
44+
public let ${prefix}_MANT_DIG = ${type}.significandBitCount + 1
45+
46+
// Where does the 1 come from? C models floating-point numbers as having a
47+
// significand in [0.5, 1), but Swift (following IEEE 754) considers the
48+
// significand to be in [1, 2). This rationale applies to ${prefix}_MIN_EXP
49+
// as well.
50+
@available(swift, deprecated: 3.0, message: "Please use '${type}.greatestFiniteMagnitude.exponent + 1'.")
51+
public let ${prefix}_MAX_EXP = ${type}.greatestFiniteMagnitude.exponent + 1
52+
53+
@available(swift, deprecated: 3.0, message: "Please use '${type}.leastNormalMagnitude.exponent + 1'.")
54+
public let ${prefix}_MIN_EXP = ${type}.leastNormalMagnitude.exponent + 1
55+
56+
@available(swift, deprecated: 3.0, message: "Please use '${type}.greatestFiniteMagnitude' or '.greatestFiniteMagnitude'.")
57+
public let ${prefix}_MAX = ${type}.greatestFiniteMagnitude
58+
59+
@available(swift, deprecated: 3.0, message: "Please use '${type}.ulpOfOne' or '.ulpOfOne'.")
60+
public let ${prefix}_EPSILON = ${type}.ulpOfOne
61+
62+
@available(swift, deprecated: 3.0, message: "Please use '${type}.leastNormalMagnitude' or '.leastNormalMagnitude'.")
63+
public let ${prefix}_MIN = ${type}.leastNormalMagnitude
64+
65+
@available(swift, deprecated: 3.0, message: "Please use '${type}.leastNonzeroMagnitude' or '.leastNonzeroMagnitude'.")
66+
public let ${prefix}_TRUE_MIN = ${type}.leastNonzeroMagnitude
67+
68+
% if type == "Float80":
69+
#endif
70+
% end
71+
%end

stdlib/public/Platform/musl.modulemap

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
//===--- musl.modulemap ---------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 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+
module SwiftMusl [system] {
14+
header "stdc-predef.h"
15+
header "features.h"
16+
17+
// C standard library
18+
header "complex.h"
19+
header "ctype.h"
20+
header "errno.h"
21+
header "fenv.h"
22+
header "float.h"
23+
header "inttypes.h"
24+
header "iso646.h"
25+
header "limits.h"
26+
header "locale.h"
27+
header "math.h"
28+
header "pty.h"
29+
header "setjmp.h"
30+
header "signal.h"
31+
header "stdarg.h"
32+
header "stdbool.h"
33+
header "stddef.h"
34+
header "stdint.h"
35+
header "stdio.h"
36+
header "stdlib.h"
37+
header "string.h"
38+
header "tgmath.h"
39+
header "time.h"
40+
header "utmp.h"
41+
42+
// POSIX
43+
header "aio.h"
44+
header "arpa/inet.h"
45+
header "cpio.h"
46+
header "dirent.h"
47+
header "dlfcn.h"
48+
header "fcntl.h"
49+
header "fmtmsg.h"
50+
header "fnmatch.h"
51+
header "ftw.h"
52+
header "glob.h"
53+
header "grp.h"
54+
header "iconv.h"
55+
header "ifaddrs.h"
56+
header "langinfo.h"
57+
header "libgen.h"
58+
header "link.h"
59+
header "monetary.h"
60+
header "net/if.h"
61+
header "netdb.h"
62+
header "netinet/in.h"
63+
header "netinet/tcp.h"
64+
header "nl_types.h"
65+
header "poll.h"
66+
header "pthread.h"
67+
header "pwd.h"
68+
header "regex.h"
69+
header "sched.h"
70+
header "search.h"
71+
header "semaphore.h"
72+
header "spawn.h"
73+
header "strings.h"
74+
header "sys/file.h"
75+
header "sys/inotify.h"
76+
header "sys/ioctl.h"
77+
header "sys/ipc.h"
78+
header "sys/mman.h"
79+
header "sys/mount.h"
80+
header "sys/msg.h"
81+
header "sys/resource.h"
82+
header "sys/select.h"
83+
header "sys/sem.h"
84+
header "sys/sendfile.h"
85+
header "sys/shm.h"
86+
header "sys/socket.h"
87+
header "sys/stat.h"
88+
header "sys/statvfs.h"
89+
header "sys/time.h"
90+
header "sys/times.h"
91+
header "sys/types.h"
92+
header "sys/uio.h"
93+
header "sys/un.h"
94+
header "sys/user.h"
95+
header "sys/utsname.h"
96+
header "sys/wait.h"
97+
header "sysexits.h"
98+
header "syslog.h"
99+
header "tar.h"
100+
header "termios.h"
101+
header "ulimit.h"
102+
header "unistd.h"
103+
header "utime.h"
104+
header "utmpx.h"
105+
header "wordexp.h"
106+
107+
// <assert.h>'s use of NDEBUG requires textual inclusion.
108+
textual header "assert.h"
109+
110+
export *
111+
}

0 commit comments

Comments
 (0)