Skip to content

Commit e58f5da

Browse files
committed
Fix build warnings
Mostly, ensure that we only use `@_implementationOnly` if we build with `RESILIENT_LIBRARIES`. Also, `strerror` is marked as unsafe and deprecated on Windows. It looks like this is because `strerror` is not thread-safe. Switch to the thread-safe version `strerror_r` instead.
1 parent f2a32a7 commit e58f5da

File tree

8 files changed

+82
-19
lines changed

8 files changed

+82
-19
lines changed

Package.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ let package = Package(
184184

185185
.target(
186186
name: "SwiftLexicalLookup",
187-
dependencies: ["SwiftSyntax", "SwiftIfConfig"]
187+
dependencies: ["SwiftSyntax", "SwiftIfConfig"],
188+
exclude: ["CMakeLists.txt"]
188189
),
189190

190191
.testTarget(

Sources/SwiftCompilerPluginMessageHandling/CompilerPluginMessageHandler.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,19 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#if compiler(>=6)
13+
#if compiler(>=6) && RESILIENT_LIBRARIES
1414
@_implementationOnly private import _SwiftSyntaxCShims
15+
#elseif compiler(>=6) && !RESILIENT_LIBRARIES
16+
private import _SwiftSyntaxCShims
17+
#elseif !compiler(>=6) && RESILIENT_LIBRARIES
18+
@_implementationOnly import _SwiftSyntaxCShims
19+
#elseif !compiler(>=6) && !RESILIENT_LIBRARIES
20+
import _SwiftSyntaxCShims
21+
#endif
22+
23+
#if compiler(>=6)
1524
public import SwiftSyntaxMacros
1625
#else
17-
@_implementationOnly import _SwiftSyntaxCShims
1826
import SwiftSyntaxMacros
1927
#endif
2028

Sources/SwiftCompilerPluginMessageHandling/JSON/JSONDecoding.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#if compiler(>=6)
13+
#if compiler(>=6) && RESILIENT_LIBRARIES
1414
@_implementationOnly private import _SwiftSyntaxCShims
15-
#else
15+
#elseif compiler(>=6) && !RESILIENT_LIBRARIES
16+
private import _SwiftSyntaxCShims
17+
#elseif !compiler(>=6) && RESILIENT_LIBRARIES
1618
@_implementationOnly import _SwiftSyntaxCShims
19+
#elseif !compiler(>=6) && !RESILIENT_LIBRARIES
20+
import _SwiftSyntaxCShims
1721
#endif
1822

1923
func decodeFromJSON<T: Decodable>(json: UnsafeBufferPointer<UInt8>) throws -> T {

Sources/SwiftCompilerPluginMessageHandling/StandardIOMessageConnection.swift

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#if compiler(>=6)
13+
#if compiler(>=6) && RESILIENT_LIBRARIES
1414
@_implementationOnly private import _SwiftSyntaxCShims
15-
#else
15+
#elseif compiler(>=6) && !RESILIENT_LIBRARIES
16+
private import _SwiftSyntaxCShims
17+
#elseif !compiler(>=6) && RESILIENT_LIBRARIES
1618
@_implementationOnly import _SwiftSyntaxCShims
19+
#elseif !compiler(>=6) && !RESILIENT_LIBRARIES
20+
import _SwiftSyntaxCShims
1721
#endif
1822

1923
#if canImport(ucrt)
@@ -173,6 +177,17 @@ private enum IOError: Error, CustomStringConvertible {
173177

174178
// Private function to construct an error message from an `errno` code.
175179
private func describe(errno: CInt) -> String {
176-
if let cStr = strerror(errno) { return String(cString: cStr) }
177-
return String(describing: errno)
180+
// We can't tell how long the error message will be but 1024 characters should be enough to hold most, if not all,
181+
// error messages.
182+
return withUnsafeTemporaryAllocation(of: CChar.self, capacity: 1024) { buffer in
183+
guard let baseAddress = buffer.baseAddress else {
184+
return ""
185+
}
186+
#if os(Windows)
187+
strerror_s(baseAddress, buffer.count, errno)
188+
#else
189+
strerror_r(errno, baseAddress, buffer.count)
190+
#endif
191+
return String(cString: baseAddress)
192+
}
178193
}

Sources/SwiftLibraryPluginProvider/LibraryPluginProvider.swift

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
public import SwiftSyntaxMacros
1515
@_spi(PluginMessage) public import SwiftCompilerPluginMessageHandling
1616
private import _SwiftLibraryPluginProviderCShims
17+
1718
// NOTE: Do not use '_SwiftSyntaxCShims' for 'dlopen' and 'LoadLibraryW' (Windows)
1819
// because we don't want other modules depend on 'WinSDK'.
1920
#if canImport(Darwin)
@@ -24,19 +25,38 @@ private import Glibc
2425
private import Musl
2526
#elseif canImport(Android)
2627
private import Android
27-
#endif
28-
#else
28+
#endif // canImport
29+
30+
#else // compiler(>=6)
31+
2932
import SwiftSyntaxMacros
3033
@_spi(PluginMessage) import SwiftCompilerPluginMessageHandling
34+
35+
#if RESILIENT_LIBRARIES
36+
3137
@_implementationOnly import _SwiftLibraryPluginProviderCShims
3238
#if canImport(Darwin)
3339
@_implementationOnly import Darwin
3440
#elseif canImport(Glibc)
3541
@_implementationOnly import Glibc
3642
#elseif canImport(Musl)
3743
@_implementationOnly import Musl
38-
#endif
39-
#endif
44+
#endif // canImport
45+
46+
#else // RESILIENT_LIBRARIES
47+
48+
import _SwiftLibraryPluginProviderCShims
49+
#if canImport(Darwin)
50+
import Darwin
51+
#elseif canImport(Glibc)
52+
import Glibc
53+
#elseif canImport(Musl)
54+
import Musl
55+
#endif // canImport
56+
57+
#endif // RESILIENT_LIBRARIES
58+
59+
#endif // compiler(>=6)
4060

4161
/// Singleton 'PluginProvider' that can serve shared library plugins.
4262
@_spi(PluginMessage)

Sources/SwiftSyntax/CMakeLists.txt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,12 @@ add_swift_syntax_library(SwiftSyntax
8383
generated/syntaxNodes/SyntaxNodesTUVWXYZ.swift
8484
)
8585

86-
target_link_swift_syntax_libraries(SwiftSyntax PRIVATE
87-
_SwiftSyntaxCShims)
86+
if (SWIFTSYNTAX_EMIT_MODULE)
87+
target_link_swift_syntax_libraries(SwiftSyntax PRIVATE
88+
_SwiftSyntaxCShims)
89+
else()
90+
# We can't use @_implementationOnly if we don't enable library evolution, so we need
91+
# to link _SwiftSyntaxCShims publicly.
92+
target_link_swift_syntax_libraries(SwiftSyntax PUBLIC
93+
_SwiftSyntaxCShims)
94+
endif()

Sources/SwiftSyntax/Raw/RawSyntaxArena.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#if compiler(>=6)
13+
#if compiler(>=6) && RESILIENT_LIBRARIES
1414
@_implementationOnly private import _SwiftSyntaxCShims
15-
#else
15+
#elseif compiler(>=6) && !RESILIENT_LIBRARIES
16+
private import _SwiftSyntaxCShims
17+
#elseif !compiler(>=6) && RESILIENT_LIBRARIES
1618
@_implementationOnly import _SwiftSyntaxCShims
19+
#elseif !compiler(>=6) && !RESILIENT_LIBRARIES
20+
import _SwiftSyntaxCShims
1721
#endif
1822

1923
/// A syntax arena owns the memory for all syntax nodes within it.

Sources/SwiftSyntax/Syntax.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#if compiler(>=6)
13+
#if compiler(>=6) && RESILIENT_LIBRARIES
1414
@_implementationOnly private import _SwiftSyntaxCShims
15-
#else
15+
#elseif compiler(>=6) && !RESILIENT_LIBRARIES
16+
private import _SwiftSyntaxCShims
17+
#elseif !compiler(>=6) && RESILIENT_LIBRARIES
1618
@_implementationOnly import _SwiftSyntaxCShims
19+
#elseif !compiler(>=6) && !RESILIENT_LIBRARIES
20+
import _SwiftSyntaxCShims
1721
#endif
1822

1923
// `Syntax` is a user facing tree wrapping `RawSyntax` tree. A value is a pair

0 commit comments

Comments
 (0)