diff --git a/Package.swift b/Package.swift index b8da017f322..7189908a617 100644 --- a/Package.swift +++ b/Package.swift @@ -184,7 +184,8 @@ let package = Package( .target( name: "SwiftLexicalLookup", - dependencies: ["SwiftSyntax", "SwiftIfConfig"] + dependencies: ["SwiftSyntax", "SwiftIfConfig"], + exclude: ["CMakeLists.txt"] ), .testTarget( diff --git a/Sources/SwiftCompilerPluginMessageHandling/CompilerPluginMessageHandler.swift b/Sources/SwiftCompilerPluginMessageHandling/CompilerPluginMessageHandler.swift index c4aa143c7fc..077aec6a646 100644 --- a/Sources/SwiftCompilerPluginMessageHandling/CompilerPluginMessageHandler.swift +++ b/Sources/SwiftCompilerPluginMessageHandling/CompilerPluginMessageHandler.swift @@ -10,11 +10,19 @@ // //===----------------------------------------------------------------------===// -#if compiler(>=6) +#if compiler(>=6) && RESILIENT_LIBRARIES @_implementationOnly private import _SwiftSyntaxCShims +#elseif compiler(>=6) && !RESILIENT_LIBRARIES +private import _SwiftSyntaxCShims +#elseif !compiler(>=6) && RESILIENT_LIBRARIES +@_implementationOnly import _SwiftSyntaxCShims +#elseif !compiler(>=6) && !RESILIENT_LIBRARIES +import _SwiftSyntaxCShims +#endif + +#if compiler(>=6) public import SwiftSyntaxMacros #else -@_implementationOnly import _SwiftSyntaxCShims import SwiftSyntaxMacros #endif diff --git a/Sources/SwiftCompilerPluginMessageHandling/JSON/JSONDecoding.swift b/Sources/SwiftCompilerPluginMessageHandling/JSON/JSONDecoding.swift index 79c77910871..20a56a633c6 100644 --- a/Sources/SwiftCompilerPluginMessageHandling/JSON/JSONDecoding.swift +++ b/Sources/SwiftCompilerPluginMessageHandling/JSON/JSONDecoding.swift @@ -10,10 +10,14 @@ // //===----------------------------------------------------------------------===// -#if compiler(>=6) +#if compiler(>=6) && RESILIENT_LIBRARIES @_implementationOnly private import _SwiftSyntaxCShims -#else +#elseif compiler(>=6) && !RESILIENT_LIBRARIES +private import _SwiftSyntaxCShims +#elseif !compiler(>=6) && RESILIENT_LIBRARIES @_implementationOnly import _SwiftSyntaxCShims +#elseif !compiler(>=6) && !RESILIENT_LIBRARIES +import _SwiftSyntaxCShims #endif func decodeFromJSON(json: UnsafeBufferPointer) throws -> T { diff --git a/Sources/SwiftCompilerPluginMessageHandling/StandardIOMessageConnection.swift b/Sources/SwiftCompilerPluginMessageHandling/StandardIOMessageConnection.swift index 8f89ac125c9..750ce3b72dd 100644 --- a/Sources/SwiftCompilerPluginMessageHandling/StandardIOMessageConnection.swift +++ b/Sources/SwiftCompilerPluginMessageHandling/StandardIOMessageConnection.swift @@ -10,10 +10,14 @@ // //===----------------------------------------------------------------------===// -#if compiler(>=6) +#if compiler(>=6) && RESILIENT_LIBRARIES @_implementationOnly private import _SwiftSyntaxCShims -#else +#elseif compiler(>=6) && !RESILIENT_LIBRARIES +private import _SwiftSyntaxCShims +#elseif !compiler(>=6) && RESILIENT_LIBRARIES @_implementationOnly import _SwiftSyntaxCShims +#elseif !compiler(>=6) && !RESILIENT_LIBRARIES +import _SwiftSyntaxCShims #endif #if canImport(ucrt) @@ -173,6 +177,17 @@ private enum IOError: Error, CustomStringConvertible { // Private function to construct an error message from an `errno` code. private func describe(errno: CInt) -> String { - if let cStr = strerror(errno) { return String(cString: cStr) } - return String(describing: errno) + // We can't tell how long the error message will be but 1024 characters should be enough to hold most, if not all, + // error messages. + return withUnsafeTemporaryAllocation(of: CChar.self, capacity: 1024) { buffer in + guard let baseAddress = buffer.baseAddress else { + return "" + } + #if os(Windows) + strerror_s(baseAddress, buffer.count, errno) + #else + strerror_r(errno, baseAddress, buffer.count) + #endif + return String(cString: baseAddress) + } } diff --git a/Sources/SwiftLibraryPluginProvider/LibraryPluginProvider.swift b/Sources/SwiftLibraryPluginProvider/LibraryPluginProvider.swift index 1f156f380a2..7cb686a0622 100644 --- a/Sources/SwiftLibraryPluginProvider/LibraryPluginProvider.swift +++ b/Sources/SwiftLibraryPluginProvider/LibraryPluginProvider.swift @@ -14,6 +14,7 @@ public import SwiftSyntaxMacros @_spi(PluginMessage) public import SwiftCompilerPluginMessageHandling private import _SwiftLibraryPluginProviderCShims + // NOTE: Do not use '_SwiftSyntaxCShims' for 'dlopen' and 'LoadLibraryW' (Windows) // because we don't want other modules depend on 'WinSDK'. #if canImport(Darwin) @@ -24,10 +25,15 @@ private import Glibc private import Musl #elseif canImport(Android) private import Android -#endif -#else +#endif // canImport + +#else // compiler(>=6) + import SwiftSyntaxMacros @_spi(PluginMessage) import SwiftCompilerPluginMessageHandling + +#if RESILIENT_LIBRARIES + @_implementationOnly import _SwiftLibraryPluginProviderCShims #if canImport(Darwin) @_implementationOnly import Darwin @@ -35,8 +41,22 @@ import SwiftSyntaxMacros @_implementationOnly import Glibc #elseif canImport(Musl) @_implementationOnly import Musl -#endif -#endif +#endif // canImport + +#else // RESILIENT_LIBRARIES + +import _SwiftLibraryPluginProviderCShims +#if canImport(Darwin) +import Darwin +#elseif canImport(Glibc) +import Glibc +#elseif canImport(Musl) +import Musl +#endif // canImport + +#endif // RESILIENT_LIBRARIES + +#endif // compiler(>=6) /// Singleton 'PluginProvider' that can serve shared library plugins. @_spi(PluginMessage) diff --git a/Sources/SwiftSyntax/CMakeLists.txt b/Sources/SwiftSyntax/CMakeLists.txt index 4d2457f6cbb..cfb8d888622 100644 --- a/Sources/SwiftSyntax/CMakeLists.txt +++ b/Sources/SwiftSyntax/CMakeLists.txt @@ -83,5 +83,12 @@ add_swift_syntax_library(SwiftSyntax generated/syntaxNodes/SyntaxNodesTUVWXYZ.swift ) -target_link_swift_syntax_libraries(SwiftSyntax PRIVATE - _SwiftSyntaxCShims) +if (SWIFTSYNTAX_EMIT_MODULE) + target_link_swift_syntax_libraries(SwiftSyntax PRIVATE + _SwiftSyntaxCShims) +else() + # We can't use @_implementationOnly if we don't enable library evolution, so we need + # to link _SwiftSyntaxCShims publicly. + target_link_swift_syntax_libraries(SwiftSyntax PUBLIC + _SwiftSyntaxCShims) +endif() diff --git a/Sources/SwiftSyntax/Raw/RawSyntaxArena.swift b/Sources/SwiftSyntax/Raw/RawSyntaxArena.swift index 3d57003ace4..f5566e831b2 100644 --- a/Sources/SwiftSyntax/Raw/RawSyntaxArena.swift +++ b/Sources/SwiftSyntax/Raw/RawSyntaxArena.swift @@ -10,10 +10,14 @@ // //===----------------------------------------------------------------------===// -#if compiler(>=6) +#if compiler(>=6) && RESILIENT_LIBRARIES @_implementationOnly private import _SwiftSyntaxCShims -#else +#elseif compiler(>=6) && !RESILIENT_LIBRARIES +private import _SwiftSyntaxCShims +#elseif !compiler(>=6) && RESILIENT_LIBRARIES @_implementationOnly import _SwiftSyntaxCShims +#elseif !compiler(>=6) && !RESILIENT_LIBRARIES +import _SwiftSyntaxCShims #endif /// A syntax arena owns the memory for all syntax nodes within it. diff --git a/Sources/SwiftSyntax/Syntax.swift b/Sources/SwiftSyntax/Syntax.swift index c214c41d5f4..407febff7ca 100644 --- a/Sources/SwiftSyntax/Syntax.swift +++ b/Sources/SwiftSyntax/Syntax.swift @@ -10,10 +10,14 @@ // //===----------------------------------------------------------------------===// -#if compiler(>=6) +#if compiler(>=6) && RESILIENT_LIBRARIES @_implementationOnly private import _SwiftSyntaxCShims -#else +#elseif compiler(>=6) && !RESILIENT_LIBRARIES +private import _SwiftSyntaxCShims +#elseif !compiler(>=6) && RESILIENT_LIBRARIES @_implementationOnly import _SwiftSyntaxCShims +#elseif !compiler(>=6) && !RESILIENT_LIBRARIES +import _SwiftSyntaxCShims #endif // `Syntax` is a user facing tree wrapping `RawSyntax` tree. A value is a pair