Skip to content

Commit 33bda28

Browse files
committed
Refactor to more closely match starter project from Xcode 16.2
1 parent 2395e13 commit 33bda28

File tree

3 files changed

+37
-20
lines changed

3 files changed

+37
-20
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/// A macro that produces both a value and a string containing the
16+
/// source code that generated the value. For example,
17+
///
18+
/// #stringify(x + y)
19+
///
20+
/// produces a tuple `(x + y, "x + y")`.
21+
@freestanding(expression)
22+
public macro stringify<T>(_ value: T) -> (T, String) =
23+
#externalMacro(module: "FirebaseAILogicMacros", type: "StringifyMacro")

FirebaseAI/Tests/Unit/Macros/GenerableMacroTests.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,15 @@
2323
import XCTest
2424

2525
final class GenerableMacroTests: XCTestCase {
26-
let testMacros: [String: Macro.Type] = [
27-
"stringify": StringifyMacro.self,
28-
]
26+
#if swift(>=6.2)
27+
nonisolated(unsafe) static let testMacros: [String: Macro.Type] = [
28+
"stringify": StringifyMacro.self,
29+
]
30+
#else
31+
static let testMacros: [String: Macro.Type] = [
32+
"stringify": StringifyMacro.self,
33+
]
34+
#endif // swift(>=6.2)
2935

3036
func testMacro() throws {
3137
assertMacroExpansion(
@@ -35,7 +41,7 @@
3541
expandedSource: """
3642
(a + b, "a + b")
3743
""",
38-
macros: testMacros
44+
macros: GenerableMacroTests.testMacros
3945
)
4046
}
4147

@@ -47,7 +53,7 @@
4753
expandedSource: #"""
4854
("Hello, \(name)", #""Hello, \(name)""#)
4955
"""#,
50-
macros: testMacros
56+
macros: GenerableMacroTests.testMacros
5157
)
5258
}
5359
}

Package.swift

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ let package = Package(
177177
),
178178
.package(url: "https://github.com/google/app-check.git",
179179
"11.0.1" ..< "12.0.0"),
180-
.package(url: "https://github.com/swiftlang/swift-syntax.git", "600.0.1" ..< "601.0.0"),
180+
.package(url: "https://github.com/swiftlang/swift-syntax.git", from: "600.0.0-latest"),
181181
],
182182
targets: [
183183
.target(
@@ -203,8 +203,6 @@ let package = Package(
203203
.macro(
204204
name: "FirebaseAILogicMacros",
205205
dependencies: [
206-
.product(name: "SwiftSyntax", package: "swift-syntax"),
207-
.product(name: "SwiftSyntaxMacroExpansion", package: "swift-syntax"),
208206
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
209207
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
210208
],
@@ -215,23 +213,13 @@ let package = Package(
215213
dependencies: [
216214
"FirebaseAILogic",
217215
"FirebaseStorage",
218-
.target(
219-
name: "FirebaseAILogicMacros",
220-
condition: .when(platforms: [.macOS])
221-
),
222-
.product(
223-
name: "SwiftSyntaxMacrosTestSupport",
224-
package: "swift-syntax",
225-
condition: .when(platforms: [.macOS])
226-
),
216+
"FirebaseAILogicMacros",
217+
.product(name: "SwiftSyntaxMacrosTestSupport", package: "swift-syntax"),
227218
],
228219
path: "FirebaseAI/Tests/Unit",
229220
resources: [
230221
.copy("vertexai-sdk-test-data/mock-responses"),
231222
.process("Resources"),
232-
],
233-
cSettings: [
234-
.headerSearchPath("../../../"),
235223
]
236224
),
237225
.target(

0 commit comments

Comments
 (0)