Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 79 additions & 4 deletions stdlib/public/Platform/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,9 @@ 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 MUSL
INSTALL_IN_COMPONENT sdk-overlay)
TARGET_SDKS LINUX_STATIC
INSTALL_IN_COMPONENT sdk-overlay
DEPENDS musl_modulemap)

add_swift_target_library(swiftWASILibc ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
${swift_platform_sources}
Expand Down Expand Up @@ -198,6 +199,80 @@ add_swift_target_library(swiftCRT ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_OVE
TARGET_SDKS WINDOWS
INSTALL_IN_COMPONENT sdk-overlay)

foreach(sdk ${SWIFT_SDKS})
# Add more platforms supporting Musl to these checks,
if(NOT "${sdk}" STREQUAL "LINUX_STATIC")
continue()
endif()

set(musl_modulemap "musl.modulemap")
set(musl_header "SwiftMusl.h")

foreach(arch ${SWIFT_SDK_${sdk}_ARCHITECTURES})
set(arch_subdir "${SWIFT_SDK_${sdk}_LIB_SUBDIR}/${arch}")
set(module_dir "${SWIFTLIB_DIR}/${arch_subdir}")
set(module_dir_static "${SWIFTSTATICLIB_DIR}/${arch_subdir}")

set(musl_modulemap_out "${module_dir}/${musl_modulemap}")
set(musl_modulemap_out_static "${module_dir_static}/${musl_modulemap}")
set(musl_header_out "${module_dir}/${musl_header}")
set(musl_header_out_static "${module_dir_static}/${musl_header}")

add_custom_command_target(
copy_musl_modulemap
COMMAND
"${CMAKE_COMMAND}" "-E" "make_directory" ${module_dir}
COMMAND
"${CMAKE_COMMAND}" "-E" "copy"
${CMAKE_CURRENT_LIST_DIR}/${musl_modulemap}
${musl_modulemap_out}
COMMAND
"${CMAKE_COMMAND}" "-E" "copy"
${CMAKE_CURRENT_LIST_DIR}/${musl_header}
${musl_header_out}
OUTPUT ${musl_modulemap_out} ${musl_header_out}
COMMENT "Copying Musl modulemap to resources")

list(APPEND musl_modulemap_target_list ${copy_musl_modulemap})

if(SWIFT_BUILD_STATIC_STDLIB OR SWIFT_SDK_${sdk}_STATIC_ONLY)
add_custom_command_target(
copy_musl_modulemap_static
COMMAND
"${CMAKE_COMMAND}" "-E" "make_directory" ${module_dir_static}
COMMAND
"${CMAKE_COMMAND}" "-E" "copy"
${CMAKE_CURRENT_LIST_DIR}/${musl_modulemap}
${musl_modulemap_out_static}
COMMAND
"${CMAKE_COMMAND}" "-E" "copy"
${CMAKE_CURRENT_LIST_DIR}/${musl_header}
${musl_header_out_static}
OUTPUT ${musl_modulemap_out_static} ${musl_header_out_static}
COMMENT "Copying Musl modulemap to static resources")

list(APPEND musl_modulemap_target_list ${copy_musl_modulemap_static})

swift_install_in_component(FILES "${musl_modulemap_out_static}"
DESTINATION "lib/swift_static/${arch_subdir}"
COMPONENT sdk-overlay)
swift_install_in_component(FILES "${musl_header_out_static}"
DESTINATION "lib/swift_static/${arch_subdir}"
COMPONENT sdk-overlay)
endif()

swift_install_in_component(FILES "${musl_modulemap_out}"
DESTINATION "lib/swift/${arch_subdir}"
COMPONENT sdk-overlay)
swift_install_in_component(FILES "${musl_header_out}"
DESTINATION "lib/swift/${arch_subdir}"
COMPONENT sdk-overlay)
endforeach()
endforeach()
add_custom_target(musl_modulemap DEPENDS ${musl_modulemap_target_list})
set_property(TARGET musl_modulemap PROPERTY FOLDER "Miscellaneous")
add_dependencies(sdk-overlay musl_modulemap)

set(glibc_modulemap_target_list)
foreach(sdk ${SWIFT_SDKS})
if(NOT "${sdk}" STREQUAL "LINUX" AND
Expand Down Expand Up @@ -238,7 +313,7 @@ foreach(sdk ${SWIFT_SDKS})
FLAGS "-DCMAKE_SDK=${sdk}")
list(APPEND glibc_modulemap_target_list ${glibc_header_target})

if(SWIFT_BUILD_STATIC_STDLIB)
if(SWIFT_BUILD_STATIC_STDLIB OR SWIFT_SDK_${sdk}_STATIC_ONLY)
add_custom_command_target(
copy_glibc_modulemap_header_static
COMMAND
Expand Down Expand Up @@ -287,7 +362,7 @@ foreach(sdk ${SWIFT_SDKS})
DESTINATION "lib/swift/${arch_subdir}"
COMPONENT sdk-overlay)

if(SWIFT_BUILD_STATIC_STDLIB)
if(SWIFT_BUILD_STATIC_STDLIB OR SWIFT_SDK_${sdk}_STATIC_ONLY)
swift_install_in_component(FILES "${glibc_modulemap_out}"
DESTINATION "lib/swift_static/${arch_subdir}"
COMPONENT sdk-overlay)
Expand Down
4 changes: 3 additions & 1 deletion stdlib/public/Platform/Platform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,9 @@ public var SIG_IGN: sig_t { return unsafeBitCast(1, to: sig_t.self) }
public var SIG_ERR: sig_t { return unsafeBitCast(-1, to: sig_t.self) }
public var SIG_HOLD: sig_t { return unsafeBitCast(3, to: sig_t.self) }
#elseif os(Linux) || os(FreeBSD) || os(PS4) || os(Android) || os(Haiku)
#if !canImport(SwiftMusl)
public typealias sighandler_t = __sighandler_t
#endif

public var SIG_DFL: sighandler_t? { return nil }
public var SIG_IGN: sighandler_t {
Expand Down Expand Up @@ -487,7 +489,7 @@ extension Duration {
public var environ: UnsafeMutablePointer<UnsafeMutablePointer<CChar>?> {
return _swift_stdlib_getEnviron()
}
#elseif os(Linux)
#elseif os(Linux) && !canImport(SwiftMusl)
public var environ: UnsafeMutablePointer<UnsafeMutablePointer<CChar>?> {
return __environ
}
Expand Down
187 changes: 187 additions & 0 deletions stdlib/public/Platform/SwiftMusl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
//===--- SwiftMusl.h ------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2023 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 <assert.h>
#include <float.h>
#include <iso646.h>
#include <limits.h>
#include <stdalign.h>
#include <stdarg.h>
#include <stdatomic.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <time.h>
#include <tgmath.h>
#include <complex.h>
#include <ctype.h>
#include <errno.h>
#include <fenv.h>
#include <inttypes.h>
#include <locale.h>
#include <math.h>
#include <setjmp.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdnoreturn.h>
#include <string.h>
#include <threads.h>
#include <uchar.h>
#include <wchar.h>
#include <wctype.h>
#include <aio.h>
#include <arpa/inet.h>
#include <arpa/ftp.h>
#include <arpa/nameser.h>
#include <arpa/nameser_compat.h>
#include <arpa/telnet.h>
#include <arpa/tftp.h>
#include <cpio.h>
#include <dirent.h>
#include <dlfcn.h>
#include <fcntl.h>
#include <fmtmsg.h>
#include <fnmatch.h>
#include <ftw.h>
#include <glob.h>
#include <grp.h>
#include <iconv.h>
#include <langinfo.h>
#include <libgen.h>
#include <monetary.h>
#include <mqueue.h>
#include <net/if.h>
#include <net/ethernet.h>
#include <net/if_arp.h>
#include <net/route.h>
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netinet/ether.h>
#include <netinet/icmp6.h>
#include <netinet/if_ether.h>
#include <netinet/igmp.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netinet/ip6.h>
#include <netinet/ip_icmp.h>
#include <netinet/udp.h>
#include <nl_types.h>
#include <poll.h>
#include <pthread.h>
#include <pwd.h>
#include <regex.h>
#include <sched.h>
#include <search.h>
#include <semaphore.h>
#include <spawn.h>
#include <strings.h>
#include <stropts.h>
#include <sys/ipc.h>
#include <sys/mman.h>
#include <sys/msg.h>
#include <sys/resource.h>
#include <sys/select.h>
#include <sys/sem.h>
#include <sys/shm.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/statvfs.h>
#include <sys/time.h>
#include <sys/times.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <sys/un.h>
#include <sys/utsname.h>
#include <sys/wait.h>
#include <sys/acct.h>
#include <sys/auxv.h>
#include <sys/cachectl.h>
#include <sys/dir.h>
#include <sys/epoll.h>
#include <sys/eventfd.h>
#include <sys/fanotify.h>
#include <sys/file.h>
#include <sys/fsuid.h>
#include <sys/inotify.h>
#include <sys/ioctl.h>
#include <sys/io.h>
#include <sys/klog.h>
#include <sys/membarrier.h>
#include <sys/mount.h>
#include <sys/mtio.h>
#include <sys/param.h>
#include <sys/personality.h>
#include <sys/prctl.h>
#include <sys/procfs.h>
#include <sys/ptrace.h>
#include <sys/quota.h>
#include <sys/random.h>
#include <sys/reboot.h>
#include <sys/reg.h>
#include <sys/sendfile.h>
#include <sys/signalfd.h>
#include <sys/statfs.h>
#include <sys/stropts.h>
#include <sys/swap.h>
#include <sys/syscall.h>
#include <sys/sysinfo.h>
#include <sys/syslog.h>
#include <sys/sysmacros.h>
#include <sys/timeb.h>
#include <sys/timerfd.h>
#include <sys/timex.h>
#include <sys/ttydefaults.h>
#include <sys/ucontext.h>
#include <sys/user.h>
#include <sys/vfs.h>
#include <sys/xattr.h>
#include <syslog.h>
#include <tar.h>
#include <termios.h>
#include <ucontext.h>
#include <unistd.h>
#include <ulimit.h>
#include <utime.h>
#include <utmpx.h>
#include <alloca.h>
#include <ar.h>
#include <byteswap.h>
#include <crypt.h>
#include <elf.h>
#include <endian.h>
#include <err.h>
#include <getopt.h>
#include <ifaddrs.h>
#include <lastlog.h>
#include <libintl.h>
#include <link.h>
#include <malloc.h>
#include <memory.h>
#include <mntent.h>
#include <netpacket/packet.h>
#include <paths.h>
#include <pty.h>
#include <resolv.h>
#include <scsi/scsi.h>
#include <scsi/scsi_ioctl.h>
#include <scsi/sg.h>
#include <shadow.h>
#include <stdio_ext.h>
#include <syscall.h>
#include <sysexits.h>
#include <utmp.h>
#include <values.h>
#include <unwind.h>
#include <wordexp.h>
#include <fts.h>
Loading