Skip to content

Commit

Permalink
Update with Swift 6
Browse files Browse the repository at this point in the history
  • Loading branch information
khlopko committed Aug 6, 2024
1 parent aad58a0 commit 463672c
Show file tree
Hide file tree
Showing 19 changed files with 516 additions and 492 deletions.
27 changes: 14 additions & 13 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# This workflow will build a Swift project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-swift

name: Swift
name: test

on:
push:
Expand All @@ -10,13 +7,17 @@ on:
branches: [ "main" ]

jobs:
build:
runs-on: macos-latest
run-tests:
runs-on: ${{ matrix.runner }}
strategy:
matrix:
runner: [ ubuntu-22.04, macos-latest ]
steps:
- uses: swift-actions/setup-swift@v1
with:
swift-version: "5.9"
- name: Build
run: swift build -v
- name: Run tests
run: swift test -v
- uses: actions/checkout@v4
- uses: khlopko/setup-swift@bfd61cbd14eeef55a27afc45138b61ced7174839
with:
swift-version: "main-snapshot"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: swift test

7 changes: 4 additions & 3 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"originHash" : "ac7a8b3c89189306fafff79842be1c9addc0a3faf5b97bab411a81122122615a",
"pins" : [
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-syntax.git",
"state" : {
"revision" : "f1e9245226002bb134884345d4809b9543da3666",
"version" : "509.0.0-swift-DEVELOPMENT-SNAPSHOT-2023-06-17-a"
"revision" : "06b5cdc432e93b60e3bdf53aff2857c6b312991a",
"version" : "600.0.0-prerelease-2024-07-30"
}
}
],
"version" : 2
"version" : 3
}
45 changes: 26 additions & 19 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,49 +1,56 @@
// swift-tools-version: 5.9
// swift-tools-version: 6.0

import PackageDescription
import CompilerPluginSupport
import PackageDescription

let package = Package(
name: "SweetDeclarations",
name: "swift-util-macros",
platforms: [
.macOS(.v10_15),
.iOS(.v13),
.tvOS(.v13),
.watchOS(.v6),
.macCatalyst(.v13)
.macCatalyst(.v13),
],
products: [
.library(
name: "SweetDeclarationsLib",
targets: ["SweetDeclarationsLib"]
name: "SwiftUtilMacros",
targets: ["SwiftUtilMacros"]
),
.executable(
name: "SweetDeclarationsClient",
targets: ["SweetDeclarationsClient"]
name: "SwiftUtilMacrosClient",
targets: ["SwiftUtilMacrosClient"]
),
],
dependencies: [
.package(
url: "https://github.com/apple/swift-syntax.git",
from: "509.0.0-swift-5.9-DEVELOPMENT-SNAPSHOT-2023-04-25-b"
),
.package(url: "https://github.com/apple/swift-syntax.git", from: "600.0.0-latest")
],
targets: [
.macro(
name: "SweetDeclarationsPlugin",
name: "SwiftUtilMacrosPlugin",
dependencies: [
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
.product(name: "SwiftCompilerPlugin", package: "swift-syntax")
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
]
),
.target(
name: "SwiftUtilMacros",
dependencies: [
.target(name: "SwiftUtilMacrosPlugin")
]
),
.executableTarget(
name: "SwiftUtilMacrosClient",
dependencies: [
.target(name: "SwiftUtilMacros")
]
),
.target(name: "SweetDeclarationsLib", dependencies: ["SweetDeclarationsPlugin"]),
.executableTarget(name: "SweetDeclarationsClient", dependencies: ["SweetDeclarationsLib"]),
.testTarget(
name: "SweetDeclarationsLibTests",
name: "SwiftUtilMacrosPluginTests",
dependencies: [
"SweetDeclarationsLib",
.target(name: "SwiftUtilMacrosPlugin"),
.product(name: "SwiftSyntaxMacrosTestSupport", package: "swift-syntax"),
]
)
),
]
)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SweetDeclarations
# swift-util-macros

A set of Swift macros to provide convenient initialization / modification over structs and classes
declarations.
Expand Down
15 changes: 0 additions & 15 deletions Sources/SweetDeclarationsLib/Macros.swift

This file was deleted.

20 changes: 20 additions & 0 deletions Sources/SwiftUtilMacros/Macros.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// Macros.swift
//

@attached(member, names: arbitrary)
public macro PublicInit() = #externalMacro(module: "SwiftUtilMacrosPlugin", type: "PublicInitMacro")

@attached(member, names: arbitrary)
public macro PublicInit(escaping: [Any.Type]) = #externalMacro(module: "SwiftUtilMacrosPlugin", type: "PublicInitMacro")

@attached(member, names: arbitrary)
public macro GranularUpdate() = #externalMacro(module: "SwiftUtilMacrosPlugin", type: "GranularUpdateMacro")

@attached(member, names: arbitrary)
public macro TestStub() = #externalMacro(module: "SwiftUtilMacrosPlugin", type: "TestStubMacro")

@attached(member)
@attached(extension, conformances: OptionSet)
public macro BitMask() = #externalMacro(module: "SwiftUtilMacrosPlugin", type: "BitMaskOptionSetMacro")

Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@

import Foundation

import SweetDeclarationsLib
import SwiftUtilMacros

public typealias GetConnections = () -> [User]

@PublicInit(escaping: [GetConnections.self])
@PublicInit
@GranularUpdate
public struct User {
var desc: String { "\(id)+\(name)" }
public let id: String
public let name: Name
public let getConnections: GetConnections
public let getConnections: () -> [User]
public let getPublications: (_ startDate: Date) -> [String]
}

Expand Down Expand Up @@ -53,3 +51,4 @@ final class SomeProtocolStub {
return method3Result!
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,15 @@
import SwiftSyntax

extension SwiftSyntax.AttributeSyntax {

internal func macrosEscapingArgs() -> [String] {
let tupleElement = argument?
.as(TupleExprElementListSyntax.self)?.first?
.as(TupleExprElementSyntax.self)
let tupleElement = arguments?.as(LabeledExprListSyntax.self)?.first
guard tupleElement?.label?.text == "escaping" else {
return []
}
return tupleElement?.expression.as(ArrayExprSyntax.self)?.elements.compactMap {
$0
.as(ArrayElementSyntax.self)?.expression
return tupleElement?.expression.as(ArrayExprSyntax.self)?.elements.compactMap { element in
element.expression
.as(MemberAccessExprSyntax.self)?.base?
.as(IdentifierExprSyntax.self)?.identifier.text
.as(DeclReferenceExprSyntax.self)?.baseName.text
} ?? []
}

}
Loading

0 comments on commit 463672c

Please sign in to comment.