Skip to content

Commit 57e342e

Browse files
committed
stdlib: add modulemap for Musl, add Musl platform module
This change is necessary to allow building Musl platform module when targeting Alpine Linux.
1 parent 1f3e159 commit 57e342e

File tree

4 files changed

+211
-0
lines changed

4 files changed

+211
-0
lines changed

stdlib/public/Platform/CMakeLists.txt

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

100+
add_swift_target_library(swiftMusl ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
101+
${swift_platform_sources}
102+
POSIXError.swift
103+
104+
GYB_SOURCES
105+
${swift_platform_gyb_sources}
106+
Musl.swift.gyb
107+
108+
SWIFT_COMPILE_FLAGS
109+
${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}
110+
${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
111+
${swift_platform_compile_flags}
112+
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
113+
TARGET_SDKS ALPINE
114+
INSTALL_IN_COMPONENT sdk-overlay)
115+
100116
add_swift_target_library(swiftCRT ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
101117
ucrt.swift
102118
${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/SwiftMusl.h

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

stdlib/public/Platform/musl.modulemap

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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 "SwiftMusl.h"
15+
16+
// <assert.h>'s use of NDEBUG requires textual inclusion.
17+
textual header "assert.h"
18+
19+
export *
20+
}

0 commit comments

Comments
 (0)