2
0

Package.swift 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  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. ],
  156. path: "Sources/GRPCCore"
  157. )
  158. static let cgrpcZlib: Target = .target(
  159. name: cgrpcZlibTargetName,
  160. path: "Sources/CGRPCZlib",
  161. linkerSettings: [
  162. .linkedLibrary("z"),
  163. ]
  164. )
  165. static let protocGenGRPCSwift: Target = .executableTarget(
  166. name: "protoc-gen-grpc-swift",
  167. dependencies: [
  168. .protobuf,
  169. .protobufPluginLibrary,
  170. ],
  171. exclude: [
  172. "README.md",
  173. ]
  174. )
  175. static let grpcSwiftPlugin: Target = .plugin(
  176. name: "GRPCSwiftPlugin",
  177. capability: .buildTool(),
  178. dependencies: [
  179. .protocGenGRPCSwift,
  180. ]
  181. )
  182. static let grpcTests: Target = .testTarget(
  183. name: "GRPCTests",
  184. dependencies: [
  185. .grpc,
  186. .echoModel,
  187. .echoImplementation,
  188. .helloWorldModel,
  189. .interopTestModels,
  190. .interopTestImplementation,
  191. .grpcSampleData,
  192. .nioCore,
  193. .nioConcurrencyHelpers,
  194. .nioPosix,
  195. .nioTLS,
  196. .nioHTTP1,
  197. .nioHTTP2,
  198. .nioEmbedded,
  199. .nioTransportServices,
  200. .logging,
  201. .reflectionService,
  202. ].appending(
  203. .nioSSL, if: includeNIOSSL
  204. ),
  205. exclude: [
  206. "Codegen/Normalization/normalization.proto",
  207. "Codegen/Serialization/echo.grpc.reflection.txt",
  208. ]
  209. )
  210. static let grpcCoreTests: Target = .testTarget(
  211. name: "GRPCCoreTests",
  212. dependencies: [
  213. .grpcCore,
  214. .dequeModule,
  215. .atomics
  216. ]
  217. )
  218. static let interopTestModels: Target = .target(
  219. name: "GRPCInteroperabilityTestModels",
  220. dependencies: [
  221. .grpc,
  222. .nio,
  223. .protobuf,
  224. ],
  225. exclude: [
  226. "README.md",
  227. "generate.sh",
  228. "src/proto/grpc/testing/empty.proto",
  229. "src/proto/grpc/testing/empty_service.proto",
  230. "src/proto/grpc/testing/messages.proto",
  231. "src/proto/grpc/testing/test.proto",
  232. "unimplemented_call.patch",
  233. ]
  234. )
  235. static let interopTestImplementation: Target = .target(
  236. name: "GRPCInteroperabilityTestsImplementation",
  237. dependencies: [
  238. .grpc,
  239. .interopTestModels,
  240. .nioCore,
  241. .nioPosix,
  242. .nioHTTP1,
  243. .logging,
  244. ].appending(
  245. .nioSSL, if: includeNIOSSL
  246. )
  247. )
  248. static let interopTests: Target = .executableTarget(
  249. name: "GRPCInteroperabilityTests",
  250. dependencies: [
  251. .grpc,
  252. .interopTestImplementation,
  253. .nioCore,
  254. .nioPosix,
  255. .logging,
  256. .argumentParser,
  257. ]
  258. )
  259. static let backoffInteropTest: Target = .executableTarget(
  260. name: "GRPCConnectionBackoffInteropTest",
  261. dependencies: [
  262. .grpc,
  263. .interopTestModels,
  264. .nioCore,
  265. .nioPosix,
  266. .logging,
  267. .argumentParser,
  268. ],
  269. exclude: [
  270. "README.md",
  271. ]
  272. )
  273. static let perfTests: Target = .executableTarget(
  274. name: "GRPCPerformanceTests",
  275. dependencies: [
  276. .grpc,
  277. .grpcSampleData,
  278. .nioCore,
  279. .nioEmbedded,
  280. .nioPosix,
  281. .nioHTTP2,
  282. .argumentParser,
  283. ]
  284. )
  285. static let grpcSampleData: Target = .target(
  286. name: "GRPCSampleData",
  287. dependencies: includeNIOSSL ? [.nioSSL] : [],
  288. exclude: [
  289. "bundle.p12",
  290. ]
  291. )
  292. static let echoModel: Target = .target(
  293. name: "EchoModel",
  294. dependencies: [
  295. .grpc,
  296. .nio,
  297. .protobuf,
  298. ],
  299. path: "Sources/Examples/Echo/Model",
  300. exclude: [
  301. "echo.proto",
  302. ]
  303. )
  304. static let echoImplementation: Target = .target(
  305. name: "EchoImplementation",
  306. dependencies: [
  307. .echoModel,
  308. .grpc,
  309. .nioCore,
  310. .nioHTTP2,
  311. .protobuf,
  312. ],
  313. path: "Sources/Examples/Echo/Implementation"
  314. )
  315. static let echo: Target = .executableTarget(
  316. name: "Echo",
  317. dependencies: [
  318. .grpc,
  319. .echoModel,
  320. .echoImplementation,
  321. .grpcSampleData,
  322. .nioCore,
  323. .nioPosix,
  324. .logging,
  325. .argumentParser,
  326. ].appending(
  327. .nioSSL, if: includeNIOSSL
  328. ),
  329. path: "Sources/Examples/Echo/Runtime"
  330. )
  331. static let helloWorldModel: Target = .target(
  332. name: "HelloWorldModel",
  333. dependencies: [
  334. .grpc,
  335. .nio,
  336. .protobuf,
  337. ],
  338. path: "Sources/Examples/HelloWorld/Model",
  339. exclude: [
  340. "helloworld.proto",
  341. ]
  342. )
  343. static let helloWorldClient: Target = .executableTarget(
  344. name: "HelloWorldClient",
  345. dependencies: [
  346. .grpc,
  347. .helloWorldModel,
  348. .nioCore,
  349. .nioPosix,
  350. .argumentParser,
  351. ],
  352. path: "Sources/Examples/HelloWorld/Client"
  353. )
  354. static let helloWorldServer: Target = .executableTarget(
  355. name: "HelloWorldServer",
  356. dependencies: [
  357. .grpc,
  358. .helloWorldModel,
  359. .nioCore,
  360. .nioPosix,
  361. .argumentParser,
  362. ],
  363. path: "Sources/Examples/HelloWorld/Server"
  364. )
  365. static let routeGuideModel: Target = .target(
  366. name: "RouteGuideModel",
  367. dependencies: [
  368. .grpc,
  369. .nio,
  370. .protobuf,
  371. ],
  372. path: "Sources/Examples/RouteGuide/Model",
  373. exclude: [
  374. "route_guide.proto",
  375. ]
  376. )
  377. static let routeGuideClient: Target = .executableTarget(
  378. name: "RouteGuideClient",
  379. dependencies: [
  380. .grpc,
  381. .routeGuideModel,
  382. .nioCore,
  383. .nioPosix,
  384. .argumentParser,
  385. ],
  386. path: "Sources/Examples/RouteGuide/Client"
  387. )
  388. static let routeGuideServer: Target = .executableTarget(
  389. name: "RouteGuideServer",
  390. dependencies: [
  391. .grpc,
  392. .routeGuideModel,
  393. .nioCore,
  394. .nioConcurrencyHelpers,
  395. .nioPosix,
  396. .argumentParser,
  397. ],
  398. path: "Sources/Examples/RouteGuide/Server"
  399. )
  400. static let packetCapture: Target = .executableTarget(
  401. name: "PacketCapture",
  402. dependencies: [
  403. .grpc,
  404. .echoModel,
  405. .nioCore,
  406. .nioPosix,
  407. .nioExtras,
  408. .argumentParser,
  409. ],
  410. path: "Sources/Examples/PacketCapture",
  411. exclude: [
  412. "README.md",
  413. ]
  414. )
  415. static let reflectionService: Target = .target(
  416. name: "GRPCReflectionService",
  417. dependencies: [
  418. .grpc,
  419. .nio,
  420. .protobuf,
  421. ],
  422. path: "Sources/GRPCReflectionService",
  423. exclude: [
  424. "Model/reflection.proto",
  425. ]
  426. )
  427. }
  428. // MARK: - Products
  429. extension Product {
  430. static let grpc: Product = .library(
  431. name: grpcProductName,
  432. targets: [grpcTargetName]
  433. )
  434. static let grpcCore: Product = .library(
  435. name: "_GRPCCore",
  436. targets: ["GRPCCore"]
  437. )
  438. static let cgrpcZlib: Product = .library(
  439. name: cgrpcZlibProductName,
  440. targets: [cgrpcZlibTargetName]
  441. )
  442. static let protocGenGRPCSwift: Product = .executable(
  443. name: "protoc-gen-grpc-swift",
  444. targets: ["protoc-gen-grpc-swift"]
  445. )
  446. static let grpcSwiftPlugin: Product = .plugin(
  447. name: "GRPCSwiftPlugin",
  448. targets: ["GRPCSwiftPlugin"]
  449. )
  450. }
  451. // MARK: - Package
  452. let package = Package(
  453. name: grpcPackageName,
  454. products: [
  455. .grpc,
  456. .grpcCore,
  457. .cgrpcZlib,
  458. .protocGenGRPCSwift,
  459. .grpcSwiftPlugin,
  460. ],
  461. dependencies: packageDependencies,
  462. targets: [
  463. // Products
  464. .grpc,
  465. .cgrpcZlib,
  466. .protocGenGRPCSwift,
  467. .grpcSwiftPlugin,
  468. .reflectionService,
  469. // Tests etc.
  470. .grpcTests,
  471. .interopTestModels,
  472. .interopTestImplementation,
  473. .interopTests,
  474. .backoffInteropTest,
  475. .perfTests,
  476. .grpcSampleData,
  477. // Examples
  478. .echoModel,
  479. .echoImplementation,
  480. .echo,
  481. .helloWorldModel,
  482. .helloWorldClient,
  483. .helloWorldServer,
  484. .routeGuideModel,
  485. .routeGuideClient,
  486. .routeGuideServer,
  487. .packetCapture,
  488. // v2
  489. .grpcCore,
  490. // v2 tests
  491. .grpcCoreTests,
  492. ]
  493. )
  494. extension Array {
  495. func appending(_ element: Element, if condition: Bool) -> [Element] {
  496. if condition {
  497. return self + [element]
  498. } else {
  499. return self
  500. }
  501. }
  502. }