From 0f5617e9095d9892e818f6b19047b34ff50f6c55 Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Fri, 25 Nov 2022 17:05:36 +0000 Subject: [PATCH 1/3] stdlib: add modulemap for Musl, add Musl platform module This change is necessary to allow building Musl platform module when targeting Alpine Linux. --- stdlib/public/Platform/CMakeLists.txt | 16 ++++ stdlib/public/Platform/Musl.swift.gyb | 71 ++++++++++++++++++ stdlib/public/Platform/SwiftMusl.h | 104 ++++++++++++++++++++++++++ stdlib/public/Platform/musl.modulemap | 20 +++++ 4 files changed, 211 insertions(+) create mode 100644 stdlib/public/Platform/Musl.swift.gyb create mode 100644 stdlib/public/Platform/SwiftMusl.h create mode 100644 stdlib/public/Platform/musl.modulemap diff --git a/stdlib/public/Platform/CMakeLists.txt b/stdlib/public/Platform/CMakeLists.txt index f478206d6a2a3..ce4fe70528380 100644 --- a/stdlib/public/Platform/CMakeLists.txt +++ b/stdlib/public/Platform/CMakeLists.txt @@ -98,6 +98,22 @@ add_swift_target_library(swiftGlibc ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_O INSTALL_IN_COMPONENT sdk-overlay DEPENDS glibc_modulemap) +add_swift_target_library(swiftMusl ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY + ${swift_platform_sources} + POSIXError.swift + + GYB_SOURCES + ${swift_platform_gyb_sources} + Musl.swift.gyb + + SWIFT_COMPILE_FLAGS + ${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS} + ${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS} + ${swift_platform_compile_flags} + LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}" + TARGET_SDKS ALPINE + INSTALL_IN_COMPONENT sdk-overlay) + add_swift_target_library(swiftCRT ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY ucrt.swift ${swift_platform_sources} diff --git a/stdlib/public/Platform/Musl.swift.gyb b/stdlib/public/Platform/Musl.swift.gyb new file mode 100644 index 0000000000000..afd256a67d43b --- /dev/null +++ b/stdlib/public/Platform/Musl.swift.gyb @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +@_exported import SwiftMusl // Clang module + +public let MAP_FAILED: UnsafeMutableRawPointer! = UnsafeMutableRawPointer(bitPattern: -1) + +// Constants defined by +@available(swift, deprecated: 3.0, message: "Please use 'Double.pi' or '.pi' to get the value of correct type and avoid casting.") +public let M_PI = Double.pi + +@available(swift, deprecated: 3.0, message: "Please use 'Double.pi / 2' or '.pi / 2' to get the value of correct type and avoid casting.") +public let M_PI_2 = Double.pi / 2 + +@available(swift, deprecated: 3.0, message: "Please use 'Double.pi / 4' or '.pi / 4' to get the value of correct type and avoid casting.") +public let M_PI_4 = Double.pi / 4 + +@available(swift, deprecated: 3.0, message: "Please use '2.squareRoot()'.") +public let M_SQRT2 = 2.squareRoot() + +@available(swift, deprecated: 3.0, message: "Please use '0.5.squareRoot()'.") +public let M_SQRT1_2 = 0.5.squareRoot() + +// Constants defined by +@available(swift, deprecated: 3.0, message: "Please use 'T.radix' to get the radix of a FloatingPoint type 'T'.") +public let FLT_RADIX = Double.radix + +%for type, prefix in [('Float', 'FLT'), ('Double', 'DBL'), ('Float80', 'LDBL')]: +% if type == "Float80": +#if !os(Android) && (arch(i386) || arch(x86_64)) +% end +// Where does the 1 come from? C counts the usually-implicit leading +// significand bit, but Swift does not. Neither is really right or wrong. +@available(swift, deprecated: 3.0, message: "Please use '${type}.significandBitCount + 1'.") +public let ${prefix}_MANT_DIG = ${type}.significandBitCount + 1 + +// Where does the 1 come from? C models floating-point numbers as having a +// significand in [0.5, 1), but Swift (following IEEE 754) considers the +// significand to be in [1, 2). This rationale applies to ${prefix}_MIN_EXP +// as well. +@available(swift, deprecated: 3.0, message: "Please use '${type}.greatestFiniteMagnitude.exponent + 1'.") +public let ${prefix}_MAX_EXP = ${type}.greatestFiniteMagnitude.exponent + 1 + +@available(swift, deprecated: 3.0, message: "Please use '${type}.leastNormalMagnitude.exponent + 1'.") +public let ${prefix}_MIN_EXP = ${type}.leastNormalMagnitude.exponent + 1 + +@available(swift, deprecated: 3.0, message: "Please use '${type}.greatestFiniteMagnitude' or '.greatestFiniteMagnitude'.") +public let ${prefix}_MAX = ${type}.greatestFiniteMagnitude + +@available(swift, deprecated: 3.0, message: "Please use '${type}.ulpOfOne' or '.ulpOfOne'.") +public let ${prefix}_EPSILON = ${type}.ulpOfOne + +@available(swift, deprecated: 3.0, message: "Please use '${type}.leastNormalMagnitude' or '.leastNormalMagnitude'.") +public let ${prefix}_MIN = ${type}.leastNormalMagnitude + +@available(swift, deprecated: 3.0, message: "Please use '${type}.leastNonzeroMagnitude' or '.leastNonzeroMagnitude'.") +public let ${prefix}_TRUE_MIN = ${type}.leastNonzeroMagnitude + +% if type == "Float80": +#endif +% end +%end diff --git a/stdlib/public/Platform/SwiftMusl.h b/stdlib/public/Platform/SwiftMusl.h new file mode 100644 index 0000000000000..516a136147511 --- /dev/null +++ b/stdlib/public/Platform/SwiftMusl.h @@ -0,0 +1,104 @@ +//===--- SwiftMusl.h ------------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +#include +#include + +// C standard library +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// POSIX +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include diff --git a/stdlib/public/Platform/musl.modulemap b/stdlib/public/Platform/musl.modulemap new file mode 100644 index 0000000000000..bd6129bf9e796 --- /dev/null +++ b/stdlib/public/Platform/musl.modulemap @@ -0,0 +1,20 @@ +//===--- musl.modulemap ---------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors +// Licensed under Apache License v2.0 with Runtime Library Exception +// +// See https://swift.org/LICENSE.txt for license information +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors +// +//===----------------------------------------------------------------------===// + +module SwiftMusl [system] { + header "SwiftMusl.h" + + // 's use of NDEBUG requires textual inclusion. + textual header "assert.h" + + export * +} From 115ddf96d5ba65c707de47a4a78bf2ec9cdf7c43 Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Wed, 5 Jul 2023 22:39:47 +0100 Subject: [PATCH 2/3] List all musl headers directly in `musl.modulemap` --- stdlib/public/Platform/SwiftMusl.h | 104 -------------------------- stdlib/public/Platform/musl.modulemap | 93 ++++++++++++++++++++++- 2 files changed, 92 insertions(+), 105 deletions(-) delete mode 100644 stdlib/public/Platform/SwiftMusl.h diff --git a/stdlib/public/Platform/SwiftMusl.h b/stdlib/public/Platform/SwiftMusl.h deleted file mode 100644 index 516a136147511..0000000000000 --- a/stdlib/public/Platform/SwiftMusl.h +++ /dev/null @@ -1,104 +0,0 @@ -//===--- SwiftMusl.h ------------------------------------------------------===// -// -// This source file is part of the Swift.org open source project -// -// Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors -// Licensed under Apache License v2.0 with Runtime Library Exception -// -// See https://swift.org/LICENSE.txt for license information -// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -// -//===----------------------------------------------------------------------===// - -#include -#include - -// C standard library -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// POSIX -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include diff --git a/stdlib/public/Platform/musl.modulemap b/stdlib/public/Platform/musl.modulemap index bd6129bf9e796..18fe29972c3e6 100644 --- a/stdlib/public/Platform/musl.modulemap +++ b/stdlib/public/Platform/musl.modulemap @@ -11,7 +11,98 @@ //===----------------------------------------------------------------------===// module SwiftMusl [system] { - header "SwiftMusl.h" + header "stdc-predef.h" + header "features.h" + + // C standard library + header "complex.h" + header "ctype.h" + header "errno.h" + header "fenv.h" + header "float.h" + header "inttypes.h" + header "iso646.h" + header "limits.h" + header "locale.h" + header "math.h" + header "pty.h" + header "setjmp.h" + header "signal.h" + header "stdarg.h" + header "stdbool.h" + header "stddef.h" + header "stdint.h" + header "stdio.h" + header "stdlib.h" + header "string.h" + header "tgmath.h" + header "time.h" + header "utmp.h" + + // POSIX + header "aio.h" + header "arpa/inet.h" + header "cpio.h" + header "dirent.h" + header "dlfcn.h" + header "fcntl.h" + header "fmtmsg.h" + header "fnmatch.h" + header "ftw.h" + header "glob.h" + header "grp.h" + header "iconv.h" + header "ifaddrs.h" + header "langinfo.h" + header "libgen.h" + header "link.h" + header "monetary.h" + header "net/if.h" + header "netdb.h" + header "netinet/in.h" + header "netinet/tcp.h" + header "nl_types.h" + header "poll.h" + header "pthread.h" + header "pwd.h" + header "regex.h" + header "sched.h" + header "search.h" + header "semaphore.h" + header "spawn.h" + header "strings.h" + header "sys/file.h" + header "sys/inotify.h" + header "sys/ioctl.h" + header "sys/ipc.h" + header "sys/mman.h" + header "sys/mount.h" + header "sys/msg.h" + header "sys/resource.h" + header "sys/select.h" + header "sys/sem.h" + header "sys/sendfile.h" + header "sys/shm.h" + header "sys/socket.h" + header "sys/stat.h" + header "sys/statvfs.h" + header "sys/time.h" + header "sys/times.h" + header "sys/types.h" + header "sys/uio.h" + header "sys/un.h" + header "sys/user.h" + header "sys/utsname.h" + header "sys/wait.h" + header "sysexits.h" + header "syslog.h" + header "tar.h" + header "termios.h" + header "ulimit.h" + header "unistd.h" + header "utime.h" + header "utmpx.h" + header "wordexp.h" // 's use of NDEBUG requires textual inclusion. textual header "assert.h" From 7581e7241c6b67cd181366be59b8c8d4b2718763 Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Thu, 6 Jul 2023 15:45:16 +0100 Subject: [PATCH 3/3] stdlib/public/platform: rename `ALPINE` to `MUSL` in `CMakeLists.txt` --- stdlib/public/Platform/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/public/Platform/CMakeLists.txt b/stdlib/public/Platform/CMakeLists.txt index ce4fe70528380..cff574c893267 100644 --- a/stdlib/public/Platform/CMakeLists.txt +++ b/stdlib/public/Platform/CMakeLists.txt @@ -111,7 +111,7 @@ add_swift_target_library(swiftMusl ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_OV ${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS} ${swift_platform_compile_flags} LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}" - TARGET_SDKS ALPINE + TARGET_SDKS MUSL INSTALL_IN_COMPONENT sdk-overlay) add_swift_target_library(swiftCRT ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY