xref: /aosp_15_r20/external/grpc-grpc/templates/Package.swift.template (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
1%YAML 1.2
2--- |
3    // swift-tools-version:5.5
4    // The swift-tools-version declares the minimum version of Swift required to build this package.
5    import PackageDescription
6    import Foundation
7
8    var basePath = FileManager.default.fileExists(atPath: "native") ? "native" : "."
9
10    let package = Package(
11      name: "gRPC",
12      products: [
13        .library(
14          name: "gRPC-Core",
15          targets: [
16            "gRPC-Core",
17          ]
18        ),
19        .library(
20          name: "gRPC-cpp",
21          targets: [
22            "gRPC-cpp",
23          ]
24        )
25      ],
26
27      dependencies: [
28        .package(url: "https://github.com/firebase/abseil-cpp-SwiftPM.git", "0.20230802.0"..<"0.20230803.0"),
29        .package(url: "https://github.com/firebase/boringssl-SwiftPM.git", "0.9.0"..<"0.10.0"),
30      ],
31
32      targets: [
33        .target(
34          name: "gRPC-Core",
35          dependencies: [
36            .product(name:"abseil", package: "abseil-cpp-SwiftPM"),
37            .product(name:"openssl_grpc", package: "boringssl-SwiftPM"),
38          ],
39          path: basePath,
40          exclude: [
41            "examples/",
42            "src/objective-c/",
43          ],
44        <%
45          files = []
46          lib_maps = {lib.name: lib for lib in libs}
47          for dep in swift_package.get('deps', []):
48            lib = lib_maps[dep]
49            files.extend(lib.get('public_headers', []) + lib.headers + lib.src)
50          files = sorted(set(files))
51        %>
52          sources: [
53            % for file in files:
54            "${file}",
55            % endfor
56          ],
57          resources: [
58            .copy("src/objective-c/PrivacyInfo.xcprivacy"),
59          ],
60          publicHeadersPath: "spm-core-include",
61          cSettings: [
62            .headerSearchPath("./"),
63            .headerSearchPath("include/"),
64            .headerSearchPath("third_party/re2/"),
65            .headerSearchPath("third_party/upb/"),
66            .headerSearchPath("third_party/utf8_range/"),
67            .headerSearchPath("third_party/xxhash/"),
68            .headerSearchPath("src/core/ext/upb-gen/"),
69            .headerSearchPath("src/core/ext/upbdefs-gen/"),
70            .define("GRPC_ARES", to: "0"),
71          ],
72          linkerSettings: [
73            .linkedFramework("CoreFoundation"),
74            .linkedLibrary("z"),
75          ]
76        ),
77        .target(
78          name: "gRPC-cpp",
79          dependencies: [
80            .product(name:"abseil", package: "abseil-cpp-SwiftPM"),
81            "gRPC-Core",
82          ],
83          path: basePath,
84          exclude: [
85            "examples/",
86            "src/cpp/client/cronet_credentials.cc",
87            "src/cpp/client/channel_test_peer.cc",
88            "src/cpp/common/alts_util.cc",
89            "src/cpp/common/alts_context.cc",
90            "src/cpp/common/insecure_create_auth_context.cc",
91            "src/cpp/server/admin/",
92            "src/cpp/server/channelz/",
93            "src/cpp/server/csds/",
94            "src/cpp/server/load_reporter/",
95            "src/cpp/ext/",
96            "src/cpp/util/core_stats.cc",
97            "src/cpp/util/core_stats.h",
98            "src/cpp/util/error_details.cc",
99            "src/objective-c/examples/",
100            "src/objective-c/manual_tests/",
101            "src/objective-c/tests/",
102          ],
103          sources: [
104            "src/cpp/",
105          ],
106          resources: [
107            .copy("src/objective-c/PrivacyInfo.xcprivacy"),
108          ],
109          publicHeadersPath: "spm-cpp-include",
110          cSettings: [
111            .headerSearchPath("./"),
112            .headerSearchPath("include/"),
113            .headerSearchPath("third_party/upb/"),
114            .headerSearchPath("src/core/ext/upb-gen"),
115          ]
116        ),
117        .testTarget(
118          name: "build-test",
119          dependencies: [
120            "gRPC-cpp",
121          ],
122          path: basePath + "/test/spm_build"
123        ),
124      ],
125      cLanguageStandard: .gnu11,
126      cxxLanguageStandard: .cxx14
127    )
128