Package@swift-6.swift 25 KB

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