Skip to content

Fix build warnings #3002

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ let package = Package(

.target(
name: "SwiftLexicalLookup",
dependencies: ["SwiftSyntax", "SwiftIfConfig"]
dependencies: ["SwiftSyntax", "SwiftIfConfig"],
exclude: ["CMakeLists.txt"]
),

.testTarget(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Decodable>(json: UnsafeBufferPointer<UInt8>) throws -> T {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
}
28 changes: 24 additions & 4 deletions Sources/SwiftLibraryPluginProvider/LibraryPluginProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -24,19 +25,38 @@ 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
#elseif canImport(Glibc)
@_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)
Expand Down
11 changes: 9 additions & 2 deletions Sources/SwiftSyntax/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
8 changes: 6 additions & 2 deletions Sources/SwiftSyntax/Raw/RawSyntaxArena.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 6 additions & 2 deletions Sources/SwiftSyntax/Syntax.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down