Skip to content

Commit

Permalink
Depend explicitly on swift-testing when on Linux as it is not bundled
Browse files Browse the repository at this point in the history
  • Loading branch information
bok- committed Jul 17, 2024
1 parent 3b266fc commit 67527fd
Show file tree
Hide file tree
Showing 2 changed files with 197 additions and 136 deletions.
175 changes: 106 additions & 69 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,82 +20,119 @@ let package = Package(
// .library(name: "Vexillographer", targets: [ "Vexillographer" ]),
],

dependencies: [
.package(url: "https://github.com/apple/swift-async-algorithms.git", from: "1.0.0"),
.package(url: "https://github.com/nicklockwood/SwiftFormat.git", from: "0.54.1"),
.package(url: "https://github.com/apple/swift-syntax.git", exact: "600.0.0-prerelease-2024-06-12"),
],
dependencies: .init {
Package.Dependency.package(url: "https://github.com/apple/swift-async-algorithms.git", from: "1.0.0")
Package.Dependency.package(url: "https://github.com/nicklockwood/SwiftFormat.git", from: "0.54.1")
Package.Dependency.package(url: "https://github.com/apple/swift-syntax.git", exact: "600.0.0-prerelease-2024-06-12")

#if os(Linux)
// Linux does not come bundled with swift-testing
Package.Dependency.package(url: "https://github.com/apple/swift-testing.git", exact: "0.11.0")
#endif

},

targets: .init {

// Vexil

Target.target(
name: "Vexil",
dependencies: [
.target(name: "VexilMacros"),
.product(name: "AsyncAlgorithms", package: "swift-async-algorithms"),
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency"),
]
)
Target.testTarget(
name: "VexilTests",
dependencies: .init {
Target.Dependency.target(name: "Vexil")

#if os(Linux)
// Linux does not come bundled with swift-testing
Target.Dependency.product(name: "Testing", package: "swift-testing")
#endif

targets: {
var targets: [Target] = [

// Vexil

.target(
name: "Vexil",
dependencies: [
.target(name: "VexilMacros"),
.product(name: "AsyncAlgorithms", package: "swift-async-algorithms"),
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency"),
]
),
.testTarget(
name: "VexilTests",
dependencies: [
.target(name: "Vexil"),
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency"),
]
),

// Vexillographer

// .target(
// name: "Vexillographer",
// dependencies: [
// .target(name: "Vexil"),
// ]
// ),

// Macros

.macro(
name: "VexilMacros",
dependencies: [
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
.product(name: "SwiftSyntax", package: "swift-syntax"),
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency"),
]
),

]
},
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency"),
]
)

// Vexillographer

// Target.target(
// name: "Vexillographer",
// dependencies: [
// .target(name: "Vexil"),
// ]
// ),

// Macros

Target.macro(
name: "VexilMacros",
dependencies: [
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
.product(name: "SwiftSyntax", package: "swift-syntax"),
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency"),
]
)

#if !os(Linux)
targets += [
.testTarget(
name: "VexilMacroTests",
dependencies: [
.target(name: "VexilMacros"),
.product(name: "SwiftSyntaxMacrosTestSupport", package: "swift-syntax"),
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency"),
]
),
]

// We can't disable macro validation using `swift test` so these are guaranteed to fail on Linux
Target.testTarget(
name: "VexilMacroTests",
dependencies: [
.target(name: "VexilMacros"),
.product(name: "SwiftSyntaxMacrosTestSupport", package: "swift-syntax"),
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency"),
]
)

#endif

return targets
}(),
},

swiftLanguageVersions: [
.v6,
]

)

// MARK: - Helpers

@resultBuilder
enum CollectionBuilder<Element> {

typealias Component = [Element]

static func buildExpression(_ expression: Element) -> Component {
[expression]
}

static func buildBlock(_ components: Component...) -> Component {
components.flatMap { $0 }
}

static func buildLimitedAvailability(_ components: [Element]) -> Component {
components
}

}

extension Array {
init(@CollectionBuilder<Element> collecting: () -> [Element]) {
self = collecting()
}
}
158 changes: 91 additions & 67 deletions [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -27,79 +27,103 @@ let package = Package(
.package(url: "https://github.com/apple/swift-testing.git", exact: "0.7.0"),
],

targets: {
var targets: [Target] = [

// Vexil

.target(
name: "Vexil",
dependencies: [
.target(name: "VexilMacros"),
.product(name: "AsyncAlgorithms", package: "swift-async-algorithms"),
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency"),
]
),
.testTarget(
name: "VexilTests",
dependencies: [
.target(name: "Vexil"),
.product(name: "Testing", package: "swift-testing"),
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency"),
.define("SWT_TARGET_OS_APPLE", .when(platforms: [.macOS, .iOS, .macCatalyst, .watchOS, .tvOS, .visionOS])),
.define("SWT_NO_FILE_IO", .when(platforms: [.wasi])),
]
),

// Vexillographer

// .target(
// name: "Vexillographer",
// dependencies: [
// .target(name: "Vexil"),
// ]
// ),

// Macros

.macro(
name: "VexilMacros",
dependencies: [
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
.product(name: "SwiftSyntax", package: "swift-syntax"),
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency"),
]
),

]
targets: .init {

// Vexil

Target.target(
name: "Vexil",
dependencies: [
.target(name: "VexilMacros"),
.product(name: "AsyncAlgorithms", package: "swift-async-algorithms"),
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency"),
]
)
Target.testTarget(
name: "VexilTests",
dependencies: [
.target(name: "Vexil"),
.product(name: "Testing", package: "swift-testing"),
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency"),
.define("SWT_TARGET_OS_APPLE", .when(platforms: [.macOS, .iOS, .macCatalyst, .watchOS, .tvOS, .visionOS])),
.define("SWT_NO_FILE_IO", .when(platforms: [.wasi])),
]
)

// Vexillographer

// Target.target(
// name: "Vexillographer",
// dependencies: [
// .target(name: "Vexil"),
// ]
// ),

// Macros

Target.macro(
name: "VexilMacros",
dependencies: [
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
.product(name: "SwiftSyntax", package: "swift-syntax"),
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency"),
]
)

#if !os(Linux)
targets += [
.testTarget(
name: "VexilMacroTests",
dependencies: [
.target(name: "VexilMacros"),
.product(name: "SwiftSyntaxMacrosTestSupport", package: "swift-syntax"),
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency"),
]
),
]

// We can't disable macro validation using `swift test` so these are guaranteed to fail on Linux
Target.testTarget(
name: "VexilMacroTests",
dependencies: [
.target(name: "VexilMacros"),
.product(name: "SwiftSyntaxMacrosTestSupport", package: "swift-syntax"),
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency"),
]
)

#endif

return targets
}(),
},

swiftLanguageVersions: [
.v5,
]
)

// MARK: - Helpers

@resultBuilder
enum CollectionBuilder<Element> {

typealias Component = [Element]

static func buildExpression(_ expression: Element) -> Component {
[expression]
}

static func buildBlock(_ components: Component...) -> Component {
components.flatMap { $0 }
}

static func buildLimitedAvailability(_ components: [Element]) -> Component {
components
}

}

extension Array {
init(@CollectionBuilder<Element> collecting: () -> [Element]) {
self = collecting()
}
}

0 comments on commit 67527fd

Please sign in to comment.