diff --git a/cmake/modules/AddPureSwift.cmake b/cmake/modules/AddPureSwift.cmake index fc7ded0db64b5..ad177634dbca9 100644 --- a/cmake/modules/AddPureSwift.cmake +++ b/cmake/modules/AddPureSwift.cmake @@ -5,17 +5,16 @@ function(force_target_link_libraries TARGET) cmake_parse_arguments(ARGS "" "" "PUBLIC" ${ARGN}) foreach(DEPENDENCY ${ARGS_PUBLIC}) - target_link_libraries(${TARGET} PRIVATE - ${DEPENDENCY} - ) + target_link_libraries(${TARGET} PRIVATE ${DEPENDENCY}) add_dependencies(${TARGET} ${DEPENDENCY}) - add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/forced-${DEPENDENCY}-dep.swift - COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/forced-${DEPENDENCY}-dep.swift + string(REGEX REPLACE [<>:\"/\\|?*] _ sanitized ${DEPENDENCY}) + add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/forced-${sanitized}-dep.swift + COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/forced-${sanitized}-dep.swift DEPENDS ${DEPENDENCY} ) target_sources(${TARGET} PRIVATE - ${CMAKE_CURRENT_BINARY_DIR}/forced-${DEPENDENCY}-dep.swift + ${CMAKE_CURRENT_BINARY_DIR}/forced-${sanitized}-dep.swift ) endforeach() endfunction() @@ -270,7 +269,8 @@ function(add_pure_swift_host_tool name) # Option handling set(options) - set(single_parameter_options) + set(single_parameter_options + SWIFT_COMPONENT) set(multiple_parameter_options DEPENDENCIES SWIFT_DEPENDENCIES) @@ -324,6 +324,17 @@ function(add_pure_swift_host_tool name) target_include_directories(${name} PUBLIC ${SWIFT_HOST_LIBRARIES_DEST_DIR}) - # Export this target. - set_property(GLOBAL APPEND PROPERTY SWIFT_EXPORTS ${name}) + if(NOT APSHT_SWIFT_COMPONENT STREQUAL no_component) + add_dependencies(${APSHT_SWIFT_COMPONENT} ${name}) + swift_install_in_component(TARGETS ${name} + COMPONENT ${APSHT_SWIFT_COMPONENT} + RUNTIME DESTINATION bin) + swift_is_installing_component(${APSHT_SWIFT_COMPONENT} is_installing) + endif() + + if(NOT is_installing) + set_property(GLOBAL APPEND PROPERTY SWIFT_BUILDTREE_EXPORTS ${name}) + else() + set_property(GLOBAL APPEND PROPERTY SWIFT_EXPORTS ${name}) + endif() endfunction() diff --git a/cmake/modules/AddSwift.cmake b/cmake/modules/AddSwift.cmake index 328af19adc60d..35faa2ddb9adf 100644 --- a/cmake/modules/AddSwift.cmake +++ b/cmake/modules/AddSwift.cmake @@ -570,6 +570,9 @@ function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping) else() message(FATAL_ERROR "Unknown BOOTSTRAPPING_MODE '${ASRLF_BOOTSTRAPPING_MODE}'") endif() + else() + target_link_directories(${target} PRIVATE + ${SWIFT_PATH_TO_SWIFT_SDK}/usr/lib/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}/${SWIFT_HOST_VARIANT_ARCH}) endif() if(SWIFT_SWIFT_PARSER) diff --git a/include/swift/AST/CASTBridging.h b/include/swift/AST/CASTBridging.h index 4699a291a1fc2..e30951d490749 100644 --- a/include/swift/AST/CASTBridging.h +++ b/include/swift/AST/CASTBridging.h @@ -39,12 +39,9 @@ SWIFT_BEGIN_NULLABILITY_ANNOTATIONS -typedef long SwiftInt; -typedef unsigned long SwiftUInt; - typedef struct { const void *_Nullable data; - long numElements; + SwiftInt numElements; } BridgedArrayRef; typedef struct { @@ -65,7 +62,7 @@ typedef struct { void *_Nullable TrailingCommaLoc; } BridgedTupleTypeElement; -typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedRequirementReprKind : long { +typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedRequirementReprKind : SwiftInt { /// A type bound T : P, where T is a type that depends on a generic /// parameter and P is some type that should bound T, either as a concrete /// supertype or a protocol to which T must conform. @@ -92,7 +89,7 @@ typedef struct { } BridgedRequirementRepr; /// Diagnostic severity when reporting diagnostics. -typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedDiagnosticSeverity : long { +typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedDiagnosticSeverity : SwiftInt { BridgedFatalError, BridgedError, BridgedWarning, @@ -102,7 +99,7 @@ typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedDiagnosticSeverity : long { typedef void* BridgedDiagnostic; -typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedMacroDefinitionKind : long { +typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedMacroDefinitionKind : SwiftInt { /// An expanded macro. BridgedExpandedMacro = 0, /// An external macro, spelled with either the old spelling (Module.Type) @@ -130,7 +127,7 @@ BridgedDiagnostic SwiftDiagnostic_create(void *diagnosticEngine, BridgedDiagnosticSeverity severity, const void *_Nullable sourceLoc, const unsigned char *_Nullable text, - long textLen); + SwiftInt textLen); /// Highlight a source range as part of the diagnostic. void SwiftDiagnostic_highlight( @@ -141,14 +138,14 @@ void SwiftDiagnostic_fixItReplace(BridgedDiagnostic diag, const void *_Nullable replaceStartLoc, const void *_Nullable replaceEndLoc, const unsigned char *_Nullable newText, - long newTextLen); + SwiftInt newTextLen); /// Finish the given diagnostic and emit it. void SwiftDiagnostic_finish(BridgedDiagnostic diag); BridgedIdentifier SwiftASTContext_getIdentifier(void *ctx, const unsigned char *_Nullable str, - long len); + SwiftInt len); void *SwiftImportDecl_create(void *, void *, void *, char, void *, BridgedArrayRef, BridgedArrayRef); @@ -173,11 +170,11 @@ void *SwiftIdentifierExpr_create(void *ctx, BridgedIdentifier base, void *loc); void *SwiftStringLiteralExpr_create(void *ctx, const unsigned char *_Nullable string, - long len, void *TokenLoc); + SwiftInt len, void *TokenLoc); void *SwiftIntegerLiteralExpr_create(void *ctx, const unsigned char *_Nullable string, - long len, void *TokenLoc); + SwiftInt len, void *TokenLoc); void *SwiftBooleanLiteralExpr_create(void *ctx, _Bool value, void *TokenLoc); @@ -194,7 +191,7 @@ void *SingleValueStmtExpr_createWithWrappedBranches(void *ctx, void *S, void *IfStmt_create(void *ctx, void *ifLoc, void *cond, void *_Nullable then, void *_Nullable elseLoc, void *_Nullable elseStmt); -typedef enum ENUM_EXTENSIBILITY_ATTR(open) ASTNodeKind : long { +typedef enum ENUM_EXTENSIBILITY_ATTR(open) ASTNodeKind : SwiftInt { ASTNodeKindExpr, ASTNodeKindStmt, ASTNodeKindDecl @@ -208,7 +205,7 @@ struct ASTNodeBridged { void *BraceStmt_create(void *ctx, void *lbloc, BridgedArrayRef elements, void *rbloc); -void *BridgedSourceLoc_advanced(void *loc, long len); +void *BridgedSourceLoc_advanced(void *loc, SwiftInt len); void *ParamDecl_create(void *ctx, void *loc, void *_Nullable argLoc, void *_Nullable argName, void *_Nullable paramLoc, @@ -282,7 +279,7 @@ void *GenericParamList_create(void *ctx, void *lAngleLoc, BridgedArrayRef reqs, void *rAngleLoc); void *GenericTypeParamDecl_create(void *ctx, void *declContext, BridgedIdentifier name, void *nameLoc, - void *_Nullable eachLoc, long index, + void *_Nullable eachLoc, SwiftInt index, _Bool isParameterPack); void GenericTypeParamDecl_setInheritedType(void *ctx, void *Param, void *ty); diff --git a/include/swift/AST/PluginRegistry.h b/include/swift/AST/PluginRegistry.h index e2f1fcb0f64a6..8ee553c8903c4 100644 --- a/include/swift/AST/PluginRegistry.h +++ b/include/swift/AST/PluginRegistry.h @@ -52,14 +52,13 @@ class LoadedExecutablePlugin { /// Represents the current process of the executable plugin. struct PluginProcess { - const llvm::sys::procid_t pid; - const int inputFileDescriptor; - const int outputFileDescriptor; + const llvm::sys::ProcessInfo process; + const int input; + const int output; bool isStale = false; - PluginProcess(llvm::sys::procid_t pid, int inputFileDescriptor, - int outputFileDescriptor); - + PluginProcess(llvm::sys::ProcessInfo process, int input, int output) + : process(process), input(input), output(output) {} ~PluginProcess(); ssize_t write(const void *buf, size_t nbyte) const; @@ -138,7 +137,8 @@ class LoadedExecutablePlugin { llvm::erase_value(onReconnect, fn); } - llvm::sys::procid_t getPid() { return Process->pid; } + llvm::sys::procid_t getPid() { return Process->process.Pid; } + llvm::sys::process_t getProcess() { return Process->process.Process; } NullTerminatedStringRef getExecutablePath() { return {ExecutablePath.c_str(), ExecutablePath.size()}; diff --git a/include/swift/Basic/CBasicBridging.h b/include/swift/Basic/CBasicBridging.h index 86e7d5081d6dc..0835b111bee69 100644 --- a/include/swift/Basic/CBasicBridging.h +++ b/include/swift/Basic/CBasicBridging.h @@ -20,6 +20,69 @@ // it causes importing the "Darwin"/"Glibc" overlay module. That violates // layering. i.e. Darwin overlay is created by Swift compiler. +// NOTE: Partially ported from SwiftShim's SwiftStdint.h. We cannot include +// that header here because it belongs to the runtime, but we need the same +// logic for interoperability with Swift code in the compiler itself. +// stdint.h is provided by Clang, but it dispatches to libc's stdint.h. As a +// result, using stdint.h here would pull in Darwin module (which includes +// libc). This creates a dependency cycle, so we can't use stdint.h in +// SwiftShims. +// On Linux, the story is different. We get the error message +// "/usr/include/x86_64-linux-gnu/sys/types.h:146:10: error: 'stddef.h' file not +// found" +// This is a known Clang/Ubuntu bug. + +// Clang has been defining __INTxx_TYPE__ macros for a long time. +// __UINTxx_TYPE__ are defined only since Clang 3.5. +#if defined(_MSC_VER) && !defined(__clang__) +typedef __int64 __swiftc_int64_t; +typedef unsigned __int64 __swiftc_uint64_t; +typedef int __swiftc_int32_t; +typedef unsigned int __swiftc_uint32_t; +#elif !defined(__APPLE__) && !defined(__linux__) && !defined(__OpenBSD__) && !defined(__wasi__) +#include +typedef int64_t __swiftc_int64_t; +typedef uint64_t __swiftc_uint64_t; +typedef int32_t __swiftc_int32_t; +typedef uint32_t __swiftc_uint32_t; +typedef intptr_t __swiftc_intptr_t; +typedef uintptr_t __swiftc_uintptr_t; +#else +typedef __INT64_TYPE__ __swiftc_int64_t; +#ifdef __UINT64_TYPE__ +typedef __UINT64_TYPE__ __swiftc_uint64_t; +#else +typedef unsigned __INT64_TYPE__ __swiftc_uint64_t; +#endif + +typedef __INT32_TYPE__ __swiftc_int32_t; +#ifdef __UINT32_TYPE__ +typedef __UINT32_TYPE__ __swiftc_uint32_t; +#else +typedef unsigned __INT32_TYPE__ __swiftc_uint32_t; +#endif +#endif + +#define __swiftc_join3(a,b,c) a ## b ## c + +#define __swiftc_intn_t(n) __swiftc_join3(__swiftc_int, n, _t) +#define __swiftc_uintn_t(n) __swiftc_join3(__swiftc_uint, n, _t) + +#if defined(_MSC_VER) && !defined(__clang__) +#if defined(_WIN64) +typedef __swiftc_int64_t SwiftInt; +typedef __swiftc_uint64_t SwiftUInt; +#elif defined(_WIN32) +typedef __swiftc_int32_t SwiftInt; +typedef __swiftc_uint32_t SwiftUInt; +#else +#error unknown windows pointer width +#endif +#else +typedef __swiftc_intn_t(__INTPTR_WIDTH__) SwiftInt; +typedef __swiftc_uintn_t(__INTPTR_WIDTH__) SwiftUInt; +#endif + #if __clang__ // Provide macros to temporarily suppress warning about the use of // _Nullable and _Nonnull. @@ -48,7 +111,7 @@ extern "C" { typedef struct BridgedData { const char *_Nullable baseAddress; - unsigned long size; + SwiftUInt size; } BridgedData; void BridgedData_free(BridgedData data); diff --git a/include/swift/Basic/Program.h b/include/swift/Basic/Program.h index 0a4acffe23f82..6efa12b40773a 100644 --- a/include/swift/Basic/Program.h +++ b/include/swift/Basic/Program.h @@ -40,14 +40,12 @@ int ExecuteInPlace(const char *Program, const char **args, const char **env = nullptr); struct ChildProcessInfo { - llvm::sys::procid_t Pid; - int WriteFileDescriptor; - int ReadFileDescriptor; + llvm::sys::ProcessInfo ProcessInfo; + int Write; + int Read; - ChildProcessInfo(llvm::sys::procid_t Pid, int WriteFileDescriptor, - int ReadFileDescriptor) - : Pid(Pid), WriteFileDescriptor(WriteFileDescriptor), - ReadFileDescriptor(ReadFileDescriptor) {} + ChildProcessInfo(llvm::sys::ProcessInfo ProcessInfo, int Write, int Read) + : ProcessInfo(ProcessInfo), Write(Write), Read(Read) {} }; /// This function executes the program using the argument provided. diff --git a/include/swift/Driver/ToolChain.h b/include/swift/Driver/ToolChain.h index b50c720ead1e3..5829dd543fd40 100644 --- a/include/swift/Driver/ToolChain.h +++ b/include/swift/Driver/ToolChain.h @@ -340,7 +340,10 @@ class ToolChain { void addLinkRuntimeLib(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &Arguments, StringRef LibName) const; - + + virtual void addPluginArguments(const llvm::opt::ArgList &Args, + llvm::opt::ArgStringList &Arguments) const {} + /// Validates arguments passed to the toolchain. /// /// An override point for platform-specific subclasses to customize the diff --git a/lib/AST/CASTBridging.cpp b/lib/AST/CASTBridging.cpp index 5b935d4cebb11..85a10183a0ac4 100644 --- a/lib/AST/CASTBridging.cpp +++ b/lib/AST/CASTBridging.cpp @@ -27,6 +27,8 @@ static SourceLoc getSourceLocFromPointer(const void *loc) { namespace { struct BridgedDiagnosticImpl { + typedef llvm::MallocAllocator Allocator; + InFlightDiagnostic inFlight; std::vector textBlobs; @@ -37,8 +39,10 @@ namespace { ~BridgedDiagnosticImpl() { inFlight.flush(); + + Allocator allocator; for (auto text: textBlobs) { - free((void*)text.data()); + allocator.Deallocate(text.data(), text.size()); } } }; @@ -48,11 +52,11 @@ BridgedDiagnostic SwiftDiagnostic_create(void *diagnosticEngine, BridgedDiagnosticSeverity severity, const void *sourceLocPtr, const unsigned char *textPtr, - long textLen) { + SwiftInt textLen) { StringRef origText{ reinterpret_cast(textPtr), size_t(textLen)}; - llvm::MallocAllocator mallocAlloc; - StringRef text = origText.copy(mallocAlloc); + BridgedDiagnosticImpl::Allocator alloc; + StringRef text = origText.copy(alloc); SourceLoc loc = getSourceLocFromPointer(sourceLocPtr); @@ -95,15 +99,15 @@ void SwiftDiagnostic_fixItReplace(BridgedDiagnostic diagPtr, const void *replaceStartLocPtr, const void *replaceEndLocPtr, const unsigned char *newTextPtr, - long newTextLen) { + SwiftInt newTextLen) { SourceLoc startLoc = getSourceLocFromPointer(replaceStartLocPtr); SourceLoc endLoc = getSourceLocFromPointer(replaceEndLocPtr); StringRef origReplaceText{ reinterpret_cast(newTextPtr), size_t(newTextLen)}; - llvm::MallocAllocator mallocAlloc; - StringRef replaceText = origReplaceText.copy(mallocAlloc); + BridgedDiagnosticImpl::Allocator alloc; + StringRef replaceText = origReplaceText.copy(alloc); BridgedDiagnosticImpl *impl = static_cast(diagPtr); impl->textBlobs.push_back(replaceText); @@ -118,7 +122,7 @@ void SwiftDiagnostic_finish(BridgedDiagnostic diagPtr) { BridgedIdentifier SwiftASTContext_getIdentifier(void *ctx, const unsigned char *_Nullable str, - long len) { + SwiftInt len) { return const_cast( static_cast(ctx) ->getIdentifier( @@ -145,7 +149,7 @@ void *SwiftImportDecl_create(void *ctx, void *dc, void *importLoc, char kind, getSourceLocFromPointer(kindLoc), std::move(importPath).get()); } -void *BridgedSourceLoc_advanced(void *loc, long len) { +void *BridgedSourceLoc_advanced(void *loc, SwiftInt len) { SourceLoc l = getSourceLocFromPointer(loc).getAdvancedLoc(len); return const_cast(l.getOpaquePointerValue()); } @@ -216,7 +220,7 @@ void *SwiftIdentifierExpr_create(void *ctx, BridgedIdentifier base, void *loc) { void *SwiftStringLiteralExpr_create(void *ctx, const unsigned char *_Nullable string, - long len, void *TokenLoc) { + SwiftInt len, void *TokenLoc) { ASTContext &Context = *static_cast(ctx); auto stringRef = Context.AllocateCopy( StringRef{reinterpret_cast(string), size_t(len)}); @@ -226,7 +230,7 @@ void *SwiftStringLiteralExpr_create(void *ctx, void *SwiftIntegerLiteralExpr_create(void *ctx, const unsigned char *_Nullable string, - long len, void *TokenLoc) { + SwiftInt len, void *TokenLoc) { ASTContext &Context = *static_cast(ctx); auto stringRef = Context.AllocateCopy( StringRef{reinterpret_cast(string), size_t(len)}); @@ -582,7 +586,7 @@ void *GenericParamList_create(void *ctx, void *lAngleLoc, void *GenericTypeParamDecl_create(void *ctx, void *declContext, BridgedIdentifier name, void *nameLoc, - void *_Nullable eachLoc, long index, + void *_Nullable eachLoc, SwiftInt index, bool isParameterPack) { return GenericTypeParamDecl::createParsed( static_cast(declContext), @@ -695,6 +699,6 @@ bool Plugin_waitForNextMessage(PluginHandle handle, BridgedData *out) { auto size = message.size(); auto outPtr = malloc(size); memcpy(outPtr, message.data(), size); - *out = BridgedData{(const char *)outPtr, (unsigned long)size}; + *out = BridgedData{(const char *)outPtr, (SwiftUInt)size}; return false; } diff --git a/lib/AST/PluginLoader.cpp b/lib/AST/PluginLoader.cpp index 2f89336577107..3a78138fb766f 100644 --- a/lib/AST/PluginLoader.cpp +++ b/lib/AST/PluginLoader.cpp @@ -41,8 +41,13 @@ PluginRegistry *PluginLoader::getRegistry() { static StringRef pluginModuleNameStringFromPath(StringRef path) { // Plugin library must be named 'lib${module name}(.dylib|.so|.dll)'. // FIXME: Shared library prefix might be different between platforms. +#if defined(_WIN32) + constexpr StringRef libPrefix{}; + constexpr StringRef libSuffix = ".dll"; +#else constexpr StringRef libPrefix = "lib"; constexpr StringRef libSuffix = LTDL_SHLIB_EXT; +#endif StringRef filename = llvm::sys::path::filename(path); if (filename.starts_with(libPrefix) && filename.ends_with(libSuffix)) { diff --git a/lib/AST/PluginRegistry.cpp b/lib/AST/PluginRegistry.cpp index 25cdcf62d6fe5..beceff366b7d2 100644 --- a/lib/AST/PluginRegistry.cpp +++ b/lib/AST/PluginRegistry.cpp @@ -75,7 +75,9 @@ void *LoadedLibraryPlugin::getAddressOfSymbol(const char *symbolName) { auto &cached = resolvedSymbols[symbolName]; if (cached) return cached; -#if !defined(_WIN32) +#if defined(_WIN32) + cached = GetProcAddress(static_cast(handle), symbolName); +#else cached = dlsym(handle, symbolName); #endif return cached; @@ -153,9 +155,8 @@ llvm::Error LoadedExecutablePlugin::spawnIfNeeded() { return llvm::errorCodeToError(childInfo.getError()); } - Process = std::make_unique(childInfo->Pid, - childInfo->ReadFileDescriptor, - childInfo->WriteFileDescriptor); + Process = std::make_unique(childInfo->ProcessInfo, + childInfo->Read, childInfo->Write); // Call "on reconnect" callbacks. for (auto *callback : onReconnect) { @@ -165,15 +166,15 @@ llvm::Error LoadedExecutablePlugin::spawnIfNeeded() { return llvm::Error::success(); } -LoadedExecutablePlugin::PluginProcess::PluginProcess(llvm::sys::procid_t pid, - int inputFileDescriptor, - int outputFileDescriptor) - : pid(pid), inputFileDescriptor(inputFileDescriptor), - outputFileDescriptor(outputFileDescriptor) {} - LoadedExecutablePlugin::PluginProcess::~PluginProcess() { - close(inputFileDescriptor); - close(outputFileDescriptor); +#if defined(_WIN32) + _close(input); + _close(output); + CloseHandle(process.Process); +#else + close(input); + close(output); +#endif } LoadedExecutablePlugin::~LoadedExecutablePlugin() { @@ -184,6 +185,17 @@ LoadedExecutablePlugin::~LoadedExecutablePlugin() { ssize_t LoadedExecutablePlugin::PluginProcess::read(void *buf, size_t nbyte) const { +#if defined(_WIN32) + size_t nread = 0; + while (nread < nbyte) { + int n = _read(input, static_cast(buf) + nread, + std::min(static_cast(UINT32_MAX), nbyte - nread)); + if (n <= 0) + break; + nread += n; + } + return nread; +#else ssize_t bytesToRead = nbyte; void *ptr = buf; @@ -195,7 +207,7 @@ ssize_t LoadedExecutablePlugin::PluginProcess::read(void *buf, while (bytesToRead > 0) { ssize_t readingSize = std::min(ssize_t(INT32_MAX), bytesToRead); - ssize_t readSize = ::read(inputFileDescriptor, ptr, readingSize); + ssize_t readSize = ::read(input, ptr, readingSize); if (readSize <= 0) { // 0: EOF (the plugin exited?), -1: error (e.g. broken pipe.) // FIXME: Mark the plugin 'stale' and relaunch later. @@ -206,10 +218,22 @@ ssize_t LoadedExecutablePlugin::PluginProcess::read(void *buf, } return nbyte - bytesToRead; +#endif } ssize_t LoadedExecutablePlugin::PluginProcess::write(const void *buf, size_t nbyte) const { +#if defined(_WIN32) + size_t nwritten = 0; + while (nwritten < nbyte) { + int n = _write(output, static_cast(buf) + nwritten, + std::min(static_cast(UINT32_MAX), nbyte - nwritten)); + if (n <= 0) + break; + nwritten += n; + } + return nwritten; +#else ssize_t bytesToWrite = nbyte; const void *ptr = buf; @@ -221,7 +245,7 @@ ssize_t LoadedExecutablePlugin::PluginProcess::write(const void *buf, while (bytesToWrite > 0) { ssize_t writingSize = std::min(ssize_t(INT32_MAX), bytesToWrite); - ssize_t writtenSize = ::write(outputFileDescriptor, ptr, writingSize); + ssize_t writtenSize = ::write(output, ptr, writingSize); if (writtenSize <= 0) { // -1: error (e.g. broken pipe,) // FIXME: Mark the plugin 'stale' and relaunch later. @@ -231,13 +255,14 @@ ssize_t LoadedExecutablePlugin::PluginProcess::write(const void *buf, bytesToWrite -= writtenSize; } return nbyte - bytesToWrite; +#endif } llvm::Error LoadedExecutablePlugin::sendMessage(llvm::StringRef message) const { ssize_t writtenSize = 0; if (dumpMessaging) { - llvm::dbgs() << "->(plugin:" << Process->pid << ") " << message << "\n"; + llvm::dbgs() << "->(plugin:" << Process->process.Pid << ") " << message << '\n'; } const char *data = message.data(); @@ -297,7 +322,7 @@ llvm::Expected LoadedExecutablePlugin::waitForNextMessage() const { } if (dumpMessaging) { - llvm::dbgs() << "<-(plugin:" << Process->pid << ") " << message << "\n"; + llvm::dbgs() << "<-(plugin:" << Process->process.Pid << ") " << message << "\n"; } return message; diff --git a/lib/ASTGen/Sources/ASTGen/ASTGen.swift b/lib/ASTGen/Sources/ASTGen/ASTGen.swift index 4aa3321190403..7a57715000942 100644 --- a/lib/ASTGen/Sources/ASTGen/ASTGen.swift +++ b/lib/ASTGen/Sources/ASTGen/ASTGen.swift @@ -1,11 +1,12 @@ import CASTBridging +import CBasicBridging import SwiftParser import SwiftSyntax extension Array { public func withBridgedArrayRef(_ c: (BridgedArrayRef) -> T) -> T { withUnsafeBytes { buf in - c(BridgedArrayRef(data: buf.baseAddress!, numElements: count)) + c(BridgedArrayRef(data: buf.baseAddress!, numElements: SwiftInt(count))) } } } diff --git a/lib/ASTGen/Sources/ASTGen/Decls.swift b/lib/ASTGen/Sources/ASTGen/Decls.swift index 815bb696b137b..6c725e5642ef0 100644 --- a/lib/ASTGen/Sources/ASTGen/Decls.swift +++ b/lib/ASTGen/Sources/ASTGen/Decls.swift @@ -1,4 +1,5 @@ import CASTBridging +import CBasicBridging import SwiftParser import SwiftSyntax @@ -8,7 +9,7 @@ extension ASTGenVisitor { let equalLoc = self.base.advanced(by: node.initializer.equal.position.utf8Offset).raw var nameText = node.identifier.text let name = nameText.withUTF8 { buf in - return SwiftASTContext_getIdentifier(ctx, buf.baseAddress, buf.count) + return SwiftASTContext_getIdentifier(ctx, buf.baseAddress, SwiftInt(buf.count)) } let nameLoc = self.base.advanced(by: node.identifier.position.utf8Offset).raw let genericParams = node.genericParameterClause.map { self.visit($0).rawValue } @@ -29,7 +30,7 @@ extension ASTGenVisitor { let loc = self.base.advanced(by: node.position.utf8Offset).raw var nameText = node.identifier.text let name = nameText.withUTF8 { buf in - return SwiftASTContext_getIdentifier(ctx, buf.baseAddress, buf.count) + return SwiftASTContext_getIdentifier(ctx, buf.baseAddress, SwiftInt(buf.count)) } let genericParams = node.genericParameterClause @@ -52,7 +53,7 @@ extension ASTGenVisitor { let loc = self.base.advanced(by: node.position.utf8Offset).raw var nameText = node.identifier.text let name = nameText.withUTF8 { buf in - return SwiftASTContext_getIdentifier(ctx, buf.baseAddress, buf.count) + return SwiftASTContext_getIdentifier(ctx, buf.baseAddress, SwiftInt(buf.count)) } let out = ClassDecl_create(ctx, loc, name, loc, declContext) @@ -95,7 +96,7 @@ extension ASTGenVisitor { // Swift AST represents "_" as nil. var text = nodeFirstName.text firstName = text.withUTF8 { buf in - SwiftASTContext_getIdentifier(ctx, buf.baseAddress, buf.count) + SwiftASTContext_getIdentifier(ctx, buf.baseAddress, SwiftInt(buf.count)) } } else { firstName = nil @@ -104,7 +105,7 @@ extension ASTGenVisitor { if let nodeSecondName = node.secondName { var text = nodeSecondName.text secondName = text.withUTF8 { buf in - SwiftASTContext_getIdentifier(ctx, buf.baseAddress, buf.count) + SwiftASTContext_getIdentifier(ctx, buf.baseAddress, SwiftInt(buf.count)) } } else { secondName = nil @@ -124,7 +125,7 @@ extension ASTGenVisitor { var nameText = node.identifier.text let name = nameText.withUTF8 { buf in - return SwiftASTContext_getIdentifier(ctx, buf.baseAddress, buf.count) + return SwiftASTContext_getIdentifier(ctx, buf.baseAddress, SwiftInt(buf.count)) } let returnType: ASTNode? diff --git a/lib/ASTGen/Sources/ASTGen/Diagnostics.swift b/lib/ASTGen/Sources/ASTGen/Diagnostics.swift index 7071029c43983..e0a41b819d7b4 100644 --- a/lib/ASTGen/Sources/ASTGen/Diagnostics.swift +++ b/lib/ASTGen/Sources/ASTGen/Diagnostics.swift @@ -1,4 +1,5 @@ import CASTBridging +import CBasicBridging import SwiftDiagnostics import SwiftSyntax @@ -37,7 +38,7 @@ fileprivate func emitDiagnosticParts( let diag = mutableMessage.withUTF8 { messageBuffer in SwiftDiagnostic_create( diagEnginePtr, bridgedSeverity, sourceLoc(at: position), - messageBuffer.baseAddress, messageBuffer.count + messageBuffer.baseAddress, SwiftInt(messageBuffer.count) ) } @@ -76,7 +77,7 @@ fileprivate func emitDiagnosticParts( newText.withUTF8 { textBuffer in SwiftDiagnostic_fixItReplace( diag, replaceStartLoc, replaceEndLoc, - textBuffer.baseAddress, textBuffer.count + textBuffer.baseAddress, SwiftInt(textBuffer.count) ) } } @@ -149,7 +150,7 @@ extension SourceManager { SwiftDiagnostic_create( cxxDiagnosticEngine, bridgedSeverity, cxxSourceLocation(for: node, at: position), - messageBuffer.baseAddress, messageBuffer.count + messageBuffer.baseAddress, SwiftInt(messageBuffer.count) ) } @@ -202,7 +203,7 @@ extension SourceManager { newText.withUTF8 { textBuffer in SwiftDiagnostic_fixItReplace( diag, replaceStartLoc, replaceEndLoc, - textBuffer.baseAddress, textBuffer.count + textBuffer.baseAddress, SwiftInt(textBuffer.count) ) } } diff --git a/lib/ASTGen/Sources/ASTGen/Exprs.swift b/lib/ASTGen/Sources/ASTGen/Exprs.swift index 38097c72cc218..b02ad452a37e6 100644 --- a/lib/ASTGen/Sources/ASTGen/Exprs.swift +++ b/lib/ASTGen/Sources/ASTGen/Exprs.swift @@ -1,4 +1,5 @@ import CASTBridging +import CBasicBridging import SwiftParser import SwiftSyntax @@ -34,7 +35,7 @@ extension ASTGenVisitor { var text = node.identifier.text let id = text.withUTF8 { buf in - return SwiftASTContext_getIdentifier(ctx, buf.baseAddress, buf.count) + return SwiftASTContext_getIdentifier(ctx, buf.baseAddress, SwiftInt(buf.count)) } return .expr(SwiftIdentifierExpr_create(ctx, id, loc)) @@ -45,7 +46,7 @@ extension ASTGenVisitor { var text = node.identifier.text let id = text.withUTF8 { buf in - return SwiftASTContext_getIdentifier(ctx, buf.baseAddress, buf.count) + return SwiftASTContext_getIdentifier(ctx, buf.baseAddress, SwiftInt(buf.count)) } return .expr(SwiftIdentifierExpr_create(ctx, id, loc)) @@ -56,7 +57,7 @@ extension ASTGenVisitor { let base = visit(node.base!).rawValue var nameText = node.name.text let name = nameText.withUTF8 { buf in - return SwiftASTContext_getIdentifier(ctx, buf.baseAddress, buf.count) + return SwiftASTContext_getIdentifier(ctx, buf.baseAddress, SwiftInt(buf.count)) } return .expr(UnresolvedDotExpr_create(ctx, base, loc, name, loc)) @@ -78,7 +79,7 @@ extension ASTGenVisitor { return nil } return name.withUTF8 { buf in - SwiftASTContext_getIdentifier(ctx, buf.baseAddress, buf.count) + SwiftASTContext_getIdentifier(ctx, buf.baseAddress, SwiftInt(buf.count)) } } let labelLocs: [UnsafeMutableRawPointer] = node.map { diff --git a/lib/ASTGen/Sources/ASTGen/Generics.swift b/lib/ASTGen/Sources/ASTGen/Generics.swift index 22163381143b0..4976560b85f91 100644 --- a/lib/ASTGen/Sources/ASTGen/Generics.swift +++ b/lib/ASTGen/Sources/ASTGen/Generics.swift @@ -1,4 +1,5 @@ import CASTBridging +import CBasicBridging import SwiftParser import SwiftSyntax @@ -18,7 +19,7 @@ extension ASTGenVisitor { func visit(_ node: GenericParameterSyntax) -> ASTNode { var nodeName = node.name.text let name = nodeName.withUTF8 { buf in - return SwiftASTContext_getIdentifier(ctx, buf.baseAddress, buf.count) + return SwiftASTContext_getIdentifier(ctx, buf.baseAddress, SwiftInt(buf.count)) } let nameLoc = self.base.advanced(by: node.name.position.utf8Offset).raw let eachLoc = node.each.map { self.base.advanced(by: $0.position.utf8Offset).raw } @@ -36,7 +37,7 @@ extension ASTGenVisitor { return .decl( GenericTypeParamDecl_create( - self.ctx, self.declContext, name, nameLoc, eachLoc, genericParameterIndex, + self.ctx, self.declContext, name, nameLoc, eachLoc, SwiftInt(genericParameterIndex), eachLoc != nil)) } } diff --git a/lib/ASTGen/Sources/ASTGen/Literals.swift b/lib/ASTGen/Sources/ASTGen/Literals.swift index 1653d09ac348d..c80eedf8ee1a2 100644 --- a/lib/ASTGen/Sources/ASTGen/Literals.swift +++ b/lib/ASTGen/Sources/ASTGen/Literals.swift @@ -1,4 +1,5 @@ import CASTBridging +import CBasicBridging import SwiftParser import SwiftSyntax @@ -8,7 +9,7 @@ extension ASTGenVisitor { var segment = node.segments.first!.as(StringSegmentSyntax.self)!.content.text return .expr( segment.withUTF8 { buf in - return SwiftStringLiteralExpr_create(ctx, buf.baseAddress, buf.count, loc) + return SwiftStringLiteralExpr_create(ctx, buf.baseAddress, SwiftInt(buf.count), loc) }) } @@ -17,7 +18,7 @@ extension ASTGenVisitor { var segment = node.digits.text return .expr( segment.withUTF8 { buf in - return SwiftIntegerLiteralExpr_create(ctx, buf.baseAddress, buf.count, loc) + return SwiftIntegerLiteralExpr_create(ctx, buf.baseAddress, SwiftInt(buf.count), loc) }) } diff --git a/lib/ASTGen/Sources/ASTGen/Macros.swift b/lib/ASTGen/Sources/ASTGen/Macros.swift index 4ee025884bd42..4ead5f21ecc98 100644 --- a/lib/ASTGen/Sources/ASTGen/Macros.swift +++ b/lib/ASTGen/Sources/ASTGen/Macros.swift @@ -167,6 +167,11 @@ func allocateUTF8String( } } +@_cdecl("swift_ASTGen_freeString") +public func freeString(pointer: UnsafePointer?) { + pointer?.deallocate() +} + /// Diagnostics produced here. enum ASTGenMacroDiagnostic: DiagnosticMessage, FixItMessage { case thrownError(Error) @@ -178,7 +183,11 @@ enum ASTGenMacroDiagnostic: DiagnosticMessage, FixItMessage { var message: String { switch self { case .thrownError(let error): - return String(describing: error) + if let err = error as? PluginError { + return err.description + } else { + return String(describing: error) + } case .oldStyleExternalMacro: return "external macro definitions are now written using #externalMacro" @@ -278,7 +287,7 @@ func checkMacroDefinition( if module == "Builtin" { switch type { case "ExternalMacro": - return BridgedMacroDefinitionKind.builtinExternalMacro.rawValue + return Int(BridgedMacroDefinitionKind.builtinExternalMacro.rawValue) default: // Warn about the unknown builtin. @@ -323,7 +332,7 @@ func checkMacroDefinition( ] ) ) - return BridgedMacroDefinitionKind.externalMacro.rawValue + return Int(BridgedMacroDefinitionKind.externalMacro.rawValue) case let .expansion(expansionSyntax, replacements: _) where expansionSyntax.macro.text == "externalMacro": @@ -362,7 +371,7 @@ func checkMacroDefinition( // Form the "ModuleName.TypeName" result string. (externalMacroPointer.pointee, externalMacroLength.pointee) = allocateUTF8String("\(module).\(type)", nullTerminated: true) - return BridgedMacroDefinitionKind.externalMacro.rawValue + return Int(BridgedMacroDefinitionKind.externalMacro.rawValue) case let .expansion(expansionSyntax, replacements: replacements): // Provide the expansion syntax. @@ -373,7 +382,7 @@ func checkMacroDefinition( // If there are no replacements, we're done. if replacements.isEmpty { - return BridgedMacroDefinitionKind.expandedMacro.rawValue + return Int(BridgedMacroDefinitionKind.expandedMacro.rawValue) } // The replacements are triples: (startOffset, endOffset, parameter index). @@ -388,7 +397,7 @@ func checkMacroDefinition( replacementsPtr.pointee = replacementBuffer.baseAddress numReplacementsPtr.pointee = replacements.count - return BridgedMacroDefinitionKind.expandedMacro.rawValue + return Int(BridgedMacroDefinitionKind.expandedMacro.rawValue) } } catch let errDiags as DiagnosticsError { let srcMgr = SourceManager(cxxDiagnosticEngine: diagEnginePtr) @@ -410,6 +419,14 @@ func checkMacroDefinition( } } +@_cdecl("swift_ASTGen_freeExpansionReplacements") +public func freeExpansionReplacements( + pointer: UnsafeMutablePointer?, + numReplacements: Int +) { + UnsafeMutableBufferPointer(start: pointer, count: numReplacements).deallocate() +} + // Make an expansion result for '@_cdecl' function caller. func makeExpansionOutputResult( expandedSource: String?, diff --git a/lib/ASTGen/Sources/ASTGen/Misc.swift b/lib/ASTGen/Sources/ASTGen/Misc.swift index bb63fd0b1b181..422821744e6b1 100644 --- a/lib/ASTGen/Sources/ASTGen/Misc.swift +++ b/lib/ASTGen/Sources/ASTGen/Misc.swift @@ -1,4 +1,5 @@ import CASTBridging +import CBasicBridging import SwiftParser import SwiftSyntax diff --git a/lib/ASTGen/Sources/ASTGen/PluginHost.swift b/lib/ASTGen/Sources/ASTGen/PluginHost.swift index 33a87ca898eb2..7edb51aaf0854 100644 --- a/lib/ASTGen/Sources/ASTGen/PluginHost.swift +++ b/lib/ASTGen/Sources/ASTGen/PluginHost.swift @@ -121,7 +121,7 @@ struct CompilerPlugin { private func sendMessage(_ message: HostToPluginMessage) throws { let hadError = try LLVMJSON.encoding(message) { (data) -> Bool in - return Plugin_sendMessage(opaqueHandle, BridgedData(baseAddress: data.baseAddress, size: UInt(data.count))) + return Plugin_sendMessage(opaqueHandle, BridgedData(baseAddress: data.baseAddress, size: SwiftUInt(data.count))) } if hadError { throw PluginError.failedToSendMessage @@ -277,7 +277,7 @@ class PluginDiagnosticsEngine { SwiftDiagnostic_create( cxxDiagnosticEngine, bridgedSeverity, cxxSourceLocation(at: position), - messageBuffer.baseAddress, messageBuffer.count) + messageBuffer.baseAddress, SwiftInt(messageBuffer.count)) } // Emit highlights @@ -296,7 +296,7 @@ class PluginDiagnosticsEngine { var newText = change.newText newText.withUTF8 { textBuffer in SwiftDiagnostic_fixItReplace( - diag, startLoc, endLoc, textBuffer.baseAddress, textBuffer.count) + diag, startLoc, endLoc, textBuffer.baseAddress, SwiftInt(textBuffer.count)) } } diff --git a/lib/ASTGen/Sources/ASTGen/SourceManager+MacroExpansionContext.swift b/lib/ASTGen/Sources/ASTGen/SourceManager+MacroExpansionContext.swift index 9f74cb212aa62..b42fbc6186d7d 100644 --- a/lib/ASTGen/Sources/ASTGen/SourceManager+MacroExpansionContext.swift +++ b/lib/ASTGen/Sources/ASTGen/SourceManager+MacroExpansionContext.swift @@ -43,7 +43,13 @@ extension String { /// Retrieve the base name of a string that represents a path, removing the /// directory. var basename: String { - guard let lastSlash = lastIndex(of: "/") else { + guard let lastSlash = lastIndex(where: { +#if os(iOS) || os(macOS) || os(tvOS) || os(watchOS) || os(Android) || os(Linux) + ["/"].contains($0) +#else + ["/", "\\"].contains($0) +#endif + }) else { return self } diff --git a/lib/ASTGen/Sources/ASTGen/Types.swift b/lib/ASTGen/Sources/ASTGen/Types.swift index eb2be48a8a89b..3bb73ef19d184 100644 --- a/lib/ASTGen/Sources/ASTGen/Types.swift +++ b/lib/ASTGen/Sources/ASTGen/Types.swift @@ -1,4 +1,5 @@ import CASTBridging +import CBasicBridging import SwiftParser import SwiftSyntax @@ -8,7 +9,7 @@ extension ASTGenVisitor { var text = node.name.text let id = text.withUTF8 { buf in - return SwiftASTContext_getIdentifier(ctx, buf.baseAddress, buf.count) + return SwiftASTContext_getIdentifier(ctx, buf.baseAddress, SwiftInt(buf.count)) } guard let generics = node.genericArgumentClause else { @@ -38,7 +39,7 @@ extension ASTGenVisitor { var nameText = nameToken.text let name = nameText.withUTF8 { buf in - return SwiftASTContext_getIdentifier(ctx, buf.baseAddress, buf.count) + return SwiftASTContext_getIdentifier(ctx, buf.baseAddress, SwiftInt(buf.count)) } let nameLoc = self.base.advanced(by: nameToken.position.utf8Offset).raw @@ -175,12 +176,12 @@ extension ASTGenVisitor { for element in elementList { var nameText = element.name?.text let name = nameText?.withUTF8 { buf in - return SwiftASTContext_getIdentifier(ctx, buf.baseAddress, buf.count) + return SwiftASTContext_getIdentifier(ctx, buf.baseAddress, SwiftInt(buf.count)) } let nameLoc = element.name.map { self.base.advanced(by: $0.position.utf8Offset).raw } var secondNameText = element.secondName?.text let secondName = secondNameText?.withUTF8 { buf in - return SwiftASTContext_getIdentifier(ctx, buf.baseAddress, buf.count) + return SwiftASTContext_getIdentifier(ctx, buf.baseAddress, SwiftInt(buf.count)) } let secondNameLoc = element.secondName.map { self.base.advanced(by: $0.position.utf8Offset).raw diff --git a/lib/ASTGen/Sources/LLVMJSON/LLVMJSON.swift b/lib/ASTGen/Sources/LLVMJSON/LLVMJSON.swift index c0b98123881d9..1ab7a991c5e43 100644 --- a/lib/ASTGen/Sources/LLVMJSON/LLVMJSON.swift +++ b/lib/ASTGen/Sources/LLVMJSON/LLVMJSON.swift @@ -41,7 +41,7 @@ public struct LLVMJSON { /// Decode a JSON data to a Swift value. public static func decode(_ type: T.Type, from json: UnsafeBufferPointer) throws -> T { - let data = BridgedData(baseAddress: json.baseAddress, size: UInt(json.count)) + let data = BridgedData(baseAddress: json.baseAddress, size: SwiftUInt(json.count)) let valuePtr = JSON_deserializedValue(data) defer { JSON_value_delete(valuePtr) } diff --git a/lib/Basic/Program.cpp b/lib/Basic/Program.cpp index 8c322f865a6fa..ac82fe52d4657 100644 --- a/lib/Basic/Program.cpp +++ b/lib/Basic/Program.cpp @@ -18,7 +18,11 @@ #include "llvm/Config/config.h" #include "llvm/Support/Allocator.h" #include "llvm/Support/Program.h" +#if defined(_WIN32) +#include "llvm/Support/Windows/WindowsSupport.h" +#endif +#include #include #if HAVE_POSIX_SPAWN @@ -29,6 +33,12 @@ #include #endif +#if defined(_WIN32) +#define WIN32_LEAN_AND_MEAN +#include +#include +#endif + using namespace swift; int swift::ExecuteInPlace(const char *Program, const char **args, @@ -175,7 +185,100 @@ swift::ExecuteWithPipe(llvm::StringRef program, #endif close(p1.read); close(p2.write); - return ChildProcessInfo(pid, p1.write, p2.read); + llvm::sys::ProcessInfo proc; + proc.Pid = pid; + return ChildProcessInfo(proc, p1.write, p2.read); +} + +#elif defined(_WIN32) + +llvm::ErrorOr +swift::ExecuteWithPipe(llvm::StringRef program, + llvm::ArrayRef args, + llvm::Optional> env) { + using unique_handle = std::unique_ptr; + enum { PI_READ, PI_WRITE }; + + unique_handle input[2] = { + {INVALID_HANDLE_VALUE, CloseHandle}, + {INVALID_HANDLE_VALUE, CloseHandle}, + }; + unique_handle output[2] = { + {INVALID_HANDLE_VALUE, CloseHandle}, + {INVALID_HANDLE_VALUE, CloseHandle}, + }; + unique_handle error{INVALID_HANDLE_VALUE, CloseHandle}; + HANDLE hRead = INVALID_HANDLE_VALUE, hWrite = INVALID_HANDLE_VALUE; + SECURITY_ATTRIBUTES saAttrs{sizeof(SECURITY_ATTRIBUTES), NULL, TRUE}; + + if (!CreatePipe(&hRead, &hWrite, &saAttrs, 0)) + return std::error_code(GetLastError(), std::system_category()); + output[PI_READ].reset(hRead); + output[PI_WRITE].reset(hWrite); + + if (!SetHandleInformation(output[PI_READ].get(), HANDLE_FLAG_INHERIT, FALSE)) + return std::error_code(GetLastError(), std::system_category()); + + if (!CreatePipe(&hRead, &hWrite, &saAttrs, 0)) + return std::error_code(GetLastError(), std::system_category()); + input[PI_READ].reset(hRead); + input[PI_WRITE].reset(hWrite); + + if (!SetHandleInformation(input[PI_WRITE].get(), HANDLE_FLAG_INHERIT, FALSE)) + return std::error_code(GetLastError(), std::system_category()); + + if (!DuplicateHandle(GetCurrentProcess(), GetStdHandle(STD_ERROR_HANDLE), + GetCurrentProcess(), &hWrite, DUPLICATE_SAME_ACCESS, + TRUE, DUPLICATE_SAME_ACCESS)) + return std::error_code(GetLastError(), std::system_category()); + error.reset(hWrite); + + STARTUPINFO si = {0}; + si.cb = sizeof(si); + si.hStdInput = input[PI_READ].get(); + si.hStdOutput = output[PI_WRITE].get(); + si.hStdError = error.get(); + si.dwFlags = STARTF_USESTDHANDLES; + + llvm::SmallVector executable; + if (std::error_code ec = llvm::sys::windows::widenPath(program, executable)) + return ec; + + std::vector components; + components.push_back(program); + components.assign(args.begin(), args.end()); + llvm::ErrorOr commandline = + llvm::sys::flattenWindowsCommandLine(components); + if (!commandline) + return commandline.getError(); + + std::vector command(commandline->size() + 1, 0); + std::copy(commandline->begin(), commandline->end(), command.begin()); + + PROCESS_INFORMATION pi = {0}; + if (!CreateProcessW(executable.data(), + command.data(), nullptr, nullptr, TRUE, 0, nullptr, + nullptr, &si, &pi)) + return std::error_code(GetLastError(), std::system_category()); + + unique_handle hThread{pi.hThread, CloseHandle}; + unique_handle hProcess{pi.hProcess, CloseHandle}; + + int ifd = _open_osfhandle(reinterpret_cast(input[PI_WRITE].get()), 0); + if (ifd < 0) + return std::error_code(errno, std::system_category()); + input[PI_WRITE].release(); + + int ofd = _open_osfhandle(reinterpret_cast(output[PI_READ].get()), 0); + if (ofd < 0) { + _close(ifd); + return std::error_code(errno, std::system_category()); + } + output[PI_READ].release(); + + llvm::sys::ProcessInfo proc; + proc.Process = pi.hProcess; + return ChildProcessInfo(proc, ifd, ofd); } #else // HAVE_UNISTD_H diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 846d165345b56..7d61c18522a1c 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -43,12 +43,18 @@ if (SWIFT_SWIFT_PARSER) # Determine the SwiftSyntax shared library files that were built as # part of earlyswiftsyntax. - list(TRANSFORM SWIFT_SYNTAX_MODULES PREPEND ${CMAKE_SHARED_LIBRARY_PREFIX} + list(TRANSFORM SWIFT_SYNTAX_MODULES PREPEND "${CMAKE_SHARED_LIBRARY_PREFIX}" OUTPUT_VARIABLE SWIFT_SYNTAX_SHARED_LIBRARIES) list(TRANSFORM SWIFT_SYNTAX_SHARED_LIBRARIES APPEND - ${CMAKE_SHARED_LIBRARY_SUFFIX} + "${CMAKE_SHARED_LIBRARY_SUFFIX}" OUTPUT_VARIABLE SWIFT_SYNTAX_SHARED_LIBRARIES) + list(TRANSFORM SWIFT_SYNTAX_MODULES PREPEND "${CMAKE_IMPORT_LIBRARY_PREFIX}" + OUTPUT_VARIABLE SWIFT_SYNTAX_IMPORT_LIBRARIES) + list(TRANSFORM SWIFT_SYNTAX_IMPORT_LIBRARIES APPEND + "${CMAKE_IMPORT_LIBRARY_SUFFIX}" OUTPUT_VARIABLE + SWIFT_SYNTAX_IMPORT_LIBRARIES) + # Interface library to collect swiftinterfaces and swiftmodules from # SwiftSyntax add_library(swiftSyntaxLibraries INTERFACE) @@ -67,27 +73,47 @@ if (SWIFT_SWIFT_PARSER) ) endif() - add_custom_command( - OUTPUT "${SWIFT_HOST_LIBRARIES_DEST_DIR}/${sharedlib}" - DEPENDS "${SWIFT_SYNTAX_LIBRARIES_BUILD_DIR}/${sharedlib}" - COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SWIFT_SYNTAX_LIBRARIES_BUILD_DIR}/${sharedlib} ${SWIFT_HOST_LIBRARIES_DEST_DIR}/${sharedlib} - ${add_origin_rpath} - ) - - add_custom_target(copy_swiftSyntaxLibrary_${sharedlib} - DEPENDS "${SWIFT_HOST_LIBRARIES_DEST_DIR}/${sharedlib}" - COMMENT "Copying ${sharedlib}" - ) - - swift_install_in_component( - PROGRAMS "${SWIFT_HOST_LIBRARIES_DEST_DIR}/${sharedlib}" - DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/host" - COMPONENT compiler - ) + if(CMAKE_SYSTEM_NAME MATCHES Windows) + add_custom_command(OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${sharedlib} + DEPENDS "${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR}/bin/${sharedlib}" + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR}/bin/${sharedlib} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${sharedlib}) + add_custom_target(copy_swiftSyntaxLibrary_${sharedlib} + DEPENDS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${sharedlib} + COMMENT "copying ${sharedlib}") + swift_install_in_component(PROGRAMS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${sharedlib} + DESTINATION bin + COMPONENT compiler) + else() + add_custom_command(OUTPUT "${SWIFT_HOST_LIBRARIES_DEST_DIR}/${sharedlib}" + DEPENDS "${SWIFT_SYNTAX_LIBRARIES_BUILD_DIR}/${sharedlib}" + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SWIFT_SYNTAX_LIBRARIES_BUILD_DIR}/${sharedlib} ${SWIFT_HOST_LIBRARIES_DEST_DIR}/${sharedlib} + ${add_origin_rpath}) + add_custom_target(copy_swiftSyntaxLibrary_${sharedlib} + DEPENDS "${SWIFT_HOST_LIBRARIES_DEST_DIR}/${sharedlib}" + COMMENT "Copying ${sharedlib}") + swift_install_in_component(PROGRAMS "${SWIFT_HOST_LIBRARIES_DEST_DIR}/${sharedlib}" + DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/host" + COMPONENT compiler) + endif() add_dependencies(swiftSyntaxLibraries copy_swiftSyntaxLibrary_${sharedlib}) endforeach() + if(CMAKE_SYSTEM_NAME MATCHES Windows) + foreach(implib ${SWIFT_SYNTAX_IMPORT_LIBRARIES}) + add_custom_command(OUTPUT ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/swift/windows/${SWIFT_HOST_VARIANT_ARCH}/${implib} + DEPENDS ${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR}/lib/swift/host/${implib} + COMMAND "${CMAKE_COMMAND}" -E copy_if_different ${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR}/lib/swift/host/${implib} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/swift/windows/${SWIFT_HOST_VARIANT_ARCH}/${implib}) + add_custom_target(copy_swiftSyntaxLibrary_${implib} + DEPENDS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/swift/windows/${SWIFT_HOST_VARIANT_ARCH}/${implib} + COMMENT "Copying ${implib}") + swift_install_in_component(PROGRAMS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/swift/windows/${SWIFT_HOST_VARIANT_ARCH}/${implib} + DESTINATION lib + COMPONENT compiler) + add_dependencies(swiftSyntaxLibraries copy_swiftSyntaxLibrary_${implib}) + endforeach() + endif() + # Copy all of the Swift modules from earlyswiftsyntax so they can be found # in the same relative place within the build directory as in the final # toolchain. diff --git a/lib/Driver/DarwinToolChains.cpp b/lib/Driver/DarwinToolChains.cpp index a06f1cc77d0b0..9dc66f83a6ead 100644 --- a/lib/Driver/DarwinToolChains.cpp +++ b/lib/Driver/DarwinToolChains.cpp @@ -24,6 +24,7 @@ #include "swift/Driver/Compilation.h" #include "swift/Driver/Driver.h" #include "swift/Driver/Job.h" +#include "swift/IDETool/CompilerInvocation.h" #include "swift/Option/Options.h" #include "clang/Basic/DarwinSDKInfo.h" #include "clang/Basic/Version.h" @@ -123,6 +124,31 @@ std::string toolchains::Darwin::sanitizerRuntimeLibName(StringRef Sanitizer, .str(); } +void +toolchains::Darwin::addPluginArguments(const ArgList &Args, + ArgStringList &Arguments) const { + SmallString<64> pluginPath; + auto programPath = getDriver().getSwiftProgramPath(); + CompilerInvocation::computeRuntimeResourcePathFromExecutablePath( + programPath, /*shared=*/true, pluginPath); + + auto defaultPluginPath = pluginPath; + llvm::sys::path::append(defaultPluginPath, "host", "plugins"); + + // Default plugin path. + Arguments.push_back("-plugin-path"); + Arguments.push_back(Args.MakeArgString(defaultPluginPath)); + + // Local plugin path. + llvm::sys::path::remove_filename(pluginPath); // Remove "swift" + llvm::sys::path::remove_filename(pluginPath); // Remove "lib" + llvm::sys::path::append(pluginPath, "local", "lib"); + llvm::sys::path::append(pluginPath, "swift"); + llvm::sys::path::append(pluginPath, "host", "plugins"); + Arguments.push_back("-plugin-path"); + Arguments.push_back(Args.MakeArgString(pluginPath)); +} + static void addLinkRuntimeLibRPath(const ArgList &Args, ArgStringList &Arguments, StringRef DarwinLibName, diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp index e232a46962a9c..a290cc5e1d27b 100644 --- a/lib/Driver/ToolChains.cpp +++ b/lib/Driver/ToolChains.cpp @@ -376,30 +376,8 @@ void ToolChain::addCommonFrontendArgs(const OutputInfo &OI, // options. inputArgs.AddAllArgs(arguments, options::OPT_plugin_search_Group); addPlatformSpecificPluginFrontendArgs(OI, output, inputArgs, arguments); - - // Toolchain-relative plugin paths - { - SmallString<64> pluginPath; - auto programPath = getDriver().getSwiftProgramPath(); - CompilerInvocation::computeRuntimeResourcePathFromExecutablePath( - programPath, /*shared=*/true, pluginPath); - auto defaultPluginPath = pluginPath; - llvm::sys::path::append(defaultPluginPath, "host", "plugins"); - - // Default plugin path. - arguments.push_back("-plugin-path"); - arguments.push_back(inputArgs.MakeArgString(defaultPluginPath)); - - // Local plugin path. - llvm::sys::path::remove_filename(pluginPath); // Remove "swift" - llvm::sys::path::remove_filename(pluginPath); // Remove "lib" - llvm::sys::path::append(pluginPath, "local", "lib"); - llvm::sys::path::append(pluginPath, "swift"); - llvm::sys::path::append(pluginPath, "host", "plugins"); - arguments.push_back("-plugin-path"); - arguments.push_back(inputArgs.MakeArgString(pluginPath)); - } + addPluginArguments(inputArgs, arguments); // Pass through any subsystem flags. inputArgs.AddAllArgs(arguments, options::OPT_Xllvm); diff --git a/lib/Driver/ToolChains.h b/lib/Driver/ToolChains.h index c552d6b81246e..a7aab90990a1d 100644 --- a/lib/Driver/ToolChains.h +++ b/lib/Driver/ToolChains.h @@ -65,7 +65,10 @@ class LLVM_LIBRARY_VISIBILITY Darwin : public ToolChain { const JobContext &context) const override; InvocationInfo constructInvocation(const StaticLinkJobAction &job, const JobContext &context) const override; - + + void addPluginArguments(const llvm::opt::ArgList &Args, + llvm::opt::ArgStringList &Arguments) const override; + void validateArguments(DiagnosticEngine &diags, const llvm::opt::ArgList &args, StringRef defaultTarget) const override; @@ -113,8 +116,12 @@ class LLVM_LIBRARY_VISIBILITY Windows : public ToolChain { public: Windows(const Driver &D, const llvm::Triple &Triple) : ToolChain(D, Triple) {} ~Windows() = default; + std::string sanitizerRuntimeLibName(StringRef Sanitizer, bool shared = true) const override; + + void addPluginArguments(const llvm::opt::ArgList &Args, + llvm::opt::ArgStringList &Arguments) const override; }; class LLVM_LIBRARY_VISIBILITY WebAssembly : public ToolChain { @@ -168,6 +175,9 @@ class LLVM_LIBRARY_VISIBILITY GenericUnix : public ToolChain { ~GenericUnix() = default; std::string sanitizerRuntimeLibName(StringRef Sanitizer, bool shared = true) const override; + + void addPluginArguments(const llvm::opt::ArgList &Args, + llvm::opt::ArgStringList &Arguments) const override; }; class LLVM_LIBRARY_VISIBILITY Android : public GenericUnix { diff --git a/lib/Driver/UnixToolChains.cpp b/lib/Driver/UnixToolChains.cpp index 389afb821dd61..61498c144a28b 100644 --- a/lib/Driver/UnixToolChains.cpp +++ b/lib/Driver/UnixToolChains.cpp @@ -21,6 +21,7 @@ #include "swift/Driver/Compilation.h" #include "swift/Driver/Driver.h" #include "swift/Driver/Job.h" +#include "swift/IDETool/CompilerInvocation.h" #include "swift/Option/Options.h" #include "swift/Option/SanitizerOptions.h" #include "clang/Basic/Version.h" @@ -47,6 +48,31 @@ toolchains::GenericUnix::sanitizerRuntimeLibName(StringRef Sanitizer, .str(); } +void +toolchains::GenericUnix::addPluginArguments(const ArgList &Args, + ArgStringList &Arguments) const { + SmallString<64> pluginPath; + auto programPath = getDriver().getSwiftProgramPath(); + CompilerInvocation::computeRuntimeResourcePathFromExecutablePath( + programPath, /*shared=*/true, pluginPath); + + auto defaultPluginPath = pluginPath; + llvm::sys::path::append(defaultPluginPath, "host", "plugins"); + + // Default plugin path. + Arguments.push_back("-plugin-path"); + Arguments.push_back(Args.MakeArgString(defaultPluginPath)); + + // Local plugin path. + llvm::sys::path::remove_filename(pluginPath); // Remove "swift" + llvm::sys::path::remove_filename(pluginPath); // Remove "lib" + llvm::sys::path::append(pluginPath, "local", "lib"); + llvm::sys::path::append(pluginPath, "swift"); + llvm::sys::path::append(pluginPath, "host", "plugins"); + Arguments.push_back("-plugin-path"); + Arguments.push_back(Args.MakeArgString(pluginPath)); +} + ToolChain::InvocationInfo toolchains::GenericUnix::constructInvocation(const InterpretJobAction &job, const JobContext &context) const { diff --git a/lib/Driver/WindowsToolChains.cpp b/lib/Driver/WindowsToolChains.cpp index 5001fa33fd2a5..481daa7ba3640 100644 --- a/lib/Driver/WindowsToolChains.cpp +++ b/lib/Driver/WindowsToolChains.cpp @@ -44,6 +44,17 @@ std::string toolchains::Windows::sanitizerRuntimeLibName(StringRef Sanitizer, .str(); } +void +toolchains::Windows::addPluginArguments(const ArgList &Args, + ArgStringList &Arguments) const { + SmallString<261> LibraryPath = StringRef(getDriver().getSwiftProgramPath()); + llvm::sys::path::remove_filename(LibraryPath); // Remove `swift` + + // Default plugin path. + Arguments.push_back("-plugin-path"); + Arguments.push_back(Args.MakeArgString(LibraryPath)); +} + ToolChain::InvocationInfo toolchains::Windows::constructInvocation(const DynamicLinkJobAction &job, const JobContext &context) const { diff --git a/lib/Sema/TypeCheckMacros.cpp b/lib/Sema/TypeCheckMacros.cpp index 07eeebbc10baf..385dac2818162 100644 --- a/lib/Sema/TypeCheckMacros.cpp +++ b/lib/Sema/TypeCheckMacros.cpp @@ -49,6 +49,8 @@ using namespace swift; extern "C" void *swift_ASTGen_resolveMacroType(const void *macroType); extern "C" void swift_ASTGen_destroyMacro(void *macro); +extern "C" void swift_ASTGen_freeString(const char *str); + extern "C" void *swift_ASTGen_resolveExecutableMacro( const char *moduleName, ptrdiff_t moduleNameLength, const char *typeName, ptrdiff_t typeNameLength, @@ -64,6 +66,9 @@ extern "C" ptrdiff_t swift_ASTGen_checkMacroDefinition( ptrdiff_t **replacementsPtr, ptrdiff_t *numReplacements ); +extern "C" void swift_ASTGen_freeExpansionReplacements( + ptrdiff_t *replacementsPtr, + ptrdiff_t numReplacements); extern "C" ptrdiff_t swift_ASTGen_expandFreestandingMacro( void *diagEngine, void *macro, uint8_t externalKind, @@ -197,8 +202,8 @@ MacroDefinition MacroDefinitionRequest::evaluate( // Clean up after the call. SWIFT_DEFER { - free(externalMacroNamePtr); - free(replacements); + swift_ASTGen_freeString(externalMacroNamePtr); + swift_ASTGen_freeExpansionReplacements(replacements, numReplacements); }; if (checkResult < 0 && ctx.CompletionCallback) { @@ -1054,7 +1059,7 @@ evaluateFreestandingMacro(FreestandingMacroExpansion *expansion, evaluatedSource = llvm::MemoryBuffer::getMemBufferCopy( {evaluatedSourceAddress, (size_t)evaluatedSourceLength}, adjustMacroExpansionBufferName(*discriminator)); - free((void *)evaluatedSourceAddress); + swift_ASTGen_freeString(evaluatedSourceAddress); break; #else ctx.Diags.diagnose(loc, diag::macro_unsupported); @@ -1333,7 +1338,7 @@ static SourceFile *evaluateAttachedMacro(MacroDecl *macro, Decl *attachedTo, evaluatedSource = llvm::MemoryBuffer::getMemBufferCopy( {evaluatedSourceAddress, (size_t)evaluatedSourceLength}, adjustMacroExpansionBufferName(*discriminator)); - free((void *)evaluatedSourceAddress); + swift_ASTGen_freeString(evaluatedSourceAddress); break; #else attachedTo->diagnose(diag::macro_unsupported); diff --git a/stdlib/public/SwiftShims/swift/shims/SwiftStdint.h b/stdlib/public/SwiftShims/swift/shims/SwiftStdint.h index 7b83e90d72799..cd8d808cbd6a2 100644 --- a/stdlib/public/SwiftShims/swift/shims/SwiftStdint.h +++ b/stdlib/public/SwiftShims/swift/shims/SwiftStdint.h @@ -71,12 +71,12 @@ typedef unsigned __INT8_TYPE__ __swift_uint8_t; #define __swift_uintn_t(n) __swift_join3(__swift_uint, n, _t) #if defined(_MSC_VER) && !defined(__clang__) -#if defined(_WIN32) -typedef __swift_int32_t __swift_intptr_t; -typedef __swift_uint32_t __swift_uintptr_t; -#elif defined(_WIN64) +#if defined(_WIN64) typedef __swift_int64_t __swift_intptr_t; typedef __swift_uint64_t __swift_uintptr_t; +#elif defined(_WIN32) +typedef __swift_int32_t __swift_intptr_t; +typedef __swift_uint32_t __swift_uintptr_t; #else #error unknown windows pointer width #endif diff --git a/stdlib/public/stubs/LibcShims.cpp b/stdlib/public/stubs/LibcShims.cpp index 4c6e29e2a64b3..0350c515503bd 100644 --- a/stdlib/public/stubs/LibcShims.cpp +++ b/stdlib/public/stubs/LibcShims.cpp @@ -22,6 +22,7 @@ #endif #include +#include #include "swift/shims/LibcShims.h" diff --git a/test/ClangImporter/pch-bridging-header-deps-fine.swift b/test/ClangImporter/pch-bridging-header-deps-fine.swift index 4f21828ba3d32..4dbb1fea1812c 100644 --- a/test/ClangImporter/pch-bridging-header-deps-fine.swift +++ b/test/ClangImporter/pch-bridging-header-deps-fine.swift @@ -1,30 +1,26 @@ -// REQUIRES: shell -// Also uses awk: -// XFAIL OS=windows - // RUN: rm -f %t.* -// + // Generate a bridging PCH, use it in a swift file, and check that the swift file's .swiftdeps // mention the .h the PCH was generated from, and any .h files included in it. -// + // RUN: %target-swift-frontend -emit-pch -o %t.pch %/S/Inputs/chained-unit-test-bridging-header-to-pch.h // RUN: %target-swift-frontend -module-name test -c -emit-dependencies-path %t.d -emit-reference-dependencies-path %t.swiftdeps -primary-file %s -import-objc-header %t.pch // RUN: %FileCheck --check-prefix CHECK-DEPS %s < %t.d -// RUN: %S/../Inputs/process_fine_grained_swiftdeps.sh %swift-dependency-tool %t.swiftdeps %t-processed.swiftdeps +// RUN: %{python} %S/../Inputs/process_fine_grained_swiftdeps.py %swift-dependency-tool %t.swiftdeps > %t-processed.swiftdeps // RUN: %FileCheck --check-prefix CHECK-SWIFTDEPS --enable-yaml-compatibility %s < %t-processed.swiftdeps // RUN: %FileCheck --check-prefix CHECK-SWIFTDEPS2 --enable-yaml-compatibility %s < %t-processed.swiftdeps // RUN: %target-swift-frontend -module-name test -c -emit-dependencies-path %t.persistent.d -emit-reference-dependencies-path %t.persistent.swiftdeps -primary-file %s -import-objc-header %/S/Inputs/chained-unit-test-bridging-header-to-pch.h -pch-output-dir %t/pch // RUN: %FileCheck --check-prefix CHECK-DEPS %s < %t.persistent.d -// RUN: %S/../Inputs/process_fine_grained_swiftdeps.sh %swift-dependency-tool %t.persistent.swiftdeps %t-processed.persistent.swiftdeps +// RUN: %{python} %S/../Inputs/process_fine_grained_swiftdeps.py %swift-dependency-tool %t.persistent.swiftdeps > %t-processed.persistent.swiftdeps // RUN: %FileCheck --check-prefix CHECK-SWIFTDEPS --enable-yaml-compatibility %s < %t-processed.persistent.swiftdeps // RUN: %FileCheck --check-prefix CHECK-SWIFTDEPS2 --enable-yaml-compatibility %s < %t-processed.persistent.swiftdeps print(app_function(1)) -// CHECK-DEPS: pch-bridging-header-deps-fine.o : {{.*}}SOURCE_DIR{{/|\\}}test{{/|\\}}ClangImporter{{/|\\}}Inputs{{/|\\}}app-bridging-header-to-pch.h {{.*}}SOURCE_DIR{{/|\\}}test{{/|\\}}ClangImporter{{/|\\}}Inputs{{/|\\}}chained-unit-test-bridging-header-to-pch.h +// CHECK-DEPS: pch-bridging-header-deps-fine.o : {{.*}}{{/|\\}}test{{/|\\}}ClangImporter{{/|\\}}Inputs{{/|\\}}app-bridging-header-to-pch.h {{.*}}{{/|\\}}test{{/|\\}}ClangImporter{{/|\\}}Inputs{{/|\\}}chained-unit-test-bridging-header-to-pch.h -// CHECK-SWIFTDEPS: externalDepend {{.*}} 'SOURCE_DIR{{/|\\\\}}test{{/|\\\\}}ClangImporter{{/|\\\\}}Inputs{{/|\\\\}}app-bridging-header-to-pch.h' -// CHECK-SWIFTDEPS: externalDepend {{.*}} 'SOURCE_DIR{{/|\\\\}}test{{/|\\\\}}ClangImporter{{/|\\\\}}Inputs{{/|\\\\}}chained-unit-test-bridging-header-to-pch.h' +// CHECK-SWIFTDEPS: externalDepend {{.*}} '{{.*}}{{/|\\}}test{{/|\\}}ClangImporter{{/|\\}}Inputs{{/|\\}}app-bridging-header-to-pch.h' +// CHECK-SWIFTDEPS: externalDepend {{.*}} '{{.*}}{{/|\\}}test{{/|\\}}ClangImporter{{/|\\}}Inputs{{/|\\}}chained-unit-test-bridging-header-to-pch.h' // CHECK-SWIFTDEPS2-NOT: {{.*}}.pch diff --git a/test/Driver/windows-link-job.swift b/test/Driver/windows-link-job.swift index eb2cb06891a73..78fe8873b0ac2 100644 --- a/test/Driver/windows-link-job.swift +++ b/test/Driver/windows-link-job.swift @@ -1,10 +1,11 @@ // RUN: %empty-directory(%t/DISTINCTIVE-WINDOWS-PATH/usr/bin) // RUN: %empty-directory(%t/DISTINCTIVE-WINDOWS-PATH/usr/lib) // RUN: %hardlink-or-copy(from: %swift_frontend_plain, to: %t/DISTINCTIVE-WINDOWS-PATH/usr/bin/swiftc) -// RUN: %host-library-env PATH= %t/DISTINCTIVE-WINDOWS-PATH/usr/bin/swiftc -target x86_64-unknown-windows-msvc -### -module-name link -emit-library %s 2>&1 | %FileCheck %s +// RUN: env PATH= %t/DISTINCTIVE-WINDOWS-PATH/usr/bin/swiftc -target x86_64-unknown-windows-msvc -### -module-name link -emit-library %s 2>&1 | %FileCheck %s // swift-frontend cannot be copied to another location with bootstrapping because // it will not find the libswiftCore library with its relative RPATH. // UNSUPPORTED: swift_in_compiler +// UNSUPPORTED: swift_swift_parser // CHECK: {{^}}clang diff --git a/test/Frontend/dependencies-fine.swift b/test/Frontend/dependencies-fine.swift index f7256e925cfb0..e540d1b59f5f2 100644 --- a/test/Frontend/dependencies-fine.swift +++ b/test/Frontend/dependencies-fine.swift @@ -1,17 +1,13 @@ -// REQUIRES: shell -// Also uses awk: -// XFAIL OS=windows - // RUN: %empty-directory(%t) // RUN: %target-swift-frontend -emit-dependencies-path - -resolve-imports "%S/../Inputs/empty file.swift" | %FileCheck -check-prefix=CHECK-BASIC %s // RUN: %target-swift-frontend -emit-reference-dependencies-path - -typecheck -primary-file "%S/../Inputs/empty file.swift" > %t.swiftdeps -// RUN: %S/../Inputs/process_fine_grained_swiftdeps.sh %swift-dependency-tool %t.swiftdeps %t-processed.swiftdeps +// RUN: %{python} %S/../Inputs/process_fine_grained_swiftdeps.py %swift-dependency-tool %t.swiftdeps > %t-processed.swiftdeps // RUN: %FileCheck -check-prefix=CHECK-BASIC-YAML %s <%t-processed.swiftdeps // RUN: %target-swift-frontend -emit-dependencies-path %t.d -emit-reference-dependencies-path %t.swiftdeps -typecheck -primary-file "%S/../Inputs/empty file.swift" // RUN: %FileCheck -check-prefix=CHECK-BASIC %s < %t.d -// RUN: %S/../Inputs/process_fine_grained_swiftdeps.sh %swift-dependency-tool %t.swiftdeps %t-processed.swiftdeps +// RUN: %{python} %S/../Inputs/process_fine_grained_swiftdeps.py %swift-dependency-tool %t.swiftdeps > %t-processed.swiftdeps // RUN: %FileCheck -check-prefix=CHECK-BASIC-YAML %s < %t-processed.swiftdeps // CHECK-BASIC-LABEL: - : @@ -20,7 +16,7 @@ // CHECK-BASIC-NOT: {{ }}:{{ }} // CHECK-BASIC-YAML-NOT: externalDepend {{.*}}empty -// CHECK-BASIC-YAML: externalDepend {{.*}} '{{.*}}Swift.swiftmodule{{(/.+[.]swiftmodule)?}}' +// CHECK-BASIC-YAML: externalDepend {{.*}} '{{.*}}Swift.swiftmodule{{/|\\}}{{(.+[.]swiftmodule)?}}' // RUN: %target-swift-frontend -emit-dependencies-path %t.d -emit-reference-dependencies-path %t.swiftdeps -typecheck "%S/../Inputs/empty file.swift" 2>&1 | %FileCheck -check-prefix=NO-PRIMARY-FILE %s @@ -48,7 +44,7 @@ // RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-objc-interop -disable-objc-attr-requires-foundation-module -import-objc-header %S/Inputs/dependencies/extra-header.h -track-system-dependencies -emit-dependencies-path - -resolve-imports %s | %FileCheck -check-prefix=CHECK-IMPORT-TRACK-SYSTEM %s // RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-objc-interop -disable-objc-attr-requires-foundation-module -import-objc-header %S/Inputs/dependencies/extra-header.h -emit-reference-dependencies-path %t.swiftdeps -typecheck -primary-file %s -// RUN: %S/../Inputs/process_fine_grained_swiftdeps.sh %swift-dependency-tool %t.swiftdeps %t-processed.swiftdeps +// RUN: %{python} %S/../Inputs/process_fine_grained_swiftdeps.py %swift-dependency-tool %t.swiftdeps > %t-processed.swiftdeps // RUN: %FileCheck -check-prefix=CHECK-IMPORT-YAML %s <%t-processed.swiftdeps // CHECK-IMPORT-LABEL: - : @@ -87,14 +83,14 @@ // CHECK-IMPORT-TRACK-SYSTEM-NOT: {{[^\\]}}: // CHECK-IMPORT-YAML-NOT: externalDepend {{.*}}dependencies-fine.swift -// CHECK-IMPORT-YAML-DAG: externalDepend {{.*}} '{{.*}}{{/|\\}}Swift.swiftmodule{{(/.+[.]swiftmodule)?}}' +// CHECK-IMPORT-YAML-DAG: externalDepend {{.*}} '{{.*}}{{/|\\}}Swift.swiftmodule{{/|\\}}{{(.+[.]swiftmodule)?}}' // CHECK-IMPORT-YAML-DAG: externalDepend {{.*}} '{{.*}}Inputs/dependencies/$$$$$.h' -// CHECK-IMPORT-YAML-DAG: externalDepend {{.*}} '{{.*}}Inputs/dependencies{{/|\\\\}}UserClangModule.h' +// CHECK-IMPORT-YAML-DAG: externalDepend {{.*}} '{{.*}}Inputs/dependencies{{/|\\}}UserClangModule.h' // CHECK-IMPORT-YAML-DAG: externalDepend {{.*}} '{{.*}}Inputs/dependencies/extra-header.h' -// CHECK-IMPORT-YAML-DAG: externalDepend {{.*}} '{{.*}}Inputs/dependencies{{/|\\\\}}module.modulemap' -// CHECK-IMPORT-YAML-DAG: externalDepend {{.*}} '{{.*}}{{/|\\\\}}ObjectiveC.swift' -// CHECK-IMPORT-YAML-DAG: externalDepend {{.*}} '{{.*}}{{/|\\\\}}Foundation.swift' -// CHECK-IMPORT-YAML-DAG: externalDepend {{.*}} '{{.*}}{{/|\\\\}}CoreGraphics.swift' +// CHECK-IMPORT-YAML-DAG: externalDepend {{.*}} '{{.*}}Inputs/dependencies{{/|\\}}module.modulemap' +// CHECK-IMPORT-YAML-DAG: externalDepend {{.*}} '{{.*}}{{/|\\}}ObjectiveC.swift' +// CHECK-IMPORT-YAML-DAG: externalDepend {{.*}} '{{.*}}{{/|\\}}Foundation.swift' +// CHECK-IMPORT-YAML-DAG: externalDepend {{.*}} '{{.*}}{{/|\\}}CoreGraphics.swift' // CHECK-ERROR-YAML: # Dependencies are unknown because a compilation error occurred. diff --git a/test/Frontend/dependencies-preservation-fine.swift b/test/Frontend/dependencies-preservation-fine.swift index 4e2a29865a789..ab54154aeba37 100644 --- a/test/Frontend/dependencies-preservation-fine.swift +++ b/test/Frontend/dependencies-preservation-fine.swift @@ -1,7 +1,3 @@ -// REQUIRES: shell -// Also uses awk: -// XFAIL OS=windows - // This test verifies that copies of dependency files are preserved after a // compilation. For example, if the first compilation produces 'foo.swiftdeps', // a second compilation should move 'foo.swiftdeps' to 'foo.swiftdeps~', then @@ -11,7 +7,7 @@ // First, produce the dependency files and verify their contents. // RUN: %target-swift-frontend -emit-reference-dependencies-path %t.swiftdeps -typecheck -primary-file "%S/../Inputs/empty file.swift" -// RUN: %S/../Inputs/process_fine_grained_swiftdeps.sh %swift-dependency-tool %t.swiftdeps %t-processed.swiftdeps +// RUN: %{python} %S/../Inputs/process_fine_grained_swiftdeps.py %swift-dependency-tool %t.swiftdeps > %t-processed.swiftdeps // RUN: %FileCheck -check-prefix=CHECK %s < %t-processed.swiftdeps // CHECK-NOT: topLevel{{.*}}EmptyStruct{{.*}}true @@ -22,7 +18,7 @@ // file. // RUN: %target-swift-frontend -emit-reference-dependencies-path %t.swiftdeps -typecheck -primary-file %S/../Inputs/global_resilience.swift // RUN: %FileCheck -check-prefix=CHECK %s < %t.swiftdeps~ -// RUN: %S/../Inputs/process_fine_grained_swiftdeps.sh %swift-dependency-tool %t.swiftdeps %t-processed.swiftdeps +// RUN: %{python} %S/../Inputs/process_fine_grained_swiftdeps.py %swift-dependency-tool %t.swiftdeps > %t-processed.swiftdeps // RUN: %FileCheck -check-prefix=CHECK-OVERWRITTEN %s < %t-processed.swiftdeps // CHECK-OVERWRITTEN:topLevel{{.*}}EmptyStruct{{.*}}true diff --git a/test/IDE/complete_optionset.swift b/test/IDE/complete_optionset.swift index 271e618324efd..fd3917c37e2d4 100644 --- a/test/IDE/complete_optionset.swift +++ b/test/IDE/complete_optionset.swift @@ -1,6 +1,7 @@ -// REQUIRES: swift_swift_parser // RUN: %empty-directory(%t) -// RUN: %target-swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t -plugin-path %swift-host-lib-dir/plugins +// RUN: %target-swift-ide-test -batch-code-completion -source-filename %s -filecheck %raw-FileCheck -completion-output-dir %t -plugin-path %swift-plugin-dir + +// REQUIRES: swift_swift_parser @OptionSet struct ShippingOptions { diff --git a/test/Incremental/Dependencies/function-fine.swift b/test/Incremental/Dependencies/function-fine.swift index e72ab6f29cc53..42cf0b00f9f24 100644 --- a/test/Incremental/Dependencies/function-fine.swift +++ b/test/Incremental/Dependencies/function-fine.swift @@ -1,13 +1,9 @@ -// REQUIRES: shell -// Also uses awk: -// XFAIL OS=windows - // RUN: %target-swift-frontend -emit-silgen -primary-file %s %S/Inputs/InterestingType.swift -DOLD -emit-reference-dependencies-path %t.swiftdeps -module-name main | %FileCheck %s -check-prefix=CHECK-OLD -// RUN: %S/../../Inputs/process_fine_grained_swiftdeps.sh %swift-dependency-tool %t.swiftdeps %t-processed.swiftdeps +// RUN: %{python} %S/../../Inputs/process_fine_grained_swiftdeps.py %swift-dependency-tool %t.swiftdeps > %t-processed.swiftdeps // RUN: %FileCheck -check-prefix=CHECK-DEPS %s < %t-processed.swiftdeps // RUN: %target-swift-frontend -emit-silgen -primary-file %s %S/Inputs/InterestingType.swift -DNEW -emit-reference-dependencies-path %t.swiftdeps -module-name main | %FileCheck %s -check-prefix=CHECK-NEW -// RUN: %S/../../Inputs/process_fine_grained_swiftdeps.sh %swift-dependency-tool %t.swiftdeps %t-processed.swiftdeps +// RUN: %{python} %S/../../Inputs/process_fine_grained_swiftdeps.py %swift-dependency-tool %t.swiftdeps > %t-processed.swiftdeps // RUN: %FileCheck -check-prefix=CHECK-DEPS %s < %t-processed.swiftdeps private func testParamType(_: InterestingType) {} diff --git a/test/Incremental/Dependencies/function-return-type-fine.swift b/test/Incremental/Dependencies/function-return-type-fine.swift index f9ffb1d4f3c90..0852a9b06dc3a 100644 --- a/test/Incremental/Dependencies/function-return-type-fine.swift +++ b/test/Incremental/Dependencies/function-return-type-fine.swift @@ -1,13 +1,9 @@ -// REQUIRES: shell -// Also uses awk: -// XFAIL OS=windows - // RUN: %target-swift-frontend -emit-silgen -primary-file %s %S/Inputs/InterestingType.swift -DOLD -emit-reference-dependencies-path %t.swiftdeps -module-name main | %FileCheck %s -check-prefix=CHECK-OLD -// RUN: %S/../../Inputs/process_fine_grained_swiftdeps.sh %swift-dependency-tool %t.swiftdeps %t-processed.swiftdeps +// RUN: %{python} %S/../../Inputs/process_fine_grained_swiftdeps.py %swift-dependency-tool %t.swiftdeps > %t-processed.swiftdeps // RUN: %FileCheck -check-prefix=CHECK-DEPS %s < %t-processed.swiftdeps // RUN: %target-swift-frontend -emit-silgen -primary-file %s %S/Inputs/InterestingType.swift -DNEW -emit-reference-dependencies-path %t.swiftdeps -module-name main | %FileCheck %s -check-prefix=CHECK-NEW -// RUN: %S/../../Inputs/process_fine_grained_swiftdeps.sh %swift-dependency-tool %t.swiftdeps %t-processed.swiftdeps +// RUN: %{python} %S/../../Inputs/process_fine_grained_swiftdeps.py %swift-dependency-tool %t.swiftdeps > %t-processed.swiftdeps // RUN: %FileCheck -check-prefix=CHECK-DEPS %s < %t-processed.swiftdeps private func testReturnType() -> InterestingType { fatalError() } diff --git a/test/Incremental/Dependencies/protocol-conformer-ext-fine.swift b/test/Incremental/Dependencies/protocol-conformer-ext-fine.swift index 49330bda51a75..53b3ea9745d9e 100644 --- a/test/Incremental/Dependencies/protocol-conformer-ext-fine.swift +++ b/test/Incremental/Dependencies/protocol-conformer-ext-fine.swift @@ -1,13 +1,9 @@ -// REQUIRES: shell -// Also uses awk: -// XFAIL OS=windows - // RUN: %target-swift-frontend -emit-silgen -primary-file %s %S/Inputs/InterestingType.swift -DOLD -emit-reference-dependencies-path %t.swiftdeps -module-name main | %FileCheck %s -check-prefix=CHECK-OLD -// RUN: %S/../../Inputs/process_fine_grained_swiftdeps.sh %swift-dependency-tool %t.swiftdeps %t-processed.swiftdeps +// RUN: %{python} %S/../../Inputs/process_fine_grained_swiftdeps.py %swift-dependency-tool %t.swiftdeps > %t-processed.swiftdeps // RUN: %FileCheck -check-prefix=CHECK-DEPS %s < %t-processed.swiftdeps // RUN: %target-swift-frontend -emit-silgen -primary-file %s %S/Inputs/InterestingType.swift -DNEW -emit-reference-dependencies-path %t.swiftdeps -module-name main | %FileCheck %s -check-prefix=CHECK-NEW -// RUN: %S/../../Inputs/process_fine_grained_swiftdeps.sh %swift-dependency-tool %t.swiftdeps %t-processed.swiftdeps +// RUN: %{python} %S/../../Inputs/process_fine_grained_swiftdeps.py %swift-dependency-tool %t.swiftdeps > %t-processed.swiftdeps // RUN: %FileCheck -check-prefix=CHECK-DEPS %s < %t-processed.swiftdeps private struct Test {} diff --git a/test/Incremental/Dependencies/protocol-conformer-fine.swift b/test/Incremental/Dependencies/protocol-conformer-fine.swift index 9642793aee895..f73f340739dae 100644 --- a/test/Incremental/Dependencies/protocol-conformer-fine.swift +++ b/test/Incremental/Dependencies/protocol-conformer-fine.swift @@ -1,13 +1,9 @@ -// REQUIRES: shell -// Also uses awk: -// XFAIL OS=windows - // RUN: %target-swift-frontend -emit-silgen -primary-file %s %S/Inputs/InterestingType.swift -DOLD -emit-reference-dependencies-path %t.swiftdeps -module-name main | %FileCheck %s -check-prefix=CHECK-OLD -// RUN: %S/../../Inputs/process_fine_grained_swiftdeps.sh %swift-dependency-tool %t.swiftdeps %t-processed.swiftdeps +// RUN: %{python} %S/../../Inputs/process_fine_grained_swiftdeps.py %swift-dependency-tool %t.swiftdeps > %t-processed.swiftdeps // RUN: %FileCheck -check-prefix=CHECK-DEPS %s < %t-processed.swiftdeps // RUN: %target-swift-frontend -emit-silgen -primary-file %s %S/Inputs/InterestingType.swift -DNEW -emit-reference-dependencies-path %t.swiftdeps -module-name main | %FileCheck %s -check-prefix=CHECK-NEW -// RUN: %S/../../Inputs/process_fine_grained_swiftdeps.sh %swift-dependency-tool %t.swiftdeps %t-processed.swiftdeps +// RUN: %{python} %S/../../Inputs/process_fine_grained_swiftdeps.py %swift-dependency-tool %t.swiftdeps > %t-processed.swiftdeps // RUN: %FileCheck -check-prefix=CHECK-DEPS %s < %t-processed.swiftdeps private struct Test : InterestingProto {} diff --git a/test/Incremental/Dependencies/reference-dependencies-dynamic-lookup-fine.swift b/test/Incremental/Dependencies/reference-dependencies-dynamic-lookup-fine.swift index 3c0c74e79c9eb..2d24d68b8d1c1 100644 --- a/test/Incremental/Dependencies/reference-dependencies-dynamic-lookup-fine.swift +++ b/test/Incremental/Dependencies/reference-dependencies-dynamic-lookup-fine.swift @@ -1,15 +1,11 @@ -// REQUIRES: shell -// Also uses awk: -// XFAIL OS=windows - // RUN: %empty-directory(%t) // RUN: cp %s %t/main.swift // RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -primary-file %t/main.swift -emit-reference-dependencies-path - > %t.swiftdeps // Check that the output is deterministic. // RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -primary-file %t/main.swift -emit-reference-dependencies-path - > %t-2.swiftdeps -// RUN: %S/../../Inputs/process_fine_grained_swiftdeps.sh %swift-dependency-tool %t.swiftdeps %t-processed.swiftdeps -// RUN: %S/../../Inputs/process_fine_grained_swiftdeps.sh %swift-dependency-tool %t-2.swiftdeps %t-2-processed.swiftdeps +// RUN: %{python} %S/../../Inputs/process_fine_grained_swiftdeps.py %swift-dependency-tool %t.swiftdeps > %t-processed.swiftdeps +// RUN: %{python} %S/../../Inputs/process_fine_grained_swiftdeps.py %swift-dependency-tool %t-2.swiftdeps > %t-2-processed.swiftdeps // RUN: diff %t-processed.swiftdeps %t-2-processed.swiftdeps // RUN: %FileCheck %s < %t-processed.swiftdeps diff --git a/test/Incremental/Dependencies/reference-dependencies-fine.swift b/test/Incremental/Dependencies/reference-dependencies-fine.swift index e2fba6628bf13..1081e31a7f309 100644 --- a/test/Incremental/Dependencies/reference-dependencies-fine.swift +++ b/test/Incremental/Dependencies/reference-dependencies-fine.swift @@ -1,7 +1,3 @@ -// REQUIRES: shell -// Also uses awk: -// XFAIL OS=windows - // RUN: %empty-directory(%t) // RUN: cp %s %t/main.swift @@ -10,8 +6,8 @@ // RUN: %target-swift-frontend -typecheck -primary-file %t/main.swift %S/../Inputs/reference-dependencies-helper.swift -emit-reference-dependencies-path - > %t-2.swiftdeps // Merge each entry onto one line and sort to overcome order differences -// RUN: %S/../../Inputs/process_fine_grained_swiftdeps.sh %swift-dependency-tool %t.swiftdeps %t-processed.swiftdeps -// RUN: %S/../../Inputs/process_fine_grained_swiftdeps.sh %swift-dependency-tool %t-2.swiftdeps %t-2-processed.swiftdeps +// RUN: %{python} %S/../../Inputs/process_fine_grained_swiftdeps.py %swift-dependency-tool %t.swiftdeps > %t-processed.swiftdeps +// RUN: %{python} %S/../../Inputs/process_fine_grained_swiftdeps.py %swift-dependency-tool %t-2.swiftdeps > %t-2-processed.swiftdeps // RUN: diff %t-processed.swiftdeps %t-2-processed.swiftdeps // RUN: %FileCheck -check-prefix=NEGATIVE %s < %t-processed.swiftdeps diff --git a/test/Incremental/Dependencies/reference-dependencies-members-fine.swift b/test/Incremental/Dependencies/reference-dependencies-members-fine.swift index 0fec187e1d91d..bfe167373208d 100644 --- a/test/Incremental/Dependencies/reference-dependencies-members-fine.swift +++ b/test/Incremental/Dependencies/reference-dependencies-members-fine.swift @@ -1,15 +1,11 @@ -// REQUIRES: shell -// Also uses awk: -// XFAIL OS=windows - // RUN: %empty-directory(%t) // RUN: cp %s %t/main.swift // RUN: %target-swift-frontend -typecheck -primary-file %t/main.swift %S/../Inputs/reference-dependencies-members-helper.swift -emit-reference-dependencies-path - > %t.swiftdeps // RUN: %target-swift-frontend -typecheck -primary-file %t/main.swift %S/../Inputs/reference-dependencies-members-helper.swift -emit-reference-dependencies-path - > %t-2.swiftdeps -// RUN: %S/../../Inputs/process_fine_grained_swiftdeps.sh %swift-dependency-tool %t.swiftdeps %t-processed.swiftdeps -// RUN: %S/../../Inputs/process_fine_grained_swiftdeps.sh %swift-dependency-tool %t-2.swiftdeps %t-2-processed.swiftdeps +// RUN: %{python} %S/../../Inputs/process_fine_grained_swiftdeps.py %swift-dependency-tool %t.swiftdeps > %t-processed.swiftdeps +// RUN: %{python} %S/../../Inputs/process_fine_grained_swiftdeps.py %swift-dependency-tool %t-2.swiftdeps > %t-2-processed.swiftdeps // RUN: diff %t-processed.swiftdeps %t-2-processed.swiftdeps diff --git a/test/Incremental/Dependencies/struct-member-fine.swift b/test/Incremental/Dependencies/struct-member-fine.swift index 629d5e4ed3b10..b723c68989f5e 100644 --- a/test/Incremental/Dependencies/struct-member-fine.swift +++ b/test/Incremental/Dependencies/struct-member-fine.swift @@ -1,13 +1,9 @@ -// REQUIRES: shell -// Also uses awk: -// XFAIL OS=windows - // RUN: %target-swift-frontend -emit-silgen -primary-file %s %S/Inputs/InterestingType.swift -DOLD -emit-reference-dependencies-path %t.swiftdeps -module-name main | %FileCheck %s -check-prefix=CHECK-OLD -// RUN: %S/../../Inputs/process_fine_grained_swiftdeps.sh %swift-dependency-tool %t.swiftdeps %t-processed.swiftdeps +// RUN: %{python} %S/../../Inputs/process_fine_grained_swiftdeps.py %swift-dependency-tool %t.swiftdeps > %t-processed.swiftdeps // RUN: %FileCheck -check-prefix=CHECK-DEPS %s < %t-processed.swiftdeps // RUN: %target-swift-frontend -emit-silgen -primary-file %s %S/Inputs/InterestingType.swift -DNEW -emit-reference-dependencies-path %t.swiftdeps -module-name main | %FileCheck %s -check-prefix=CHECK-NEW -// RUN: %S/../../Inputs/process_fine_grained_swiftdeps.sh %swift-dependency-tool %t.swiftdeps %t-processed.swiftdeps +// RUN: %{python} %S/../../Inputs/process_fine_grained_swiftdeps.py %swift-dependency-tool %t.swiftdeps > %t-processed.swiftdeps // RUN: %FileCheck -check-prefix=CHECK-DEPS %s < %t-processed.swiftdeps private struct Wrapper { diff --git a/test/Incremental/Dependencies/subscript-fine.swift b/test/Incremental/Dependencies/subscript-fine.swift index 8907034198080..994a4bd61cfe1 100644 --- a/test/Incremental/Dependencies/subscript-fine.swift +++ b/test/Incremental/Dependencies/subscript-fine.swift @@ -1,13 +1,9 @@ -// REQUIRES: shell -// Also uses awk: -// XFAIL OS=windows - // RUN: %target-swift-frontend -emit-silgen -primary-file %s %S/Inputs/InterestingType.swift -DOLD -emit-reference-dependencies-path %t.swiftdeps -module-name main | %FileCheck %s -check-prefix=CHECK-OLD -// RUN: %S/../../Inputs/process_fine_grained_swiftdeps.sh %swift-dependency-tool %t.swiftdeps %t-processed.swiftdeps +// RUN: %{python} %S/../../Inputs/process_fine_grained_swiftdeps.py %swift-dependency-tool %t.swiftdeps > %t-processed.swiftdeps // RUN: %FileCheck -check-prefix=CHECK-DEPS %s < %t-processed.swiftdeps // RUN: %target-swift-frontend -emit-silgen -primary-file %s %S/Inputs/InterestingType.swift -DNEW -emit-reference-dependencies-path %t.swiftdeps -module-name main | %FileCheck %s -check-prefix=CHECK-NEW -// RUN: %S/../../Inputs/process_fine_grained_swiftdeps.sh %swift-dependency-tool %t.swiftdeps %t-processed.swiftdeps +// RUN: %{python} %S/../../Inputs/process_fine_grained_swiftdeps.py %swift-dependency-tool %t.swiftdeps > %t-processed.swiftdeps // RUN: %FileCheck -check-prefix=CHECK-DEPS %s < %t-processed.swiftdeps struct Wrapper { diff --git a/test/Incremental/Dependencies/typealias-fine.swift b/test/Incremental/Dependencies/typealias-fine.swift index b9e27e265b69f..af140c8605b83 100644 --- a/test/Incremental/Dependencies/typealias-fine.swift +++ b/test/Incremental/Dependencies/typealias-fine.swift @@ -1,13 +1,9 @@ -// REQUIRES: shell -// Also uses awk: -// XFAIL OS=windows - // RUN: %target-swift-frontend -emit-silgen -primary-file %s %S/Inputs/InterestingType.swift -DOLD -emit-reference-dependencies-path %t.swiftdeps -module-name main | %FileCheck %s -check-prefix=CHECK-OLD -// RUN: %S/../../Inputs/process_fine_grained_swiftdeps.sh %swift-dependency-tool %t.swiftdeps %t-processed.swiftdeps +// RUN: %{python} %S/../../Inputs/process_fine_grained_swiftdeps.py %swift-dependency-tool %t.swiftdeps > %t-processed.swiftdeps // RUN: %FileCheck -check-prefix=CHECK-DEPS %s < %t-processed.swiftdeps // RUN: %target-swift-frontend -emit-silgen -primary-file %s %S/Inputs/InterestingType.swift -DNEW -emit-reference-dependencies-path %t.swiftdeps -module-name main | %FileCheck %s -check-prefix=CHECK-NEW -// RUN: %S/../../Inputs/process_fine_grained_swiftdeps.sh %swift-dependency-tool %t.swiftdeps %t-processed.swiftdeps +// RUN: %{python} %S/../../Inputs/process_fine_grained_swiftdeps.py %swift-dependency-tool %t.swiftdeps > %t-processed.swiftdeps // RUN: %FileCheck -check-prefix=CHECK-DEPS %s < %t-processed.swiftdeps private struct Wrapper { diff --git a/test/Incremental/Dependencies/var-fine.swift b/test/Incremental/Dependencies/var-fine.swift index 89aafb9452132..90b1d75a83bd1 100644 --- a/test/Incremental/Dependencies/var-fine.swift +++ b/test/Incremental/Dependencies/var-fine.swift @@ -1,10 +1,6 @@ -// REQUIRES: shell -// Also uses awk: -// XFAIL OS=windows - // RUN: %target-swift-frontend -emit-silgen -primary-file %s %S/Inputs/InterestingType.swift -DOLD -emit-reference-dependencies-path %t.swiftdeps -module-name main | %FileCheck %s -check-prefix=CHECK-OLD -// RUN: %S/../../Inputs/process_fine_grained_swiftdeps.sh %swift-dependency-tool %t.swiftdeps %t-processed.swiftdeps +// RUN: %{python} %S/../../Inputs/process_fine_grained_swiftdeps.py %swift-dependency-tool %t.swiftdeps > %t-processed.swiftdeps // RUN: %FileCheck -check-prefix=CHECK-DEPS %s < %t-processed.swiftdeps diff --git a/test/Inputs/process_fine_grained_swiftdeps.py b/test/Inputs/process_fine_grained_swiftdeps.py new file mode 100644 index 0000000000000..5396d68c2aadb --- /dev/null +++ b/test/Inputs/process_fine_grained_swiftdeps.py @@ -0,0 +1,36 @@ + +import subprocess +import sys + +# Fine-grained swiftdeps files use multiple lines for each graph node. +# Compress such a file so that each entry is one line of the form: +# +# Also sort for consistency, since the node order can vary. + +output = subprocess.run( + [ + sys.argv[1], + "--to-yaml", + "--input-filename={}".format(sys.argv[2]), + "--output-filename=-", + ], + stdout=subprocess.PIPE, +) +entries = [] +k = a = c = n = s = p = "" +for line in output.stdout.decode("utf-8").split("\n"): + if "kind:" in line: + k = line.split()[1] + if "aspect:" in line: + a = line.split()[1] + if "context:" in line: + c = line.split()[1] + if "name:" in line: + n = ' '.join(line.split()[1:]) + if "sequenceNumber:" in line: + s = line.split()[1] + if "isProvides:" in line: + p = line.split()[1] + entries.append(' '.join([k, a, c, n, p])) +entries.sort() +print("\n".join(entries)) diff --git a/test/Inputs/process_fine_grained_swiftdeps.sh b/test/Inputs/process_fine_grained_swiftdeps.sh deleted file mode 100755 index fb91c3875e95e..0000000000000 --- a/test/Inputs/process_fine_grained_swiftdeps.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env sh -# Fine-grained swiftdeps files use multiple lines for each graph node. -# Compress such a file so that each entry is one line of the form: -# -# Also sort for consistency, since the node order can vary. - -${1} --to-yaml --input-filename=${2} --output-filename=${3}.tmp - -awk '/kind:/ {k = $2}; /aspect:/ {a = $2}; /context:/ {c = $2}; /name/ {n = $2}; /sequenceNumber/ {s = $2}; /isProvides:/ {print k, a, c, n, $2}' < ${3}.tmp | sort > ${3} \ No newline at end of file diff --git a/test/Macros/lit.local.cfg b/test/Macros/lit.local.cfg index 521ceea67705e..1ae3d3a80fb24 100644 --- a/test/Macros/lit.local.cfg +++ b/test/Macros/lit.local.cfg @@ -1,3 +1,30 @@ # '-enable-experimental-feature Macros' requires an asserts build. if 'asserts' not in config.available_features: config.unsupported = True + +config.subsitutions = list(config.substitutions) + +def get_target_os(): + import re + (run_cpu, run_vendor, run_os, run_version) = re.match('([^-]+)-([^-]+)-([^0-9]+)(.*)', config.variant_triple).groups() + return run_os + +if get_target_os() in ['windows-msvc']: + config.substitutions.insert(0, ('%target-abi', 'WIN')) + config.substitutions.insert( + 0, + ( + '%swift-build-cxx-plugin', + '%clang -isysroot %host_sdk -I %swift_src_root/include -L %swift-lib-dir -l_swiftMockPlugin' + ) + ) +else: + # FIXME(compnerd) do all the targets we currently support use SysV ABI? + config.substitutions.insert(0, ('%target-abi', 'SYSV')) + config.substitutions.insert( + 0, + ( + '%swift-build-cxx-plugin', + '%clang -isysroot %host_sdk -I %swift_src_root/include -L %swift-lib-dir -l_swiftMockPlugin -Xlinker -rpath -Xlinker %swift-lib-dir' + ) + ) diff --git a/test/Macros/macro_expand.swift b/test/Macros/macro_expand.swift index 0ed70ec49448d..1e98a656e5db3 100644 --- a/test/Macros/macro_expand.swift +++ b/test/Macros/macro_expand.swift @@ -1,7 +1,7 @@ // REQUIRES: swift_swift_parser, executable_test // RUN: %empty-directory(%t) -// RUN: %host-build-swift -swift-version 5 -emit-library -o %t/%target-library-name(MacroDefinition) -module-name=MacroDefinition %S/Inputs/syntax_macro_definitions.swift -g -no-toolchain-stdlib-rpath -swift-version 5 +// RUN: %host-build-swift -swift-version 5 -emit-library -o %t/%target-library-name(MacroDefinition) -module-name=MacroDefinition %S/Inputs/syntax_macro_definitions.swift // Diagnostics testing // RUN: %target-typecheck-verify-swift -swift-version 5 -load-plugin-library %t/%target-library-name(MacroDefinition) -module-name MacroUser -DTEST_DIAGNOSTICS diff --git a/test/Macros/macro_expand_other.swift b/test/Macros/macro_expand_other.swift index d6c21f7e0f3f2..cac2ca04f9983 100644 --- a/test/Macros/macro_expand_other.swift +++ b/test/Macros/macro_expand_other.swift @@ -1,15 +1,16 @@ // Expanding macros that are defined in terms of other macros. // RUN: %empty-directory(%t) -// RUN: %host-build-swift -swift-version 5 -emit-library -o %t/%target-library-name(MacroDefinition) -parse-as-library -module-name=MacroDefinition %S/Inputs/syntax_macro_definitions.swift -g -no-toolchain-stdlib-rpath +// RUN: %host-build-swift -swift-version 5 -emit-library -o %t/%target-library-name(MacroDefinition) -parse-as-library -module-name=MacroDefinition %S/Inputs/syntax_macro_definitions.swift // Diagnostics testing -// RUN: %target-typecheck-verify-swift -swift-version 5 -load-plugin-library %t/%target-library-name(MacroDefinition) -I %swift-host-lib-dir -module-name MacroUser -DTEST_DIAGNOSTICS +// RUN: %target-typecheck-verify-swift -swift-version 5 -load-plugin-library %t/%target-library-name(MacroDefinition) -module-name MacroUser -DTEST_DIAGNOSTICS // Execution testing -// RUN: %target-build-swift -swift-version 5 -load-plugin-library %t/%target-library-name(MacroDefinition) -I %swift-host-lib-dir -L %swift-host-lib-dir %s -o %t/main -module-name MacroUser +// RUN: %target-build-swift -swift-version 5 -load-plugin-library %t/%target-library-name(MacroDefinition) %s -o %t/main -module-name MacroUser // RUN: %target-codesign %t/main // RUN: %target-run %t/main | %FileCheck %s + // REQUIRES: swift_swift_parser, executable_test @freestanding(expression) macro stringify(_ value: T) -> (T, String) = #externalMacro(module: "MacroDefinition", type: "StringifyMacro") diff --git a/test/Macros/macro_plugin_basic.swift b/test/Macros/macro_plugin_basic.swift index 1280c11f937a1..6bcfa7a89d264 100644 --- a/test/Macros/macro_plugin_basic.swift +++ b/test/Macros/macro_plugin_basic.swift @@ -3,30 +3,24 @@ // RUN: %empty-directory(%t) // RUN: split-file %s %t -// RUN: %clang \ -// RUN: -isysroot %host_sdk \ -// RUN: -I %swift_src_root/include \ -// RUN: -L %swift-lib-dir -l_swiftMockPlugin \ -// RUN: -Wl,-rpath,%swift-lib-dir \ -// RUN: -o %t/mock-plugin \ -// RUN: %t/plugin.c +// RUN: %swift-build-cxx-plugin -o %t/mock-plugin %t/plugin.c -// RUN: SWIFT_DUMP_PLUGIN_MESSAGING=1 %swift-target-frontend \ +// RUN: env SWIFT_DUMP_PLUGIN_MESSAGING=1 %swift-target-frontend \ // RUN: -typecheck -verify \ // RUN: -swift-version 5 \ // RUN: -load-plugin-executable %t/mock-plugin#TestPlugin \ // RUN: -module-name MyApp \ // RUN: %t/test.swift \ -// RUN: 2>&1 | tee %t/macro-expansions.txt +// RUN: > %t/macro-expansions.txt 2>&1 // RUN: %FileCheck -strict-whitespace %s < %t/macro-expansions.txt // CHECK: ->(plugin:[[#PID:]]) {"getCapability":{"capability":{"protocolVersion":[[#PROTOCOL_VERSION:]]}}} // CHECK: <-(plugin:[[#PID]]) {"getCapabilityResult":{"capability":{"protocolVersion":1}}} -// CHECK: ->(plugin:[[#PID]]) {"expandFreestandingMacro":{"discriminator":"$s{{.+}}","macro":{"moduleName":"TestPlugin","name":"testString","typeName":"TestStringMacro"},"macroRole":"expression","syntax":{"kind":"expression","location":{"column":19,"fileID":"MyApp/test.swift","fileName":"BUILD_DIR{{.+}}test.swift","line":5,"offset":301},"source":"#testString(123)"}}} +// CHECK: ->(plugin:[[#PID]]) {"expandFreestandingMacro":{"discriminator":"$s{{.+}}","macro":{"moduleName":"TestPlugin","name":"testString","typeName":"TestStringMacro"},"macroRole":"expression","syntax":{"kind":"expression","location":{"column":19,"fileID":"MyApp/test.swift","fileName":"{{.+}}test.swift","line":5,"offset":301},"source":"#testString(123)"}}} // CHECK: <-(plugin:[[#PID]]) {"expandFreestandingMacroResult":{"diagnostics":[],"expandedSource":"\"123\"\n + \"foo \""}} -// CHECK: ->(plugin:[[#PID]]) {"expandFreestandingMacro":{"discriminator":"$s{{.+}}","macro":{"moduleName":"TestPlugin","name":"testStringWithError","typeName":"TestStringWithErrorMacro"},"macroRole":"expression","syntax":{"kind":"expression","location":{"column":19,"fileID":"MyApp/test.swift","fileName":"BUILD_DIR{{.+}}test.swift","line":6,"offset":336},"source":"#testStringWithError(321)"}}} -// CHECK: <-(plugin:[[#PID]]) {"expandFreestandingMacroResult":{"diagnostics":[{"fixIts":[],"highlights":[],"message":"message from plugin","notes":[],"position":{"fileName":"BUILD_DIR{{.*}}test.swift","offset":336},"severity":"error"}],"expandedSource":"\"bar\""}} +// CHECK: ->(plugin:[[#PID]]) {"expandFreestandingMacro":{"discriminator":"$s{{.+}}","macro":{"moduleName":"TestPlugin","name":"testStringWithError","typeName":"TestStringWithErrorMacro"},"macroRole":"expression","syntax":{"kind":"expression","location":{"column":19,"fileID":"MyApp/test.swift","fileName":"{{.+}}test.swift","line":6,"offset":336},"source":"#testStringWithError(321)"}}} +// CHECK: <-(plugin:[[#PID]]) {"expandFreestandingMacroResult":{"diagnostics":[{"fixIts":[],"highlights":[],"message":"message from plugin","notes":[],"position":{"fileName":"{{.*}}test.swift","offset":336},"severity":"error"}],"expandedSource":"\"bar\""}} //--- test.swift @freestanding(expression) macro testString(_: Any) -> String = #externalMacro(module: "TestPlugin", type: "TestStringMacro") diff --git a/test/Macros/macro_plugin_broken.swift b/test/Macros/macro_plugin_broken.swift index 6ec89f4050ffb..cd20d18a96c83 100644 --- a/test/Macros/macro_plugin_broken.swift +++ b/test/Macros/macro_plugin_broken.swift @@ -6,8 +6,7 @@ // RUN: %host-build-swift \ // RUN: -swift-version 5 -o %t/broken-plugin \ // RUN: -module-name=TestPlugin \ -// RUN: %t/broken_plugin.swift \ -// RUN: -g -no-toolchain-stdlib-rpath -swift-version 5 +// RUN: %t/broken_plugin.swift // RUN: not %swift-target-frontend \ // RUN: -typecheck \ diff --git a/test/Macros/macro_plugin_error.swift b/test/Macros/macro_plugin_error.swift index ebab709d4798c..e50edef4dc89b 100644 --- a/test/Macros/macro_plugin_error.swift +++ b/test/Macros/macro_plugin_error.swift @@ -3,34 +3,28 @@ // RUN: %empty-directory(%t) // RUN: split-file %s %t -// RUN: %clang \ -// RUN: -isysroot %host_sdk \ -// RUN: -I %swift_src_root/include \ -// RUN: -L %swift-lib-dir -l_swiftMockPlugin \ -// RUN: -Wl,-rpath,%swift-lib-dir \ -// RUN: -o %t/mock-plugin \ -// RUN: %t/plugin.c +// RUN: %swift-build-cxx-plugin -o %t/mock-plugin %t/plugin.c -// RUN: SWIFT_DUMP_PLUGIN_MESSAGING=1 %swift-target-frontend \ +// RUN: env SWIFT_DUMP_PLUGIN_MESSAGING=1 %swift-target-frontend \ // RUN: -typecheck -verify \ // RUN: -swift-version 5 -enable-experimental-feature Macros \ // RUN: -load-plugin-executable %t/mock-plugin#TestPlugin \ // RUN: -module-name MyApp \ // RUN: %t/test.swift \ -// RUN: 2>&1 | tee %t/macro-expansions.txt +// RUN: > %t/macro-expansions.txt 2>&1 // RUN: %FileCheck -strict-whitespace %s < %t/macro-expansions.txt // CHECK: ->(plugin:[[#PID1:]]) {"getCapability":{"capability":{"protocolVersion":[[#PROTOCOL_VERSION:]]}}} // CHECK-NEXT: <-(plugin:[[#PID1]]) {"getCapabilityResult":{"capability":{"protocolVersion":1}}} -// CHECK-NEXT: ->(plugin:[[#PID1]]) {"expandFreestandingMacro":{"discriminator":"$s{{.+}}","macro":{"moduleName":"TestPlugin","name":"fooMacro","typeName":"FooMacro"},"macroRole":"expression","syntax":{"kind":"expression","location":{"column":19,"fileID":"MyApp/test.swift","fileName":"BUILD_DIR{{.+}}test.swift","line":6,"offset":[[#]]},"source":"#fooMacro(1)"}}} +// CHECK-NEXT: ->(plugin:[[#PID1]]) {"expandFreestandingMacro":{"discriminator":"$s{{.+}}","macro":{"moduleName":"TestPlugin","name":"fooMacro","typeName":"FooMacro"},"macroRole":"expression","syntax":{"kind":"expression","location":{"column":19,"fileID":"MyApp/test.swift","fileName":"{{.+}}test.swift","line":6,"offset":[[#]]},"source":"#fooMacro(1)"}}} // CHECK-NEXT: <-(plugin:[[#PID1]]) {"invalidResponse":{}} -// CHECK-NEXT: ->(plugin:[[#PID1]]) {"expandFreestandingMacro":{"discriminator":"$s{{.+}}","macro":{"moduleName":"TestPlugin","name":"fooMacro","typeName":"FooMacro"},"macroRole":"expression","syntax":{"kind":"expression","location":{"column":19,"fileID":"MyApp/test.swift","fileName":"BUILD_DIR{{.+}}test.swift","line":8,"offset":[[#]]},"source":"#fooMacro(2)"}}} +// CHECK-NEXT: ->(plugin:[[#PID1]]) {"expandFreestandingMacro":{"discriminator":"$s{{.+}}","macro":{"moduleName":"TestPlugin","name":"fooMacro","typeName":"FooMacro"},"macroRole":"expression","syntax":{"kind":"expression","location":{"column":19,"fileID":"MyApp/test.swift","fileName":"{{.+}}test.swift","line":8,"offset":[[#]]},"source":"#fooMacro(2)"}}} // ^ This messages causes the mock plugin exit because there's no matching expected message. // CHECK: ->(plugin:[[#PID2:]]) {"getCapability":{"capability":{"protocolVersion":[[#PROTOCOL_VERSION]]}}} // CHECK-NEXT: <-(plugin:[[#PID2]]) {"getCapabilityResult":{"capability":{"protocolVersion":1}}} -// CHECK-NEXT: ->(plugin:[[#PID2]]) {"expandFreestandingMacro":{"discriminator":"$s{{.+}}","macro":{"moduleName":"TestPlugin","name":"fooMacro","typeName":"FooMacro"},"macroRole":"expression","syntax":{"kind":"expression","location":{"column":19,"fileID":"MyApp/test.swift","fileName":"BUILD_DIR{{.+}}test.swift","line":10,"offset":[[#]]},"source":"#fooMacro(3)"}}} +// CHECK-NEXT: ->(plugin:[[#PID2]]) {"expandFreestandingMacro":{"discriminator":"$s{{.+}}","macro":{"moduleName":"TestPlugin","name":"fooMacro","typeName":"FooMacro"},"macroRole":"expression","syntax":{"kind":"expression","location":{"column":19,"fileID":"MyApp/test.swift","fileName":"{{.+}}test.swift","line":10,"offset":[[#]]},"source":"#fooMacro(3)"}}} // CHECK-NEXT: <-(plugin:[[#PID2:]]) {"expandFreestandingMacroResult":{"diagnostics":[],"expandedSource":"3.description"}} //--- test.swift diff --git a/test/Macros/macro_plugin_searchorder.swift b/test/Macros/macro_plugin_searchorder.swift index 562144fa86b48..2373e09c95ac2 100644 --- a/test/Macros/macro_plugin_searchorder.swift +++ b/test/Macros/macro_plugin_searchorder.swift @@ -18,8 +18,7 @@ // RUN: -emit-library -o %t/lib/plugins/%target-library-name(MacroDefinition) \ // RUN: -module-name MacroDefinition \ // RUN: -D PLUGIN_PATH \ -// RUN: %t/src/MacroDefinition.swift \ -// RUN: -g -no-toolchain-stdlib-rpath +// RUN: %t/src/MacroDefinition.swift //#-- For -load-plugin-library // RUN: %host-build-swift \ @@ -27,8 +26,7 @@ // RUN: -emit-library -o %t/lib/tmp/%target-library-name(MacroDefinition) \ // RUN: -module-name MacroDefinition \ // RUN: -D LOAD_PLUGIN_LIBRARY \ -// RUN: %t/src/MacroDefinition.swift \ -// RUN: -g -no-toolchain-stdlib-rpath +// RUN: %t/src/MacroDefinition.swift //#-- For -external-plugin-path // RUN: %host-build-swift \ @@ -36,17 +34,10 @@ // RUN: -emit-library -o %t/external/%target-library-name(MacroDefinition) \ // RUN: -module-name MacroDefinition \ // RUN: -D EXTERNAL_PLUGIN_PATH \ -// RUN: %t/src/MacroDefinition.swift \ -// RUN: -g -no-toolchain-stdlib-rpath +// RUN: %t/src/MacroDefinition.swift //#-- For -load-plugin-executable -// RUN: %clang \ -// RUN: -isysroot %host_sdk \ -// RUN: -I %swift_src_root/include \ -// RUN: -L %swift-lib-dir -l_swiftMockPlugin \ -// RUN: -Wl,-rpath,%swift-lib-dir \ -// RUN: -o %t/libexec/MacroDefinitionPlugin \ -// RUN: %t/src/MacroDefinition.c +// RUN: %swift-build-cxx-plugin -o %t/libexec/MacroDefinitionPlugin %t/src/MacroDefinition.c //#-- Expect -load-plugin-library // RUN: %target-build-swift %t/src/test.swift \ diff --git a/test/Macros/macro_swiftdeps.swift b/test/Macros/macro_swiftdeps.swift index 2b6438e7ffada..118ef1cc364ad 100644 --- a/test/Macros/macro_swiftdeps.swift +++ b/test/Macros/macro_swiftdeps.swift @@ -12,17 +12,10 @@ // RUN: -swift-version 5 \ // RUN: -emit-library -o %t/plugin/%target-library-name(MacroDefinition) \ // RUN: -module-name MacroDefinition \ -// RUN: %S/Inputs/syntax_macro_definitions.swift \ -// RUN: -g -no-toolchain-stdlib-rpath +// RUN: %S/Inputs/syntax_macro_definitions.swift //#-- Prepare the macro executable plugin. -// RUN: %clang \ -// RUN: -isysroot %host_sdk \ -// RUN: -I %swift_src_root/include \ -// RUN: -L %swift-lib-dir -l_swiftMockPlugin \ -// RUN: -Wl,-rpath,%swift-lib-dir \ -// RUN: -o %t/mock-plugin \ -// RUN: %t/src/plugin.c +// RUN: %swift-build-cxx-plugin -o %t/mock-plugin %t/src/plugin.c //#-- Prepare the macro library. // RUN: %target-swift-frontend \ @@ -34,7 +27,7 @@ // RUN: -primary-file %t/src/macro_library.swift \ // RUN: -emit-reference-dependencies-path %t/macro_library.swiftdeps \ // RUN: -emit-dependencies-path %t/macro_library.d -// RUN: %S/../Inputs/process_fine_grained_swiftdeps.sh %swift-dependency-tool %t/macro_library.swiftdeps %t/macro_library.swiftdeps.processed +// RUN: %{python} %S/../Inputs/process_fine_grained_swiftdeps.py %swift-dependency-tool %t/macro_library.swiftdeps > %t/macro_library.swiftdeps.processed // RUN: %FileCheck --check-prefix WITH_PLUGIN %s < %t/macro_library.swiftdeps.processed //#-- Without macro (no -D USE_MACRO) @@ -46,7 +39,7 @@ // RUN: -load-plugin-executable %t/mock-plugin#TestPlugin \ // RUN: -emit-reference-dependencies-path %t/without_macro.swiftdeps \ // RUN: -emit-dependencies-path %t/without_macro.d -// RUN: %S/../Inputs/process_fine_grained_swiftdeps.sh %swift-dependency-tool %t/without_macro.swiftdeps %t/without_macro.swiftdeps.processed +// RUN: %{python} %S/../Inputs/process_fine_grained_swiftdeps.py %swift-dependency-tool %t/without_macro.swiftdeps > %t/without_macro.swiftdeps.processed // RUN: %FileCheck --check-prefix WITHOUT_PLUGIN %s < %t/without_macro.swiftdeps.processed //#-- With macro - primary (-D USE_MACRO) @@ -59,7 +52,7 @@ // RUN: -load-plugin-executable %t/mock-plugin#TestPlugin \ // RUN: -emit-reference-dependencies-path %t/with_macro_primary.swiftdeps \ // RUN: -emit-dependencies-path %t/with_macro_primary.d -// RUN: %S/../Inputs/process_fine_grained_swiftdeps.sh %swift-dependency-tool %t/with_macro_primary.swiftdeps %t/with_macro_primary.swiftdeps.processed +// RUN: %{python} %S/../Inputs/process_fine_grained_swiftdeps.py %swift-dependency-tool %t/with_macro_primary.swiftdeps > %t/with_macro_primary.swiftdeps.processed // RUN: %FileCheck --check-prefix WITH_PLUGIN %s < %t/with_macro_primary.swiftdeps.processed //#-- With macro - non-primary (-D USE_MACRO) @@ -72,11 +65,11 @@ // RUN: -load-plugin-executable %t/mock-plugin#TestPlugin \ // RUN: -emit-reference-dependencies-path %t/with_macro_nonprimary.swiftdeps \ // RUN: -emit-dependencies-path %t/with_macro_nonprimary.d -// RUN: %S/../Inputs/process_fine_grained_swiftdeps.sh %swift-dependency-tool %t/with_macro_nonprimary.swiftdeps %t/with_macro_nonprimary.swiftdeps.processed +// RUN: %{python} %S/../Inputs/process_fine_grained_swiftdeps.py %swift-dependency-tool %t/with_macro_nonprimary.swiftdeps > %t/with_macro_nonprimary.swiftdeps.processed // RUN: %FileCheck --check-prefix WITHOUT_PLUGIN %s < %t/with_macro_nonprimary.swiftdeps.processed -// WITH_PLUGIN: externalDepend interface '' 'BUILD_DIR{{.*}}mock-plugin' false -// WITH_PLUGIN: externalDepend interface '' 'BUILD_DIR{{.*}}libMacroDefinition.{{(dylib|so|dll)}}' false +// WITH_PLUGIN: externalDepend interface '' '{{.*}}mock-plugin' false +// WITH_PLUGIN: externalDepend interface '' '{{.*}}MacroDefinition.{{(dylib|so|dll)}}' false // WITHOUT_PLUGIN-NOT: MacroDefinition // WITHOUT_PLUGIN-NOT: mock-plugin diff --git a/test/Macros/option_set.swift b/test/Macros/option_set.swift index eda8136594651..ce9d87ba81a50 100644 --- a/test/Macros/option_set.swift +++ b/test/Macros/option_set.swift @@ -1,6 +1,6 @@ // REQUIRES: swift_swift_parser, executable_test -// RUN: %target-run-simple-swift(-Xfrontend -plugin-path -Xfrontend %swift-host-lib-dir/plugins -emit-tbd -emit-tbd-path %t.tbd) +// RUN: %target-run-simple-swift(-Xfrontend -plugin-path -Xfrontend %swift-plugin-dir -emit-tbd -emit-tbd-path %t.tbd) import Swift diff --git a/test/Macros/serialize_plugin_search_paths.swift b/test/Macros/serialize_plugin_search_paths.swift index cd4b53fc4725f..9295e124f8e46 100644 --- a/test/Macros/serialize_plugin_search_paths.swift +++ b/test/Macros/serialize_plugin_search_paths.swift @@ -16,5 +16,5 @@ // CHECK: -external-plugin-path {{.*}}plugins#{{.*}}swift-plugin-server // CHECK: -load-plugin-library {{.*}}MacroDefinition.{{dylib|so|dll}} // CHECK: -load-plugin-executable {{.*}}mock-plugin#TestPlugin -// CHECK: -plugin-path {{.*}}plugins -// CHECK: -plugin-path {{.*}}plugins +// CHECK-SYSV:-plugin-path {{.*}}plugins +// CHECK-SYSV:-plugin-path {{.*}}plugins diff --git a/test/ModuleInterface/Observable.swift b/test/ModuleInterface/Observable.swift index 59a571a226659..ce62c8d99be32 100644 --- a/test/ModuleInterface/Observable.swift +++ b/test/ModuleInterface/Observable.swift @@ -1,5 +1,5 @@ // RUN: %empty-directory(%t) -// RUN: %target-swift-emit-module-interface(%t/Library.swiftinterface) %s -module-name Library -plugin-path %swift-host-lib-dir/plugins -disable-availability-checking +// RUN: %target-swift-emit-module-interface(%t/Library.swiftinterface) %s -module-name Library -plugin-path %swift-plugin-dir -disable-availability-checking // RUN: %target-swift-typecheck-module-from-interface(%t/Library.swiftinterface) -module-name Library -disable-availability-checking // RUN: %FileCheck %s < %t/Library.swiftinterface diff --git a/test/lit.cfg b/test/lit.cfg index 76d61f614b7dd..35d6ac55029a7 100644 --- a/test/lit.cfg +++ b/test/lit.cfg @@ -524,7 +524,14 @@ shutil.rmtree(completion_cache_path, ignore_errors=True) ccp_opt = "-completion-cache-path %r" % completion_cache_path lit_config.note("Using code completion cache: " + completion_cache_path) -config.swift_host_lib_dir = make_path(config.swift_lib_dir, 'swift', 'host') +if kIsWindows: + config.swift_plugin_dir = config.swift_bin_dir + # FIXME: this is a workaround for the collsion between the build toolchain + # and the current build, this should be `make_path(config.swift_lib_dir, 'swift')` + config.swift_build_lib_dir = make_path(config.swift_lib_dir, 'swift', 'host') +else: + config.swift_plugin_dir = make_path(config.swift_lib_dir, 'swift', 'host', 'plugins') + config.swift_build_lib_dir = make_path(config.swift_lib_dir, 'swift', 'host') if platform.system() == 'Darwin': config.swift_driver = ( @@ -534,8 +541,14 @@ if platform.system() == 'Darwin': "env SDKROOT=%s %r -toolchain-stdlib-rpath -Xlinker -rpath -Xlinker /usr/lib/swift %s %s %s" % (shell_quote(config.host_sdkroot), config.swiftc, mcp_opt, config.swift_test_options, config.swift_driver_test_options)) config.host_build_swift = ( - "%s -sdk %s -target %s -I %s -L %s" - % (config.swiftc_driver, config.host_sdkroot, config.host_triple, config.swift_host_lib_dir, config.swift_host_lib_dir)) + "%s -sdk %s -target %s -no-toolchain-stdlib-rpath -I %s -L %s" % ( + config.swiftc_driver, + config.host_sdkroot, + config.host_triple, + config.swift_build_lib_dir, + config.swift_build_lib_dir + ) + ) else: config.swift_driver = ( "%r %s %s %s" @@ -543,18 +556,31 @@ else: if kIsWindows: config.swift_driver += " -libc " + config.swift_stdlib_msvc_runtime config.swiftc_driver = ( - "%r -toolchain-stdlib-rpath %s %s %s" - % (config.swiftc, mcp_opt, config.swift_test_options, config.swift_driver_test_options)) + "%r %s %s %s %s" % ( + config.swiftc, + '' if kIsWindows else '-toolchain-stdlib-rpath', + mcp_opt, + config.swift_test_options, + config.swift_driver_test_options, + ) + ) # Parse the host triple. (host_cpu, host_vendor, host_os, host_vers) = re.match('([^-]+)-([^-]+)-([^0-9-]+)(.*)', config.host_triple).groups() toolchain_lib_dir = make_path(config.swift_lib_dir, 'swift', host_os) config.host_build_swift = ( - "%s -target %s -I %s -L %s -Xlinker -rpath -Xlinker %s" - % (config.swiftc_driver, config.host_triple, config.swift_host_lib_dir, config.swift_host_lib_dir, toolchain_lib_dir)) + "%s -target %s -g %s -I %s -L %s %s" % ( + config.swiftc_driver, + config.host_triple, + '' if kIsWindows else '-no-toolchain-stdlib-rpath', + config.swift_build_lib_dir, + config.swift_build_lib_dir, + '' if kIsWindows else '-Xlinker -rpath -Xlinker {}'.format(toolchain_lib_dir) + ) + ) config.substitutions.append( ('%llvm_obj_root', config.llvm_obj_root) ) config.substitutions.append( ('%swift-lib-dir', config.swift_lib_dir) ) -config.substitutions.append( ('%swift-host-lib-dir', config.swift_host_lib_dir)) +config.substitutions.append( ('%swift-plugin-dir', config.swift_plugin_dir) ) config.substitutions.append( ('%llvm_src_root', config.llvm_src_root) ) config.substitutions.append( ('%swift_obj_root', config.swift_obj_root) ) config.substitutions.append( ('%swift_src_root', config.swift_src_root) ) @@ -2651,9 +2677,9 @@ config.substitutions.append(('%llvm-cov', config.llvm_cov)) if hasattr(config, 'target_library_path_var'): host_library_env = ( "/usr/bin/env " + - construct_library_path_env([config.swift_host_lib_dir])) + construct_library_path_env([make_path(config.swift_lib_dir, 'swift', 'host')])) else: - host_library_env = "env" + host_library_env = "" config.substitutions.append(('%host-library-env', host_library_env)) diff --git a/test/stdlib/Observation/Observable.swift b/test/stdlib/Observation/Observable.swift index 83fa7dca33103..a01117ebb5431 100644 --- a/test/stdlib/Observation/Observable.swift +++ b/test/stdlib/Observation/Observable.swift @@ -1,9 +1,9 @@ // REQUIRES: swift_swift_parser, executable_test -// RUN: %target-run-simple-swift( -Xfrontend -disable-availability-checking -parse-as-library -enable-experimental-feature Macros -enable-experimental-feature ExtensionMacros -Xfrontend -plugin-path -Xfrontend %swift-host-lib-dir/plugins) +// RUN: %target-run-simple-swift( -Xfrontend -disable-availability-checking -parse-as-library -enable-experimental-feature Macros -enable-experimental-feature ExtensionMacros -Xfrontend -plugin-path -Xfrontend %swift-plugin-dir) // Run this test via the swift-plugin-server -// RUN: %target-run-simple-swift( -Xfrontend -disable-availability-checking -parse-as-library -enable-experimental-feature Macros -enable-experimental-feature ExtensionMacros -Xfrontend -external-plugin-path -Xfrontend %swift-host-lib-dir/plugins#%swift-plugin-server) +// RUN: %target-run-simple-swift( -Xfrontend -disable-availability-checking -parse-as-library -enable-experimental-feature Macros -enable-experimental-feature ExtensionMacros -Xfrontend -external-plugin-path -Xfrontend %swift-plugin-dir#%swift-plugin-server) // REQUIRES: observation // REQUIRES: concurrency diff --git a/test/stdlib/Observation/ObservableAvailabilityCycle.swift b/test/stdlib/Observation/ObservableAvailabilityCycle.swift index 74a305d7216f3..7e1f20bd352fb 100644 --- a/test/stdlib/Observation/ObservableAvailabilityCycle.swift +++ b/test/stdlib/Observation/ObservableAvailabilityCycle.swift @@ -1,8 +1,8 @@ // REQUIRES: swift_swift_parser -// RUN: %target-swift-frontend -typecheck -parse-as-library -external-plugin-path %swift-host-lib-dir/plugins#%swift-plugin-server -primary-file %s %S/Inputs/ObservableClass.swift +// RUN: %target-swift-frontend -typecheck -parse-as-library -external-plugin-path %swift-plugin-dir#%swift-plugin-server -primary-file %s %S/Inputs/ObservableClass.swift -// RUN: %target-swift-frontend -typecheck -parse-as-library -external-plugin-path %swift-host-lib-dir/plugins#%swift-plugin-server %s -primary-file %S/Inputs/ObservableClass.swift +// RUN: %target-swift-frontend -typecheck -parse-as-library -external-plugin-path %swift-plugin-dir#%swift-plugin-server %s -primary-file %S/Inputs/ObservableClass.swift // REQUIRES: observation // REQUIRES: concurrency diff --git a/test/stdlib/Observation/ObservableDidSetWillSet.swift b/test/stdlib/Observation/ObservableDidSetWillSet.swift index ffa9ecb649700..e990d2d1881e8 100644 --- a/test/stdlib/Observation/ObservableDidSetWillSet.swift +++ b/test/stdlib/Observation/ObservableDidSetWillSet.swift @@ -1,6 +1,6 @@ // REQUIRES: swift_swift_parser, executable_test -// RUN: %target-run-simple-swift( -Xfrontend -disable-availability-checking -enable-experimental-feature Macros -enable-experimental-feature ExtensionMacros -Xfrontend -plugin-path -Xfrontend %swift-host-lib-dir/plugins) | %FileCheck %s +// RUN: %target-run-simple-swift( -Xfrontend -disable-availability-checking -enable-experimental-feature Macros -enable-experimental-feature ExtensionMacros -Xfrontend -plugin-path -Xfrontend %swift-plugin-dir) | %FileCheck %s // REQUIRES: observation // REQUIRES: concurrency diff --git a/tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake b/tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake index 7e2e1bc16e763..5514431eea9ce 100644 --- a/tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake +++ b/tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake @@ -162,6 +162,9 @@ function(add_sourcekit_swift_runtime_link_flags target path HAS_SWIFT_MODULES) file(RELATIVE_PATH relative_hostlib_path "${path}" "${SWIFTLIB_DIR}/host") list(APPEND RPATH_LIST "$ORIGIN/${relative_hostlib_path}") endif() + else() + target_link_directories(${target} PRIVATE + ${SWIFT_PATH_TO_SWIFT_SDK}/usr/lib/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}/${SWIFT_HOST_VARIANT_ARCH}) endif() if(SWIFT_SWIFT_PARSER) diff --git a/tools/SourceKit/tools/sourcekitd-test/sourcekitd-test.cpp b/tools/SourceKit/tools/sourcekitd-test/sourcekitd-test.cpp index ff383ae105462..1f72f36c5f9e6 100644 --- a/tools/SourceKit/tools/sourcekitd-test/sourcekitd-test.cpp +++ b/tools/SourceKit/tools/sourcekitd-test/sourcekitd-test.cpp @@ -427,7 +427,7 @@ static bool setSyntacticMacroExpansions(sourcekitd_object_t req, SmallVector expansions; for (std::string &opt : opts.RequestOptions) { SmallVector args; - StringRef(opt).split(args, ":"); + StringRef(opt).split(args, ":", /*maxSplits=*/2); unsigned line, column; if (args.size() != 3 || args[0].getAsInteger(10, line) || diff --git a/tools/driver/CMakeLists.txt b/tools/driver/CMakeLists.txt index 649510e8771fa..9c2e5ed6486a9 100644 --- a/tools/driver/CMakeLists.txt +++ b/tools/driver/CMakeLists.txt @@ -5,6 +5,8 @@ # parser is built in. function(add_swift_parser_link_libraries target) if(SWIFT_SWIFT_PARSER) + target_link_directories(${target} PRIVATE + ${SWIFT_PATH_TO_SWIFT_SDK}/usr/lib/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}/${SWIFT_HOST_VARIANT_ARCH}) target_link_libraries(${target} PRIVATE swiftCore) diff --git a/tools/swift-plugin-server/CMakeLists.txt b/tools/swift-plugin-server/CMakeLists.txt index 09332309b10c9..1d1b88b22bd8a 100644 --- a/tools/swift-plugin-server/CMakeLists.txt +++ b/tools/swift-plugin-server/CMakeLists.txt @@ -16,6 +16,8 @@ if (SWIFT_SWIFT_PARSER) DEPENDENCIES swiftDemangling $ + SWIFT_COMPONENT + compiler SWIFT_DEPENDENCIES SwiftSyntax::SwiftSyntaxMacros SwiftSyntax::SwiftSyntaxMacroExpansion @@ -25,9 +27,4 @@ if (SWIFT_SWIFT_PARSER) target_include_directories(swift-plugin-server PRIVATE Sources/CSwiftPluginServer/include ) - swift_install_in_component(TARGETS swift-plugin-server - RUNTIME - DESTINATION bin - COMPONENT compiler - ) endif() diff --git a/tools/swift-plugin-server/Sources/CSwiftPluginServer/PluginServer.cpp b/tools/swift-plugin-server/Sources/CSwiftPluginServer/PluginServer.cpp index 707b40a5d182c..a689f18d8ebc8 100644 --- a/tools/swift-plugin-server/Sources/CSwiftPluginServer/PluginServer.cpp +++ b/tools/swift-plugin-server/Sources/CSwiftPluginServer/PluginServer.cpp @@ -13,11 +13,17 @@ #include "PluginServer.h" #include "swift/ABI/MetadataValues.h" #include "swift/Demangling/Demangle.h" +#include "llvm/Support/DynamicLibrary.h" +#if defined(_WIN32) +#include +#elif defined(__unix__) || defined(__APPLE__) #include +#include +#endif + #include #include -#include using namespace swift; @@ -32,6 +38,46 @@ struct ConnectionHandle { } // namespace const void *PluginServer_createConnection(const char **errorMessage) { +#if defined(_WIN32) + struct unique_fd { + unique_fd(int fd) : fd_(fd) {} + unique_fd(const unique_fd &) = delete; + unique_fd &operator=(const unique_fd &) = delete; + unique_fd &operator=(unique_fd &&) = delete; + unique_fd(unique_fd &&uf) : fd_(uf.fd_) { uf.fd_ = -1; } + ~unique_fd() { if (fd_ > 0) _close(fd_); } + + int operator*() const { return fd_; } + int release() { int fd = fd_; fd_ = -1; return fd; } + + private: + int fd_; + }; + + unique_fd ifd{_dup(_fileno(stdin))}; + if (*ifd < 0) { + *errorMessage = _strerror(nullptr); + return nullptr; + } + + if (_close(_fileno(stdin)) < 0) { + *errorMessage = _strerror(nullptr); + return nullptr; + } + + unique_fd ofd{_dup(_fileno(stdout))}; + if (*ofd < 0) { + *errorMessage = _strerror(nullptr); + return nullptr; + } + + if (_dup2(_fileno(stderr), _fileno(stdout)) < 0) { + *errorMessage = _strerror(nullptr); + return nullptr; + } + + return new ConnectionHandle(ifd.release(), ofd.release()); +#else // Duplicate the `stdin` file descriptor, which we will then use for // receiving messages from the plugin host. auto inputFD = dup(STDIN_FILENO); @@ -65,37 +111,48 @@ const void *PluginServer_createConnection(const char **errorMessage) { // Open a message channel for communicating with the plugin host. return new ConnectionHandle(inputFD, outputFD); +#endif } -void PluginServer_destroyConnection(const void *connHandle) { - const auto *conn = static_cast(connHandle); - delete conn; +void PluginServer_destroyConnection(const void *server) { + delete static_cast(server); } -long PluginServer_read(const void *connHandle, void *data, - unsigned long nbyte) { - const auto *conn = static_cast(connHandle); - return ::read(conn->inputFD, data, nbyte); +SwiftInt PluginServer_read(const void *server, void *data, SwiftUInt nbyte) { + const auto *connection = static_cast(server); +#if defined(_WIN32) + return _read(connection->inputFD, data, nbyte); +#else + return ::read(connection->inputFD, data, nbyte); +#endif } -long PluginServer_write(const void *connHandle, const void *data, - unsigned long nbyte) { - const auto *conn = static_cast(connHandle); - return ::write(conn->outputFD, data, nbyte); +SwiftInt PluginServer_write(const void *server, const void *data, SwiftUInt nbyte) { + const auto *connection = static_cast(server); +#if defined(_WIN32) + return _write(connection->outputFD, data, nbyte); +#else + return ::write(connection->outputFD, data, nbyte); +#endif } -void *PluginServer_dlopen(const char *filename, const char **errorMessage) { - auto *handle = ::dlopen(filename, RTLD_LAZY | RTLD_LOCAL); - if (!handle) { - *errorMessage = dlerror(); - } - return handle; +void *PluginServer_load(const char *plugin, const char **errorMessage) { + // Use a static allocation for the error as the client will not release the + // string. POSIX 2008 (IEEE-1003.1-2008) specifies that it is implementation + // defined if `dlerror` is re-entrant. Take advantage of that and make it + // thread-unsafe. This ensures that the string outlives the call permitting + // the client to duplicate it. + static std::string error; + auto library = llvm::sys::DynamicLibrary::getLibrary(plugin, &error); + if (library.isValid()) + return library.getOSSpecificHandle(); + *errorMessage = error.c_str(); + return nullptr; } const void *PluginServer_lookupMacroTypeMetadataByExternalName( const char *moduleName, const char *typeName, void *libraryHint, const char **errorMessage) { - // Look up the type metadata accessor as a struct, enum, or class. const Demangle::Node::Kind typeKinds[] = { Demangle::Node::Kind::Structure, @@ -108,8 +165,12 @@ const void *PluginServer_lookupMacroTypeMetadataByExternalName( auto symbolName = mangledNameForTypeMetadataAccessor(moduleName, typeName, typeKind); - auto *handle = libraryHint ? libraryHint : RTLD_DEFAULT; - accessorAddr = ::dlsym(handle, symbolName.c_str()); +#if !defined(_WIN32) + if (libraryHint == nullptr) + libraryHint = RTLD_DEFAULT; +#endif + accessorAddr = llvm::sys::DynamicLibrary{libraryHint} + .getAddressOfSymbol(symbolName.c_str()); if (accessorAddr) break; } diff --git a/tools/swift-plugin-server/Sources/CSwiftPluginServer/include/PluginServer.h b/tools/swift-plugin-server/Sources/CSwiftPluginServer/include/PluginServer.h index dba78fedf8139..d30c48b86dbc9 100644 --- a/tools/swift-plugin-server/Sources/CSwiftPluginServer/include/PluginServer.h +++ b/tools/swift-plugin-server/Sources/CSwiftPluginServer/include/PluginServer.h @@ -13,6 +13,69 @@ #ifndef SWIFT_PLUGINSERVER_PLUGINSERVER_H #define SWIFT_PLUGINSERVER_PLUGINSERVER_H +// NOTE: Partially ported from SwiftShim's SwiftStdint.h. We cannot include +// that header here because it belongs to the runtime, but we need the same +// logic for interoperability with Swift code in the compiler itself. +// stdint.h is provided by Clang, but it dispatches to libc's stdint.h. As a +// result, using stdint.h here would pull in Darwin module (which includes +// libc). This creates a dependency cycle, so we can't use stdint.h in +// SwiftShims. +// On Linux, the story is different. We get the error message +// "/usr/include/x86_64-linux-gnu/sys/types.h:146:10: error: 'stddef.h' file not +// found" +// This is a known Clang/Ubuntu bug. + +// Clang has been defining __INTxx_TYPE__ macros for a long time. +// __UINTxx_TYPE__ are defined only since Clang 3.5. +#if defined(_MSC_VER) && !defined(__clang__) +typedef __int64 __swiftc_int64_t; +typedef unsigned __int64 __swiftc_uint64_t; +typedef int __swiftc_int32_t; +typedef unsigned int __swiftc_uint32_t; +#elif !defined(__APPLE__) && !defined(__linux__) && !defined(__OpenBSD__) && !defined(__wasi__) +#include +typedef int64_t __swiftc_int64_t; +typedef uint64_t __swiftc_uint64_t; +typedef int32_t __swiftc_int32_t; +typedef uint32_t __swiftc_uint32_t; +typedef intptr_t __swiftc_intptr_t; +typedef uintptr_t __swiftc_uintptr_t; +#else +typedef __INT64_TYPE__ __swiftc_int64_t; +#ifdef __UINT64_TYPE__ +typedef __UINT64_TYPE__ __swiftc_uint64_t; +#else +typedef unsigned __INT64_TYPE__ __swiftc_uint64_t; +#endif + +typedef __INT32_TYPE__ __swiftc_int32_t; +#ifdef __UINT32_TYPE__ +typedef __UINT32_TYPE__ __swiftc_uint32_t; +#else +typedef unsigned __INT32_TYPE__ __swiftc_uint32_t; +#endif +#endif + +#define __swiftc_join3(a,b,c) a ## b ## c + +#define __swiftc_intn_t(n) __swiftc_join3(__swiftc_int, n, _t) +#define __swiftc_uintn_t(n) __swiftc_join3(__swiftc_uint, n, _t) + +#if defined(_MSC_VER) && !defined(__clang__) +#if defined(_WIN64) +typedef __swiftc_int64_t SwiftInt; +typedef __swiftc_uint64_t SwiftUInt; +#elif defined(_WIN32) +typedef __swiftc_int32_t SwiftInt; +typedef __swiftc_uint32_t SwiftUInt; +#else +#error unknown windows pointer width +#endif +#else +typedef __swiftc_intn_t(__INTPTR_WIDTH__) SwiftInt; +typedef __swiftc_uintn_t(__INTPTR_WIDTH__) SwiftUInt; +#endif + #ifdef __cplusplus extern "C" { #endif @@ -29,18 +92,17 @@ const void *PluginServer_createConnection(const char **errorMessage); void PluginServer_destroyConnection(const void *connHandle); /// Read bytes from the IPC communication handle. -long PluginServer_read(const void *connHandle, void *data, unsigned long nbyte); +SwiftInt PluginServer_read(const void *connHandle, void *data, SwiftUInt nbyte); /// Write bytes to the IPC communication handle. -long PluginServer_write(const void *connHandle, const void *data, - unsigned long nbyte); +SwiftInt PluginServer_write(const void *connHandle, const void *data, SwiftUInt nbyte); //===----------------------------------------------------------------------===// // Dynamic link //===----------------------------------------------------------------------===// /// Load a dynamic link library, and return the handle. -void *PluginServer_dlopen(const char *filename, const char **errorMessage); +void *PluginServer_load(const char *filename, const char **errorMessage); /// Resolve a type metadata by a pair of the module name and the type name. /// 'libraryHint' is a diff --git a/tools/swift-plugin-server/Sources/swift-plugin-server/swift-plugin-server.swift b/tools/swift-plugin-server/Sources/swift-plugin-server/swift-plugin-server.swift index e1f8bae8b898a..ad117e4d8e50e 100644 --- a/tools/swift-plugin-server/Sources/swift-plugin-server/swift-plugin-server.swift +++ b/tools/swift-plugin-server/Sources/swift-plugin-server/swift-plugin-server.swift @@ -47,7 +47,7 @@ extension SwiftPluginServer: PluginProvider { /// Load a macro implementation from the dynamic link library. func loadPluginLibrary(libraryPath: String, moduleName: String) throws { var errorMessage: UnsafePointer? - guard let dlHandle = PluginServer_dlopen(libraryPath, &errorMessage) else { + guard let dlHandle = PluginServer_load(libraryPath, &errorMessage) else { throw PluginServerError(message: String(cString: errorMessage!)) } loadedLibraryPlugins[moduleName] = dlHandle @@ -172,13 +172,13 @@ final class PluginHostConnection: MessageConnection { var ptr = buffer.baseAddress! while (bytesToWrite > 0) { - let writtenSize = PluginServer_write(handle, ptr, UInt(bytesToWrite)) + let writtenSize = PluginServer_write(handle, ptr, SwiftUInt(bytesToWrite)) if (writtenSize <= 0) { // error e.g. broken pipe. break } - ptr = ptr.advanced(by: writtenSize) - bytesToWrite -= writtenSize + ptr = ptr.advanced(by: Int(writtenSize)) + bytesToWrite -= Int(writtenSize) } return buffer.count - bytesToWrite } @@ -193,13 +193,13 @@ final class PluginHostConnection: MessageConnection { var ptr = buffer.baseAddress! while bytesToRead > 0 { - let readSize = PluginServer_read(handle, ptr, UInt(bytesToRead)) + let readSize = PluginServer_read(handle, ptr, SwiftUInt(bytesToRead)) if (readSize <= 0) { // 0: EOF (the host closed), -1: Broken pipe (the host crashed?) break; } - ptr = ptr.advanced(by: readSize) - bytesToRead -= readSize + ptr = ptr.advanced(by: Int(readSize)) + bytesToRead -= Int(readSize) } return buffer.count - bytesToRead }