diff --git a/include/swift/Basic/Platform.h b/include/swift/Basic/Platform.h index 7667b2165f7..799b90e4860 100644 --- a/include/swift/Basic/Platform.h +++ b/include/swift/Basic/Platform.h @@ -74,6 +74,17 @@ namespace swift { /// /// This is a stop-gap until full Triple support (ala Clang) exists within swiftc. StringRef getMajorArchitectureName(const llvm::Triple &triple); + + /// Computes the normalized target triple used as the most preferred name for + /// module loading. + /// + /// For platforms with module stability, this canonicalizes architecture, + /// vendor, and OS names, strips OS versions, and makes inferred environments + /// explicit. For other platforms, it returns the unmodified triple. + /// + /// The input triple should already be "normalized" in the sense that + /// llvm::Triple::normalize() would not affect it. + llvm::Triple getTargetSpecificModuleTriple(const llvm::Triple &triple); } // end namespace swift #endif // SWIFT_BASIC_PLATFORM_H diff --git a/lib/Basic/Platform.cpp b/lib/Basic/Platform.cpp index 1bd72f056d7..27211bf0d71 100644 --- a/lib/Basic/Platform.cpp +++ b/lib/Basic/Platform.cpp @@ -12,6 +12,8 @@ #include "swift/Basic/Platform.h" #include "llvm/ADT/Triple.h" +#include "llvm/ADT/StringSwitch.h" +#include "llvm/ADT/StringExtras.h" using namespace swift; @@ -188,3 +190,78 @@ StringRef swift::getMajorArchitectureName(const llvm::Triple &Triple) { return Triple.getArchName(); } } + +static StringRef +getArchForAppleTargetSpecificModuleTriple(const llvm::Triple &triple) { + auto tripleArchName = triple.getArchName(); + + return llvm::StringSwitch(tripleArchName) + .Cases("arm64", "aarch64", "arm64") + .Case ("armv7s", "armv7s") + .Case ("armv7k", "armv7k") + .Case ("armv7", "armv7") + .Case ("x86_64h", "x86_64h") + .Cases("x86_64", "amd64", "x86_64") + .Cases("i386", "i486", "i586", "i686", "i786", "i886", "i986", + "i386") + .Cases("unknown", "", "unknown") + .Default(tripleArchName); +} + +static StringRef +getVendorForAppleTargetSpecificModuleTriple(const llvm::Triple &triple) { + return "apple"; +} + +static StringRef +getOSForAppleTargetSpecificModuleTriple(const llvm::Triple &triple) { + auto tripleOSName = triple.getOSName(); + + // Truncate the OS name before the first digit. + auto tripleOSNameNoVersion = tripleOSName.take_until(llvm::isDigit); + + return llvm::StringSwitch(tripleOSNameNoVersion) + .Cases("macos", "macosx", "darwin", "macos") + .Case ("ios", "ios") + .Case ("tvos", "tvos") + .Cases("unknown", "", "unknown") + .Default(tripleOSNameNoVersion); +} + +static Optional +getEnvironmentForAppleTargetSpecificModuleTriple(const llvm::Triple &triple) { + auto tripleEnvironment = triple.getEnvironmentName(); + + if (tripleEnvironment == "") { + if (swift::tripleIsAnySimulator(triple)) + return StringRef("simulator"); + else + return None; + } + + return llvm::StringSwitch>(tripleEnvironment) + .Case("simulator", StringRef("simulator")) + .Case("unknown", None) + .Default(tripleEnvironment); +} + +llvm::Triple swift::getTargetSpecificModuleTriple(const llvm::Triple &triple) { + if (triple.isOSDarwin()) { + StringRef newArch = getArchForAppleTargetSpecificModuleTriple(triple); + + StringRef newVendor = getVendorForAppleTargetSpecificModuleTriple(triple); + + StringRef newOS = getOSForAppleTargetSpecificModuleTriple(triple); + + Optional newEnvironment = + getEnvironmentForAppleTargetSpecificModuleTriple(triple); + + if (newEnvironment) + return llvm::Triple(newArch, newVendor, newOS, *newEnvironment); + else + return llvm::Triple(newArch, newVendor, newOS); + } else { + return triple; + } +} + diff --git a/lib/Serialization/SerializedModuleLoader.cpp b/lib/Serialization/SerializedModuleLoader.cpp index 89e633a5693..5b8aacb3524 100644 --- a/lib/Serialization/SerializedModuleLoader.cpp +++ b/lib/Serialization/SerializedModuleLoader.cpp @@ -16,6 +16,7 @@ #include "swift/AST/DiagnosticsSema.h" #include "swift/Basic/Defer.h" #include "swift/Basic/FileTypes.h" +#include "swift/Basic/Platform.h" #include "swift/Basic/STLExtras.h" #include "swift/Basic/SourceManager.h" #include "swift/Basic/Version.h" @@ -166,10 +167,16 @@ SerializedModuleLoaderBase::findModule(AccessPathElem moduleID, llvm::SmallString<64> moduleName(moduleID.first.str()); ModuleFilenamePair fileNames(moduleName); - StringRef archName = Ctx.LangOpts.Target.getArchName(); - SmallVector targetFileNamePairs; - targetFileNamePairs.push_back(archName); + + auto normalizedTarget = getTargetSpecificModuleTriple(Ctx.LangOpts.Target); + targetFileNamePairs.push_back(ModuleFilenamePair(normalizedTarget.str())); + + // Before this, we used the un-normalized architecture as a target-specific + // module name. Fall back to that behavior. + targetFileNamePairs.push_back( + ModuleFilenamePair(Ctx.LangOpts.Target.getArchName()) + ); // FIXME: We used to use "major architecture" names for these files---the // names checked in "#if arch(...)". Fall back to that name in the one case @@ -177,7 +184,7 @@ SerializedModuleLoaderBase::findModule(AccessPathElem moduleID, // We should be able to drop this once there's an Xcode that supports the // new names. if (Ctx.LangOpts.Target.getArch() == llvm::Triple::ArchType::arm) - targetFileNamePairs.push_back(StringRef("arm")); + targetFileNamePairs.push_back(ModuleFilenamePair("arm")); auto &fs = *Ctx.SourceMgr.getFileSystem(); isFramework = false; @@ -202,7 +209,7 @@ SerializedModuleLoaderBase::findModule(AccessPathElem moduleID, // We can only get here if all targetFileNamePairs failed with // 'std::errc::no_such_file_or_directory'. if (maybeDiagnoseArchitectureMismatch(moduleID.second, - moduleName, archName, currPath)) { + moduleName, normalizedTarget.str(), currPath)) { return false; } else { return None; diff --git a/test/ParseableInterface/ModuleCache/force-module-loading-mode-archs.swift b/test/ParseableInterface/ModuleCache/force-module-loading-mode-archs.swift index a764bafe357..33d5f4a65d1 100644 --- a/test/ParseableInterface/ModuleCache/force-module-loading-mode-archs.swift +++ b/test/ParseableInterface/ModuleCache/force-module-loading-mode-archs.swift @@ -60,12 +60,12 @@ // RUN: %empty-directory(%t/Lib.swiftmodule) // RUN: touch %t/Lib.swiftmodule/garbage.swiftmodule // RUN: touch %t/Lib.swiftmodule/garbage.swiftinterface -// RUN: not env SWIFT_FORCE_MODULE_LOADING=prefer-parseable %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -I %t 2>&1 | %FileCheck -check-prefix=WRONG-ARCH -DARCH=%target-cpu %s -// RUN: not env SWIFT_FORCE_MODULE_LOADING=prefer-serialized %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -I %t 2>&1 | %FileCheck -check-prefix=WRONG-ARCH -DARCH=%target-cpu %s +// RUN: not env SWIFT_FORCE_MODULE_LOADING=prefer-parseable %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -I %t 2>&1 | %FileCheck -check-prefix=WRONG-ARCH -DARCH=%module-target-triple %s +// RUN: not env SWIFT_FORCE_MODULE_LOADING=prefer-serialized %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -I %t 2>&1 | %FileCheck -check-prefix=WRONG-ARCH -DARCH=%module-target-triple %s // RUN: not env SWIFT_FORCE_MODULE_LOADING=only-parseable %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -I %t 2>&1 | %FileCheck -check-prefix=NO-SUCH-MODULE %s -// RUN: not env SWIFT_FORCE_MODULE_LOADING=only-serialized %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -I %t 2>&1 | %FileCheck -check-prefix=WRONG-ARCH -DARCH=%target-cpu %s +// RUN: not env SWIFT_FORCE_MODULE_LOADING=only-serialized %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -I %t 2>&1 | %FileCheck -check-prefix=WRONG-ARCH -DARCH=%module-target-triple %s // (default) -// RUN: not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP -I %t %s 2>&1 | %FileCheck -check-prefix=WRONG-ARCH -DARCH=%target-cpu %s +// RUN: not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP -I %t %s 2>&1 | %FileCheck -check-prefix=WRONG-ARCH -DARCH=%module-target-triple %s // 8. Only the interface is present but for the wrong architecture. // (Diagnostics for the module only are tested elsewhere.) diff --git a/test/ParseableInterface/ModuleCache/force-module-loading-mode-framework.swift b/test/ParseableInterface/ModuleCache/force-module-loading-mode-framework.swift index b2f705be4b5..54328c61e29 100644 --- a/test/ParseableInterface/ModuleCache/force-module-loading-mode-framework.swift +++ b/test/ParseableInterface/ModuleCache/force-module-loading-mode-framework.swift @@ -60,12 +60,12 @@ // RUN: %empty-directory(%t/Lib.framework/Modules/Lib.swiftmodule) // RUN: touch %t/Lib.framework/Modules/Lib.swiftmodule/garbage.swiftmodule // RUN: touch %t/Lib.framework/Modules/Lib.swiftmodule/garbage.swiftinterface -// RUN: not env SWIFT_FORCE_MODULE_LOADING=prefer-parseable %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -F %t 2>&1 | %FileCheck -check-prefix=WRONG-ARCH -DARCH=%target-cpu %s -// RUN: not env SWIFT_FORCE_MODULE_LOADING=prefer-serialized %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -F %t 2>&1 | %FileCheck -check-prefix=WRONG-ARCH -DARCH=%target-cpu %s +// RUN: not env SWIFT_FORCE_MODULE_LOADING=prefer-parseable %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -F %t 2>&1 | %FileCheck -check-prefix=WRONG-ARCH -DARCH=%module-target-triple %s +// RUN: not env SWIFT_FORCE_MODULE_LOADING=prefer-serialized %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -F %t 2>&1 | %FileCheck -check-prefix=WRONG-ARCH -DARCH=%module-target-triple %s // RUN: not env SWIFT_FORCE_MODULE_LOADING=only-parseable %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -F %t 2>&1 | %FileCheck -check-prefix=NO-SUCH-MODULE %s -// RUN: not env SWIFT_FORCE_MODULE_LOADING=only-serialized %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -F %t 2>&1 | %FileCheck -check-prefix=WRONG-ARCH -DARCH=%target-cpu %s +// RUN: not env SWIFT_FORCE_MODULE_LOADING=only-serialized %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP %s -F %t 2>&1 | %FileCheck -check-prefix=WRONG-ARCH -DARCH=%module-target-triple %s // (default) -// RUN: not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP -F %t %s 2>&1 | %FileCheck -check-prefix=WRONG-ARCH -DARCH=%target-cpu %s +// RUN: not %target-swift-frontend -typecheck -parse-stdlib -module-cache-path %t/MCP -F %t %s 2>&1 | %FileCheck -check-prefix=WRONG-ARCH -DARCH=%module-target-triple %s // 8. Only the interface is present but for the wrong architecture. // (Diagnostics for the module only are tested elsewhere.) diff --git a/test/Serialization/load-invalid-arch.swift b/test/Serialization/load-invalid-arch.swift index 2ac1f7020ae..34604e64016 100644 --- a/test/Serialization/load-invalid-arch.swift +++ b/test/Serialization/load-invalid-arch.swift @@ -5,13 +5,13 @@ // RUN: touch %t/new_module.swiftmodule/ppc65.swiftmodule // RUN: touch %t/new_module.swiftmodule/i387.swiftdoc // RUN: touch %t/new_module.swiftmodule/ppc65.swiftdoc -// RUN: not %target-swift-frontend %s -typecheck -I %t -show-diagnostics-after-fatal 2>&1 | %FileCheck %s -check-prefix=CHECK -check-prefix CHECK-ALL -DTARGET_ARCHITECTURE=%target-cpu +// RUN: not %target-swift-frontend %s -typecheck -I %t -show-diagnostics-after-fatal 2>&1 | %FileCheck %s -check-prefix=CHECK -check-prefix CHECK-ALL -DTARGET_ARCHITECTURE=%module-target-triple // RUN: %empty-directory(%t) // RUN: mkdir -p %t/new_module.framework/Modules/new_module.swiftmodule/ // RUN: touch %t/new_module.framework/Modules/new_module.swiftmodule/i387.swiftmodule // RUN: touch %t/new_module.framework/Modules/new_module.swiftmodule/ppc65.swiftmodule -// RUN: not %target-swift-frontend %s -F %t -typecheck -show-diagnostics-after-fatal 2>&1 | %FileCheck %s -check-prefix=CHECK -check-prefix CHECK-ALL -DTARGET_ARCHITECTURE=%target-cpu +// RUN: not %target-swift-frontend %s -F %t -typecheck -show-diagnostics-after-fatal 2>&1 | %FileCheck %s -check-prefix=CHECK -check-prefix CHECK-ALL -DTARGET_ARCHITECTURE=%module-target-triple // RUN: %empty-directory(%t) // RUN: mkdir %t/new_module.swiftmodule diff --git a/test/Serialization/load-target-fallback.swift b/test/Serialization/load-target-fallback.swift new file mode 100644 index 00000000000..40009c44507 --- /dev/null +++ b/test/Serialization/load-target-fallback.swift @@ -0,0 +1,28 @@ +// RUN: %empty-directory(%t) + +// Tests that we prefer the normalized target triple name for a .swiftmodule, +// but fall back to the legacy architecture name if necessary. + +// RUN: mkdir %t/TargetLibrary.swiftmodule +// RUN: %target-swift-frontend -emit-module -o %t/TargetLibrary.swiftmodule/%module-target-triple.swiftmodule %S/Inputs/def_func.swift -module-name TargetLibrary +// RUN: touch %t/TargetLibrary.swiftmodule/%target-cpu.swiftmodule + +import TargetLibrary + +// RUN: mkdir %t/ArchLibrary.swiftmodule +// RUN: %target-swift-frontend -emit-module -o %t/ArchLibrary.swiftmodule/%target-cpu.swiftmodule %S/Inputs/def_func.swift -module-name ArchLibrary + +import ArchLibrary + +// RUN: mkdir -p %t/TargetModule.framework/Modules/TargetModule.swiftmodule +// RUN: %target-swift-frontend -emit-module -o %t/TargetModule.framework/Modules/TargetModule.swiftmodule/%module-target-triple.swiftmodule %S/Inputs/def_func.swift -module-name TargetModule +// RUN: touch %t/TargetModule.framework/Modules/TargetModule.swiftmodule/%target-cpu.swiftmodule + +import TargetModule + +// RUN: mkdir -p %t/ArchModule.framework/Modules/ArchModule.swiftmodule +// RUN: %target-swift-frontend -emit-module -o %t/ArchModule.framework/Modules/ArchModule.swiftmodule/%target-cpu.swiftmodule %S/Inputs/def_func.swift -module-name ArchModule + +import ArchModule + +// RUN: %target-swift-frontend %s -typecheck -I %t -F %t diff --git a/test/Serialization/load-target-normalization.swift b/test/Serialization/load-target-normalization.swift new file mode 100644 index 00000000000..cdf0899e483 --- /dev/null +++ b/test/Serialization/load-target-normalization.swift @@ -0,0 +1,133 @@ +// RUN: %empty-directory(%t/ForeignModule.swiftmodule) +// RUN: touch %t/ForeignModule.swiftmodule/garbage-garbage-garbage.swiftmodule + +// Test format: We try to import ForeignModule with architectures besides +// garbage-garbage-garbage and check the target triple listed in the error +// message to make sure it was normalized correctly. This works in lieu of a +// mechanism to query the compiler for normalized triples. +// +// The extra flags in the RUN lines serve the following purposes: +// +// * "-parse-stdlib" ensures we don't reject any of these for not having an +// appropriate standard library built. +// * "-Xcc -arch -Xcc i386" makes sure the clang importer doesn't reject triples +// clang considers invalid. + +import ForeignModule + +// CHECK: error: could not find module 'ForeignModule' +// CHECK-SAME: '[[NORM]]' + +// Run lines for individual test cases follow. + +// +// OSES +// + +// OS version numbers should be stripped. + +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target x86_64-apple-macosx10.42 2>&1 | %FileCheck -DNORM=x86_64-apple-macos %s + +// macos, macosx, and darwin should all normalize to macos. + +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target x86_64-apple-macos10.42 2>&1 | %FileCheck -DNORM=x86_64-apple-macos %s +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target x86_64-apple-macosx10.42 2>&1 | %FileCheck -DNORM=x86_64-apple-macos %s +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target x86_64-apple-darwin46.0 2>&1 | %FileCheck -DNORM=x86_64-apple-macos %s + +// ios, tvos, watchos should be accepted. + +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target arm64-apple-ios40.0 2>&1 | %FileCheck -DNORM=arm64-apple-ios %s +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target arm64-apple-tvos40 2>&1 | %FileCheck -DNORM=arm64-apple-tvos %s +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target arm64-apple-watchos9.1.1 2>&1 | %FileCheck -DNORM=arm64-apple-watchos %s + +// Other OSes should be passed through without version stripping. We can't test +// a totally garbage case because we'll get diag::error_unsupported_target_os. + +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target x86_64-apple-linux40.04 2>&1 | %FileCheck -DNORM=x86_64-apple-linux40.04 %s + +// +// VENDORS +// + +// If the OS looks like an Apple OS, vendor should be normalized to apple. + +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target x86_64-unknown-macos10.42 2>&1 | %FileCheck -DNORM=x86_64-apple-macos %s +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target arm64--ios40.0 2>&1 | %FileCheck -DNORM=arm64-apple-ios %s +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target arm64-ibm-tvos40 2>&1 | %FileCheck -DNORM=arm64-apple-tvos %s +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target arm64-snapple-watchos9.1.1 2>&1 | %FileCheck -DNORM=arm64-apple-watchos %s + +// +// ARCHITECTURES +// + +// arm64 and aarch64 are normalized to arm64. + +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target arm64-apple-ios40.0 2>&1 | %FileCheck -DNORM=arm64-apple-ios %s +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target aarch64-apple-ios40.0 2>&1 | %FileCheck -DNORM=arm64-apple-ios %s + +// armv7s, armv7k, armv7 should be accepted. + +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target armv7s-apple-ios40.0 2>&1 | %FileCheck -DNORM=armv7s-apple-ios %s +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target armv7k-apple-ios40.0 2>&1 | %FileCheck -DNORM=armv7k-apple-ios %s +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target armv7-apple-ios40.0 2>&1 | %FileCheck -DNORM=armv7-apple-ios %s + +// x86_64h should be accepted. + +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target x86_64h-apple-macos10.11 2>&1 | %FileCheck -DNORM=x86_64h-apple-macos %s + +// x64_64 and amd64 are normalized to x86_64. + +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target x86_64-apple-macos10.11 2>&1 | %FileCheck -DNORM=x86_64-apple-macos %s +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target amd64-apple-macos10.11 2>&1 | %FileCheck -DNORM=x86_64-apple-macos %s + +// i[3-9]86 are normalized to i386. + +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target i386-apple-macos10.11 2>&1 | %FileCheck -DNORM=i386-apple-macos %s +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target i486-apple-macos10.11 2>&1 | %FileCheck -DNORM=i386-apple-macos %s +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target i586-apple-macos10.11 2>&1 | %FileCheck -DNORM=i386-apple-macos %s +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target i686-apple-macos10.11 2>&1 | %FileCheck -DNORM=i386-apple-macos %s +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target i786-apple-macos10.11 2>&1 | %FileCheck -DNORM=i386-apple-macos %s +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target i886-apple-macos10.11 2>&1 | %FileCheck -DNORM=i386-apple-macos %s +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target i986-apple-macos10.11 2>&1 | %FileCheck -DNORM=i386-apple-macos %s + +// Other arches should be passed through. We can't test a totally garbage case +// because we'll get diag::error_unsupported_target_arch. + +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target powerpc64-apple-macos10.11 2>&1 | %FileCheck -DNORM=powerpc64-apple-macos %s + +// +// ENVIRONMENTS +// + +// simulator should be permitted on the non-Mac operating systems. + +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target x86_64-apple-ios40.0-simulator 2>&1 | %FileCheck -DNORM=x86_64-apple-ios-simulator %s +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target x86_64-apple-tvos40-simulator 2>&1 | %FileCheck -DNORM=x86_64-apple-tvos-simulator %s +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target x86_64-apple-watchos9.1.1-simulator 2>&1 | %FileCheck -DNORM=x86_64-apple-watchos-simulator %s +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target i386-apple-ios40.0-simulator 2>&1 | %FileCheck -DNORM=i386-apple-ios-simulator %s +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target i386-apple-tvos40-simulator 2>&1 | %FileCheck -DNORM=i386-apple-tvos-simulator %s +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target i386-apple-watchos9.1.1-simulator 2>&1 | %FileCheck -DNORM=i386-apple-watchos-simulator %s + +// simulator should be inferred when an Intel architecture is used with iOS, tvOS, or watchOS. + +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target x86_64-apple-ios40.0 2>&1 | %FileCheck -DNORM=x86_64-apple-ios-simulator %s +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target x86_64-apple-tvos40 2>&1 | %FileCheck -DNORM=x86_64-apple-tvos-simulator %s +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target x86_64-apple-watchos9.1.1 2>&1 | %FileCheck -DNORM=x86_64-apple-watchos-simulator %s +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target i386-apple-ios40.0 2>&1 | %FileCheck -DNORM=i386-apple-ios-simulator %s +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target i386-apple-tvos40 2>&1 | %FileCheck -DNORM=i386-apple-tvos-simulator %s +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target i386-apple-watchos9.1.1 2>&1 | %FileCheck -DNORM=i386-apple-watchos-simulator %s + +// Other environments should be passed through. + +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target i386-apple-ios40.0-in_spaaaaaaace 2>&1 | %FileCheck -DNORM=i386-apple-ios-in_spaaaaaaace %s + +// +// DARWIN ONLY +// + +// Non-isDarwinOS() OSes should have no normalization applied. + +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target x86_64-unknown-linux40.04 2>&1 | %FileCheck -DNORM=x86_64-unknown-linux40.04 %s +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target aarch64--linux-android 2>&1 | %FileCheck -DNORM=aarch64--linux-android %s +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target amd64-ibm-linux40.04 2>&1 | %FileCheck -DNORM=amd64-ibm-linux40.04 %s +// RUN: not %target-swift-frontend %s -typecheck -I %t -parse-stdlib -Xcc -arch -Xcc i386 -target i986-snapple-haiku 2>&1 | %FileCheck -DNORM=i986-snapple-haiku %s diff --git a/test/lit.cfg b/test/lit.cfg index d8366ae28e7..31801436651 100644 --- a/test/lit.cfg +++ b/test/lit.cfg @@ -624,7 +624,14 @@ def use_interpreter_for_simple_runs(): config.target_run_simple_swift_parameterized = make_simple_target_run(parameterized=True) config.available_features.add('interpret') +target_specific_module_triple = config.variant_triple + if run_vendor == 'apple': + target_specific_module_triple = '{}-apple-{}'.format( + { 'aarch64': 'arm64', 'amd64': 'x86_64' }.get(run_cpu, run_cpu), + { 'macosx': 'macos', 'darwin': 'macos' }.get(run_os, run_os) + ) + config.available_features.add('objc_interop') config.target_object_format = "macho" config.target_shared_library_prefix = 'lib' @@ -694,6 +701,8 @@ if run_vendor == 'apple': lit_config.note("Testing AppleTV simulator " + config.variant_triple) xcrun_sdk_name = "appletvsimulator" + target_specific_module_triple += "-simulator" + config.target_cc_options = ( "-arch %s -m%s-simulator-version-min=%s %s" % (run_cpu, run_os, run_vers, clang_mcp_opt)) @@ -986,6 +995,8 @@ else: lit_config.fatal("Don't know how to define target_run and " "target_build_swift for platform " + config.variant_triple) +config.substitutions.append(('%module-target-triple', + target_specific_module_triple)) # Different OS's require different prefixes for the environment variables to be # propagated to the calling contexts.