forked from trinhngocthuyen/cocoapods-spm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEAT: Support local macro pod (trinhngocthuyen#138)
* Add a local macro pkg * FEAT: Support local macro pod
- Loading branch information
1 parent
4868173
commit 7d6293c
Showing
14 changed files
with
131 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// swift-tools-version: 5.9 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
||
import PackageDescription | ||
import CompilerPluginSupport | ||
|
||
let package = Package( | ||
name: "Wizard", | ||
platforms: [.macOS(.v11), .iOS(.v14), .tvOS(.v13), .watchOS(.v6), .macCatalyst(.v13)], | ||
products: [ | ||
.library( | ||
name: "Wizard", | ||
targets: ["Wizard"] | ||
), | ||
.executable( | ||
name: "WizardPlayground", | ||
targets: ["WizardPlayground"] | ||
), | ||
], | ||
dependencies: [ | ||
.package(url: "https://github.com/apple/swift-syntax.git", from: "509.0.0"), | ||
.package(url: "https://github.com/stackotter/swift-macro-toolkit.git", from: "0.3.1"), | ||
], | ||
targets: [ | ||
.macro( | ||
name: "WizardImpl", | ||
dependencies: [ | ||
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"), | ||
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"), | ||
.product(name: "MacroToolkit", package: "swift-macro-toolkit"), | ||
] | ||
), | ||
.target(name: "Wizard", dependencies: ["WizardImpl"]), | ||
.executableTarget(name: "WizardPlayground", dependencies: ["Wizard"]), | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import UIKit | ||
|
||
@freestanding(expression) | ||
public macro uiColor(_ intLiteral: IntegerLiteralType ) -> UIColor = #externalMacro(module: "WizardImpl", type: "HexToUIColorMacro") |
28 changes: 28 additions & 0 deletions
28
examples/LocalPackages/ex-macros/Sources/WizardImpl/HexColorMacro.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import SwiftCompilerPlugin | ||
import SwiftSyntax | ||
import SwiftSyntaxBuilder | ||
import SwiftSyntaxMacros | ||
import MacroToolkit | ||
|
||
enum HexColorMacroError: Error { | ||
case notFoundHex | ||
} | ||
|
||
public struct HexToUIColorMacro: ExpressionMacro { | ||
public static func expansion( | ||
of node: some FreestandingMacroExpansionSyntax, | ||
in context: some MacroExpansionContext | ||
) throws -> ExprSyntax { | ||
guard let arg = node.argumentList.first, let hex = Expr(arg.expression).asIntegerLiteral?.value else { | ||
throw HexColorMacroError.notFoundHex | ||
} | ||
return """ | ||
UIColor( | ||
red: CGFloat((\(raw: hex) >> 16) & 0xff) / 255, | ||
green: CGFloat((\(raw: hex) >> 8) & 0xff) / 255, | ||
blue: CGFloat((\(raw: hex) >> 0) & 0xff) / 255, | ||
alpha: CGFloat(1) | ||
) | ||
""" | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
examples/LocalPackages/ex-macros/Sources/WizardImpl/WizardImpl.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import SwiftCompilerPlugin | ||
import SwiftSyntax | ||
import SwiftSyntaxBuilder | ||
import SwiftSyntaxMacros | ||
|
||
@main | ||
struct HexColorMacroPlugin: CompilerPlugin { | ||
let providingMacros: [Macro.Type] = [ | ||
HexToUIColorMacro.self, | ||
] | ||
} |
4 changes: 4 additions & 0 deletions
4
examples/LocalPackages/ex-macros/Sources/WizardPlayground/main.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import UIKit | ||
import Wizard | ||
|
||
let color = #uiColor(0xff0000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters