Avatar
Kishikawa Katsumi 3/13/2023 8:36 AM
Swiftマクロ、パッケージマネージャで配布して動かせるようになったわ。 https://github.com/kishikawakatsumi/swift-power-assert-macro マクロを提供する側の定義はこんな感じで、 // swift-tools-version: 999.0 import CompilerPluginSupport import PackageDescription let package = Package( name: "SwiftPowerAssert", platforms: [ .iOS("13.0"), .macOS("10.15") ], products: [ .library( name: "SwiftPowerAssertLib", targets: ["SwiftPowerAssertLib"] ), ], dependencies: [ .package( url: "https://github.com/apple/swift-syntax.git", branch: "main" ), ], targets: [ .macro(name: "SwiftPowerAssertPlugin", dependencies: [ .product(name: "SwiftSyntax", package: "swift-syntax"), .product(name: "SwiftSyntaxMacros", package: "swift-syntax"), .product(name: "SwiftOperators", package: "swift-syntax"), .product(name: "SwiftParser", package: "swift-syntax"), .product(name: "SwiftParserDiagnostics", package: "swift-syntax"), .product(name: "SwiftCompilerPlugin", package: "swift-syntax"), ] ), .target(name: "SwiftPowerAssertLib", dependencies: ["SwiftPowerAssertPlugin"] ), ] ) マクロを使う側の定義はこう。ライブラリを依存関係に追加するだけで使う側はそれがマクロを含んでるかどうかはPackage.swiftを見るだけだとわからない。普通にライブラリを導入するのと一緒。だと思う。 // swift-tools-version: 999.0 import PackageDescription let package = Package( name: "swift-power-assert-client", platforms: [ .iOS("13.0"), .macOS("10.15") ], products: [ .executable( name: "swift-power-assert-client", targets: ["swift-power-assert-client"] ), ], dependencies: [ .package( url: "https://github.com/kishikawakatsumi/swift-power-assert-macro.git", branch: "main" ), ], targets: [ .executableTarget( name: "swift-power-assert-client", dependencies: [ .product(name: "SwiftPowerAssertLib", package: "swift-power-assert-macro") ] ), ] ) (edited)
👍 4
👀 1