ProtobufAPIVersionCheck.swift 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Sources/SwiftProtobuf/ProtobufAPIVersionCheck.swift - Version checking
  2. //
  3. // Copyright (c) 2014 - 2016 Apple Inc. and the project authors
  4. // Licensed under Apache License v2.0 with Runtime Library Exception
  5. //
  6. // See LICENSE.txt for license information:
  7. // https://github.com/apple/swift-protobuf/blob/main/LICENSE.txt
  8. //
  9. // -----------------------------------------------------------------------------
  10. ///
  11. /// A scheme that ensures that generated protos cannot be compiled or linked
  12. /// against a version of the runtime with which they are not compatible.
  13. ///
  14. /// In many cases, API changes themselves might introduce incompatibilities
  15. /// between generated code and the runtime library, but we also want to protect
  16. /// against cases where breaking behavioral changes (without affecting the API)
  17. /// would cause generated code to be incompatible with a particular version of
  18. /// the runtime.
  19. ///
  20. // -----------------------------------------------------------------------------
  21. /// An empty protocol that encodes the version of the runtime library.
  22. ///
  23. /// This protocol will be replaced with one containing a different version
  24. /// number any time that breaking changes are made to the Swift Protobuf API.
  25. /// Combined with the protocol below, this lets us verify that generated code is
  26. /// never compiled against a version of the API with which it is incompatible.
  27. ///
  28. /// The version associated with a particular build of the compiler is defined as
  29. /// `Version.compatibilityVersion` in `protoc-gen-swift`. That version and this
  30. /// version must match for the generated protos to be compatible, so if you
  31. /// update one, make sure to update it here and in the associated type below.
  32. public protocol ProtobufAPIVersion_2 {}
  33. /// This protocol is expected to be implemented by a `fileprivate` type in each
  34. /// source file emitted by `protoc-gen-swift`. It effectively creates a binding
  35. /// between the version of the generated code and the version of this library,
  36. /// causing a compile-time error (with reasonable diagnostics) if they are
  37. /// incompatible.
  38. public protocol ProtobufAPIVersionCheck {
  39. associatedtype Version: ProtobufAPIVersion_2
  40. }