Pārlūkot izejas kodu

Add Package manifest and tidy up scripts

George Barnett 1 gadu atpakaļ
vecāks
revīzija
791446e687

+ 0 - 71
NOTICES.txt

@@ -1,71 +0,0 @@
-                          The gRPC Swift Project
-                          ======================
-
-Copyright 2021 The gRPC Swift Project
-
-The gRPC Swift project licenses this file to you under the Apache License,
-version 2.0 (the "License"); you may not use this file except in compliance
-with the License. You may obtain a copy of the License at:
-
-  https://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-License for the specific language governing permissions and limitations
-under the License.
-
--------------------------------------------------------------------------------
-
-This product uses scripts derived from SwiftNIO's integration testing
-framework: 'test_01_allocation_counts.sh', 'run-nio-alloc-counter-tests.sh' and
-'test_functions.sh'.
-
-It also uses derivations of SwiftNIO's lock 'NIOLock.swift' and locked value box
-'NIOLockedValueBox.swift'.
-
-  * LICENSE (Apache License 2.0):
-    * https://github.com/apple/swift-nio/blob/main/LICENSE.txt
-  * HOMEPAGE:
-    * https://github.com/apple/swift-nio
-
----
-
-This product uses derivations of SwiftNIOHTTP2's implementation of case
-insensitive comparison of strings, found in 'HPACKHeader.swift'.
-    
-    * LICENSE (Apache License 2.0):
-      * https://github.com/apple/swift-nio-http2/blob/main/LICENSE.txt
-    * HOMEPAGE:
-      * https://github.com/apple/swift-nio-http2
-
----
-
-This product contains a derivation of the backpressure aware async stream from
-the Swift project.
-
-  * LICENSE (Apache License 2.0):
-    * https://github.com/apple/swift/blob/main/LICENSE.txt
-  * HOMEPAGE:
-    * https://github.com/apple/swift
-
----
-
-This product uses derivations of swift-extras/swift-extras-base64 'Base64.swift'.
-
-  * LICENSE (Apache License 2.0):
-    * https://github.com/swift-extras/swift-extras-base64/blob/main/LICENSE
-  * HOMEPAGE:
-    * https://github.com/swift-extras/swift-extras-base64
-
----
-
-This product uses derivations of apple/swift-openapi-generator 'StructuredSwiftRepresentation.swift',
-'TypeName.swift', 'TypeUsage.swift', 'Builtins.swift', 'RendererProtocol.swift', 'TextBasedProtocol',
-'Test_TextBasedRenderer', and 'SnippetBasedReferenceTests.swift'.
-    
-    * LICENSE (Apache License 2.0):
-      * https://github.com/apple/swift-openapi-generator/blob/main/LICENSE.txt
-    * HOMEPAGE:
-      * https://github.com/apple/swift-openapi-generator
-

+ 141 - 0
Package.swift

@@ -0,0 +1,141 @@
+// swift-tools-version: 6.0
+/*
+ * Copyright 2024, gRPC Authors All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import PackageDescription
+
+let products: [Product] = [
+  .library(
+    name: "GRPCNIOTransportHTTP2",
+    targets: ["GRPCNIOTransportHTTP2"]
+  ),
+  .library(
+    name: "GRPCNIOTransportHTTP2Posix",
+    targets: ["GRPCNIOTransportHTTP2Posix"]
+  ),
+  .library(
+    name: "GRPCNIOTransportHTTP2TransportServices",
+    targets: ["GRPCNIOTransportHTTP2TransportServices"]
+  ),
+]
+
+let dependencies: [Package.Dependency] = [
+  .package(
+    url: "https://github.com/grpc/grpc-swift.git",
+    branch: "main"
+  ),
+  .package(
+    url: "https://github.com/apple/swift-nio.git",
+    from: "2.65.0"
+  ),
+  .package(
+    url: "https://github.com/apple/swift-nio-http2.git",
+    from: "1.32.0"
+  ),
+  .package(
+    url: "https://github.com/apple/swift-nio-transport-services.git",
+    from: "1.15.0"
+  ),
+  .package(
+    url: "https://github.com/apple/swift-nio-ssl.git",
+    from: "2.27.2"
+  ),
+  .package(
+    url: "https://github.com/apple/swift-nio-extras.git",
+    from: "1.4.0"
+  ),
+]
+
+let defaultSwiftSettings: [SwiftSetting] = [
+  .swiftLanguageMode(.v6),
+  .enableUpcomingFeature("ExistentialAny"),
+  .enableUpcomingFeature("InternalImportsByDefault")
+]
+
+let targets: [Target] = [
+  // C-module for z-lib shims
+  .target(
+    name: "CGRPCZlib",
+    dependencies: []
+  ),
+
+  // Core module containing shared compionents for the NIOPosix and NIOTS variants.
+  .target(
+    name: "GRPCNIOTransportCore",
+    dependencies: [
+      .product(name: "GRPCCore", package: "grpc-swift"),
+      .product(name: "NIOCore", package: "swift-nio"),
+      .product(name: "NIOHTTP2", package: "swift-nio-http2"),
+      .product(name: "NIOExtras", package: "swift-nio-extras"),
+      .target(name: "CGRPCZlib")
+    ],
+    swiftSettings: defaultSwiftSettings
+  ),
+  .testTarget(
+    name: "GRPCNIOTransportCoreTests",
+    dependencies: [
+      .target(name: "GRPCNIOTransportCore"),
+      .product(name: "NIOCore", package: "swift-nio"),
+      .product(name: "NIOEmbedded", package: "swift-nio"),
+      .product(name: "NIOTestUtils", package: "swift-nio"),
+    ]
+  ),
+
+  // NIOPosix variant of the HTTP/2 transports.
+  .target(
+    name: "GRPCNIOTransportHTTP2Posix",
+    dependencies: [
+      .target(name: "GRPCNIOTransportCore"),
+      .product(name: "GRPCCore", package: "grpc-swift"),
+      .product(name: "NIOPosix", package: "swift-nio"),
+    ],
+    swiftSettings: defaultSwiftSettings
+  ),
+
+  // NIOTransportServices variant of the HTTP/2 transports.
+  .target(
+    name: "GRPCNIOTransportHTTP2TransportServices",
+    dependencies: [
+      .target(name: "GRPCNIOTransportCore"),
+      .product(name: "GRPCCore", package: "grpc-swift"),
+      .product(name: "NIOTransportServices", package: "swift-nio-transport-services"),
+    ],
+    swiftSettings: defaultSwiftSettings
+  ),
+
+  // Umbrella module exporting NIOPosix and NIOTransportServices variants.
+  .target(
+    name: "GRPCNIOTransportHTTP2",
+    dependencies: [
+      .target(name: "GRPCNIOTransportHTTP2Posix"),
+      .target(name: "GRPCNIOTransportHTTP2TransportServices"),
+    ],
+    swiftSettings: defaultSwiftSettings
+  ),
+  .testTarget(
+    name: "GRPCNIOTransportHTTP2Tests",
+    dependencies: [
+      .target(name: "GRPCNIOTransportHTTP2"),
+    ]
+  )
+]
+
+let package = Package(
+  name: "grpc-swift-nio-transport",
+  products: products,
+  dependencies: dependencies,
+  targets: targets
+)

+ 41 - 0
Sources/GRPCNIOTransportCore/Internal/CallOptions+MethodConfig.swift

@@ -0,0 +1,41 @@
+/*
+ * Copyright 2024, gRPC Authors All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package import GRPCCore
+
+@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
+extension CallOptions {
+  package mutating func formUnion(with methodConfig: MethodConfig?) {
+    guard let methodConfig = methodConfig else { return }
+
+    self.timeout.setIfNone(to: methodConfig.timeout)
+    self.waitForReady.setIfNone(to: methodConfig.waitForReady)
+    self.maxRequestMessageBytes.setIfNone(to: methodConfig.maxRequestMessageBytes)
+    self.maxResponseMessageBytes.setIfNone(to: methodConfig.maxResponseMessageBytes)
+    self.executionPolicy.setIfNone(to: methodConfig.executionPolicy)
+  }
+}
+
+extension Optional {
+  fileprivate mutating func setIfNone(to value: Self) {
+    switch self {
+    case .some:
+      ()
+    case .none:
+      self = value
+    }
+  }
+}

+ 105 - 0
Sources/GRPCNIOTransportCore/Internal/MethodConfigs.swift

@@ -0,0 +1,105 @@
+/*
+ * Copyright 2023, gRPC Authors All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package import GRPCCore
+
+/// A collection of ``MethodConfig``s, mapped to specific methods or services.
+///
+/// When creating a new instance, no overrides and no default will be set for using when getting
+/// a configuration for a method that has not been given a specific override.
+/// Use ``setDefaultConfig(_:forService:)`` to set a specific override for a whole
+/// service, or set a default configuration for all methods by calling ``setDefaultConfig(_:)``.
+///
+/// Use the subscript to get and set configurations for specific methods.
+@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
+package struct MethodConfigs: Sendable, Hashable {
+  private var elements: [MethodConfig.Name: MethodConfig]
+
+  /// Create a new ``_MethodConfigs``.
+  ///
+  /// - Parameter serviceConfig: The configuration to read ``MethodConfig`` from.
+  package init(serviceConfig: ServiceConfig = ServiceConfig()) {
+    self.elements = [:]
+
+    for configuration in serviceConfig.methodConfig {
+      for name in configuration.names {
+        self.elements[name] = configuration
+      }
+    }
+  }
+
+  /// Get or set the corresponding ``MethodConfig`` for the given ``MethodDescriptor``.
+  ///
+  /// Configuration is hierarchical and can be set per-method, per-service
+  /// (``setDefaultConfig(_:forService:)``) and globally (``setDefaultConfig(_:)``).
+  /// This subscript sets the per-method configuration but retrieves a configuration respecting
+  /// the hierarchy. If no per-method configuration is present, the per-service configuration is
+  /// checked and returned if present. If the per-service configuration isn't present then the
+  /// global configuration is returned, if present.
+  ///
+  /// - Parameters:
+  ///  - descriptor: The ``MethodDescriptor`` for which to get or set a ``MethodConfig``.
+  package subscript(_ descriptor: MethodDescriptor) -> MethodConfig? {
+    get {
+      var name = MethodConfig.Name(service: descriptor.service, method: descriptor.method)
+
+      if let configuration = self.elements[name] {
+        return configuration
+      }
+
+      // Check if the config is set at the service level by clearing the method.
+      name.method = ""
+
+      if let configuration = self.elements[name] {
+        return configuration
+      }
+
+      // Check if the config is set at the global level by clearing the service and method.
+      name.service = ""
+      return self.elements[name]
+    }
+
+    set {
+      let name = MethodConfig.Name(service: descriptor.service, method: descriptor.method)
+      self.elements[name] = newValue
+    }
+  }
+
+  /// Set a default configuration for all methods that have no overrides.
+  ///
+  /// - Parameter config: The default configuration.
+  package mutating func setDefaultConfig(_ config: MethodConfig?) {
+    let name = MethodConfig.Name(service: "", method: "")
+    self.elements[name] = config
+  }
+
+  /// Set a default configuration for a service.
+  ///
+  /// If getting a configuration for a method that's part of a service, and the method itself doesn't have an
+  /// override, then this configuration will be used instead of the default configuration passed when creating
+  /// this instance of ``MethodConfigs``.
+  ///
+  /// - Parameters:
+  ///   - config: The default configuration for the service.
+  ///   - service: The name of the service for which this override applies.
+  package mutating func setDefaultConfig(
+    _ config: MethodConfig?,
+    forService service: String
+  ) {
+    let name = MethodConfig.Name(service: "", method: "")
+    self.elements[name] = config
+  }
+}

+ 0 - 4
scripts/format.sh → dev/format.sh

@@ -60,8 +60,6 @@ if "$lint"; then
     --parallel --recursive --strict \
     "${repo}/Sources" \
     "${repo}/Tests" \
-    "${repo}/Plugins" \
-    "${repo}/Performance/Benchmarks/Benchmarks/GRPCSwiftBenchmark" \
     && SWIFT_FORMAT_RC=$? || SWIFT_FORMAT_RC=$?
 
   if [[ "${SWIFT_FORMAT_RC}" -ne 0 ]]; then
@@ -80,8 +78,6 @@ elif "$format"; then
     --parallel --recursive --in-place \
     "${repo}/Sources" \
     "${repo}/Tests" \
-    "${repo}/Plugins" \
-    "${repo}/Performance/Benchmarks/Benchmarks/GRPCSwiftBenchmark" \
     && SWIFT_FORMAT_RC=$? || SWIFT_FORMAT_RC=$?
 
   if [[ "${SWIFT_FORMAT_RC}" -ne 0 ]]; then

+ 0 - 7
scripts/license-check.sh → dev/license-check.sh

@@ -105,13 +105,6 @@ check_copyright_headers() {
   done < <(find . -name '*.swift' \
     ! -name '*.pb.swift' \
     ! -name '*.grpc.swift' \
-    ! -name 'LinuxMain.swift' \
-    ! -name 'XCTestManifests.swift' \
-    ! -path './Sources/GRPCCore/Documentation.docc/*' \
-    ! -path './FuzzTesting/.build/*' \
-    ! -path './Performance/QPSBenchmark/.build/*' \
-    ! -path './Performance/Benchmarks/.build/*' \
-    ! -path './scripts/.swift-format-source/*' \
     ! -path './.build/*')
 }
 

+ 0 - 5
scripts/sanity.sh → dev/sanity.sh

@@ -45,12 +45,7 @@ function check_formatting() {
   run_logged "Checking formatting" "$here/format.sh -l"
 }
 
-function check_generated_code_is_up_to_date() {
-  run_logged "Checking generated code is up-to-date" "$here/check-generated-code.sh"
-}
-
 errors=0
 check_license_headers
 check_formatting
-check_generated_code_is_up_to_date
 exit $errors