Package@swift-6.swift 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008
  1. // swift-tools-version:6.0
  2. /*
  3. * Copyright 2024, gRPC Authors All rights reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. import PackageDescription
  18. // swiftformat puts the next import before the tools version.
  19. // swiftformat:disable:next sortImports
  20. import class Foundation.ProcessInfo
  21. let grpcPackageName = "grpc-swift"
  22. let grpcProductName = "GRPC"
  23. let cgrpcZlibProductName = "CGRPCZlib"
  24. let grpcTargetName = grpcProductName
  25. let cgrpcZlibTargetName = cgrpcZlibProductName
  26. let includeNIOSSL = ProcessInfo.processInfo.environment["GRPC_NO_NIO_SSL"] == nil
  27. // MARK: - Package Dependencies
  28. let packageDependencies: [Package.Dependency] = [
  29. .package(
  30. url: "https://github.com/apple/swift-nio.git",
  31. from: "2.65.0"
  32. ),
  33. .package(
  34. url: "https://github.com/apple/swift-nio-http2.git",
  35. from: "1.32.0"
  36. ),
  37. .package(
  38. url: "https://github.com/apple/swift-nio-transport-services.git",
  39. from: "1.15.0"
  40. ),
  41. .package(
  42. url: "https://github.com/apple/swift-nio-extras.git",
  43. from: "1.4.0"
  44. ),
  45. .package(
  46. url: "https://github.com/apple/swift-collections.git",
  47. from: "1.0.5"
  48. ),
  49. .package(
  50. url: "https://github.com/apple/swift-atomics.git",
  51. from: "1.2.0"
  52. ),
  53. .package(
  54. url: "https://github.com/apple/swift-protobuf.git",
  55. from: "1.27.0"
  56. ),
  57. .package(
  58. url: "https://github.com/apple/swift-log.git",
  59. from: "1.4.4"
  60. ),
  61. .package(
  62. url: "https://github.com/apple/swift-argument-parser.git",
  63. // Version is higher than in other Package@swift manifests: 1.1.0 raised the minimum Swift
  64. // version and indluded async support.
  65. from: "1.1.1"
  66. ),
  67. .package(
  68. url: "https://github.com/apple/swift-distributed-tracing.git",
  69. from: "1.0.0"
  70. ),
  71. ].appending(
  72. .package(
  73. url: "https://github.com/apple/swift-nio-ssl.git",
  74. from: "2.23.0"
  75. ),
  76. if: includeNIOSSL
  77. )
  78. // MARK: - Target Dependencies
  79. extension Target.Dependency {
  80. // Target dependencies; external
  81. static var grpc: Self { .target(name: grpcTargetName) }
  82. static var cgrpcZlib: Self { .target(name: cgrpcZlibTargetName) }
  83. static var protocGenGRPCSwift: Self { .target(name: "protoc-gen-grpc-swift") }
  84. static var performanceWorker: Self { .target(name: "performance-worker") }
  85. static var reflectionService: Self { .target(name: "GRPCReflectionService") }
  86. static var grpcCodeGen: Self { .target(name: "GRPCCodeGen") }
  87. static var grpcProtobuf: Self { .target(name: "GRPCProtobuf") }
  88. static var grpcProtobufCodeGen: Self { .target(name: "GRPCProtobufCodeGen") }
  89. // Target dependencies; internal
  90. static var grpcSampleData: Self { .target(name: "GRPCSampleData") }
  91. static var echoModel: Self { .target(name: "EchoModel") }
  92. static var echoImplementation: Self { .target(name: "EchoImplementation") }
  93. static var helloWorldModel: Self { .target(name: "HelloWorldModel") }
  94. static var routeGuideModel: Self { .target(name: "RouteGuideModel") }
  95. static var interopTestModels: Self { .target(name: "GRPCInteroperabilityTestModels") }
  96. static var interopTestImplementation: Self {
  97. .target(name: "GRPCInteroperabilityTestsImplementation")
  98. }
  99. static var interoperabilityTests: Self { .target(name: "InteroperabilityTests") }
  100. // Product dependencies
  101. static var argumentParser: Self {
  102. .product(
  103. name: "ArgumentParser",
  104. package: "swift-argument-parser"
  105. )
  106. }
  107. static var nio: Self { .product(name: "NIO", package: "swift-nio") }
  108. static var nioConcurrencyHelpers: Self {
  109. .product(
  110. name: "NIOConcurrencyHelpers",
  111. package: "swift-nio"
  112. )
  113. }
  114. static var nioCore: Self { .product(name: "NIOCore", package: "swift-nio") }
  115. static var nioEmbedded: Self { .product(name: "NIOEmbedded", package: "swift-nio") }
  116. static var nioExtras: Self { .product(name: "NIOExtras", package: "swift-nio-extras") }
  117. static var nioFoundationCompat: Self { .product(name: "NIOFoundationCompat", package: "swift-nio") }
  118. static var nioHTTP1: Self { .product(name: "NIOHTTP1", package: "swift-nio") }
  119. static var nioHTTP2: Self { .product(name: "NIOHTTP2", package: "swift-nio-http2") }
  120. static var nioPosix: Self { .product(name: "NIOPosix", package: "swift-nio") }
  121. static var nioSSL: Self { .product(name: "NIOSSL", package: "swift-nio-ssl") }
  122. static var nioTLS: Self { .product(name: "NIOTLS", package: "swift-nio") }
  123. static var nioTransportServices: Self {
  124. .product(
  125. name: "NIOTransportServices",
  126. package: "swift-nio-transport-services"
  127. )
  128. }
  129. static var nioTestUtils: Self { .product(name: "NIOTestUtils", package: "swift-nio") }
  130. static var nioFileSystem: Self { .product(name: "_NIOFileSystem", package: "swift-nio") }
  131. static var logging: Self { .product(name: "Logging", package: "swift-log") }
  132. static var protobuf: Self { .product(name: "SwiftProtobuf", package: "swift-protobuf") }
  133. static var protobufPluginLibrary: Self {
  134. .product(
  135. name: "SwiftProtobufPluginLibrary",
  136. package: "swift-protobuf"
  137. )
  138. }
  139. static var dequeModule: Self { .product(name: "DequeModule", package: "swift-collections") }
  140. static var atomics: Self { .product(name: "Atomics", package: "swift-atomics") }
  141. static var tracing: Self { .product(name: "Tracing", package: "swift-distributed-tracing") }
  142. static var grpcCore: Self { .target(name: "GRPCCore") }
  143. static var grpcInProcessTransport: Self { .target(name: "GRPCInProcessTransport") }
  144. static var grpcInterceptors: Self { .target(name: "GRPCInterceptors") }
  145. static var grpcHTTP2Core: Self { .target(name: "GRPCHTTP2Core") }
  146. static var grpcHTTP2TransportNIOPosix: Self { .target(name: "GRPCHTTP2TransportNIOPosix") }
  147. static var grpcHTTP2TransportNIOTransportServices: Self { .target(name: "GRPCHTTP2TransportNIOTransportServices") }
  148. }
  149. // MARK: - Targets
  150. extension Target {
  151. static var grpc: Target {
  152. .target(
  153. name: grpcTargetName,
  154. dependencies: [
  155. .cgrpcZlib,
  156. .nio,
  157. .nioCore,
  158. .nioPosix,
  159. .nioEmbedded,
  160. .nioFoundationCompat,
  161. .nioTLS,
  162. .nioTransportServices,
  163. .nioHTTP1,
  164. .nioHTTP2,
  165. .nioExtras,
  166. .logging,
  167. .protobuf,
  168. .dequeModule,
  169. ].appending(
  170. .nioSSL, if: includeNIOSSL
  171. ),
  172. path: "Sources/GRPC",
  173. swiftSettings: [.swiftLanguageVersion(.v5)]
  174. )
  175. }
  176. static var grpcCore: Target {
  177. .target(
  178. name: "GRPCCore",
  179. dependencies: [
  180. .dequeModule,
  181. .atomics
  182. ],
  183. path: "Sources/GRPCCore",
  184. swiftSettings: [.swiftLanguageVersion(.v5), .enableUpcomingFeature("ExistentialAny")]
  185. )
  186. }
  187. static var grpcInProcessTransport: Target {
  188. .target(
  189. name: "GRPCInProcessTransport",
  190. dependencies: [
  191. .grpcCore
  192. ],
  193. swiftSettings: [.swiftLanguageVersion(.v6), .enableUpcomingFeature("ExistentialAny")]
  194. )
  195. }
  196. static var grpcInterceptors: Target {
  197. .target(
  198. name: "GRPCInterceptors",
  199. dependencies: [
  200. .grpcCore,
  201. .tracing
  202. ],
  203. swiftSettings: [.swiftLanguageVersion(.v6), .enableUpcomingFeature("ExistentialAny")]
  204. )
  205. }
  206. static var grpcHTTP2Core: Target {
  207. .target(
  208. name: "GRPCHTTP2Core",
  209. dependencies: [
  210. .grpcCore,
  211. .nioCore,
  212. .nioHTTP2,
  213. .cgrpcZlib,
  214. .dequeModule,
  215. .atomics
  216. ],
  217. swiftSettings: [.swiftLanguageVersion(.v6), .enableUpcomingFeature("ExistentialAny")]
  218. )
  219. }
  220. static var grpcHTTP2TransportNIOPosix: Target {
  221. .target(
  222. name: "GRPCHTTP2TransportNIOPosix",
  223. dependencies: [
  224. .grpcCore,
  225. .grpcHTTP2Core,
  226. .nioPosix,
  227. .nioExtras
  228. ],
  229. swiftSettings: [.swiftLanguageVersion(.v6), .enableUpcomingFeature("ExistentialAny")]
  230. )
  231. }
  232. static var grpcHTTP2TransportNIOTransportServices: Target {
  233. .target(
  234. name: "GRPCHTTP2TransportNIOTransportServices",
  235. dependencies: [
  236. .grpcCore,
  237. .grpcHTTP2Core,
  238. .nioCore,
  239. .nioExtras,
  240. .nioTransportServices
  241. ],
  242. swiftSettings: [.swiftLanguageVersion(.v6), .enableUpcomingFeature("ExistentialAny")]
  243. )
  244. }
  245. static var grpcHTTP2Transport: Target {
  246. .target(
  247. name: "GRPCHTTP2Transport",
  248. dependencies: [
  249. .grpcCore,
  250. .grpcHTTP2Core,
  251. .grpcHTTP2TransportNIOPosix,
  252. .grpcHTTP2TransportNIOTransportServices,
  253. ],
  254. swiftSettings: [.swiftLanguageVersion(.v6), .enableUpcomingFeature("ExistentialAny")]
  255. )
  256. }
  257. static var cgrpcZlib: Target {
  258. .target(
  259. name: cgrpcZlibTargetName,
  260. path: "Sources/CGRPCZlib",
  261. linkerSettings: [
  262. .linkedLibrary("z"),
  263. ]
  264. )
  265. }
  266. static var protocGenGRPCSwift: Target {
  267. .executableTarget(
  268. name: "protoc-gen-grpc-swift",
  269. dependencies: [
  270. .protobuf,
  271. .protobufPluginLibrary,
  272. .grpcCodeGen,
  273. .grpcProtobufCodeGen
  274. ],
  275. exclude: [
  276. "README.md",
  277. ],
  278. swiftSettings: [.swiftLanguageVersion(.v5)]
  279. )
  280. }
  281. static var performanceWorker: Target {
  282. .executableTarget(
  283. name: "performance-worker",
  284. dependencies: [
  285. .grpcCore,
  286. .grpcHTTP2Core,
  287. .grpcHTTP2TransportNIOPosix,
  288. .grpcProtobuf,
  289. .nioCore,
  290. .nioFileSystem,
  291. .argumentParser
  292. ],
  293. swiftSettings: [.swiftLanguageVersion(.v6), .enableUpcomingFeature("ExistentialAny")]
  294. )
  295. }
  296. static var grpcSwiftPlugin: Target {
  297. .plugin(
  298. name: "GRPCSwiftPlugin",
  299. capability: .buildTool(),
  300. dependencies: [
  301. .protocGenGRPCSwift,
  302. ]
  303. )
  304. }
  305. static var grpcTests: Target {
  306. .testTarget(
  307. name: "GRPCTests",
  308. dependencies: [
  309. .grpc,
  310. .echoModel,
  311. .echoImplementation,
  312. .helloWorldModel,
  313. .interopTestModels,
  314. .interopTestImplementation,
  315. .grpcSampleData,
  316. .nioCore,
  317. .nioConcurrencyHelpers,
  318. .nioPosix,
  319. .nioTLS,
  320. .nioHTTP1,
  321. .nioHTTP2,
  322. .nioEmbedded,
  323. .nioTransportServices,
  324. .logging,
  325. .reflectionService
  326. ].appending(
  327. .nioSSL, if: includeNIOSSL
  328. ),
  329. exclude: [
  330. "Codegen/Serialization/echo.grpc.reflection"
  331. ],
  332. swiftSettings: [.swiftLanguageVersion(.v5)]
  333. )
  334. }
  335. static var grpcCoreTests: Target {
  336. .testTarget(
  337. name: "GRPCCoreTests",
  338. dependencies: [
  339. .grpcCore,
  340. .grpcInProcessTransport,
  341. .dequeModule,
  342. .atomics,
  343. .protobuf,
  344. ],
  345. swiftSettings: [.swiftLanguageVersion(.v6), .enableUpcomingFeature("ExistentialAny")]
  346. )
  347. }
  348. static var grpcInProcessTransportTests: Target {
  349. .testTarget(
  350. name: "GRPCInProcessTransportTests",
  351. dependencies: [
  352. .grpcCore,
  353. .grpcInProcessTransport
  354. ],
  355. swiftSettings: [.swiftLanguageVersion(.v6), .enableUpcomingFeature("ExistentialAny")]
  356. )
  357. }
  358. static var grpcInterceptorsTests: Target {
  359. .testTarget(
  360. name: "GRPCInterceptorsTests",
  361. dependencies: [
  362. .grpcCore,
  363. .tracing,
  364. .nioCore,
  365. .grpcInterceptors
  366. ],
  367. swiftSettings: [.swiftLanguageVersion(.v6), .enableUpcomingFeature("ExistentialAny")]
  368. )
  369. }
  370. static var grpcHTTP2CoreTests: Target {
  371. .testTarget(
  372. name: "GRPCHTTP2CoreTests",
  373. dependencies: [
  374. .grpcHTTP2Core,
  375. .nioCore,
  376. .nioHTTP2,
  377. .nioEmbedded,
  378. .nioTestUtils,
  379. ],
  380. swiftSettings: [.swiftLanguageVersion(.v6), .enableUpcomingFeature("ExistentialAny")]
  381. )
  382. }
  383. static var grpcHTTP2TransportTests: Target {
  384. .testTarget(
  385. name: "GRPCHTTP2TransportTests",
  386. dependencies: [
  387. .grpcHTTP2Core,
  388. .grpcHTTP2TransportNIOPosix,
  389. .grpcHTTP2TransportNIOTransportServices,
  390. .grpcProtobuf
  391. ],
  392. swiftSettings: [.swiftLanguageVersion(.v6), .enableUpcomingFeature("ExistentialAny")]
  393. )
  394. }
  395. static var grpcCodeGenTests: Target {
  396. .testTarget(
  397. name: "GRPCCodeGenTests",
  398. dependencies: [
  399. .grpcCodeGen
  400. ],
  401. swiftSettings: [.swiftLanguageVersion(.v6), .enableUpcomingFeature("ExistentialAny")]
  402. )
  403. }
  404. static var grpcProtobufTests: Target {
  405. .testTarget(
  406. name: "GRPCProtobufTests",
  407. dependencies: [
  408. .grpcProtobuf,
  409. .grpcCore,
  410. .protobuf
  411. ],
  412. swiftSettings: [.swiftLanguageVersion(.v6), .enableUpcomingFeature("ExistentialAny")]
  413. )
  414. }
  415. static var grpcProtobufCodeGenTests: Target {
  416. .testTarget(
  417. name: "GRPCProtobufCodeGenTests",
  418. dependencies: [
  419. .grpcCodeGen,
  420. .grpcProtobufCodeGen,
  421. .protobuf,
  422. .protobufPluginLibrary
  423. ],
  424. swiftSettings: [.swiftLanguageVersion(.v6), .enableUpcomingFeature("ExistentialAny")]
  425. )
  426. }
  427. static var inProcessInteroperabilityTests: Target {
  428. .testTarget(
  429. name: "InProcessInteroperabilityTests",
  430. dependencies: [
  431. .grpcInProcessTransport,
  432. .interoperabilityTests,
  433. .grpcCore
  434. ],
  435. swiftSettings: [.swiftLanguageVersion(.v6), .enableUpcomingFeature("ExistentialAny")]
  436. )
  437. }
  438. static var interopTestModels: Target {
  439. .target(
  440. name: "GRPCInteroperabilityTestModels",
  441. dependencies: [
  442. .grpc,
  443. .nio,
  444. .protobuf,
  445. ],
  446. exclude: [
  447. "README.md",
  448. "generate.sh",
  449. "src/proto/grpc/testing/empty.proto",
  450. "src/proto/grpc/testing/empty_service.proto",
  451. "src/proto/grpc/testing/messages.proto",
  452. "src/proto/grpc/testing/test.proto",
  453. "unimplemented_call.patch",
  454. ],
  455. swiftSettings: [.swiftLanguageVersion(.v5)]
  456. )
  457. }
  458. static var interoperabilityTestImplementation: Target {
  459. .target(
  460. name: "InteroperabilityTests",
  461. dependencies: [
  462. .grpcCore,
  463. .grpcProtobuf
  464. ],
  465. swiftSettings: [.swiftLanguageVersion(.v5), .enableUpcomingFeature("ExistentialAny")]
  466. )
  467. }
  468. static var interoperabilityTestsExecutable: Target {
  469. .executableTarget(
  470. name: "interoperability-tests",
  471. dependencies: [
  472. .grpcCore,
  473. .grpcHTTP2Core,
  474. .grpcHTTP2TransportNIOPosix,
  475. .interoperabilityTests,
  476. .argumentParser
  477. ],
  478. swiftSettings: [.swiftLanguageVersion(.v6), .enableUpcomingFeature("ExistentialAny")]
  479. )
  480. }
  481. static var interopTestImplementation: Target {
  482. .target(
  483. name: "GRPCInteroperabilityTestsImplementation",
  484. dependencies: [
  485. .grpc,
  486. .interopTestModels,
  487. .nioCore,
  488. .nioPosix,
  489. .nioHTTP1,
  490. .logging,
  491. ].appending(
  492. .nioSSL, if: includeNIOSSL
  493. ),
  494. swiftSettings: [.swiftLanguageVersion(.v5)]
  495. )
  496. }
  497. static var interopTests: Target {
  498. .executableTarget(
  499. name: "GRPCInteroperabilityTests",
  500. dependencies: [
  501. .grpc,
  502. .interopTestImplementation,
  503. .nioCore,
  504. .nioPosix,
  505. .logging,
  506. .argumentParser,
  507. ],
  508. swiftSettings: [.swiftLanguageVersion(.v5)]
  509. )
  510. }
  511. static var backoffInteropTest: Target {
  512. .executableTarget(
  513. name: "GRPCConnectionBackoffInteropTest",
  514. dependencies: [
  515. .grpc,
  516. .interopTestModels,
  517. .nioCore,
  518. .nioPosix,
  519. .logging,
  520. .argumentParser,
  521. ],
  522. exclude: [
  523. "README.md",
  524. ],
  525. swiftSettings: [.swiftLanguageVersion(.v5)]
  526. )
  527. }
  528. static var perfTests: Target {
  529. .executableTarget(
  530. name: "GRPCPerformanceTests",
  531. dependencies: [
  532. .grpc,
  533. .grpcSampleData,
  534. .nioCore,
  535. .nioEmbedded,
  536. .nioPosix,
  537. .nioHTTP2,
  538. .argumentParser,
  539. ],
  540. swiftSettings: [.swiftLanguageVersion(.v5)]
  541. )
  542. }
  543. static var grpcSampleData: Target {
  544. .target(
  545. name: "GRPCSampleData",
  546. dependencies: includeNIOSSL ? [.nioSSL] : [],
  547. exclude: [
  548. "bundle.p12",
  549. ],
  550. swiftSettings: [.swiftLanguageVersion(.v5)]
  551. )
  552. }
  553. static var echoModel: Target {
  554. .target(
  555. name: "EchoModel",
  556. dependencies: [
  557. .grpc,
  558. .nio,
  559. .protobuf,
  560. ],
  561. path: "Sources/Examples/v1/Echo/Model",
  562. swiftSettings: [.swiftLanguageVersion(.v5)]
  563. )
  564. }
  565. static var echoImplementation: Target {
  566. .target(
  567. name: "EchoImplementation",
  568. dependencies: [
  569. .echoModel,
  570. .grpc,
  571. .nioCore,
  572. .nioHTTP2,
  573. .protobuf,
  574. ],
  575. path: "Sources/Examples/v1/Echo/Implementation",
  576. swiftSettings: [.swiftLanguageVersion(.v5)]
  577. )
  578. }
  579. static var echo: Target {
  580. .executableTarget(
  581. name: "Echo",
  582. dependencies: [
  583. .grpc,
  584. .echoModel,
  585. .echoImplementation,
  586. .grpcSampleData,
  587. .nioCore,
  588. .nioPosix,
  589. .logging,
  590. .argumentParser,
  591. ].appending(
  592. .nioSSL, if: includeNIOSSL
  593. ),
  594. path: "Sources/Examples/v1/Echo/Runtime",
  595. swiftSettings: [.swiftLanguageVersion(.v5)]
  596. )
  597. }
  598. static var echo_v2: Target {
  599. .executableTarget(
  600. name: "echo-v2",
  601. dependencies: [
  602. .grpcCore,
  603. .grpcProtobuf,
  604. .grpcHTTP2Core,
  605. .grpcHTTP2TransportNIOPosix,
  606. .argumentParser,
  607. ].appending(
  608. .nioSSL, if: includeNIOSSL
  609. ),
  610. path: "Sources/Examples/v2/Echo",
  611. swiftSettings: [.swiftLanguageVersion(.v6), .enableUpcomingFeature("ExistentialAny")]
  612. )
  613. }
  614. static var helloWorldModel: Target {
  615. .target(
  616. name: "HelloWorldModel",
  617. dependencies: [
  618. .grpc,
  619. .nio,
  620. .protobuf,
  621. ],
  622. path: "Sources/Examples/v1/HelloWorld/Model",
  623. swiftSettings: [.swiftLanguageVersion(.v5)]
  624. )
  625. }
  626. static var helloWorldClient: Target {
  627. .executableTarget(
  628. name: "HelloWorldClient",
  629. dependencies: [
  630. .grpc,
  631. .helloWorldModel,
  632. .nioCore,
  633. .nioPosix,
  634. .argumentParser,
  635. ],
  636. path: "Sources/Examples/v1/HelloWorld/Client",
  637. swiftSettings: [.swiftLanguageVersion(.v5)]
  638. )
  639. }
  640. static var helloWorldServer: Target {
  641. .executableTarget(
  642. name: "HelloWorldServer",
  643. dependencies: [
  644. .grpc,
  645. .helloWorldModel,
  646. .nioCore,
  647. .nioPosix,
  648. .argumentParser,
  649. ],
  650. path: "Sources/Examples/v1/HelloWorld/Server",
  651. swiftSettings: [.swiftLanguageVersion(.v5)]
  652. )
  653. }
  654. static var routeGuideModel: Target {
  655. .target(
  656. name: "RouteGuideModel",
  657. dependencies: [
  658. .grpc,
  659. .nio,
  660. .protobuf,
  661. ],
  662. path: "Sources/Examples/v1/RouteGuide/Model",
  663. swiftSettings: [.swiftLanguageVersion(.v5)]
  664. )
  665. }
  666. static var routeGuideClient: Target {
  667. .executableTarget(
  668. name: "RouteGuideClient",
  669. dependencies: [
  670. .grpc,
  671. .routeGuideModel,
  672. .nioCore,
  673. .nioPosix,
  674. .argumentParser,
  675. ],
  676. path: "Sources/Examples/v1/RouteGuide/Client",
  677. swiftSettings: [.swiftLanguageVersion(.v5)]
  678. )
  679. }
  680. static var routeGuideServer: Target {
  681. .executableTarget(
  682. name: "RouteGuideServer",
  683. dependencies: [
  684. .grpc,
  685. .routeGuideModel,
  686. .nioCore,
  687. .nioConcurrencyHelpers,
  688. .nioPosix,
  689. .argumentParser,
  690. ],
  691. path: "Sources/Examples/v1/RouteGuide/Server",
  692. swiftSettings: [.swiftLanguageVersion(.v5)]
  693. )
  694. }
  695. static var packetCapture: Target {
  696. .executableTarget(
  697. name: "PacketCapture",
  698. dependencies: [
  699. .grpc,
  700. .echoModel,
  701. .nioCore,
  702. .nioPosix,
  703. .nioExtras,
  704. .argumentParser,
  705. ],
  706. path: "Sources/Examples/v1/PacketCapture",
  707. exclude: [
  708. "README.md",
  709. ],
  710. swiftSettings: [.swiftLanguageVersion(.v5)]
  711. )
  712. }
  713. static var reflectionService: Target {
  714. .target(
  715. name: "GRPCReflectionService",
  716. dependencies: [
  717. .grpc,
  718. .nio,
  719. .protobuf,
  720. ],
  721. path: "Sources/GRPCReflectionService",
  722. swiftSettings: [.swiftLanguageVersion(.v5)]
  723. )
  724. }
  725. static var reflectionServer: Target {
  726. .executableTarget(
  727. name: "ReflectionServer",
  728. dependencies: [
  729. .grpc,
  730. .reflectionService,
  731. .helloWorldModel,
  732. .nioCore,
  733. .nioPosix,
  734. .argumentParser,
  735. .echoModel,
  736. .echoImplementation
  737. ],
  738. path: "Sources/Examples/v1/ReflectionService",
  739. resources: [
  740. .copy("Generated")
  741. ],
  742. swiftSettings: [.swiftLanguageVersion(.v5)]
  743. )
  744. }
  745. static var grpcCodeGen: Target {
  746. .target(
  747. name: "GRPCCodeGen",
  748. path: "Sources/GRPCCodeGen",
  749. swiftSettings: [.swiftLanguageVersion(.v6), .enableUpcomingFeature("ExistentialAny")]
  750. )
  751. }
  752. static var grpcProtobuf: Target {
  753. .target(
  754. name: "GRPCProtobuf",
  755. dependencies: [
  756. .grpcCore,
  757. .protobuf,
  758. ],
  759. path: "Sources/GRPCProtobuf",
  760. swiftSettings: [.swiftLanguageVersion(.v6), .enableUpcomingFeature("ExistentialAny")]
  761. )
  762. }
  763. static var grpcProtobufCodeGen: Target {
  764. .target(
  765. name: "GRPCProtobufCodeGen",
  766. dependencies: [
  767. .protobuf,
  768. .protobufPluginLibrary,
  769. .grpcCodeGen
  770. ],
  771. path: "Sources/GRPCProtobufCodeGen",
  772. swiftSettings: [.swiftLanguageVersion(.v6), .enableUpcomingFeature("ExistentialAny")]
  773. )
  774. }
  775. static var grpcHealth: Target {
  776. .target(
  777. name: "GRPCHealth",
  778. dependencies: [
  779. .grpcCore,
  780. .grpcProtobuf
  781. ],
  782. path: "Sources/Services/Health",
  783. swiftSettings: [.swiftLanguageVersion(.v6)]
  784. )
  785. }
  786. }
  787. // MARK: - Products
  788. extension Product {
  789. static var grpc: Product {
  790. .library(
  791. name: grpcProductName,
  792. targets: [grpcTargetName]
  793. )
  794. }
  795. static var _grpcCore: Product {
  796. .library(
  797. name: "_GRPCCore",
  798. targets: ["GRPCCore"]
  799. )
  800. }
  801. static var _grpcProtobuf: Product {
  802. .library(
  803. name: "_GRPCProtobuf",
  804. targets: ["GRPCProtobuf"]
  805. )
  806. }
  807. static var _grpcInProcessTransport: Product {
  808. .library(
  809. name: "_GRPCInProcessTransport",
  810. targets: ["GRPCInProcessTransport"]
  811. )
  812. }
  813. static var _grpcHTTP2Transport: Product {
  814. .library(
  815. name: "_GRPCHTTP2Transport",
  816. targets: ["GRPCHTTP2Transport"]
  817. )
  818. }
  819. static var cgrpcZlib: Product {
  820. .library(
  821. name: cgrpcZlibProductName,
  822. targets: [cgrpcZlibTargetName]
  823. )
  824. }
  825. static var grpcReflectionService: Product {
  826. .library(
  827. name: "GRPCReflectionService",
  828. targets: ["GRPCReflectionService"]
  829. )
  830. }
  831. static var protocGenGRPCSwift: Product {
  832. .executable(
  833. name: "protoc-gen-grpc-swift",
  834. targets: ["protoc-gen-grpc-swift"]
  835. )
  836. }
  837. static var grpcSwiftPlugin: Product {
  838. .plugin(
  839. name: "GRPCSwiftPlugin",
  840. targets: ["GRPCSwiftPlugin"]
  841. )
  842. }
  843. }
  844. // MARK: - Package
  845. let package = Package(
  846. name: grpcPackageName,
  847. products: [
  848. // v1
  849. .grpc,
  850. .cgrpcZlib,
  851. .grpcReflectionService,
  852. .protocGenGRPCSwift,
  853. .grpcSwiftPlugin,
  854. // v2
  855. ._grpcCore,
  856. ._grpcProtobuf,
  857. ._grpcHTTP2Transport,
  858. ._grpcInProcessTransport,
  859. ],
  860. dependencies: packageDependencies,
  861. targets: [
  862. // Products
  863. .grpc,
  864. .cgrpcZlib,
  865. .protocGenGRPCSwift,
  866. .grpcSwiftPlugin,
  867. .reflectionService,
  868. // Tests etc.
  869. .grpcTests,
  870. .interopTestModels,
  871. .interopTestImplementation,
  872. .interopTests,
  873. .backoffInteropTest,
  874. .perfTests,
  875. .grpcSampleData,
  876. // Examples
  877. .echoModel,
  878. .echoImplementation,
  879. .echo,
  880. .helloWorldModel,
  881. .helloWorldClient,
  882. .helloWorldServer,
  883. .routeGuideModel,
  884. .routeGuideClient,
  885. .routeGuideServer,
  886. .packetCapture,
  887. .reflectionServer,
  888. // v2
  889. .grpcCore,
  890. .grpcCodeGen,
  891. // v2 transports
  892. .grpcInProcessTransport,
  893. .grpcHTTP2Core,
  894. .grpcHTTP2TransportNIOPosix,
  895. .grpcHTTP2TransportNIOTransportServices,
  896. .grpcHTTP2Transport,
  897. // v2 Protobuf support
  898. .grpcProtobuf,
  899. .grpcProtobufCodeGen,
  900. // v2 add-ons
  901. .grpcInterceptors,
  902. .grpcHealth,
  903. // v2 integration testing
  904. .interoperabilityTestImplementation,
  905. .interoperabilityTestsExecutable,
  906. .performanceWorker,
  907. // v2 unit tests
  908. .grpcCoreTests,
  909. .grpcInProcessTransportTests,
  910. .grpcCodeGenTests,
  911. .grpcInterceptorsTests,
  912. .grpcHTTP2CoreTests,
  913. .grpcHTTP2TransportTests,
  914. .grpcProtobufTests,
  915. .grpcProtobufCodeGenTests,
  916. .inProcessInteroperabilityTests,
  917. // v2 examples
  918. .echo_v2,
  919. ]
  920. )
  921. extension Array {
  922. func appending(_ element: Element, if condition: Bool) -> [Element] {
  923. if condition {
  924. return self + [element]
  925. } else {
  926. return self
  927. }
  928. }
  929. }