Package.swift 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. // swift-tools-version:5.7
  2. /*
  3. * Copyright 2017, 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.58.0"
  32. ),
  33. .package(
  34. url: "https://github.com/apple/swift-nio-http2.git",
  35. from: "1.24.1"
  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-docc-plugin",
  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 let grpc: Self = .target(name: grpcTargetName)
  82. static let cgrpcZlib: Self = .target(name: cgrpcZlibTargetName)
  83. static let protocGenGRPCSwift: Self = .target(name: "protoc-gen-grpc-swift")
  84. // Target dependencies; internal
  85. static let grpcSampleData: Self = .target(name: "GRPCSampleData")
  86. static let echoModel: Self = .target(name: "EchoModel")
  87. static let echoImplementation: Self = .target(name: "EchoImplementation")
  88. static let helloWorldModel: Self = .target(name: "HelloWorldModel")
  89. static let routeGuideModel: Self = .target(name: "RouteGuideModel")
  90. static let interopTestModels: Self = .target(name: "GRPCInteroperabilityTestModels")
  91. static let interopTestImplementation: Self =
  92. .target(name: "GRPCInteroperabilityTestsImplementation")
  93. static let reflectionService: Self = .target(name: "GRPCReflectionService")
  94. // Product dependencies
  95. static let argumentParser: Self = .product(
  96. name: "ArgumentParser",
  97. package: "swift-argument-parser"
  98. )
  99. static let nio: Self = .product(name: "NIO", package: "swift-nio")
  100. static let nioConcurrencyHelpers: Self = .product(
  101. name: "NIOConcurrencyHelpers",
  102. package: "swift-nio"
  103. )
  104. static let nioCore: Self = .product(name: "NIOCore", package: "swift-nio")
  105. static let nioEmbedded: Self = .product(name: "NIOEmbedded", package: "swift-nio")
  106. static let nioExtras: Self = .product(name: "NIOExtras", package: "swift-nio-extras")
  107. static let nioFoundationCompat: Self = .product(name: "NIOFoundationCompat", package: "swift-nio")
  108. static let nioHTTP1: Self = .product(name: "NIOHTTP1", package: "swift-nio")
  109. static let nioHTTP2: Self = .product(name: "NIOHTTP2", package: "swift-nio-http2")
  110. static let nioPosix: Self = .product(name: "NIOPosix", package: "swift-nio")
  111. static let nioSSL: Self = .product(name: "NIOSSL", package: "swift-nio-ssl")
  112. static let nioTLS: Self = .product(name: "NIOTLS", package: "swift-nio")
  113. static let nioTransportServices: Self = .product(
  114. name: "NIOTransportServices",
  115. package: "swift-nio-transport-services"
  116. )
  117. static let logging: Self = .product(name: "Logging", package: "swift-log")
  118. static let protobuf: Self = .product(name: "SwiftProtobuf", package: "swift-protobuf")
  119. static let protobufPluginLibrary: Self = .product(
  120. name: "SwiftProtobufPluginLibrary",
  121. package: "swift-protobuf"
  122. )
  123. static let dequeModule: Self = .product(name: "DequeModule", package: "swift-collections")
  124. static let atomics: Self = .product(name: "Atomics", package: "swift-atomics")
  125. static let grpcCore: Self = .target(name: "GRPCCore")
  126. }
  127. // MARK: - Targets
  128. extension Target {
  129. static let grpc: Target = .target(
  130. name: grpcTargetName,
  131. dependencies: [
  132. .cgrpcZlib,
  133. .nio,
  134. .nioCore,
  135. .nioPosix,
  136. .nioEmbedded,
  137. .nioFoundationCompat,
  138. .nioTLS,
  139. .nioTransportServices,
  140. .nioHTTP1,
  141. .nioHTTP2,
  142. .nioExtras,
  143. .logging,
  144. .protobuf,
  145. .dequeModule,
  146. ].appending(
  147. .nioSSL, if: includeNIOSSL
  148. ),
  149. path: "Sources/GRPC"
  150. )
  151. static let grpcCore: Target = .target(
  152. name: "GRPCCore",
  153. dependencies: [
  154. .dequeModule,
  155. .atomics
  156. ],
  157. path: "Sources/GRPCCore"
  158. )
  159. static let cgrpcZlib: Target = .target(
  160. name: cgrpcZlibTargetName,
  161. path: "Sources/CGRPCZlib",
  162. linkerSettings: [
  163. .linkedLibrary("z"),
  164. ]
  165. )
  166. static let protocGenGRPCSwift: Target = .executableTarget(
  167. name: "protoc-gen-grpc-swift",
  168. dependencies: [
  169. .protobuf,
  170. .protobufPluginLibrary,
  171. ],
  172. exclude: [
  173. "README.md",
  174. ]
  175. )
  176. static let grpcSwiftPlugin: Target = .plugin(
  177. name: "GRPCSwiftPlugin",
  178. capability: .buildTool(),
  179. dependencies: [
  180. .protocGenGRPCSwift,
  181. ]
  182. )
  183. static let grpcTests: Target = .testTarget(
  184. name: "GRPCTests",
  185. dependencies: [
  186. .grpc,
  187. .echoModel,
  188. .echoImplementation,
  189. .helloWorldModel,
  190. .interopTestModels,
  191. .interopTestImplementation,
  192. .grpcSampleData,
  193. .nioCore,
  194. .nioConcurrencyHelpers,
  195. .nioPosix,
  196. .nioTLS,
  197. .nioHTTP1,
  198. .nioHTTP2,
  199. .nioEmbedded,
  200. .nioTransportServices,
  201. .logging,
  202. .reflectionService,
  203. ].appending(
  204. .nioSSL, if: includeNIOSSL
  205. ),
  206. exclude: [
  207. "Codegen/Normalization/normalization.proto",
  208. "Codegen/Serialization/echo.grpc.reflection.txt",
  209. ]
  210. )
  211. static let grpcCoreTests: Target = .testTarget(
  212. name: "GRPCCoreTests",
  213. dependencies: [
  214. .grpcCore,
  215. .dequeModule,
  216. .atomics
  217. ]
  218. )
  219. static let interopTestModels: Target = .target(
  220. name: "GRPCInteroperabilityTestModels",
  221. dependencies: [
  222. .grpc,
  223. .nio,
  224. .protobuf,
  225. ],
  226. exclude: [
  227. "README.md",
  228. "generate.sh",
  229. "src/proto/grpc/testing/empty.proto",
  230. "src/proto/grpc/testing/empty_service.proto",
  231. "src/proto/grpc/testing/messages.proto",
  232. "src/proto/grpc/testing/test.proto",
  233. "unimplemented_call.patch",
  234. ]
  235. )
  236. static let interopTestImplementation: Target = .target(
  237. name: "GRPCInteroperabilityTestsImplementation",
  238. dependencies: [
  239. .grpc,
  240. .interopTestModels,
  241. .nioCore,
  242. .nioPosix,
  243. .nioHTTP1,
  244. .logging,
  245. ].appending(
  246. .nioSSL, if: includeNIOSSL
  247. )
  248. )
  249. static let interopTests: Target = .executableTarget(
  250. name: "GRPCInteroperabilityTests",
  251. dependencies: [
  252. .grpc,
  253. .interopTestImplementation,
  254. .nioCore,
  255. .nioPosix,
  256. .logging,
  257. .argumentParser,
  258. ]
  259. )
  260. static let backoffInteropTest: Target = .executableTarget(
  261. name: "GRPCConnectionBackoffInteropTest",
  262. dependencies: [
  263. .grpc,
  264. .interopTestModels,
  265. .nioCore,
  266. .nioPosix,
  267. .logging,
  268. .argumentParser,
  269. ],
  270. exclude: [
  271. "README.md",
  272. ]
  273. )
  274. static let perfTests: Target = .executableTarget(
  275. name: "GRPCPerformanceTests",
  276. dependencies: [
  277. .grpc,
  278. .grpcSampleData,
  279. .nioCore,
  280. .nioEmbedded,
  281. .nioPosix,
  282. .nioHTTP2,
  283. .argumentParser,
  284. ]
  285. )
  286. static let grpcSampleData: Target = .target(
  287. name: "GRPCSampleData",
  288. dependencies: includeNIOSSL ? [.nioSSL] : [],
  289. exclude: [
  290. "bundle.p12",
  291. ]
  292. )
  293. static let echoModel: Target = .target(
  294. name: "EchoModel",
  295. dependencies: [
  296. .grpc,
  297. .nio,
  298. .protobuf,
  299. ],
  300. path: "Sources/Examples/Echo/Model",
  301. exclude: [
  302. "echo.proto",
  303. ]
  304. )
  305. static let echoImplementation: Target = .target(
  306. name: "EchoImplementation",
  307. dependencies: [
  308. .echoModel,
  309. .grpc,
  310. .nioCore,
  311. .nioHTTP2,
  312. .protobuf,
  313. ],
  314. path: "Sources/Examples/Echo/Implementation"
  315. )
  316. static let echo: Target = .executableTarget(
  317. name: "Echo",
  318. dependencies: [
  319. .grpc,
  320. .echoModel,
  321. .echoImplementation,
  322. .grpcSampleData,
  323. .nioCore,
  324. .nioPosix,
  325. .logging,
  326. .argumentParser,
  327. ].appending(
  328. .nioSSL, if: includeNIOSSL
  329. ),
  330. path: "Sources/Examples/Echo/Runtime"
  331. )
  332. static let helloWorldModel: Target = .target(
  333. name: "HelloWorldModel",
  334. dependencies: [
  335. .grpc,
  336. .nio,
  337. .protobuf,
  338. ],
  339. path: "Sources/Examples/HelloWorld/Model",
  340. exclude: [
  341. "helloworld.proto",
  342. ]
  343. )
  344. static let helloWorldClient: Target = .executableTarget(
  345. name: "HelloWorldClient",
  346. dependencies: [
  347. .grpc,
  348. .helloWorldModel,
  349. .nioCore,
  350. .nioPosix,
  351. .argumentParser,
  352. ],
  353. path: "Sources/Examples/HelloWorld/Client"
  354. )
  355. static let helloWorldServer: Target = .executableTarget(
  356. name: "HelloWorldServer",
  357. dependencies: [
  358. .grpc,
  359. .helloWorldModel,
  360. .nioCore,
  361. .nioPosix,
  362. .argumentParser,
  363. ],
  364. path: "Sources/Examples/HelloWorld/Server"
  365. )
  366. static let routeGuideModel: Target = .target(
  367. name: "RouteGuideModel",
  368. dependencies: [
  369. .grpc,
  370. .nio,
  371. .protobuf,
  372. ],
  373. path: "Sources/Examples/RouteGuide/Model",
  374. exclude: [
  375. "route_guide.proto",
  376. ]
  377. )
  378. static let routeGuideClient: Target = .executableTarget(
  379. name: "RouteGuideClient",
  380. dependencies: [
  381. .grpc,
  382. .routeGuideModel,
  383. .nioCore,
  384. .nioPosix,
  385. .argumentParser,
  386. ],
  387. path: "Sources/Examples/RouteGuide/Client"
  388. )
  389. static let routeGuideServer: Target = .executableTarget(
  390. name: "RouteGuideServer",
  391. dependencies: [
  392. .grpc,
  393. .routeGuideModel,
  394. .nioCore,
  395. .nioConcurrencyHelpers,
  396. .nioPosix,
  397. .argumentParser,
  398. ],
  399. path: "Sources/Examples/RouteGuide/Server"
  400. )
  401. static let packetCapture: Target = .executableTarget(
  402. name: "PacketCapture",
  403. dependencies: [
  404. .grpc,
  405. .echoModel,
  406. .nioCore,
  407. .nioPosix,
  408. .nioExtras,
  409. .argumentParser,
  410. ],
  411. path: "Sources/Examples/PacketCapture",
  412. exclude: [
  413. "README.md",
  414. ]
  415. )
  416. static let reflectionService: Target = .target(
  417. name: "GRPCReflectionService",
  418. dependencies: [
  419. .grpc,
  420. .nio,
  421. .protobuf,
  422. ],
  423. path: "Sources/GRPCReflectionService",
  424. exclude: [
  425. "v1/reflection-v1.proto",
  426. "v1Alpha/reflection-v1alpha.proto"
  427. ]
  428. )
  429. static let reflectionServer: Target = .executableTarget(
  430. name: "ReflectionServer",
  431. dependencies: [
  432. .grpc,
  433. .reflectionService,
  434. .helloWorldModel,
  435. .nioCore,
  436. .nioPosix,
  437. .argumentParser,
  438. .echoModel,
  439. .echoImplementation
  440. ],
  441. path: "Sources/Examples/ReflectionService",
  442. resources: [
  443. .copy("Generated")
  444. ]
  445. )
  446. }
  447. // MARK: - Products
  448. extension Product {
  449. static let grpc: Product = .library(
  450. name: grpcProductName,
  451. targets: [grpcTargetName]
  452. )
  453. static let grpcCore: Product = .library(
  454. name: "_GRPCCore",
  455. targets: ["GRPCCore"]
  456. )
  457. static let cgrpcZlib: Product = .library(
  458. name: cgrpcZlibProductName,
  459. targets: [cgrpcZlibTargetName]
  460. )
  461. static let protocGenGRPCSwift: Product = .executable(
  462. name: "protoc-gen-grpc-swift",
  463. targets: ["protoc-gen-grpc-swift"]
  464. )
  465. static let grpcSwiftPlugin: Product = .plugin(
  466. name: "GRPCSwiftPlugin",
  467. targets: ["GRPCSwiftPlugin"]
  468. )
  469. }
  470. // MARK: - Package
  471. let package = Package(
  472. name: grpcPackageName,
  473. products: [
  474. .grpc,
  475. .grpcCore,
  476. .cgrpcZlib,
  477. .protocGenGRPCSwift,
  478. .grpcSwiftPlugin,
  479. ],
  480. dependencies: packageDependencies,
  481. targets: [
  482. // Products
  483. .grpc,
  484. .cgrpcZlib,
  485. .protocGenGRPCSwift,
  486. .grpcSwiftPlugin,
  487. .reflectionService,
  488. // Tests etc.
  489. .grpcTests,
  490. .interopTestModels,
  491. .interopTestImplementation,
  492. .interopTests,
  493. .backoffInteropTest,
  494. .perfTests,
  495. .grpcSampleData,
  496. // Examples
  497. .echoModel,
  498. .echoImplementation,
  499. .echo,
  500. .helloWorldModel,
  501. .helloWorldClient,
  502. .helloWorldServer,
  503. .routeGuideModel,
  504. .routeGuideClient,
  505. .routeGuideServer,
  506. .packetCapture,
  507. .reflectionServer,
  508. // v2
  509. .grpcCore,
  510. // v2 tests
  511. .grpcCoreTests,
  512. ]
  513. )
  514. extension Array {
  515. func appending(_ element: Element, if condition: Bool) -> [Element] {
  516. if condition {
  517. return self + [element]
  518. } else {
  519. return self
  520. }
  521. }
  522. }