Skip to content

Commit

Permalink
#35: Maintain support for swift <5.9
Browse files Browse the repository at this point in the history
  • Loading branch information
tdeleon committed Jan 3, 2024
1 parent 5de1bf5 commit 7a77394
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 56 deletions.
16 changes: 4 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,16 @@ on: [push]
jobs:
build:
strategy:
max-parallel: 5
fail-fast: false
matrix:
os: [macos-13, ubuntu-latest, windows-latest]
swift: ["5.7", "5.8", "5.9"]
runs-on: ${{ matrix.os }}

steps:

- if: runner.os == 'Windows'
name: Setup Swift
uses: compnerd/gha-setup-swift@main
- uses: SwiftyLab/setup-swift@latest
with:
branch: swift-5.9.2-release
tag: 5.9.2-RELEASE

- if: runner.os != 'Windows'
uses: swift-actions/setup-swift@v1
with:
swift-version: "5.9"
swift-version: ${{ matrix.swift }}

- name: Checkout
uses: actions/checkout@v4
Expand All @@ -33,3 +24,4 @@ jobs:

- name: Test
run: swift test

63 changes: 19 additions & 44 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,48 +1,7 @@
// swift-tools-version:5.9
// swift-tools-version:5.7
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
import CompilerPluginSupport


var targets: [Target] = [
.target(
name: "URLMock",
dependencies: ["Relax"]
),
.testTarget(
name: "RelaxTests",
dependencies: ["Relax", "URLMock"]
),
]

var dependencies = [Package.Dependency]()

// Macros do not currently compile on windows when building tests: https://github.com/apple/swift-package-manager/issues/7174
#if canImport(XCTest) && os(Windows)
targets.append(.target(name: "Relax"))
#else
targets.append(
contentsOf: [
.target(name: "Relax", dependencies: ["RelaxMacros"]),
.macro(
name: "RelaxMacros",
dependencies: [
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
.product(name: "SwiftCompilerPlugin", package: "swift-syntax")
]
),
.testTarget(
name: "RelaxMacrosTests",
dependencies: ["RelaxMacros", .product(name: "SwiftSyntaxMacrosTestSupport", package: "swift-syntax")]
)
]
)
dependencies = [
// Depend on the Swift 5.9 release of SwiftSyntax
.package(url: "https://github.com/apple/swift-syntax.git", from: "509.0.0"),
]
#endif

let package = Package(
name: "Relax",
Expand All @@ -61,6 +20,22 @@ let package = Package(
name: "URLMock",
targets: ["URLMock"])
],
dependencies: dependencies,
targets: targets
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "Relax",
dependencies: []),
.target(
name: "URLMock",
dependencies: ["Relax"]
),
.testTarget(
name: "RelaxTests",
dependencies: ["Relax", "URLMock"]),
]
)
66 changes: 66 additions & 0 deletions Package@swift-5.9.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// swift-tools-version:5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
import CompilerPluginSupport


var targets: [Target] = [
.target(
name: "URLMock",
dependencies: ["Relax"]
),
.testTarget(
name: "RelaxTests",
dependencies: ["Relax", "URLMock"]
),
]

var dependencies = [Package.Dependency]()

// Macros do not currently compile on windows when building tests: https://github.com/apple/swift-package-manager/issues/7174
#if canImport(XCTest) && os(Windows)
targets.append(.target(name: "Relax"))
#else
targets.append(
contentsOf: [
.target(name: "Relax", dependencies: ["RelaxMacros"]),
.macro(
name: "RelaxMacros",
dependencies: [
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
.product(name: "SwiftCompilerPlugin", package: "swift-syntax")
]
),
.testTarget(
name: "RelaxMacrosTests",
dependencies: ["RelaxMacros", .product(name: "SwiftSyntaxMacrosTestSupport", package: "swift-syntax")]
)
]
)
dependencies = [
// Depend on the Swift 5.9 release of SwiftSyntax
.package(url: "https://github.com/apple/swift-syntax.git", from: "509.0.0"),
]
#endif

let package = Package(
name: "Relax",
platforms: [
.iOS(.v14),
.tvOS(.v14),
.watchOS(.v7),
.macOS(.v12),
],
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "Relax",
targets: ["Relax"]),
.library(
name: "URLMock",
targets: ["URLMock"])
],
dependencies: dependencies,
targets: targets
)
2 changes: 2 additions & 0 deletions Sources/Relax/Macros/APIService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
// Created by Thomas De Leon on 12/27/23.
//

#if swift(>=5.9)
import Foundation

@attached(extension, conformances: APIComponent, names: named(baseURL))
public macro APIService(_ baseURL: String) = #externalMacro(module: "RelaxMacros", type: "APIServiceMacro")
#endif

0 comments on commit 7a77394

Please sign in to comment.