How grpc/grpc-ios works
Project Type & Purpose
• This is an open-source, multi-language RPC framework. At its heart is a C++ core library (“src/core”) implementing RPC logic (transport, call lifecycle, credentials, load-balancing, etc.). On top of this core sit language-specific client/server APIs (C++, Objective-C, Python, Ruby, PHP, C#, etc.). Tools, scripts, and CI integrate and package the libraries for various ecosystems.
Logical Components
a. Core C++ Library (src/core)
• Subsystems:
– Call handling (call spine, filters, message batching)
– Transport (HTTP/2, in-proc, channel stacks)
– Credentials & security (TLS, ALTS, token fetchers)
– Resolver & naming (DNS, xDS, polling)
– Load balancing (grpclb, round robin, pick-first, xDS)
– Service config & filters (fault injection, auth, census)
– Surface API (public C API, channel and call factories)
• Extensions & plugins: gRPC plugins, upb codegen, third-party libs (re2, zlib, upb).
b. Language Bindings & Wrappers
• C++ Wrapper (“src/cpp”): idiomatic C++ class interfaces (CompletionQueue, Stub, ServerBuilder) built atop core C API.
• Objective-C (src/objective-c), Python (src/python), Ruby (src/ruby), PHP (src/php), C# (src/csharp), etc.: each defines a thin layer calling into the core library.
c. Public Headers & Packaging
• “include/” and “spm-*-include/”: publicly exposed headers for CocoaPods, SwiftPM, and other package managers.
• Podspecs, Package.swift, scripts/: build and package for SPM, CocoaPods, NuGet, pip, gem.
d. CI & Release Automation
• .github/workflows: sync sources, lint, tests, publish to package registries.
• scripts/: pre-submit checks, build sample apps, publish pods, handle versioning.
e. Tests & Samples
• tests/spm, tests/cocoapod: sample applications demonstrating usage.
• end-to-end and unit tests in each language directory.
Relationships & Data Flow
• Language API → links against → Core C++ Library → uses → Third-Party Dependencies (upb, re2, zlib)
• Core Library interacts with system/network via Transport & I/O (posix, event engine).
• Resolver subsystem queries DNS/xDS to discover endpoints.
• Load Balancer picks subchannels for RPC; filters apply logging, metrics, auth.
• Service config directs behavior (timeouts, retry, fault inject).
• CI workflows invoke scripts, which call build tools and generate language packages.
Architectural Patterns & Principles
• Modular layering: core engine separated from language surface.
• Plugin/extension-based filters and transport.
• Factory patterns for channels, resolvers, credentials.
• Asynchronous event‐driven model (CompletionQueue).
• Code-generation (upb, protobuf) for APIs and xDS.
Essential Elements
• Modules grouped by functionality (transport, security, resolver, load balancing, surface API).