Bring up tests + validation tests for the 'freestanding' build and the standalone_minimal preset (#34386)

This commit is contained in:
Kuba (Brecka) Mracek
2020-10-26 16:32:36 -07:00
committed by GitHub
parent 38d759c43a
commit d7dfa3e942
29 changed files with 125 additions and 26 deletions

View File

@@ -38,6 +38,12 @@ else()
set(SWIFT_STDLIB_STABLE_ABI_default FALSE)
endif()
if(SWIFT_BUILD_SDK_OVERLAY OR SWIFT_INCLUDE_TESTS)
set(SWIFT_BUILD_TEST_SUPPORT_MODULES_default TRUE)
else()
set(SWIFT_BUILD_TEST_SUPPORT_MODULES_default FALSE)
endif()
#
# User-configurable options for the standard library.
#
@@ -46,28 +52,32 @@ endif()
# so that interfaces are emitted when overlays are separately built.
option(SWIFT_STDLIB_STABLE_ABI
"Should stdlib be built with stable ABI (library evolution, resilience)."
"${SWIFT_STDLIB_STABLE_ABI_default}")
"Should stdlib be built with stable ABI (library evolution, resilience)."
"${SWIFT_STDLIB_STABLE_ABI_default}")
option(SWIFT_ENABLE_MODULE_INTERFACES
"Generate .swiftinterface files alongside .swiftmodule files"
"${SWIFT_STDLIB_STABLE_ABI}")
"Generate .swiftinterface files alongside .swiftmodule files"
"${SWIFT_STDLIB_STABLE_ABI}")
option(SWIFT_ENABLE_COMPATIBILITY_OVERRIDES
"Support back-deploying compatibility fixes for newer apps running on older runtimes."
TRUE)
"Support back-deploying compatibility fixes for newer apps running on older runtimes."
TRUE)
option(SWIFT_RUNTIME_MACHO_NO_DYLD
"Build stdlib assuming the runtime environment uses Mach-O but does not support dynamic modules."
FALSE)
"Build stdlib assuming the runtime environment uses Mach-O but does not support dynamic modules."
FALSE)
option(SWIFT_STDLIB_SINGLE_THREADED_RUNTIME
"Build the standard libraries assuming that they will be used in an environment with only a single thread."
FALSE)
"Build the standard libraries assuming that they will be used in an environment with only a single thread."
FALSE)
option(SWIFT_STDLIB_OS_VERSIONING
"Build stdlib with availability based on OS versions (Darwin only)."
TRUE)
"Build stdlib with availability based on OS versions (Darwin only)."
TRUE)
option(SWIFT_BUILD_TEST_SUPPORT_MODULES
"Whether to build StdlibUnittest and other test support modules. Defaults to On when SWIFT_BUILD_SDK_OVERLAY is On, or when SWIFT_INCLUDE_TESTS is On."
"${SWIFT_BUILD_TEST_SUPPORT_MODULES_default}")
#
# End of user-configurable options.

View File

@@ -1438,6 +1438,9 @@ endfunction()
# SWIFT_MODULE_DEPENDS_WATCHOS
# Swift modules this library depends on when built for watchOS.
#
# SWIFT_MODULE_DEPENDS_FREESTANDING
# Swift modules this library depends on when built for Freestanding.
#
# SWIFT_MODULE_DEPENDS_FREEBSD
# Swift modules this library depends on when built for FreeBSD.
#
@@ -1562,6 +1565,7 @@ function(add_swift_target_library name)
SWIFT_MODULE_DEPENDS
SWIFT_MODULE_DEPENDS_CYGWIN
SWIFT_MODULE_DEPENDS_FREEBSD
SWIFT_MODULE_DEPENDS_FREESTANDING
SWIFT_MODULE_DEPENDS_OPENBSD
SWIFT_MODULE_DEPENDS_HAIKU
SWIFT_MODULE_DEPENDS_IOS
@@ -1719,6 +1723,9 @@ function(add_swift_target_library name)
elseif(${sdk} STREQUAL WATCHOS OR ${sdk} STREQUAL WATCHOS_SIMULATOR)
list(APPEND swiftlib_module_depends_flattened
${SWIFTLIB_SWIFT_MODULE_DEPENDS_WATCHOS})
elseif(${sdk} STREQUAL FREESTANDING)
list(APPEND swiftlib_module_depends_flattened
${SWIFTLIB_SWIFT_MODULE_DEPENDS_FREESTANDING})
elseif(${sdk} STREQUAL FREEBSD)
list(APPEND swiftlib_module_depends_flattened
${SWIFTLIB_SWIFT_MODULE_DEPENDS_FREEBSD})

View File

@@ -8,6 +8,9 @@ if(SWIFT_BUILD_SDK_OVERLAY)
if(SWIFT_ENABLE_EXPERIMENTAL_DIFFERENTIABLE_PROGRAMMING)
add_subdirectory(DifferentiationUnittest)
endif()
endif()
if(SWIFT_BUILD_SDK_OVERLAY OR SWIFT_BUILD_TEST_SUPPORT_MODULES)
add_subdirectory(RuntimeUnittest)
add_subdirectory(StdlibUnicodeUnittest)
add_subdirectory(StdlibCollectionUnittest)
@@ -18,7 +21,9 @@ if(SWIFT_BUILD_SDK_OVERLAY)
# SwiftPrivateThreadExtras to ensure that the dependency targets are setup in
# the correct order for Windows.
add_subdirectory(StdlibUnittest)
endif()
if(SWIFT_BUILD_SDK_OVERLAY)
add_subdirectory(OSLog)
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")

View File

@@ -36,6 +36,7 @@ add_swift_target_library(swiftStdlibUnittest ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES}
SWIFT_MODULE_DEPENDS_OSX Darwin Foundation
SWIFT_MODULE_DEPENDS_TVOS Darwin Foundation
SWIFT_MODULE_DEPENDS_WATCHOS Darwin Foundation
SWIFT_MODULE_DEPENDS_FREESTANDING Darwin
SWIFT_MODULE_DEPENDS_LINUX Glibc
SWIFT_MODULE_DEPENDS_FREEBSD Glibc
SWIFT_MODULE_DEPENDS_OPENBSD Glibc

View File

@@ -16,7 +16,9 @@ import SwiftPrivateThreadExtras
import SwiftPrivateLibcExtras
#if canImport(Darwin)
#if _runtime(_ObjC)
import Foundation
#endif
import Darwin
#elseif canImport(Glibc)
import Glibc
@@ -1729,9 +1731,19 @@ public final class TestSuite {
}
#if canImport(Darwin)
#if _runtime(_ObjC)
func _getSystemVersionPlistProperty(_ propertyName: String) -> String? {
return NSDictionary(contentsOfFile: "/System/Library/CoreServices/SystemVersion.plist")?[propertyName] as? String
}
#else
func _getSystemVersionPlistProperty(_ propertyName: String) -> String? {
var count = 0
sysctlbyname("kern.osproductversion", nil, &count, nil, 0)
var s = [CChar](repeating: 0, count: count)
sysctlbyname("kern.osproductversion", &s, &count, nil, 0)
return String(cString: &s)
}
#endif
#endif
public enum OSVersion : CustomStringConvertible {

View File

@@ -13,6 +13,7 @@ add_swift_target_library(swiftSwiftPrivateLibcExtras ${SWIFT_STDLIB_LIBRARY_BUIL
SWIFT_MODULE_DEPENDS_IOS Darwin
SWIFT_MODULE_DEPENDS_TVOS Darwin
SWIFT_MODULE_DEPENDS_WATCHOS Darwin
SWIFT_MODULE_DEPENDS_FREESTANDING Darwin
SWIFT_MODULE_DEPENDS_LINUX Glibc
SWIFT_MODULE_DEPENDS_FREEBSD Glibc
SWIFT_MODULE_DEPENDS_OPENBSD Glibc

View File

@@ -10,6 +10,7 @@ add_swift_target_library(swiftSwiftPrivateThreadExtras ${SWIFT_STDLIB_LIBRARY_BU
SWIFT_MODULE_DEPENDS_OSX Darwin
SWIFT_MODULE_DEPENDS_TVOS Darwin
SWIFT_MODULE_DEPENDS_WATCHOS Darwin
SWIFT_MODULE_DEPENDS_FREESTANDING Darwin
SWIFT_MODULE_DEPENDS_LINUX Glibc
SWIFT_MODULE_DEPENDS_FREEBSD Glibc
SWIFT_MODULE_DEPENDS_OPENBSD Glibc
@@ -17,7 +18,6 @@ add_swift_target_library(swiftSwiftPrivateThreadExtras ${SWIFT_STDLIB_LIBRARY_BU
SWIFT_MODULE_DEPENDS_HAIKU Glibc
SWIFT_MODULE_DEPENDS_WINDOWS CRT WinSDK
SWIFT_COMPILE_FLAGS ${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
TARGET_SDKS ALL_APPLE_PLATFORMS CYGWIN FREEBSD OPENBSD HAIKU LINUX WINDOWS ANDROID
INSTALL_IN_COMPONENT stdlib-experimental
DARWIN_INSTALL_NAME_DIR "${SWIFT_DARWIN_STDLIB_PRIVATE_INSTALL_NAME_DIR}")

View File

@@ -104,7 +104,7 @@ if(SWIFT_BUILD_STDLIB OR SWIFT_BUILD_REMOTE_MIRROR)
add_subdirectory(SwiftRemoteMirror)
endif()
if(SWIFT_BUILD_SDK_OVERLAY)
if(SWIFT_BUILD_SDK_OVERLAY OR SWIFT_BUILD_TEST_SUPPORT_MODULES)
add_subdirectory(Platform)
endif()

View File

@@ -27,7 +27,7 @@ add_swift_target_library(swiftDarwin ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_
${SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS}
-Xfrontend -disable-objc-attr-requires-foundation-module
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
TARGET_SDKS ALL_APPLE_PLATFORMS
TARGET_SDKS ALL_APPLE_PLATFORMS FREESTANDING
INSTALL_IN_COMPONENT sdk-overlay
DEPENDS ${darwin_depends})

View File

@@ -10,7 +10,7 @@
//
//===----------------------------------------------------------------------===//
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
#if (os(macOS) || os(iOS) || os(tvOS) || os(watchOS)) && _runtime(_ObjC)
/// Enumeration describing Mach error codes.
@objc
public enum MachErrorCode : Int32 {
@@ -202,4 +202,4 @@ public enum MachErrorCode : Int32 {
/// The requested property cannot be changed at this time.
case policyStatic = 51
}
#endif // os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
#endif // (os(macOS) || os(iOS) || os(tvOS) || os(watchOS)) && _runtime(_ObjC)

View File

@@ -10,7 +10,7 @@
//
//===----------------------------------------------------------------------===//
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
#if (os(macOS) || os(iOS) || os(tvOS) || os(watchOS)) && _runtime(_ObjC)
/// Enumeration describing POSIX error codes.
@objc

View File

@@ -6059,3 +6059,8 @@ inline void _Atomic_storage<::PoolRange, 16>::_Unlock() const noexcept {
}
}
#endif
// Autolink with libc++, for cases where libswiftCore is linked statically.
#if defined(__MACH__)
asm(".linker_option \"-lc++\"\n");
#endif // defined(__MACH__)

View File

@@ -1,3 +1,5 @@
# Keep in sync with test/CMakeLists.txt: swift-reflection-test is
# only used when testing dynamic stdlib.
if(SWIFT_BUILD_DYNAMIC_STDLIB AND SWIFT_INCLUDE_TESTS)
add_subdirectory(swift-reflection-test)
endif()

View File

@@ -252,7 +252,9 @@ foreach(SDK ${SWIFT_SDKS})
set(test_dependencies)
get_test_dependencies("${SDK}" test_dependencies)
if(SWIFT_BUILD_STDLIB AND SWIFT_INCLUDE_TESTS)
# Keep in sync with stdlib/tools/CMakeLists.txt: swift-reflection-test is
# only used when testing dynamic stdlib.
if(SWIFT_BUILD_DYNAMIC_STDLIB AND SWIFT_INCLUDE_TESTS)
# NOTE create a stub BlocksRuntime library that can be used for the
# reflection tests
file(WRITE ${test_bin_dir}/Inputs/BlocksRuntime.c

View File

@@ -850,6 +850,36 @@ if run_vendor == 'apple':
config.available_features.add('foundation')
config.available_features.add('objc_interop')
# The "freestanding" tests will link against the static libswiftCore.a and
# cannot use any of Obj-C / Dispatch / Foundation.
if "-freestanding" in config.variant_suffix:
config.target_runtime = "native"
config.available_features.remove('libdispatch')
config.available_features.remove('foundation')
config.available_features.remove('objc_interop')
config.available_features.add('freestanding')
# Build all "freestanding" tests with -disable-objc-interop
swift_execution_tests_extra_flags += ' -Xfrontend -disable-objc-interop'
# Link all "freestanding" tests with -dead_strip, which can effectively
# even remove parts of the stdlib and runtime, if it's not needed. Since
# it's a very desired behavior, let's enable it for all executable tests.
swift_execution_tests_extra_flags += ' -Xlinker -dead_strip'
# Build a resource dir for freestanding tests.
new_resource_dir = os.path.join(config.test_exec_root, "resource_dir")
if not os.path.exists(new_resource_dir): os.mkdir(new_resource_dir)
def symlink_if_not_exists(src, dst):
src = os.path.join(test_resource_dir, src)
dst = os.path.join(new_resource_dir, dst)
if not os.path.exists(dst): os.symlink(src, dst)
symlink_if_not_exists("clang", "clang")
symlink_if_not_exists("shims", "shims")
symlink_if_not_exists("freestanding", "macosx")
resource_dir_opt = "-resource-dir %s" % new_resource_dir
lit_config.note('Using freestanding resource dir: ' + new_resource_dir)
xcrun_prefix = (
"xcrun --toolchain %s --sdk %r" %
(config.darwin_xcrun_toolchain, config.variant_sdk))

View File

@@ -1,4 +1,4 @@
// RUN: %swift -swift-version 4 -typecheck -verify %s
// RUN: %target-typecheck-verify-swift -swift-version 4
func flatMapOnSequence<
S : Sequence

View File

@@ -1,5 +1,6 @@
// RUN: %target-run-stdlib-swift | %FileCheck %s
// REQUIRES: executable_test
// REQUIRES: foundation
//
// Parts of this test depend on memory allocator specifics. The test
// should be rewritten soon so it doesn't expose legacy components

View File

@@ -7,6 +7,7 @@
// RUN: %target-codesign %t/OSLogExecutionTest
// RUN: %target-run %t/OSLogExecutionTest
// REQUIRES: executable_test
// REQUIRES: foundation
//
// REQUIRES: VENDOR=apple

View File

@@ -591,6 +591,7 @@ Runtime.test("Struct layout with reference storage types") {
print(malkovich)
}
#if !(canImport(Darwin) && !_runtime(_ObjC))
Runtime.test("SwiftError layout constants for LLDB") {
let offsetof_SwiftError_typeMetadata = pointerToSwiftCoreSymbol(name: "_swift_lldb_offsetof_SwiftError_typeMetadata")!
let sizeof_SwiftError = pointerToSwiftCoreSymbol(name: "_swift_lldb_sizeof_SwiftError")!
@@ -610,6 +611,7 @@ Runtime.test("SwiftError layout constants for LLDB") {
_UnimplementedError()
#endif
}
#endif
var Reflection = TestSuite("Reflection")
@@ -762,7 +764,7 @@ AvailabilityVersionsTestSuite.test("_stdlib_isOSVersionAtLeast") {
// _stdlib_isOSVersionAtLeast is broken for
// watchOS. rdar://problem/20234735
#if canImport(Darwin)
#if canImport(Darwin) && _runtime(_ObjC)
// This test assumes that no version component on an OS we test upon
// will ever be greater than 1066 and that every major version will always
// be greater than 1.

View File

@@ -1,4 +1,4 @@
// RUN: %target-typecheck-verify-swift -enable-invalid-ephemeralness-as-error
// RUN: %target-typecheck-verify-swift -enable-invalid-ephemeralness-as-error -disable-objc-interop
// Test availability attributes on UnsafePointer initializers.
// Assume the original source contains no UnsafeRawPointer types.

View File

@@ -1,4 +1,4 @@
// RUN: %target-typecheck-verify-swift
// RUN: %target-typecheck-verify-swift -disable-objc-interop
// Test that we get a custom diagnostic for an ephemeral conversion to non-ephemeral param for an Unsafe[Mutable][Raw][Buffer]Pointer init.
func unsafePointerInitEphemeralConversions() {

View File

@@ -3,9 +3,17 @@
import Swift
#if _runtime(_ObjC)
#if canImport(Darwin)
import Darwin
import CoreGraphics
#if _runtime(_ObjC)
import CoreGraphics
#else
#if arch(x86_64) || arch(arm64)
typealias CGFloat = Double
#else
typealias CGFloat = Float
#endif
#endif
#elseif canImport(Glibc)
import Glibc
typealias CGFloat = Double

View File

@@ -1,2 +1,3 @@
// RUN: %llvm-nm --defined-only -C %platform-dylib-dir/%target-library-name(swiftCore) | %FileCheck --allow-empty %s
// CHECK-NOT: [^:]llvm::
// UNSUPPORTED: freestanding

View File

@@ -19,3 +19,4 @@
// symbols are handled properly.
// REQUIRES: VENDOR=apple
// UNSUPPORTED: freestanding

View File

@@ -176,7 +176,7 @@ internal extension TGMath {
% if T == 'Float80':
#if (arch(i386) || arch(x86_64)) && !os(Windows)
% elif T == 'CGFloat':
#if canImport(CoreGraphics)
#if _runtime(_ObjC) && canImport(CoreGraphics)
import CoreGraphics
% end

View File

@@ -2344,6 +2344,13 @@ swift-freestanding-triple-name=macosx11.0
swift-freestanding-module-name=macos
swift-freestanding-archs=x86_64
[preset: stdlib_S_standalone_minimal_macho_x86_64,build,test]
mixin-preset=stdlib_S_standalone_minimal_macho_x86_64,build
test
validation-test
#===----------------------------------------------------------------------===#
# Preset for Source Compatibility Suite
#===----------------------------------------------------------------------===#

View File

@@ -1,6 +1,7 @@
// RUN: %target-run-simple-swift
// REQUIRES: executable_test
// REQUIRES: VENDOR=apple || OS=linux-androideabi || OS=linux-android || OS=linux-gnu
// UNSUPPORTED: freestanding
import Swift
import StdlibUnittest

View File

@@ -6,6 +6,7 @@
// RUN: %target-run %t/String
// REQUIRES: executable_test
// XFAIL: interpret
// UNSUPPORTED: freestanding
// With a non-optimized stdlib the test takes very long.
// REQUIRES: optimized_stdlib

View File

@@ -6,6 +6,7 @@
// RUN: %target-run %t/String
// REQUIRES: executable_test
// XFAIL: interpret
// UNSUPPORTED: freestanding
import StdlibUnittest
import StdlibCollectionUnittest