Package.swift 13 KB

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