|
1 | | -// swift-tools-version: 5.9 |
| 1 | +// swift-tools-version: 6.0 |
2 | 2 | import CompilerPluginSupport |
3 | 3 | import PackageDescription |
4 | 4 |
|
5 | 5 | let package = Package( |
6 | 6 | name: "SmartCodable", |
7 | | - platforms: [.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6), .macCatalyst(.v13), .visionOS(.v1)], |
| 7 | + platforms: [ |
| 8 | + .macOS(.v10_15), |
| 9 | + .iOS(.v13), |
| 10 | + .tvOS(.v13), |
| 11 | + .watchOS(.v6), |
| 12 | + .macCatalyst(.v13), |
| 13 | + .visionOS(.v1) |
| 14 | + ], |
| 15 | + |
8 | 16 | products: [ |
9 | | - // Products define the executables and libraries a package produces, making them visible to other packages. |
| 17 | + // 纯运行时库,不依赖宏或 SwiftSyntax |
10 | 18 | .library( |
11 | 19 | name: "SmartCodable", |
12 | 20 | targets: ["SmartCodable"] |
13 | 21 | ), |
| 22 | + |
| 23 | + // 带继承/宏能力,依赖 SwiftSyntax |
14 | 24 | .library( |
15 | 25 | name: "SmartCodableInherit", |
16 | 26 | targets: ["SmartCodableInherit"] |
17 | 27 | ) |
18 | 28 | ], |
| 29 | + |
19 | 30 | dependencies: [ |
20 | | - // Depend on the latest Swift 5.9 SwiftSyntax |
21 | | - .package(url: "https://github.com/swiftlang/swift-syntax", "600.0.0"..<"700.0.0") |
| 31 | + // SwiftSyntax 只会被 macro target 使用 |
| 32 | + // 注意:严格锁定版本,确保 Xcode26.3 / Swift6.1+ 可用 |
| 33 | + .package( |
| 34 | + url: "https://github.com/apple/swift-syntax.git", |
| 35 | + from: "610.0.0" |
| 36 | + ) |
22 | 37 | ], |
| 38 | + |
23 | 39 | targets: [ |
24 | | - // Targets are the basic building blocks of a package, defining a module or a test suite. |
25 | | - // Targets can depend on other targets in this package and products from dependencies. |
26 | | - // Macro implementation that performs the source transformation of a macro. |
| 40 | + // ========================= |
| 41 | + // MARK: Runtime target (no macro) |
| 42 | + // ========================= |
| 43 | + .target( |
| 44 | + name: "SmartCodable", |
| 45 | + path: "Sources/SmartCodable", |
| 46 | + exclude: ["MacroSupport"] // 运行时不需要 macro 文件 |
| 47 | + ), |
| 48 | + |
| 49 | + // ========================= |
| 50 | + // MARK: Macro target |
| 51 | + // ========================= |
27 | 52 | .macro( |
28 | 53 | name: "SmartCodableMacros", |
29 | 54 | dependencies: [ |
30 | 55 | .product(name: "SwiftSyntax", package: "swift-syntax"), |
31 | 56 | .product(name: "SwiftSyntaxMacros", package: "swift-syntax"), |
32 | | - .product(name: "SwiftOperators", package: "swift-syntax"), |
33 | | - .product(name: "SwiftParser", package: "swift-syntax"), |
34 | | - .product(name: "SwiftParserDiagnostics", package: "swift-syntax"), |
35 | 57 | .product(name: "SwiftCompilerPlugin", package: "swift-syntax"), |
36 | | - ] |
| 58 | + .product(name: "SwiftSyntaxBuilder", package: "swift-syntax"), |
| 59 | + .product(name: "SwiftParser", package: "swift-syntax"), |
| 60 | + .product(name: "SwiftParserDiagnostics", package: "swift-syntax") |
| 61 | + ], |
| 62 | + path: "Sources/SmartCodableMacros" |
37 | 63 | ), |
38 | 64 |
|
39 | | - // Library that exposes a macro as part of its API, which is used in client programs. |
40 | | - .target( |
41 | | - name: "SmartCodable", |
42 | | - exclude: ["MacroSupport"]), |
43 | | - |
| 65 | + // ========================= |
| 66 | + // MARK: Macro-enabled API target |
| 67 | + // ========================= |
44 | 68 | .target( |
45 | 69 | name: "SmartCodableInherit", |
46 | 70 | dependencies: [ |
| 71 | + "SmartCodable", |
47 | 72 | "SmartCodableMacros" |
48 | 73 | ], |
49 | | - path: "Sources/SmartCodable/MacroSupport"), |
50 | | - |
51 | | - // A test target used to develop the macro implementation. |
| 74 | + path: "Sources/SmartCodable/MacroSupport" |
| 75 | + ), |
| 76 | + |
| 77 | + // ========================= |
| 78 | + // MARK: Test target |
| 79 | + // ========================= |
52 | 80 | .testTarget( |
53 | 81 | name: "SmartCodableTests", |
54 | 82 | dependencies: [ |
55 | 83 | "SmartCodable", |
56 | 84 | "SmartCodableInherit", |
57 | 85 | "SmartCodableMacros", |
58 | | - .product(name: "SwiftSyntaxMacrosTestSupport", package: "swift-syntax"), |
59 | | - ] |
60 | | - ), |
| 86 | + .product( |
| 87 | + name: "SwiftSyntaxMacrosTestSupport", |
| 88 | + package: "swift-syntax" |
| 89 | + ) |
| 90 | + ], |
| 91 | + path: "Tests" |
| 92 | + ) |
61 | 93 | ] |
62 | 94 | ) |
0 commit comments