mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Thread the static build configuration (formed from language options) in to the macro plugin handler, which will serialize it for use in the macro implementation. test this with a simple macro that checks whether a particular custom configuration (set via `-D`) is enabled or not. This required some re-layering, sinking the logic for building a StaticBuildConfiguration from language options down into a new swiftBasicSwift library, which sits on top of the C++ swiftBasic and provides Swift functionality for it. That can be used by the C++ swiftAST to cache the StaticBuildConfiguration on the ASTContext, making it available for other parts of ASTGen.
29 lines
949 B
Swift
29 lines
949 B
Swift
//===--- String+BridgedString.swift ---------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2022-2025 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
import BasicBridging
|
|
|
|
extension String {
|
|
public init(bridged: BridgedStringRef) {
|
|
self.init(
|
|
decoding: UnsafeBufferPointer(start: bridged.data, count: bridged.count),
|
|
as: UTF8.self
|
|
)
|
|
}
|
|
|
|
public mutating func withBridgedString<R>(_ body: (BridgedStringRef) throws -> R) rethrows -> R {
|
|
try withUTF8 { buffer in
|
|
try body(BridgedStringRef(data: buffer.baseAddress, count: buffer.count))
|
|
}
|
|
}
|
|
}
|