Package@swift-6.swift 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970
  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.20.2"
  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)]
  185. )
  186. }
  187. static var grpcInProcessTransport: Target {
  188. .target(
  189. name: "GRPCInProcessTransport",
  190. dependencies: [
  191. .grpcCore
  192. ],
  193. swiftSettings: [.swiftLanguageVersion(.v6)]
  194. )
  195. }
  196. static var grpcInterceptors: Target {
  197. .target(
  198. name: "GRPCInterceptors",
  199. dependencies: [
  200. .grpcCore,
  201. .tracing
  202. ],
  203. swiftSettings: [.swiftLanguageVersion(.v6)]
  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)]
  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)]
  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)]
  243. )
  244. }
  245. static var cgrpcZlib: Target {
  246. .target(
  247. name: cgrpcZlibTargetName,
  248. path: "Sources/CGRPCZlib",
  249. linkerSettings: [
  250. .linkedLibrary("z"),
  251. ]
  252. )
  253. }
  254. static var protocGenGRPCSwift: Target {
  255. .executableTarget(
  256. name: "protoc-gen-grpc-swift",
  257. dependencies: [
  258. .protobuf,
  259. .protobufPluginLibrary,
  260. .grpcCodeGen,
  261. .grpcProtobufCodeGen
  262. ],
  263. exclude: [
  264. "README.md",
  265. ],
  266. swiftSettings: [.swiftLanguageVersion(.v5)]
  267. )
  268. }
  269. static var performanceWorker: Target {
  270. .executableTarget(
  271. name: "performance-worker",
  272. dependencies: [
  273. .grpcCore,
  274. .grpcHTTP2Core,
  275. .grpcHTTP2TransportNIOPosix,
  276. .grpcProtobuf,
  277. .nioCore,
  278. .nioFileSystem,
  279. .argumentParser
  280. ],
  281. swiftSettings: [.swiftLanguageVersion(.v6)]
  282. )
  283. }
  284. static var grpcSwiftPlugin: Target {
  285. .plugin(
  286. name: "GRPCSwiftPlugin",
  287. capability: .buildTool(),
  288. dependencies: [
  289. .protocGenGRPCSwift,
  290. ]
  291. )
  292. }
  293. static var grpcTests: Target {
  294. .testTarget(
  295. name: "GRPCTests",
  296. dependencies: [
  297. .grpc,
  298. .echoModel,
  299. .echoImplementation,
  300. .helloWorldModel,
  301. .interopTestModels,
  302. .interopTestImplementation,
  303. .grpcSampleData,
  304. .nioCore,
  305. .nioConcurrencyHelpers,
  306. .nioPosix,
  307. .nioTLS,
  308. .nioHTTP1,
  309. .nioHTTP2,
  310. .nioEmbedded,
  311. .nioTransportServices,
  312. .logging,
  313. .reflectionService
  314. ].appending(
  315. .nioSSL, if: includeNIOSSL
  316. ),
  317. exclude: [
  318. "Codegen/Serialization/echo.grpc.reflection"
  319. ],
  320. swiftSettings: [.swiftLanguageVersion(.v5)]
  321. )
  322. }
  323. static var grpcCoreTests: Target {
  324. .testTarget(
  325. name: "GRPCCoreTests",
  326. dependencies: [
  327. .grpcCore,
  328. .grpcInProcessTransport,
  329. .dequeModule,
  330. .atomics,
  331. .protobuf,
  332. ],
  333. swiftSettings: [.swiftLanguageVersion(.v5)]
  334. )
  335. }
  336. static var grpcInProcessTransportTests: Target {
  337. .testTarget(
  338. name: "GRPCInProcessTransportTests",
  339. dependencies: [
  340. .grpcCore,
  341. .grpcInProcessTransport
  342. ],
  343. swiftSettings: [.swiftLanguageVersion(.v5)]
  344. )
  345. }
  346. static var grpcInterceptorsTests: Target {
  347. .testTarget(
  348. name: "GRPCInterceptorsTests",
  349. dependencies: [
  350. .grpcCore,
  351. .tracing,
  352. .nioCore,
  353. .grpcInterceptors
  354. ],
  355. swiftSettings: [.swiftLanguageVersion(.v5)]
  356. )
  357. }
  358. static var grpcHTTP2CoreTests: Target {
  359. .testTarget(
  360. name: "GRPCHTTP2CoreTests",
  361. dependencies: [
  362. .grpcHTTP2Core,
  363. .nioCore,
  364. .nioHTTP2,
  365. .nioEmbedded,
  366. .nioTestUtils,
  367. ],
  368. swiftSettings: [.swiftLanguageVersion(.v5)]
  369. )
  370. }
  371. static var grpcHTTP2TransportTests: Target {
  372. .testTarget(
  373. name: "GRPCHTTP2TransportTests",
  374. dependencies: [
  375. .grpcHTTP2Core,
  376. .grpcHTTP2TransportNIOPosix,
  377. .grpcHTTP2TransportNIOTransportServices,
  378. .grpcProtobuf
  379. ],
  380. swiftSettings: [.swiftLanguageVersion(.v5)]
  381. )
  382. }
  383. static var grpcCodeGenTests: Target {
  384. .testTarget(
  385. name: "GRPCCodeGenTests",
  386. dependencies: [
  387. .grpcCodeGen
  388. ],
  389. swiftSettings: [.swiftLanguageVersion(.v5)]
  390. )
  391. }
  392. static var grpcProtobufTests: Target {
  393. .testTarget(
  394. name: "GRPCProtobufTests",
  395. dependencies: [
  396. .grpcProtobuf,
  397. .grpcCore,
  398. .protobuf
  399. ],
  400. swiftSettings: [.swiftLanguageVersion(.v6)]
  401. )
  402. }
  403. static var grpcProtobufCodeGenTests: Target {
  404. .testTarget(
  405. name: "GRPCProtobufCodeGenTests",
  406. dependencies: [
  407. .grpcCodeGen,
  408. .grpcProtobufCodeGen,
  409. .protobuf,
  410. .protobufPluginLibrary
  411. ],
  412. swiftSettings: [.swiftLanguageVersion(.v6)]
  413. )
  414. }
  415. static var inProcessInteroperabilityTests: Target {
  416. .testTarget(
  417. name: "InProcessInteroperabilityTests",
  418. dependencies: [
  419. .grpcInProcessTransport,
  420. .interoperabilityTests,
  421. .grpcCore
  422. ],
  423. swiftSettings: [.swiftLanguageVersion(.v5)]
  424. )
  425. }
  426. static var interopTestModels: Target {
  427. .target(
  428. name: "GRPCInteroperabilityTestModels",
  429. dependencies: [
  430. .grpc,
  431. .nio,
  432. .protobuf,
  433. ],
  434. exclude: [
  435. "README.md",
  436. "generate.sh",
  437. "src/proto/grpc/testing/empty.proto",
  438. "src/proto/grpc/testing/empty_service.proto",
  439. "src/proto/grpc/testing/messages.proto",
  440. "src/proto/grpc/testing/test.proto",
  441. "unimplemented_call.patch",
  442. ],
  443. swiftSettings: [.swiftLanguageVersion(.v5)]
  444. )
  445. }
  446. static var interoperabilityTestImplementation: Target {
  447. .target(
  448. name: "InteroperabilityTests",
  449. dependencies: [
  450. .grpcCore,
  451. .grpcProtobuf
  452. ],
  453. swiftSettings: [.swiftLanguageVersion(.v5)]
  454. )
  455. }
  456. static var interoperabilityTestsExecutable: Target {
  457. .executableTarget(
  458. name: "interoperability-tests",
  459. dependencies: [
  460. .grpcCore,
  461. .grpcHTTP2Core,
  462. .grpcHTTP2TransportNIOPosix,
  463. .interoperabilityTests,
  464. .argumentParser
  465. ],
  466. swiftSettings: [.swiftLanguageVersion(.v6)]
  467. )
  468. }
  469. static var interopTestImplementation: Target {
  470. .target(
  471. name: "GRPCInteroperabilityTestsImplementation",
  472. dependencies: [
  473. .grpc,
  474. .interopTestModels,
  475. .nioCore,
  476. .nioPosix,
  477. .nioHTTP1,
  478. .logging,
  479. ].appending(
  480. .nioSSL, if: includeNIOSSL
  481. ),
  482. swiftSettings: [.swiftLanguageVersion(.v5)]
  483. )
  484. }
  485. static var interopTests: Target {
  486. .executableTarget(
  487. name: "GRPCInteroperabilityTests",
  488. dependencies: [
  489. .grpc,
  490. .interopTestImplementation,
  491. .nioCore,
  492. .nioPosix,
  493. .logging,
  494. .argumentParser,
  495. ],
  496. swiftSettings: [.swiftLanguageVersion(.v5)]
  497. )
  498. }
  499. static var backoffInteropTest: Target {
  500. .executableTarget(
  501. name: "GRPCConnectionBackoffInteropTest",
  502. dependencies: [
  503. .grpc,
  504. .interopTestModels,
  505. .nioCore,
  506. .nioPosix,
  507. .logging,
  508. .argumentParser,
  509. ],
  510. exclude: [
  511. "README.md",
  512. ],
  513. swiftSettings: [.swiftLanguageVersion(.v5)]
  514. )
  515. }
  516. static var perfTests: Target {
  517. .executableTarget(
  518. name: "GRPCPerformanceTests",
  519. dependencies: [
  520. .grpc,
  521. .grpcSampleData,
  522. .nioCore,
  523. .nioEmbedded,
  524. .nioPosix,
  525. .nioHTTP2,
  526. .argumentParser,
  527. ],
  528. swiftSettings: [.swiftLanguageVersion(.v5)]
  529. )
  530. }
  531. static var grpcSampleData: Target {
  532. .target(
  533. name: "GRPCSampleData",
  534. dependencies: includeNIOSSL ? [.nioSSL] : [],
  535. exclude: [
  536. "bundle.p12",
  537. ],
  538. swiftSettings: [.swiftLanguageVersion(.v5)]
  539. )
  540. }
  541. static var echoModel: Target {
  542. .target(
  543. name: "EchoModel",
  544. dependencies: [
  545. .grpc,
  546. .nio,
  547. .protobuf,
  548. ],
  549. path: "Sources/Examples/v1/Echo/Model",
  550. swiftSettings: [.swiftLanguageVersion(.v5)]
  551. )
  552. }
  553. static var echoImplementation: Target {
  554. .target(
  555. name: "EchoImplementation",
  556. dependencies: [
  557. .echoModel,
  558. .grpc,
  559. .nioCore,
  560. .nioHTTP2,
  561. .protobuf,
  562. ],
  563. path: "Sources/Examples/v1/Echo/Implementation",
  564. swiftSettings: [.swiftLanguageVersion(.v5)]
  565. )
  566. }
  567. static var echo: Target {
  568. .executableTarget(
  569. name: "Echo",
  570. dependencies: [
  571. .grpc,
  572. .echoModel,
  573. .echoImplementation,
  574. .grpcSampleData,
  575. .nioCore,
  576. .nioPosix,
  577. .logging,
  578. .argumentParser,
  579. ].appending(
  580. .nioSSL, if: includeNIOSSL
  581. ),
  582. path: "Sources/Examples/v1/Echo/Runtime",
  583. swiftSettings: [.swiftLanguageVersion(.v5)]
  584. )
  585. }
  586. static var echo_v2: Target {
  587. .executableTarget(
  588. name: "echo-v2",
  589. dependencies: [
  590. .grpcCore,
  591. .grpcProtobuf,
  592. .grpcHTTP2Core,
  593. .grpcHTTP2TransportNIOPosix,
  594. .argumentParser,
  595. ].appending(
  596. .nioSSL, if: includeNIOSSL
  597. ),
  598. path: "Sources/Examples/v2/Echo",
  599. swiftSettings: [.swiftLanguageVersion(.v6), .enableUpcomingFeature("ExistentialAny")]
  600. )
  601. }
  602. static var helloWorldModel: Target {
  603. .target(
  604. name: "HelloWorldModel",
  605. dependencies: [
  606. .grpc,
  607. .nio,
  608. .protobuf,
  609. ],
  610. path: "Sources/Examples/v1/HelloWorld/Model",
  611. swiftSettings: [.swiftLanguageVersion(.v5)]
  612. )
  613. }
  614. static var helloWorldClient: Target {
  615. .executableTarget(
  616. name: "HelloWorldClient",
  617. dependencies: [
  618. .grpc,
  619. .helloWorldModel,
  620. .nioCore,
  621. .nioPosix,
  622. .argumentParser,
  623. ],
  624. path: "Sources/Examples/v1/HelloWorld/Client",
  625. swiftSettings: [.swiftLanguageVersion(.v5)]
  626. )
  627. }
  628. static var helloWorldServer: Target {
  629. .executableTarget(
  630. name: "HelloWorldServer",
  631. dependencies: [
  632. .grpc,
  633. .helloWorldModel,
  634. .nioCore,
  635. .nioPosix,
  636. .argumentParser,
  637. ],
  638. path: "Sources/Examples/v1/HelloWorld/Server",
  639. swiftSettings: [.swiftLanguageVersion(.v5)]
  640. )
  641. }
  642. static var routeGuideModel: Target {
  643. .target(
  644. name: "RouteGuideModel",
  645. dependencies: [
  646. .grpc,
  647. .nio,
  648. .protobuf,
  649. ],
  650. path: "Sources/Examples/v1/RouteGuide/Model",
  651. swiftSettings: [.swiftLanguageVersion(.v5)]
  652. )
  653. }
  654. static var routeGuideClient: Target {
  655. .executableTarget(
  656. name: "RouteGuideClient",
  657. dependencies: [
  658. .grpc,
  659. .routeGuideModel,
  660. .nioCore,
  661. .nioPosix,
  662. .argumentParser,
  663. ],
  664. path: "Sources/Examples/v1/RouteGuide/Client",
  665. swiftSettings: [.swiftLanguageVersion(.v5)]
  666. )
  667. }
  668. static var routeGuideServer: Target {
  669. .executableTarget(
  670. name: "RouteGuideServer",
  671. dependencies: [
  672. .grpc,
  673. .routeGuideModel,
  674. .nioCore,
  675. .nioConcurrencyHelpers,
  676. .nioPosix,
  677. .argumentParser,
  678. ],
  679. path: "Sources/Examples/v1/RouteGuide/Server",
  680. swiftSettings: [.swiftLanguageVersion(.v5)]
  681. )
  682. }
  683. static var packetCapture: Target {
  684. .executableTarget(
  685. name: "PacketCapture",
  686. dependencies: [
  687. .grpc,
  688. .echoModel,
  689. .nioCore,
  690. .nioPosix,
  691. .nioExtras,
  692. .argumentParser,
  693. ],
  694. path: "Sources/Examples/v1/PacketCapture",
  695. exclude: [
  696. "README.md",
  697. ],
  698. swiftSettings: [.swiftLanguageVersion(.v5)]
  699. )
  700. }
  701. static var reflectionService: Target {
  702. .target(
  703. name: "GRPCReflectionService",
  704. dependencies: [
  705. .grpc,
  706. .nio,
  707. .protobuf,
  708. ],
  709. path: "Sources/GRPCReflectionService",
  710. swiftSettings: [.swiftLanguageVersion(.v5)]
  711. )
  712. }
  713. static var reflectionServer: Target {
  714. .executableTarget(
  715. name: "ReflectionServer",
  716. dependencies: [
  717. .grpc,
  718. .reflectionService,
  719. .helloWorldModel,
  720. .nioCore,
  721. .nioPosix,
  722. .argumentParser,
  723. .echoModel,
  724. .echoImplementation
  725. ],
  726. path: "Sources/Examples/v1/ReflectionService",
  727. resources: [
  728. .copy("Generated")
  729. ],
  730. swiftSettings: [.swiftLanguageVersion(.v5)]
  731. )
  732. }
  733. static var grpcCodeGen: Target {
  734. .target(
  735. name: "GRPCCodeGen",
  736. path: "Sources/GRPCCodeGen",
  737. swiftSettings: [.swiftLanguageVersion(.v6)]
  738. )
  739. }
  740. static var grpcProtobuf: Target {
  741. .target(
  742. name: "GRPCProtobuf",
  743. dependencies: [
  744. .grpcCore,
  745. .protobuf,
  746. ],
  747. path: "Sources/GRPCProtobuf",
  748. swiftSettings: [.swiftLanguageVersion(.v6)]
  749. )
  750. }
  751. static var grpcProtobufCodeGen: Target {
  752. .target(
  753. name: "GRPCProtobufCodeGen",
  754. dependencies: [
  755. .protobuf,
  756. .protobufPluginLibrary,
  757. .grpcCodeGen
  758. ],
  759. path: "Sources/GRPCProtobufCodeGen",
  760. swiftSettings: [.swiftLanguageVersion(.v6)]
  761. )
  762. }
  763. static var grpcHealth: Target {
  764. .target(
  765. name: "GRPCHealth",
  766. dependencies: [
  767. .grpcCore,
  768. .grpcProtobuf
  769. ],
  770. path: "Sources/Services/Health",
  771. swiftSettings: [.swiftLanguageVersion(.v6)]
  772. )
  773. }
  774. }
  775. // MARK: - Products
  776. extension Product {
  777. static var grpc: Product {
  778. .library(
  779. name: grpcProductName,
  780. targets: [grpcTargetName]
  781. )
  782. }
  783. static var _grpcCore: Product {
  784. .library(
  785. name: "_GRPCCore",
  786. targets: ["GRPCCore"]
  787. )
  788. }
  789. static var _grpcProtobuf: Product {
  790. .library(
  791. name: "_GRPCProtobuf",
  792. targets: ["GRPCProtobuf"]
  793. )
  794. }
  795. static var cgrpcZlib: Product {
  796. .library(
  797. name: cgrpcZlibProductName,
  798. targets: [cgrpcZlibTargetName]
  799. )
  800. }
  801. static var grpcReflectionService: Product {
  802. .library(
  803. name: "GRPCReflectionService",
  804. targets: ["GRPCReflectionService"]
  805. )
  806. }
  807. static var protocGenGRPCSwift: Product {
  808. .executable(
  809. name: "protoc-gen-grpc-swift",
  810. targets: ["protoc-gen-grpc-swift"]
  811. )
  812. }
  813. static var grpcSwiftPlugin: Product {
  814. .plugin(
  815. name: "GRPCSwiftPlugin",
  816. targets: ["GRPCSwiftPlugin"]
  817. )
  818. }
  819. }
  820. // MARK: - Package
  821. let package = Package(
  822. name: grpcPackageName,
  823. products: [
  824. // v1
  825. .grpc,
  826. .cgrpcZlib,
  827. .grpcReflectionService,
  828. .protocGenGRPCSwift,
  829. .grpcSwiftPlugin,
  830. // v2
  831. ._grpcCore,
  832. ._grpcProtobuf,
  833. ],
  834. dependencies: packageDependencies,
  835. targets: [
  836. // Products
  837. .grpc,
  838. .cgrpcZlib,
  839. .protocGenGRPCSwift,
  840. .grpcSwiftPlugin,
  841. .reflectionService,
  842. // Tests etc.
  843. .grpcTests,
  844. .interopTestModels,
  845. .interopTestImplementation,
  846. .interopTests,
  847. .backoffInteropTest,
  848. .perfTests,
  849. .grpcSampleData,
  850. // Examples
  851. .echoModel,
  852. .echoImplementation,
  853. .echo,
  854. .helloWorldModel,
  855. .helloWorldClient,
  856. .helloWorldServer,
  857. .routeGuideModel,
  858. .routeGuideClient,
  859. .routeGuideServer,
  860. .packetCapture,
  861. .reflectionServer,
  862. // v2
  863. .grpcCore,
  864. .grpcInProcessTransport,
  865. .grpcCodeGen,
  866. .grpcInterceptors,
  867. .grpcHTTP2Core,
  868. .grpcHTTP2TransportNIOPosix,
  869. .grpcHTTP2TransportNIOTransportServices,
  870. .grpcProtobuf,
  871. .grpcProtobufCodeGen,
  872. .grpcHealth,
  873. .interoperabilityTestImplementation,
  874. .interoperabilityTestsExecutable,
  875. .performanceWorker,
  876. // v2 tests
  877. .grpcCoreTests,
  878. .grpcInProcessTransportTests,
  879. .grpcCodeGenTests,
  880. .grpcInterceptorsTests,
  881. .grpcHTTP2CoreTests,
  882. .grpcHTTP2TransportTests,
  883. .grpcProtobufTests,
  884. .grpcProtobufCodeGenTests,
  885. .inProcessInteroperabilityTests,
  886. // v2 examples
  887. .echo_v2,
  888. ]
  889. )
  890. extension Array {
  891. func appending(_ element: Element, if condition: Bool) -> [Element] {
  892. if condition {
  893. return self + [element]
  894. } else {
  895. return self
  896. }
  897. }
  898. }