diff --git a/lib/ClangImporter/ClangImporter.cpp b/lib/ClangImporter/ClangImporter.cpp index 2158e524b9650..f723f7be3ca50 100644 --- a/lib/ClangImporter/ClangImporter.cpp +++ b/lib/ClangImporter/ClangImporter.cpp @@ -461,6 +461,41 @@ getGlibcModuleMapPath(SearchPathOptions& Opts, llvm::Triple triple, return None; } +static Optional +getWasiLibcModuleMapPath(SearchPathOptions& Opts, llvm::Triple triple, + SmallVectorImpl &buffer) { + StringRef platform = swift::getPlatformNameForTriple(triple); + StringRef arch = swift::getMajorArchitectureName(triple); + + if (!Opts.SDKPath.empty()) { + buffer.clear(); + buffer.append(Opts.SDKPath.begin(), Opts.SDKPath.end()); + llvm::sys::path::append(buffer, "usr", "lib", "swift"); + llvm::sys::path::append(buffer, platform, arch, "wasi.modulemap"); + + // Only specify the module map if that file actually exists. It may not; + // for example in the case that `swiftc -target x86_64-unknown-linux-gnu + // -emit-ir` is invoked using a Swift compiler not built for Linux targets. + if (llvm::sys::fs::exists(buffer)) + return StringRef(buffer.data(), buffer.size()); + } + + if (!Opts.RuntimeResourcePath.empty()) { + buffer.clear(); + buffer.append(Opts.RuntimeResourcePath.begin(), + Opts.RuntimeResourcePath.end()); + llvm::sys::path::append(buffer, platform, arch, "wasi.modulemap"); + + // Only specify the module map if that file actually exists. It may not; + // for example in the case that `swiftc -target x86_64-unknown-linux-gnu + // -emit-ir` is invoked using a Swift compiler not built for Linux targets. + if (llvm::sys::fs::exists(buffer)) + return StringRef(buffer.data(), buffer.size()); + } + + return None; +} + void importer::getNormalInvocationArguments( std::vector &invocationArgStrs, @@ -604,6 +639,10 @@ importer::getNormalInvocationArguments( if (triple.isOSWASI()) { invocationArgStrs.insert(invocationArgStrs.end(), {"-D_WASI_EMULATED_MMAN"}); + SmallString<128> buffer; + if (auto path = getWasiLibcModuleMapPath(searchPathOpts, triple, buffer)) { + invocationArgStrs.push_back((Twine("-fmodule-map-file=") + *path).str()); + } } if (triple.isOSWindows()) { diff --git a/stdlib/private/StdlibUnittest/CMakeLists.txt b/stdlib/private/StdlibUnittest/CMakeLists.txt index cf2f8f0a2966a..2014d86a1431c 100644 --- a/stdlib/private/StdlibUnittest/CMakeLists.txt +++ b/stdlib/private/StdlibUnittest/CMakeLists.txt @@ -41,7 +41,7 @@ add_swift_target_library(swiftStdlibUnittest ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} SWIFT_MODULE_DEPENDS_OPENBSD Glibc SwiftPrivateThreadExtras SWIFT_MODULE_DEPENDS_CYGWIN Glibc SwiftPrivateThreadExtras SWIFT_MODULE_DEPENDS_HAIKU Glibc SwiftPrivateThreadExtras - SWIFT_MODULE_DEPENDS_WASI Glibc + SWIFT_MODULE_DEPENDS_WASI WASILibc SWIFT_MODULE_DEPENDS_WINDOWS MSVCRT WinSDK SwiftPrivateThreadExtras SWIFT_COMPILE_FLAGS ${swift_stdlib_unittest_compile_flags} ${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS} INSTALL_IN_COMPONENT stdlib-experimental diff --git a/stdlib/private/StdlibUnittest/RaceTest.swift b/stdlib/private/StdlibUnittest/RaceTest.swift index 8571052ab5bbf..e605d21f45a07 100644 --- a/stdlib/private/StdlibUnittest/RaceTest.swift +++ b/stdlib/private/StdlibUnittest/RaceTest.swift @@ -45,6 +45,8 @@ import SwiftPrivateThreadExtras import Darwin #elseif canImport(Glibc) import Glibc +#elseif os(WASI) +import WASILibc #elseif os(Windows) import MSVCRT import WinSDK diff --git a/stdlib/private/StdlibUnittest/StdlibCoreExtras.swift b/stdlib/private/StdlibUnittest/StdlibCoreExtras.swift index a734f9fc0e047..12624906eaaca 100644 --- a/stdlib/private/StdlibUnittest/StdlibCoreExtras.swift +++ b/stdlib/private/StdlibUnittest/StdlibCoreExtras.swift @@ -16,6 +16,8 @@ import SwiftPrivateLibcExtras import Darwin #elseif canImport(Glibc) import Glibc +#elseif os(WASI) +import WASILibc #elseif os(Windows) import MSVCRT #endif diff --git a/stdlib/private/StdlibUnittest/StdlibUnittest.swift b/stdlib/private/StdlibUnittest/StdlibUnittest.swift index 9e78c001b2b18..d20107fc7a359 100644 --- a/stdlib/private/StdlibUnittest/StdlibUnittest.swift +++ b/stdlib/private/StdlibUnittest/StdlibUnittest.swift @@ -22,6 +22,8 @@ import Foundation import Darwin #elseif canImport(Glibc) import Glibc +#elseif os(WASI) +import WASILibc #elseif os(Windows) import MSVCRT import WinSDK diff --git a/stdlib/private/StdlibUnittest/SymbolLookup.swift b/stdlib/private/StdlibUnittest/SymbolLookup.swift index f83cc22fe0d58..ff82758a6ccba 100644 --- a/stdlib/private/StdlibUnittest/SymbolLookup.swift +++ b/stdlib/private/StdlibUnittest/SymbolLookup.swift @@ -14,6 +14,8 @@ import Darwin #elseif canImport(Glibc) import Glibc +#elseif os(WASI) + import WASILibc #elseif os(Windows) import MSVCRT import WinSDK diff --git a/stdlib/private/SwiftPrivateLibcExtras/CMakeLists.txt b/stdlib/private/SwiftPrivateLibcExtras/CMakeLists.txt index b9245aef1f272..6e00a29c3ad10 100644 --- a/stdlib/private/SwiftPrivateLibcExtras/CMakeLists.txt +++ b/stdlib/private/SwiftPrivateLibcExtras/CMakeLists.txt @@ -18,7 +18,7 @@ add_swift_target_library(swiftSwiftPrivateLibcExtras ${SWIFT_STDLIB_LIBRARY_BUIL SWIFT_MODULE_DEPENDS_OPENBSD Glibc SWIFT_MODULE_DEPENDS_CYGWIN Glibc SWIFT_MODULE_DEPENDS_HAIKU Glibc - SWIFT_MODULE_DEPENDS_WASI Glibc + SWIFT_MODULE_DEPENDS_WASI WASILibc SWIFT_MODULE_DEPENDS_WINDOWS MSVCRT WinSDK INSTALL_IN_COMPONENT stdlib-experimental DARWIN_INSTALL_NAME_DIR "${SWIFT_DARWIN_STDLIB_PRIVATE_INSTALL_NAME_DIR}") diff --git a/stdlib/private/SwiftPrivateLibcExtras/Subprocess.swift b/stdlib/private/SwiftPrivateLibcExtras/Subprocess.swift index b07b924cb939f..4b5d71572896e 100644 --- a/stdlib/private/SwiftPrivateLibcExtras/Subprocess.swift +++ b/stdlib/private/SwiftPrivateLibcExtras/Subprocess.swift @@ -15,6 +15,8 @@ import SwiftPrivate import Darwin #elseif canImport(Glibc) import Glibc +#elseif os(WASI) +import WASILibc #elseif os(Windows) import MSVCRT import WinSDK diff --git a/stdlib/private/SwiftPrivateLibcExtras/SwiftPrivateLibcExtras.swift b/stdlib/private/SwiftPrivateLibcExtras/SwiftPrivateLibcExtras.swift index d9dd93277e471..b61efa58a1c7b 100644 --- a/stdlib/private/SwiftPrivateLibcExtras/SwiftPrivateLibcExtras.swift +++ b/stdlib/private/SwiftPrivateLibcExtras/SwiftPrivateLibcExtras.swift @@ -15,6 +15,8 @@ import SwiftPrivate import Darwin #elseif canImport(Glibc) import Glibc +#elseif os(WASI) +import WASILibc #elseif os(Windows) import MSVCRT #endif diff --git a/stdlib/private/SwiftPrivateThreadExtras/CMakeLists.txt b/stdlib/private/SwiftPrivateThreadExtras/CMakeLists.txt index 10d3ccc73e69c..239cd620ca203 100644 --- a/stdlib/private/SwiftPrivateThreadExtras/CMakeLists.txt +++ b/stdlib/private/SwiftPrivateThreadExtras/CMakeLists.txt @@ -15,7 +15,7 @@ add_swift_target_library(swiftSwiftPrivateThreadExtras ${SWIFT_STDLIB_LIBRARY_BU SWIFT_MODULE_DEPENDS_OPENBSD Glibc SWIFT_MODULE_DEPENDS_CYGWIN Glibc SWIFT_MODULE_DEPENDS_HAIKU Glibc - SWIFT_MODULE_DEPENDS_WASI Glibc + SWIFT_MODULE_DEPENDS_WASI WASILibc SWIFT_MODULE_DEPENDS_WINDOWS MSVCRT WinSDK SWIFT_COMPILE_FLAGS ${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS} TARGET_SDKS ALL_APPLE_PLATFORMS CYGWIN FREEBSD OPENBSD HAIKU LINUX WINDOWS ANDROID diff --git a/stdlib/private/SwiftPrivateThreadExtras/SwiftPrivateThreadExtras.swift b/stdlib/private/SwiftPrivateThreadExtras/SwiftPrivateThreadExtras.swift index 76eca282cef24..a83d0fe568962 100644 --- a/stdlib/private/SwiftPrivateThreadExtras/SwiftPrivateThreadExtras.swift +++ b/stdlib/private/SwiftPrivateThreadExtras/SwiftPrivateThreadExtras.swift @@ -19,6 +19,8 @@ import Darwin #elseif canImport(Glibc) import Glibc +#elseif os(WASI) +import WASILibc #elseif os(Windows) import MSVCRT import WinSDK diff --git a/stdlib/private/SwiftPrivateThreadExtras/ThreadBarriers.swift b/stdlib/private/SwiftPrivateThreadExtras/ThreadBarriers.swift index 30e5761542472..7d5a1e34090fe 100644 --- a/stdlib/private/SwiftPrivateThreadExtras/ThreadBarriers.swift +++ b/stdlib/private/SwiftPrivateThreadExtras/ThreadBarriers.swift @@ -14,6 +14,8 @@ import Darwin #elseif canImport(Glibc) import Glibc +#elseif os(WASI) +import WASILibc #elseif os(Windows) import MSVCRT import WinSDK diff --git a/stdlib/public/Differentiation/CMakeLists.txt b/stdlib/public/Differentiation/CMakeLists.txt index 275c9f68cbf06..63b0f9a1ad590 100644 --- a/stdlib/public/Differentiation/CMakeLists.txt +++ b/stdlib/public/Differentiation/CMakeLists.txt @@ -32,7 +32,7 @@ add_swift_target_library(swift_Differentiation ${SWIFT_STDLIB_LIBRARY_BUILD_TYPE SWIFT_MODULE_DEPENDS_OPENBSD Glibc SWIFT_MODULE_DEPENDS_CYGWIN Glibc SWIFT_MODULE_DEPENDS_HAIKU Glibc - SWIFT_MODULE_DEPENDS_WASI Glibc + SWIFT_MODULE_DEPENDS_WASI WASILibc SWIFT_MODULE_DEPENDS_WINDOWS MSVCRT SWIFT_COMPILE_FLAGS diff --git a/stdlib/public/Differentiation/TgmathDerivatives.swift.gyb b/stdlib/public/Differentiation/TgmathDerivatives.swift.gyb index e5f40d3ce9335..cf44f6ffd0d52 100644 --- a/stdlib/public/Differentiation/TgmathDerivatives.swift.gyb +++ b/stdlib/public/Differentiation/TgmathDerivatives.swift.gyb @@ -16,8 +16,10 @@ import Swift #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) import Darwin.C.tgmath -#elseif os(Linux) || os(FreeBSD) || os(OpenBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku) || os(WASI) +#elseif os(Linux) || os(FreeBSD) || os(OpenBSD) || os(PS4) || os(Android) || os(Cygwin) || os(Haiku) import Glibc +#elseif os(WASI) + import WASILibc #elseif os(Windows) import MSVCRT #else diff --git a/stdlib/public/Platform/CMakeLists.txt b/stdlib/public/Platform/CMakeLists.txt index d9dfcdf34dbef..aa7d37be2c82f 100644 --- a/stdlib/public/Platform/CMakeLists.txt +++ b/stdlib/public/Platform/CMakeLists.txt @@ -44,10 +44,62 @@ add_swift_target_library(swiftGlibc ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_O ${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS} ${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS} LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}" - TARGET_SDKS ANDROID CYGWIN FREEBSD OPENBSD LINUX HAIKU WASI + TARGET_SDKS ANDROID CYGWIN FREEBSD OPENBSD LINUX HAIKU INSTALL_IN_COMPONENT sdk-overlay DEPENDS glibc_modulemap) +if(WASI IN_LIST SWIFT_SDKS) + set(arch_subdir "${SWIFT_SDK_WASI_LIB_SUBDIR}/wasm32") + set(module_dir "${SWIFTLIB_DIR}/${arch_subdir}") + set(module_dir_static "${SWIFTSTATICLIB_DIR}/${arch_subdir}") + set(wasi_libc_modulemap_out "${module_dir}/wasi.modulemap") + set(wasi_libc_modulemap_out_static "${module_dir_static}/wasi.modulemap") + handle_gyb_source_single(wasi_libc_modulemap_target + SOURCE "wasi.modulemap.gyb" + OUTPUT "${wasi_libc_modulemap_out}" + FLAGS "-DGLIBC_INCLUDE_PATH=${SWIFT_SDK_WASI_ARCH_wasm32_LIBC_INCLUDE_DIRECTORY}" + "-DGLIBC_ARCH_INCLUDE_PATH=${SWIFT_SDK_WASI_ARCH_wasm32_LIBC_ARCHITECTURE_INCLUDE_DIRECTORY}") + add_custom_command_target( + copy_wasi_libc_modulemap_static + COMMAND + "${CMAKE_COMMAND}" "-E" "make_directory" ${module_dir_static} + COMMAND + "${CMAKE_COMMAND}" "-E" "copy" ${wasi_libc_modulemap_out} ${wasi_libc_modulemap_out_static} + OUTPUT ${wasi_libc_modulemap_out_static} + DEPENDS + "${wasi_libc_modulemap_target}" + COMMENT "Copying WASILlibc modulemap to static resources") + + add_swift_target_library(swiftWASILibc ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY + ${swift_platform_sources} + POSIXError.swift + + GYB_SOURCES + ${swift_platform_gyb_sources} + WASI.swift.gyb + + SWIFT_COMPILE_FLAGS + ${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS} + ${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS} + LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}" + TARGET_SDKS WASI + INSTALL_IN_COMPONENT sdk-overlay + DEPENDS ${wasi_libc_modulemap_target} ${copy_wasi_libc_modulemap_static}) + + swift_install_in_component(FILES "${wasi_libc_modulemap_out}" + DESTINATION "lib/swift/${arch_subdir}" + COMPONENT sdk-overlay) + + swift_install_in_component(FILES "${wasi_libc_modulemap_out}" + DESTINATION "lib/swift_static/${arch_subdir}" + COMPONENT sdk-overlay) + + add_custom_target(wasi_libc_modulemap + DEPENDS ${wasi_libc_modulemap_target} ${copy_wasi_libc_modulemap_static}) + set_property(TARGET wasi_libc_modulemap PROPERTY FOLDER "Miscellaneous") + add_dependencies(sdk-overlay wasi_libc_modulemap) +endif() + add_swift_target_library(swiftMSVCRT ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY msvcrt.swift ${swift_platform_sources} @@ -71,8 +123,7 @@ foreach(sdk ${SWIFT_SDKS}) NOT "${sdk}" STREQUAL "OPENBSD" AND NOT "${sdk}" STREQUAL "ANDROID" AND NOT "${sdk}" STREQUAL "CYGWIN" AND - NOT "${sdk}" STREQUAL "HAIKU" AND - NOT "${sdk}" STREQUAL "WASI") + NOT "${sdk}" STREQUAL "HAIKU") continue() endif() diff --git a/stdlib/public/Platform/WASI.swift.gyb b/stdlib/public/Platform/WASI.swift.gyb new file mode 100644 index 0000000000000..962f1202f70eb --- /dev/null +++ b/stdlib/public/Platform/WASI.swift.gyb @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2020 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 SwiftWASILibc // Clang module + +// 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')]: +// 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 + +%end + +public let MAP_FAILED: UnsafeMutableRawPointer! = UnsafeMutableRawPointer(bitPattern: -1) + +// WebAssembly's error.h uses a macro that Swift can't import. +public let EINTR:Int32 = 27 +public let EINVAL:Int32 = 28 diff --git a/stdlib/public/Platform/wasi.modulemap.gyb b/stdlib/public/Platform/wasi.modulemap.gyb new file mode 100644 index 0000000000000..77951e328f705 --- /dev/null +++ b/stdlib/public/Platform/wasi.modulemap.gyb @@ -0,0 +1,231 @@ +//===--- wasi.modulemap.gyb ----------------------------------------------===// +// +// This source file is part of the Swift.org open source project +// +// Copyright (c) 2020 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 +// +//===----------------------------------------------------------------------===// + +/// This is a semi-complete modulemap that maps WASI headers in a roughly +/// similar way to the Darwin SDK modulemap. We do not take care to list every +/// single header which may be included by a particular submodule, so there can +/// still be issues if imported into the same context as one in which someone +/// included those headers directly. +/// +/// It's not named just WASI so that it doesn't conflict in the event of a +/// future official WASI modulemap. +module SwiftWASILibc [system] { + // C standard library + module C { + module ctype { + header "${GLIBC_INCLUDE_PATH}/ctype.h" + export * + } + module errno { + header "${GLIBC_INCLUDE_PATH}/errno.h" + export * + } + + module fenv { + header "${GLIBC_INCLUDE_PATH}/fenv.h" + export * + } + + // note: supplied by compiler + // module float { + // header "${GLIBC_INCLUDE_PATH}/float.h" + // export * + // } + + module inttypes { + header "${GLIBC_INCLUDE_PATH}/inttypes.h" + export * + } + + // note: potentially supplied by compiler + // module iso646 { + // header "${GLIBC_INCLUDE_PATH}/iso646.h" + // export * + // } + // module limits { + // header "${GLIBC_INCLUDE_PATH}/limits.h" + // export * + // } + + module locale { + header "${GLIBC_INCLUDE_PATH}/locale.h" + export * + } + module math { + header "${GLIBC_INCLUDE_PATH}/math.h" + export * + } + module signal { + header "${GLIBC_INCLUDE_PATH}/signal.h" + export * + } + + // note: supplied by the compiler + // module stdarg { + // header "${GLIBC_INCLUDE_PATH}/stdarg.h" + // export * + // } + // module stdbool { + // header "${GLIBC_INCLUDE_PATH}/stdbool.h" + // export * + // } + // module stddef { + // header "${GLIBC_INCLUDE_PATH}/stddef.h" + // export * + // } + // module stdint { + // header "${GLIBC_INCLUDE_PATH}/stdint.h" + // export * + // } + + module stdio { + header "${GLIBC_INCLUDE_PATH}/stdio.h" + export * + } + module stdlib { + header "${GLIBC_INCLUDE_PATH}/stdlib.h" + export * + export stddef + } + module string { + header "${GLIBC_INCLUDE_PATH}/string.h" + export * + } + + // note: supplied by the compiler + // explicit module tgmath { + // header "${GLIBC_INCLUDE_PATH}/tgmath.h" + // export * + // } + + module time { + header "${GLIBC_INCLUDE_PATH}/time.h" + export * + } + } + + // POSIX + module POSIX { + module arpa { + module inet { + header "${GLIBC_INCLUDE_PATH}/arpa/inet.h" + export * + } + export * + } + module dirent { + header "${GLIBC_INCLUDE_PATH}/dirent.h" + export * + } + module fcntl { + header "${GLIBC_INCLUDE_PATH}/fcntl.h" + export * + } + module fnmatch { + header "${GLIBC_INCLUDE_PATH}/fnmatch.h" + export * + } + module ioctl { + header "${GLIBC_ARCH_INCLUDE_PATH}/sys/ioctl.h" + export * + } + module libgen { + header "${GLIBC_INCLUDE_PATH}/libgen.h" + export * + } + module netinet { + module in { + header "${GLIBC_INCLUDE_PATH}/netinet/in.h" + export * + + exclude header "${GLIBC_INCLUDE_PATH}/netinet6/in6.h" + } + module tcp { + header "${GLIBC_INCLUDE_PATH}/netinet/tcp.h" + export * + } + } + module poll { + header "${GLIBC_INCLUDE_PATH}/poll.h" + export * + } + module regex { + header "${GLIBC_INCLUDE_PATH}/regex.h" + export * + } + module sched { + header "${GLIBC_INCLUDE_PATH}/sched.h" + export * + } + module semaphore { + header "${GLIBC_INCLUDE_PATH}/semaphore.h" + export * + } + module strings { + header "${GLIBC_INCLUDE_PATH}/strings.h" + export * + } + + module sys { + export * + + module mman { + header "${GLIBC_ARCH_INCLUDE_PATH}/sys/mman.h" + export * + } + module resource { + header "${GLIBC_ARCH_INCLUDE_PATH}/sys/resource.h" + export * + } + module select { + header "${GLIBC_ARCH_INCLUDE_PATH}/sys/select.h" + export * + } + module socket { + header "${GLIBC_ARCH_INCLUDE_PATH}/sys/socket.h" + export * + } + module stat { + header "${GLIBC_ARCH_INCLUDE_PATH}/sys/stat.h" + export * + } + module time { + header "${GLIBC_ARCH_INCLUDE_PATH}/sys/time.h" + export * + } + module times { + header "${GLIBC_ARCH_INCLUDE_PATH}/sys/times.h" + export * + } + module types { + header "${GLIBC_ARCH_INCLUDE_PATH}/sys/types.h" + export * + } + module uio { + header "${GLIBC_ARCH_INCLUDE_PATH}/sys/uio.h" + export * + } + module un { + header "${GLIBC_ARCH_INCLUDE_PATH}/sys/un.h" + export * + } + module utsname { + header "${GLIBC_ARCH_INCLUDE_PATH}/sys/utsname.h" + export * + } + } + module unistd { + header "${GLIBC_INCLUDE_PATH}/unistd.h" + export * + } + } +} diff --git a/test/ClangImporter/clang_builtins.swift b/test/ClangImporter/clang_builtins.swift index 07557df68b723..d211a2506ad8a 100644 --- a/test/ClangImporter/clang_builtins.swift +++ b/test/ClangImporter/clang_builtins.swift @@ -4,6 +4,8 @@ import Darwin #elseif canImport(Glibc) import Glibc +#elseif os(WASI) + import WASILibc #elseif os(Windows) import MSVCRT #else diff --git a/test/IRGen/builtin_math.swift b/test/IRGen/builtin_math.swift index 3602af70075cf..5360c0c4e85c1 100644 --- a/test/IRGen/builtin_math.swift +++ b/test/IRGen/builtin_math.swift @@ -4,6 +4,8 @@ import Darwin #elseif canImport(Glibc) import Glibc +#elseif os(WASI) + import WASILibc #elseif os(Windows) import MSVCRT #else diff --git a/test/stdlib/FloatConstants.swift b/test/stdlib/FloatConstants.swift index 24e3fea8dc6d0..3825624fbe3a7 100644 --- a/test/stdlib/FloatConstants.swift +++ b/test/stdlib/FloatConstants.swift @@ -4,6 +4,8 @@ import Darwin #elseif canImport(Glibc) import Glibc +#elseif os(WASI) + import WASILibc #elseif os(Windows) import MSVCRT #else diff --git a/test/stdlib/MathConstants.swift b/test/stdlib/MathConstants.swift index 61fb01b584645..eeda1d9ad5ea1 100644 --- a/test/stdlib/MathConstants.swift +++ b/test/stdlib/MathConstants.swift @@ -4,6 +4,8 @@ import Darwin #elseif canImport(Glibc) import Glibc +#elseif os(WASI) + import WASILibc #elseif os(Windows) import MSVCRT #else diff --git a/test/stdlib/PrintFloat.swift.gyb b/test/stdlib/PrintFloat.swift.gyb index 2795a1c8a3473..e94d91d7b6c25 100644 --- a/test/stdlib/PrintFloat.swift.gyb +++ b/test/stdlib/PrintFloat.swift.gyb @@ -14,6 +14,8 @@ import StdlibUnittest import Darwin #elseif canImport(Glibc) import Glibc +#elseif os(WASI) + import WASILibc #elseif os(Windows) import MSVCRT #else diff --git a/test/stdlib/Runtime.swift.gyb b/test/stdlib/Runtime.swift.gyb index aa5092d5b84d6..c77c474d1520f 100644 --- a/test/stdlib/Runtime.swift.gyb +++ b/test/stdlib/Runtime.swift.gyb @@ -14,6 +14,8 @@ import SwiftShims import Darwin #elseif canImport(Glibc) import Glibc +#elseif os(WASI) + import WASILibc #elseif os(Windows) import MSVCRT import WinSDK diff --git a/test/stdlib/VarArgs.swift b/test/stdlib/VarArgs.swift index 90dff40f81e3a..a68931c99bc20 100644 --- a/test/stdlib/VarArgs.swift +++ b/test/stdlib/VarArgs.swift @@ -9,6 +9,9 @@ import Swift #elseif canImport(Glibc) import Glibc typealias CGFloat = Double +#elseif os(WASI) + import WASILibc + typealias CGFloat = Double #elseif os(Windows) import MSVCRT #if arch(x86_64) || arch(arm64) diff --git a/test/stdlib/tgmath.swift.gyb b/test/stdlib/tgmath.swift.gyb index 3a1e526ab30f0..9156bba0d83d2 100644 --- a/test/stdlib/tgmath.swift.gyb +++ b/test/stdlib/tgmath.swift.gyb @@ -21,6 +21,8 @@ import Darwin.C.tgmath #elseif canImport(Glibc) import Glibc +#elseif os(WASI) + import WASILibc #elseif os(Windows) import MSVCRT #else diff --git a/test/stdlib/tgmath_optimized.swift b/test/stdlib/tgmath_optimized.swift index b1628b922e707..6ec8e58d686b6 100644 --- a/test/stdlib/tgmath_optimized.swift +++ b/test/stdlib/tgmath_optimized.swift @@ -8,6 +8,8 @@ import Darwin #elseif canImport(Glibc) import Glibc +#elseif os(WASI) + import WASILibc #elseif os(Windows) import MSVCRT #else diff --git a/utils/webassembly/build-toolchain.sh b/utils/webassembly/build-toolchain.sh index 7341ec23eb14f..eecc0117d907c 100755 --- a/utils/webassembly/build-toolchain.sh +++ b/utils/webassembly/build-toolchain.sh @@ -117,7 +117,7 @@ merge_toolchains() { rsync -v -a $TARGET_TOOLCHAIN_SDK/usr/bin/ $DIST_TOOLCHAIN_SDK/usr/bin/ # Replace absolute sysroot path with relative path - sed -i -e "s@\".*/include@\"../../../../share/wasi-sysroot/include@g" $DIST_TOOLCHAIN_SDK/usr/lib/swift/wasi/wasm32/glibc.modulemap + sed -i -e "s@\".*/include@\"../../../../share/wasi-sysroot/include@g" $DIST_TOOLCHAIN_SDK/usr/lib/swift/wasi/wasm32/wasi.modulemap } build_host_toolchain