|
| 1 | +// swift-tools-version:5.10 |
| 2 | +//===----------------------------------------------------------------------===// |
| 3 | +// |
| 4 | +// This source file is part of the SwiftOpenAPIGenerator open source project |
| 5 | +// |
| 6 | +// Copyright (c) 2023 Apple Inc. and the SwiftOpenAPIGenerator project authors |
| 7 | +// Licensed under Apache License v2.0 |
| 8 | +// |
| 9 | +// See LICENSE.txt for license information |
| 10 | +// See CONTRIBUTORS.txt for the list of SwiftOpenAPIGenerator project authors |
| 11 | +// |
| 12 | +// SPDX-License-Identifier: Apache-2.0 |
| 13 | +// |
| 14 | +//===----------------------------------------------------------------------===// |
| 15 | +import Foundation |
| 16 | +import PackageDescription |
| 17 | + |
| 18 | +// General Swift-settings for all targets. |
| 19 | +var swiftSettings: [SwiftSetting] = [ |
| 20 | + // https://github.com/apple/swift-evolution/blob/main/proposals/0335-existential-any.md |
| 21 | + // Require `any` for existential types. |
| 22 | + .enableUpcomingFeature("ExistentialAny"), .enableExperimentalFeature("StrictConcurrency=complete"), |
| 23 | +] |
| 24 | + |
| 25 | +let package = Package( |
| 26 | + name: "swift-openapi-generator", |
| 27 | + platforms: [ |
| 28 | + .macOS(.v10_15), |
| 29 | + |
| 30 | + // The platforms below are not currently supported for running |
| 31 | + // the generator itself. We include them here to allow the generator |
| 32 | + // to emit a more descriptive compiler error. |
| 33 | + .iOS(.v13), .tvOS(.v13), .watchOS(.v6), .visionOS(.v1), |
| 34 | + ], |
| 35 | + products: [ |
| 36 | + .executable(name: "swift-openapi-generator", targets: ["swift-openapi-generator"]), |
| 37 | + .plugin(name: "OpenAPIGenerator", targets: ["OpenAPIGenerator"]), |
| 38 | + .plugin(name: "OpenAPIGeneratorCommand", targets: ["OpenAPIGeneratorCommand"]), |
| 39 | + .library(name: "_OpenAPIGeneratorCore", targets: ["_OpenAPIGeneratorCore"]), |
| 40 | + ], |
| 41 | + dependencies: [ |
| 42 | + |
| 43 | + // General algorithms |
| 44 | + .package(url: "https://github.com/apple/swift-algorithms", from: "1.2.0"), |
| 45 | + .package(url: "https://github.com/apple/swift-collections", from: "1.1.4"), |
| 46 | + |
| 47 | + // Read OpenAPI documents |
| 48 | + .package(url: "https://github.com/mattpolzin/OpenAPIKit", from: "3.9.0"), |
| 49 | + .package(url: "https://github.com/jpsim/Yams", "4.0.0"..<"7.0.0"), |
| 50 | + |
| 51 | + // CLI Tool |
| 52 | + .package(url: "https://github.com/apple/swift-argument-parser", from: "1.3.0"), |
| 53 | + |
| 54 | + // Tests-only: Runtime library linked by generated code, and also |
| 55 | + // helps keep the runtime library new enough to work with the generated |
| 56 | + // code. |
| 57 | + .package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.11.0"), |
| 58 | + .package(url: "https://github.com/apple/swift-http-types", from: "1.0.2"), |
| 59 | + ], |
| 60 | + targets: [ |
| 61 | + |
| 62 | + // Generator Core |
| 63 | + .target( |
| 64 | + name: "_OpenAPIGeneratorCore", |
| 65 | + dependencies: [ |
| 66 | + .product(name: "OpenAPIKit", package: "OpenAPIKit"), |
| 67 | + .product(name: "OpenAPIKit30", package: "OpenAPIKit"), |
| 68 | + .product(name: "OpenAPIKitCompat", package: "OpenAPIKit"), |
| 69 | + .product(name: "Algorithms", package: "swift-algorithms"), |
| 70 | + .product(name: "OrderedCollections", package: "swift-collections"), |
| 71 | + .product(name: "Yams", package: "Yams"), |
| 72 | + ], |
| 73 | + swiftSettings: swiftSettings |
| 74 | + ), |
| 75 | + |
| 76 | + // Generator Core Tests |
| 77 | + .testTarget( |
| 78 | + name: "OpenAPIGeneratorCoreTests", |
| 79 | + dependencies: ["_OpenAPIGeneratorCore"], |
| 80 | + swiftSettings: swiftSettings |
| 81 | + ), |
| 82 | + |
| 83 | + // GeneratorReferenceTests |
| 84 | + .testTarget( |
| 85 | + name: "OpenAPIGeneratorReferenceTests", |
| 86 | + dependencies: ["_OpenAPIGeneratorCore"], |
| 87 | + resources: [.copy("Resources")], |
| 88 | + swiftSettings: swiftSettings |
| 89 | + ), |
| 90 | + |
| 91 | + // Common types for concrete PetstoreConsumer*Tests test targets. |
| 92 | + .target( |
| 93 | + name: "PetstoreConsumerTestCore", |
| 94 | + dependencies: [ |
| 95 | + .product(name: "OpenAPIRuntime", package: "swift-openapi-runtime"), |
| 96 | + .product(name: "HTTPTypes", package: "swift-http-types"), |
| 97 | + ], |
| 98 | + swiftSettings: swiftSettings |
| 99 | + ), |
| 100 | + |
| 101 | + // PetstoreConsumerTests |
| 102 | + // Builds and tests the reference code from GeneratorReferenceTests |
| 103 | + // to ensure it actually works correctly at runtime. |
| 104 | + .testTarget( |
| 105 | + name: "PetstoreConsumerTests", |
| 106 | + dependencies: ["PetstoreConsumerTestCore"], |
| 107 | + swiftSettings: swiftSettings |
| 108 | + ), |
| 109 | + |
| 110 | + // Test Target for swift-openapi-generator |
| 111 | + .testTarget( |
| 112 | + name: "OpenAPIGeneratorTests", |
| 113 | + dependencies: [ |
| 114 | + "_OpenAPIGeneratorCore", |
| 115 | + // Everything except windows: https://github.com/swiftlang/swift-package-manager/issues/6367 |
| 116 | + .target( |
| 117 | + name: "swift-openapi-generator", |
| 118 | + condition: .when(platforms: [.android, .linux, .macOS, .openbsd, .wasi, .custom("freebsd")]) |
| 119 | + ), .product(name: "ArgumentParser", package: "swift-argument-parser"), |
| 120 | + ], |
| 121 | + resources: [.copy("Resources")], |
| 122 | + swiftSettings: swiftSettings |
| 123 | + ), |
| 124 | + |
| 125 | + // Generator CLI |
| 126 | + .executableTarget( |
| 127 | + name: "swift-openapi-generator", |
| 128 | + dependencies: [ |
| 129 | + "_OpenAPIGeneratorCore", .product(name: "ArgumentParser", package: "swift-argument-parser"), |
| 130 | + ], |
| 131 | + swiftSettings: swiftSettings |
| 132 | + ), |
| 133 | + |
| 134 | + // Build Plugin |
| 135 | + .plugin(name: "OpenAPIGenerator", capability: .buildTool(), dependencies: ["swift-openapi-generator"]), |
| 136 | + |
| 137 | + // Command Plugin |
| 138 | + .plugin( |
| 139 | + name: "OpenAPIGeneratorCommand", |
| 140 | + capability: .command( |
| 141 | + intent: .custom( |
| 142 | + verb: "generate-code-from-openapi", |
| 143 | + description: "Generate Swift code from an OpenAPI document." |
| 144 | + ), |
| 145 | + permissions: [ |
| 146 | + .writeToPackageDirectory( |
| 147 | + reason: "To write the generated Swift files back into the source directory of the package." |
| 148 | + ) |
| 149 | + ] |
| 150 | + ), |
| 151 | + dependencies: ["swift-openapi-generator"] |
| 152 | + ), |
| 153 | + ] |
| 154 | +) |
| 155 | + |
| 156 | +// --- STANDARD CROSS-REPO SETTINGS DO NOT EDIT --- // |
| 157 | +for target in package.targets { |
| 158 | + switch target.type { |
| 159 | + case .regular, .test, .executable: |
| 160 | + var settings = target.swiftSettings ?? [] |
| 161 | + // https://github.com/swiftlang/swift-evolution/blob/main/proposals/0444-member-import-visibility.md |
| 162 | + settings.append(.enableUpcomingFeature("MemberImportVisibility")) |
| 163 | + target.swiftSettings = settings |
| 164 | + case .macro, .plugin, .system, .binary: () // not applicable |
| 165 | + @unknown default: () // we don't know what to do here, do nothing |
| 166 | + } |
| 167 | +}// --- END: STANDARD CROSS-REPO SETTINGS DO NOT EDIT --- // |
0 commit comments