Skip to content

Commit 324d401

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 324d401

File tree

7 files changed

+85
-19
lines changed

7 files changed

+85
-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: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,23 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
// NOTE: Do not use '_SwiftSyntaxCShims' for 'dlopen' and 'LoadLibraryW' (Windows)
14+
// because we don't want other modules depend on 'WinSDK'.
15+
#if compiler(>=6) && RESILIENT_LIBRARIES
16+
@_implementationOnly private import _SwiftSyntaxCShims
17+
#elseif compiler(>=6) && !RESILIENT_LIBRARIES
18+
private import _SwiftSyntaxCShims
19+
#elseif !compiler(>=6) && RESILIENT_LIBRARIES
20+
@_implementationOnly import _SwiftSyntaxCShims
21+
#elseif !compiler(>=6) && !RESILIENT_LIBRARIES
22+
import _SwiftSyntaxCShims
23+
#endif
24+
1325
#if compiler(>=6)
1426
public import SwiftSyntaxMacros
1527
@_spi(PluginMessage) public import SwiftCompilerPluginMessageHandling
1628
private import _SwiftLibraryPluginProviderCShims
17-
// NOTE: Do not use '_SwiftSyntaxCShims' for 'dlopen' and 'LoadLibraryW' (Windows)
18-
// because we don't want other modules depend on 'WinSDK'.
29+
1930
#if canImport(Darwin)
2031
private import Darwin
2132
#elseif canImport(Glibc)
@@ -24,19 +35,38 @@ private import Glibc
2435
private import Musl
2536
#elseif canImport(Android)
2637
private import Android
27-
#endif
28-
#else
38+
#endif // canImport
39+
40+
#else // compiler(>=6)
41+
2942
import SwiftSyntaxMacros
3043
@_spi(PluginMessage) import SwiftCompilerPluginMessageHandling
44+
45+
#if RESILIENT_LIBRARIES
46+
3147
@_implementationOnly import _SwiftLibraryPluginProviderCShims
3248
#if canImport(Darwin)
3349
@_implementationOnly import Darwin
3450
#elseif canImport(Glibc)
3551
@_implementationOnly import Glibc
3652
#elseif canImport(Musl)
3753
@_implementationOnly import Musl
38-
#endif
39-
#endif
54+
#endif // canImport
55+
56+
#else // RESILIENT_LIBRARIES
57+
58+
import _SwiftLibraryPluginProviderCShims
59+
#if canImport(Darwin)
60+
import Darwin
61+
#elseif canImport(Glibc)
62+
import Glibc
63+
#elseif canImport(Musl)
64+
import Musl
65+
#endif // canImport
66+
67+
#endif // RESILIENT_LIBRARIES
68+
69+
#endif // compiler(>=6)
4070

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

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)