diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b738e6b0157d5..6e2cef8146043 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,6 +22,8 @@ jobs: sudo apt-get purge libgcc-9-dev gcc-9 libstdc++-9-dev sudo swapoff -a sudo rm -f /swapfile + sudo rm -rf /opt/hostedtoolcache + sudo rm -rf /usr/share/dotnet sudo apt clean docker rmi $(docker image ls -aq) df -h @@ -93,7 +95,7 @@ jobs: name: packaging-scripts path: utils/webassembly - name: Pack test results - run: tar cJf swift-test-results.tar.gz ../build/*/swift-macosx-x86_64/swift-test-results + run: tar cJf swift-test-results.tar.gz ../target-build/*/swift-macosx-x86_64/swift-test-results - name: Upload test results uses: actions/upload-artifact@v1 with: diff --git a/lib/ClangImporter/ClangImporter.cpp b/lib/ClangImporter/ClangImporter.cpp index 7eb56830539b4..ae3b4ca429f00 100644 --- a/lib/ClangImporter/ClangImporter.cpp +++ b/lib/ClangImporter/ClangImporter.cpp @@ -458,6 +458,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; +} + static void getNormalInvocationArguments(std::vector &invocationArgStrs, ASTContext &ctx, @@ -601,6 +636,10 @@ getNormalInvocationArguments(std::vector &invocationArgStrs, 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 cbd8b460d4cfa..9cfd0677f2129 100644 --- a/stdlib/private/StdlibUnittest/RaceTest.swift +++ b/stdlib/private/StdlibUnittest/RaceTest.swift @@ -43,8 +43,10 @@ import SwiftPrivateThreadExtras #endif #if os(macOS) || os(iOS) import Darwin -#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 import WinSDK diff --git a/stdlib/private/StdlibUnittest/StdlibCoreExtras.swift b/stdlib/private/StdlibUnittest/StdlibCoreExtras.swift index db3262166f40e..c612ffbcbd411 100644 --- a/stdlib/private/StdlibUnittest/StdlibCoreExtras.swift +++ b/stdlib/private/StdlibUnittest/StdlibCoreExtras.swift @@ -14,8 +14,10 @@ import SwiftPrivate import SwiftPrivateLibcExtras #if os(macOS) || os(iOS) import Darwin -#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 #endif diff --git a/stdlib/private/StdlibUnittest/StdlibUnittest.swift b/stdlib/private/StdlibUnittest/StdlibUnittest.swift index 6628000ac7782..8af0a22f294ef 100644 --- a/stdlib/private/StdlibUnittest/StdlibUnittest.swift +++ b/stdlib/private/StdlibUnittest/StdlibUnittest.swift @@ -20,8 +20,10 @@ import SwiftPrivateLibcExtras #if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) import Foundation import Darwin -#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 import WinSDK diff --git a/stdlib/private/StdlibUnittest/SymbolLookup.swift b/stdlib/private/StdlibUnittest/SymbolLookup.swift index a403f0381849f..c0d82350a8da4 100644 --- a/stdlib/private/StdlibUnittest/SymbolLookup.swift +++ b/stdlib/private/StdlibUnittest/SymbolLookup.swift @@ -12,8 +12,10 @@ #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) import Darwin -#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 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 d9c35af07f273..e7e95eee6b73e 100644 --- a/stdlib/private/SwiftPrivateLibcExtras/Subprocess.swift +++ b/stdlib/private/SwiftPrivateLibcExtras/Subprocess.swift @@ -13,8 +13,10 @@ import SwiftPrivate #if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) import Darwin -#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 import WinSDK diff --git a/stdlib/private/SwiftPrivateLibcExtras/SwiftPrivateLibcExtras.swift b/stdlib/private/SwiftPrivateLibcExtras/SwiftPrivateLibcExtras.swift index a72fa0982517e..cfc457de0e84e 100644 --- a/stdlib/private/SwiftPrivateLibcExtras/SwiftPrivateLibcExtras.swift +++ b/stdlib/private/SwiftPrivateLibcExtras/SwiftPrivateLibcExtras.swift @@ -13,8 +13,10 @@ import SwiftPrivate #if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) import Darwin -#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 #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 086dfd7bb430c..7340425218a4c 100644 --- a/stdlib/private/SwiftPrivateThreadExtras/SwiftPrivateThreadExtras.swift +++ b/stdlib/private/SwiftPrivateThreadExtras/SwiftPrivateThreadExtras.swift @@ -17,8 +17,10 @@ #if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) import Darwin -#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 import WinSDK diff --git a/stdlib/private/SwiftPrivateThreadExtras/ThreadBarriers.swift b/stdlib/private/SwiftPrivateThreadExtras/ThreadBarriers.swift index 94bcff325dfc0..d1354854b09c5 100644 --- a/stdlib/private/SwiftPrivateThreadExtras/ThreadBarriers.swift +++ b/stdlib/private/SwiftPrivateThreadExtras/ThreadBarriers.swift @@ -12,8 +12,10 @@ #if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) import Darwin -#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 import WinSDK diff --git a/stdlib/public/Differentiation/CMakeLists.txt b/stdlib/public/Differentiation/CMakeLists.txt index cceb6fc6f2560..73c2be3273c3a 100644 --- a/stdlib/public/Differentiation/CMakeLists.txt +++ b/stdlib/public/Differentiation/CMakeLists.txt @@ -31,7 +31,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 df807256e15cf..f6843e898921f 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 ea3fb40684748..49231cb4ab247 100644 --- a/test/ClangImporter/clang_builtins.swift +++ b/test/ClangImporter/clang_builtins.swift @@ -2,8 +2,10 @@ #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) import Darwin -#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/test/IRGen/builtin_math.swift b/test/IRGen/builtin_math.swift index 5c85dac5e5c20..6bde19c25f12b 100644 --- a/test/IRGen/builtin_math.swift +++ b/test/IRGen/builtin_math.swift @@ -2,8 +2,10 @@ #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) import Darwin -#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/test/stdlib/FloatConstants.swift b/test/stdlib/FloatConstants.swift index eb03d30e29622..d26b5a06a04f9 100644 --- a/test/stdlib/FloatConstants.swift +++ b/test/stdlib/FloatConstants.swift @@ -2,8 +2,10 @@ #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) import Darwin -#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/test/stdlib/MathConstants.swift b/test/stdlib/MathConstants.swift index 08284143b1a6d..c20382fff4878 100644 --- a/test/stdlib/MathConstants.swift +++ b/test/stdlib/MathConstants.swift @@ -2,8 +2,10 @@ #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) import Darwin -#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/test/stdlib/PrintFloat.swift.gyb b/test/stdlib/PrintFloat.swift.gyb index 09d8e9dc49bb2..3bda6d247edb6 100644 --- a/test/stdlib/PrintFloat.swift.gyb +++ b/test/stdlib/PrintFloat.swift.gyb @@ -12,8 +12,10 @@ import StdlibUnittest #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) import Darwin -#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/test/stdlib/Runtime.swift.gyb b/test/stdlib/Runtime.swift.gyb index 8166dfeb255b1..7fa63472b466d 100644 --- a/test/stdlib/Runtime.swift.gyb +++ b/test/stdlib/Runtime.swift.gyb @@ -12,8 +12,10 @@ import SwiftShims #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) import Darwin -#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 import WinSDK diff --git a/test/stdlib/VarArgs.swift b/test/stdlib/VarArgs.swift index ea9317fef5fe2..cb199197748f8 100644 --- a/test/stdlib/VarArgs.swift +++ b/test/stdlib/VarArgs.swift @@ -6,9 +6,12 @@ import Swift #if _runtime(_ObjC) import Darwin import CoreGraphics -#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 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 fede221f148e8..6b0ec2130042f 100644 --- a/test/stdlib/tgmath.swift.gyb +++ b/test/stdlib/tgmath.swift.gyb @@ -19,8 +19,10 @@ #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/test/stdlib/tgmath_optimized.swift b/test/stdlib/tgmath_optimized.swift index fdf3b75299db1..354243e6819f9 100644 --- a/test/stdlib/tgmath_optimized.swift +++ b/test/stdlib/tgmath_optimized.swift @@ -6,8 +6,10 @@ #if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) import Darwin -#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/utils/build-presets.ini b/utils/build-presets.ini index 70a3d5125b0ee..a112756c82f38 100644 --- a/utils/build-presets.ini +++ b/utils/build-presets.ini @@ -2442,8 +2442,9 @@ skip-build-benchmarks llvm-targets-to-build=X86;AArch64;WebAssembly install-destdir=%(INSTALL_DESTDIR)s swift-install-components=autolink-driver;compiler;clang-builtin-headers;stdlib;sdk-overlay;parser-lib;editor-integration;tools;testsuite-tools;toolchain-tools;license;sourcekit-inproc;swift-remote-mirror;swift-remote-mirror-headers;clang-resource-dir-symlink -llvm-install-components=clang +llvm-install-components=clang;compiler-rt;lld;llvm-ar;llvm-ranlib install-swift +install-llvm install-prefix=/%(TOOLCHAIN_NAME)s/usr [preset: webassembly-host] @@ -2457,7 +2458,6 @@ extra-cmake-options= llbuild swiftpm -install-llvm install-swift install-llbuild install-swiftpm diff --git a/utils/build-script-impl b/utils/build-script-impl index 3ebea70eaa2dc..c26f48c924a47 100755 --- a/utils/build-script-impl +++ b/utils/build-script-impl @@ -1610,6 +1610,11 @@ for host in "${ALL_HOSTS[@]}"; do llvm_enable_projects=("clang") + # wasm: lld is necessary to sync compiler llvm version and lld llvm version + if [[ ! "${SKIP_BUILD_LLD}" ]]; then + llvm_enable_projects+=("lld") + fi + if [[ ! "${SKIP_BUILD_COMPILER_RT}" && ! $(is_cross_tools_host ${host}) ]]; then llvm_enable_projects+=("compiler-rt") fi diff --git a/utils/webassembly/build-foundation.sh b/utils/webassembly/build-foundation.sh index 0f712825160d7..8bb07c1a200a0 100755 --- a/utils/webassembly/build-foundation.sh +++ b/utils/webassembly/build-foundation.sh @@ -3,11 +3,7 @@ set -ex DESTINATION_TOOLCHAIN=$1 SOURCE_PATH="$(cd "$(dirname $0)/../../.." && pwd)" -# Remove host CoreFoundation (which can be different from the target) headers -# to avoid shadowing the wasm32 target CoreFoundation -rm -rf $DESTINATION_TOOLCHAIN/usr/lib/swift/CoreFoundation - -FOUNDATION_BUILD="$SOURCE_PATH/build/Ninja-ReleaseAssert/foundation-wasi-wasm32" +FOUNDATION_BUILD="$SOURCE_PATH/target-build/Ninja-ReleaseAssert/foundation-wasi-wasm32" mkdir -p $FOUNDATION_BUILD cd $FOUNDATION_BUILD @@ -19,6 +15,7 @@ cmake -G Ninja \ -DWASI_SDK_PATH="$SOURCE_PATH/wasi-sdk" \ -DICU_ROOT="$SOURCE_PATH/icu_out" \ -DBUILD_SHARED_LIBS=OFF \ + -DCMAKE_Swift_COMPILER_FORCED=ON \ "${SOURCE_PATH}/swift-corelibs-foundation" ninja -v diff --git a/utils/webassembly/build-toolchain.sh b/utils/webassembly/build-toolchain.sh index 0129a373ac71c..0418f855a0644 100755 --- a/utils/webassembly/build-toolchain.sh +++ b/utils/webassembly/build-toolchain.sh @@ -11,11 +11,13 @@ case $(uname -s) in OS_SUFFIX=osx HOST_PRESET=webassembly-host TARGET_PRESET=webassembly-macos-target + HOST_SUFFIX=macosx-x86_64 ;; Linux) OS_SUFFIX=linux HOST_PRESET=webassembly-linux-host TARGET_PRESET=webassembly-linux-target + HOST_SUFFIX=linux-x86_64 ;; *) echo "Unrecognised platform $(uname -s)" @@ -37,58 +39,88 @@ BUNDLE_IDENTIFIER="swiftwasm.5.3-${YEAR}${MONTH}${DAY}" DISPLAY_NAME_SHORT="Swift for WebAssembly 5.3 Snapshot" DISPLAY_NAME="${DISPLAY_NAME_SHORT} ${YEAR}-${MONTH}-${DAY}" +DIST_TOOLCHAIN_DESTDIR=$SOURCE_PATH/dist-toolchain-sdk HOST_TOOLCHAIN_DESTDIR=$SOURCE_PATH/host-toolchain-sdk -HOST_TOOLCHAIN_SDK=$HOST_TOOLCHAIN_DESTDIR/$TOOLCHAIN_NAME +TARGET_TOOLCHAIN_DESTDIR=$SOURCE_PATH/target-toolchain-sdk -# Avoid clang headers symlink issues -mkdir -p $HOST_TOOLCHAIN_SDK/usr/lib/clang/10.0.0 - -# Build the host toolchain and SDK first. -$SOURCE_PATH/swift/utils/build-script \ - --preset=$HOST_PRESET \ - INSTALL_DESTDIR="$HOST_TOOLCHAIN_DESTDIR" \ - TOOLCHAIN_NAME="$TOOLCHAIN_NAME" \ - C_CXX_LAUNCHER="$(which sccache)" - -# Clean up the host toolchain build directory so that the next -# `build-script` invocation doesn't pick up wrong CMake config files. -# For some reason passing `--reconfigure` to `build-script` won't do this. -rm -rf $SOURCE_PATH/build/Ninja-ReleaseAssert/swift-* - -# build the cross-compilled toolchain -$SOURCE_PATH/swift/utils/build-script \ - --preset=$TARGET_PRESET \ - INSTALL_DESTDIR="$SOURCE_PATH/install" \ - SOURCE_PATH="$SOURCE_PATH" \ - BUNDLE_IDENTIFIER="${BUNDLE_IDENTIFIER}" \ - DISPLAY_NAME="${DISPLAY_NAME}" \ - DISPLAY_NAME_SHORT="${DISPLAY_NAME_SHORT}" \ - TOOLCHAIN_NAME="${TOOLCHAIN_NAME}" \ - TOOLCHAIN_VERSION="${TOOLCHAIN_VERSION}" \ - C_CXX_LAUNCHER="$(which sccache)" - -# Merge wasi-sdk and the toolchain -cp -a $WASI_SDK_PATH/lib/clang $HOST_TOOLCHAIN_SDK/usr/lib -cp -a $WASI_SDK_PATH/bin/{*ld,llvm-ar} $HOST_TOOLCHAIN_SDK/usr/bin -cp -r $WASI_SDK_PATH/share/wasi-sysroot $HOST_TOOLCHAIN_SDK/usr/share - -# Replace absolute sysroot path with relative path -sed -i -e "s@\".*/include@\"../../../../share/wasi-sysroot/include@g" $SOURCE_PATH/install/$TOOLCHAIN_NAME/usr/lib/swift/wasi/wasm32/glibc.modulemap - -# Copy the target environment stdlib into the toolchain - -# Avoid copying usr/lib/swift/clang because our toolchain's one is a directory -# but nightly's one is symbolic link. A simple copy fails to merge them. -rsync -v -a $SOURCE_PATH/install/$TOOLCHAIN_NAME/usr/lib/ $HOST_TOOLCHAIN_SDK/usr/lib/ --exclude 'swift/clang' - -# FIXME: avoid building foundation for now -$UTILS_PATH/build-foundation.sh $HOST_TOOLCHAIN_SDK -$UTILS_PATH/build-xctest.sh $HOST_TOOLCHAIN_SDK - -# Cleanup build directory on CI -if [[ -z "${CI}" ]]; then - rm -rf $SOURCE_PATH/build/Ninja-ReleaseAssert/ -fi - -cd $HOST_TOOLCHAIN_DESTDIR +DIST_TOOLCHAIN_SDK=$DIST_TOOLCHAIN_DESTDIR/$TOOLCHAIN_NAME +HOST_TOOLCHAIN_SDK=$HOST_TOOLCHAIN_DESTDIR/$TOOLCHAIN_NAME +TARGET_TOOLCHAIN_SDK=$TARGET_TOOLCHAIN_DESTDIR/$TOOLCHAIN_NAME + + +HOST_BUILD_ROOT=$SOURCE_PATH/host-build +TARGET_BUILD_ROOT=$SOURCE_PATH/target-build +HOST_BUILD_DIR=$HOST_BUILD_ROOT/Ninja-ReleaseAssert +TARGET_BUILD_DIR=$TARGET_BUILD_ROOT/Ninja-ReleaseAssert + +build_host_toolchain() { + # Avoid clang headers symlink issues + mkdir -p $HOST_TOOLCHAIN_SDK/usr/lib/clang/10.0.0 + # Build the host toolchain and SDK first. + env SWIFT_BUILD_ROOT="$HOST_BUILD_ROOT" \ + $SOURCE_PATH/swift/utils/build-script \ + --preset=$HOST_PRESET \ + --build-dir="$HOST_BUILD_DIR" \ + INSTALL_DESTDIR="$HOST_TOOLCHAIN_DESTDIR" \ + TOOLCHAIN_NAME="$TOOLCHAIN_NAME" \ + C_CXX_LAUNCHER="$(which sccache)" +} + +build_target_toolchain() { + mkdir -p $HOST_BUILD_DIR/ + # Copy the host build dir to reuse it. + if [[ ! -e "$HOST_BUILD_DIR/llvm-$HOST_SUFFIX" ]]; then + cp -r "$HOST_BUILD_DIR/llvm-$HOST_SUFFIX" "$TARGET_BUILD_DIR/llvm-$HOST_SUFFIX" + # Clean up compiler-rt dir to cross compile it for host and wasm32 + (cd "$TARGET_BUILD_DIR/llvm-$HOST_SUFFIX" && ninja compiler-rt-clear) + fi + + # Avoid clang headers symlink issues + mkdir -p $TARGET_TOOLCHAIN_SDK/usr/lib/clang/10.0.0 + + # build the cross-compilled toolchain + env SWIFT_BUILD_ROOT="$TARGET_BUILD_ROOT" \ + $SOURCE_PATH/swift/utils/build-script \ + --preset=$TARGET_PRESET --reconfigure \ + --build-dir="$TARGET_BUILD_DIR" \ + INSTALL_DESTDIR="$TARGET_TOOLCHAIN_DESTDIR" \ + SOURCE_PATH="$SOURCE_PATH" \ + BUNDLE_IDENTIFIER="${BUNDLE_IDENTIFIER}" \ + DISPLAY_NAME="${DISPLAY_NAME}" \ + DISPLAY_NAME_SHORT="${DISPLAY_NAME_SHORT}" \ + TOOLCHAIN_NAME="${TOOLCHAIN_NAME}" \ + TOOLCHAIN_VERSION="${TOOLCHAIN_VERSION}" \ + C_CXX_LAUNCHER="$(which sccache)" + + $UTILS_PATH/build-foundation.sh $TARGET_TOOLCHAIN_SDK + $UTILS_PATH/build-xctest.sh $TARGET_TOOLCHAIN_SDK + +} + +merge_toolchains() { + rm -rf "$DIST_TOOLCHAIN_DESTDIR" + # Copy the base host toolchain + cp -r "$HOST_TOOLCHAIN_DESTDIR" "$DIST_TOOLCHAIN_DESTDIR" + + # Merge wasi-sdk and the toolchain + cp -a $WASI_SDK_PATH/lib/clang $DIST_TOOLCHAIN_SDK/usr/lib + cp -a $WASI_SDK_PATH/bin/{*ld,llvm-ar} $DIST_TOOLCHAIN_SDK/usr/bin + cp -r $WASI_SDK_PATH/share/wasi-sysroot $DIST_TOOLCHAIN_SDK/usr/share + + # Copy the target environment stdlib into the toolchain + # Avoid copying usr/lib/swift/clang because our toolchain's one is a directory + # but nightly's one is symbolic link. A simple copy fails to merge them. + rsync -v -a $TARGET_TOOLCHAIN_SDK/usr/lib/ $DIST_TOOLCHAIN_SDK/usr/lib/ --exclude 'swift/clang' + 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/wasi.modulemap +} + +build_host_toolchain +build_target_toolchain + +merge_toolchains + +cd $DIST_TOOLCHAIN_DESTDIR tar cfz $PACKAGE_ARTIFACT $TOOLCHAIN_NAME diff --git a/utils/webassembly/build-xctest.sh b/utils/webassembly/build-xctest.sh index e08e0cef33db1..fe93f244ce0b3 100755 --- a/utils/webassembly/build-xctest.sh +++ b/utils/webassembly/build-xctest.sh @@ -3,7 +3,7 @@ set -ex DESTINATION_TOOLCHAIN=$1 SOURCE_PATH="$(cd "$(dirname $0)/../../.." && pwd)" -BUILD_DIR="$SOURCE_PATH/build/Ninja-ReleaseAssert/xctest-wasi-wasm32" +BUILD_DIR="$SOURCE_PATH/target-build/Ninja-ReleaseAssert/xctest-wasi-wasm32" mkdir -p $BUILD_DIR cd $BUILD_DIR @@ -14,6 +14,7 @@ cmake -G Ninja \ -DCMAKE_TOOLCHAIN_FILE="$SOURCE_PATH/swift/utils/webassembly/toolchain-wasi.cmake" \ -DWASI_SDK_PATH="$SOURCE_PATH/wasi-sdk" \ -DBUILD_SHARED_LIBS=OFF \ + -DCMAKE_Swift_COMPILER_FORCED=ON \ -DSWIFT_FOUNDATION_PATH=$DESTINATION_TOOLCHAIN/usr/lib/swift/wasi/wasm32 \ "${SOURCE_PATH}/swift-corelibs-xctest" diff --git a/utils/webassembly/ci.sh b/utils/webassembly/ci.sh index 75c9adb37ff9e..a9ca0d9a11d6f 100755 --- a/utils/webassembly/ci.sh +++ b/utils/webassembly/ci.sh @@ -13,7 +13,7 @@ fi BUILD_SCRIPT=$UTILS_PATH/build-toolchain.sh RUN_TEST_BIN=$SWIFT_PATH/utils/run-test -BUILD_DIR=$SOURCE_PATH/build/Ninja-ReleaseAssert +TARGET_BUILD_DIR=$SOURCE_PATH/target-build/Ninja-ReleaseAssert $DEPENDENCIES_SCRIPT @@ -29,14 +29,16 @@ $BUILD_SCRIPT $FLAGS if [[ "$(uname)" == "Darwin" ]]; then # workaround: host target test directory is necessary to use run-test - mkdir -p $BUILD_DIR/swift-macosx-x86_64/test-macosx-x86_64 + mkdir -p $TARGET_BUILD_DIR/swift-macosx-x86_64/test-macosx-x86_64 fi -$RUN_TEST_BIN --build-dir $BUILD_DIR --target wasi-wasm32 test/stdlib/ - if [[ "$(uname)" == "Linux" ]]; then + $RUN_TEST_BIN --build-dir $TARGET_BUILD_DIR --target wasi-wasm32 test/stdlib/ || true echo "Skip running test suites for Linux" else + + $RUN_TEST_BIN --build-dir $TARGET_BUILD_DIR --target wasi-wasm32 test/stdlib/ + # Run test but ignore failure temporarily $BUILD_SCRIPT $FLAGS -t || true fi