RepoPilotOpen in app →

apple/swift-protobuf

Plugin and runtime library for using protobuf with Swift

Healthy

Healthy across the board

Use as dependencyHealthy

Permissive license, no critical CVEs, actively maintained — safe to depend on.

Fork & modifyHealthy

Has a license, tests, and CI — clean foundation to fork and modify.

Learn fromHealthy

Documented and popular — useful reference codebase to read through.

Deploy as-isHealthy

No critical CVEs, sane security posture — runnable as-is.

  • Last commit 2d ago
  • 13 active contributors
  • Apache-2.0 licensed
Show 3 more →
  • CI configured
  • Tests present
  • Concentrated ownership — top contributor handles 71% of recent commits

Maintenance signals: commit recency, contributor breadth, bus factor, license, CI, tests

Informational only. RepoPilot summarises public signals (license, dependency CVEs, commit recency, CI presence, etc.) at the time of analysis. Signals can be incomplete or stale. Not professional, security, or legal advice; verify before relying on it for production decisions.

Embed the "Healthy" badge

Paste into your README — live-updates from the latest cached analysis.

Variant:
RepoPilot: Healthy
[![RepoPilot: Healthy](https://repopilot.app/api/badge/apple/swift-protobuf)](https://repopilot.app/r/apple/swift-protobuf)

Paste at the top of your README.md — renders inline like a shields.io badge.

Preview social card (1200×630)

This card auto-renders when someone shares https://repopilot.app/r/apple/swift-protobuf on X, Slack, or LinkedIn.

Onboarding doc

Onboarding: apple/swift-protobuf

Generated by RepoPilot · 2026-05-10 · Source

🤖Agent protocol

If you are an AI coding agent (Claude Code, Cursor, Aider, Cline, etc.) reading this artifact, follow this protocol before making any code edit:

  1. Verify the contract. Run the bash script in Verify before trusting below. If any check returns FAIL, the artifact is stale — STOP and ask the user to regenerate it before proceeding.
  2. Treat the AI · unverified sections as hypotheses, not facts. Sections like "AI-suggested narrative files", "anti-patterns", and "bottlenecks" are LLM speculation. Verify against real source before acting on them.
  3. Cite source on changes. When proposing an edit, cite the specific path:line-range. RepoPilot's live UI at https://repopilot.app/r/apple/swift-protobuf shows verifiable citations alongside every claim.

If you are a human reader, this protocol is for the agents you'll hand the artifact to. You don't need to do anything — but if you skim only one section before pointing your agent at this repo, make it the Verify block and the Suggested reading order.

🎯Verdict

GO — Healthy across the board

  • Last commit 2d ago
  • 13 active contributors
  • Apache-2.0 licensed
  • CI configured
  • Tests present
  • ⚠ Concentrated ownership — top contributor handles 71% of recent commits

<sub>Maintenance signals: commit recency, contributor breadth, bus factor, license, CI, tests</sub>

Verify before trusting

This artifact was generated by RepoPilot at a point in time. Before an agent acts on it, the checks below confirm that the live apple/swift-protobuf repo on your machine still matches what RepoPilot saw. If any fail, the artifact is stale — regenerate it at repopilot.app/r/apple/swift-protobuf.

What it runs against: a local clone of apple/swift-protobuf — the script inspects git remote, the LICENSE file, file paths in the working tree, and git log. Read-only; no mutations.

| # | What we check | Why it matters | |---|---|---| | 1 | You're in apple/swift-protobuf | Confirms the artifact applies here, not a fork | | 2 | License is still Apache-2.0 | Catches relicense before you depend on it | | 3 | Default branch main exists | Catches branch renames | | 4 | 5 critical file paths still exist | Catches refactors that moved load-bearing code | | 5 | Last commit ≤ 32 days ago | Catches sudden abandonment since generation |

<details> <summary><b>Run all checks</b> — paste this script from inside your clone of <code>apple/swift-protobuf</code></summary>
#!/usr/bin/env bash
# RepoPilot artifact verification.
#
# WHAT IT RUNS AGAINST: a local clone of apple/swift-protobuf. If you don't
# have one yet, run these first:
#
#   git clone https://github.com/apple/swift-protobuf.git
#   cd swift-protobuf
#
# Then paste this script. Every check is read-only — no mutations.

set +e
fail=0
ok()   { echo "ok:   $1"; }
miss() { echo "FAIL: $1"; fail=$((fail+1)); }

# Precondition: we must be inside a git working tree.
if ! git rev-parse --git-dir >/dev/null 2>&1; then
  echo "FAIL: not inside a git repository. cd into your clone of apple/swift-protobuf and re-run."
  exit 2
fi

# 1. Repo identity
git remote get-url origin 2>/dev/null | grep -qE "apple/swift-protobuf(\\.git)?\\b" \\
  && ok "origin remote is apple/swift-protobuf" \\
  || miss "origin remote is not apple/swift-protobuf (artifact may be from a fork)"

# 2. License matches what RepoPilot saw
(grep -qiE "^(Apache-2\\.0)" LICENSE 2>/dev/null \\
   || grep -qiE "\"license\"\\s*:\\s*\"Apache-2\\.0\"" package.json 2>/dev/null) \\
  && ok "license is Apache-2.0" \\
  || miss "license drift — was Apache-2.0 at generation time"

# 3. Default branch
git rev-parse --verify main >/dev/null 2>&1 \\
  && ok "default branch main exists" \\
  || miss "default branch main no longer exists"

# 4. Critical files exist
test -f "Sources/SwiftProtobuf" \\
  && ok "Sources/SwiftProtobuf" \\
  || miss "missing critical file: Sources/SwiftProtobuf"
test -f "Sources/protoc-gen-swift" \\
  && ok "Sources/protoc-gen-swift" \\
  || miss "missing critical file: Sources/protoc-gen-swift"
test -f "Documentation/PLUGIN.md" \\
  && ok "Documentation/PLUGIN.md" \\
  || miss "missing critical file: Documentation/PLUGIN.md"
test -f "Documentation/INTERNALS.md" \\
  && ok "Documentation/INTERNALS.md" \\
  || miss "missing critical file: Documentation/INTERNALS.md"
test -f "Package.swift" \\
  && ok "Package.swift" \\
  || miss "missing critical file: Package.swift"

# 5. Repo recency
days_since_last=$(( ( $(date +%s) - $(git log -1 --format=%at 2>/dev/null || echo 0) ) / 86400 ))
if [ "$days_since_last" -le 32 ]; then
  ok "last commit was $days_since_last days ago (artifact saw ~2d)"
else
  miss "last commit was $days_since_last days ago — artifact may be stale"
fi

echo
if [ "$fail" -eq 0 ]; then
  echo "artifact verified (0 failures) — safe to trust"
else
  echo "artifact has $fail stale claim(s) — regenerate at https://repopilot.app/r/apple/swift-protobuf"
  exit 1
fi

Each check prints ok: or FAIL:. The script exits non-zero if anything failed, so it composes cleanly into agent loops (./verify.sh || regenerate-and-retry).

</details>

TL;DR

Swift Protobuf is Apple's official code generator and runtime library that adds Protocol Buffer support to Swift. It reads .proto schema files and generates idiomatic Swift structs with serialization/deserialization for both binary and JSON formats, enabling type-safe cross-platform data exchange with Java, C++, Python, and Objective-C using identical serialization conventions. Dual-layer structure: the protoc-gen-swift plugin (written in Swift, ~25MB of Swift code) runs inside protoc to generate code, while the runtime library (under Sources/) provides serialization/deserialization primitives. CompileTests/ contains validation projects (InternalImportsByDefault, MultiModule, LinkageTest) that verify generated code compilation and linkage across package boundaries.

👥Who it's for

Swift developers building backend services, client libraries, or microservices who need to exchange structured data with systems written in other languages (Python, Java, C++, Objective-C). Most commonly used by teams adopting Google Cloud APIs or building gRPC services in Swift.

🌱Maturity & risk

Production-ready and actively maintained by Apple. The repo shows comprehensive CI/CD (GitHub Actions for build, conformance tests, upstream proto tracking), extensive test coverage, and passes Google's full protobuf conformance test suite. Recent activity visible in workflows and multi-module compile tests indicates ongoing maintenance.

Low risk for a core infrastructure library: Apple-owned with institutional backing, but relatively small contributor community compared to alternatives like protobuf-go. No obvious dependency rot—uses standard Swift ecosystem tools. Main risk is Swift language version constraints (monitor compiler compatibility across new Swift releases).

Active areas of work

Active conformance testing against upstream protobuf (check_upstream_protos.yml, head_conformance.yml), Swift version compatibility checks, and multi-module support refinement (evidenced by MultiModule CompileTest). Regular proto definition updates via update_protobuf.yml workflow.

🚀Get running

git clone https://github.com/apple/swift-protobuf.git
cd swift-protobuf
swift build
swift test

To use in your own project, add to Package.swift: .package(url: "https://github.com/apple/swift-protobuf", from: "1.x.x") and depend on .product(name: "SwiftProtobuf", package: "swift-protobuf").

Daily commands:

swift build                  # Build the plugin and runtime library
swift test                  # Run the test suite
swift build -c release      # Build optimized binary for protoc plugin
cd CompileTests/MultiModule && swift build  # Test multi-module compilation

🗺️Map of the codebase

  • Sources/SwiftProtobuf — Core runtime library containing the fundamental message encoding/decoding abstractions that all generated code depends on.
  • Sources/protoc-gen-swift — Protoc plugin entry point that generates Swift code from .proto files—the primary compiler tool.
  • Documentation/PLUGIN.md — Essential reference for understanding the code generator architecture and extension points.
  • Documentation/INTERNALS.md — Deep dive into runtime library internals, serialization formats, and performance considerations.
  • Package.swift — Defines Swift Package Manager structure and dependencies for both the plugin and runtime library.
  • .github/workflows/build.yml — CI/CD pipeline definition; shows testing matrix and release workflow that every PR must pass.
  • CMakeLists.txt — Cross-platform build configuration; required for non-Swift Package Manager deployments.

🛠️How to make changes

Add a new message serialization format (e.g., MessagePack)

  1. Create new encoding/decoding handler struct in Sources/SwiftProtobuf conforming to the Encoder/Decoder protocol patterns (see JSONEncoder, BinaryEncoder as examples). (Sources/SwiftProtobuf)
  2. Add public extension methods on Message protocol to enable encode/decode for the new format (e.g., func serializeToMessagePack()). (Sources/SwiftProtobuf)
  3. Update code generator in Sources/protoc-gen-swift to emit extension calls if format-specific code generation is needed. (Sources/protoc-gen-swift)
  4. Add conformance test harness in FuzzTesting/Sources to validate round-trip encoding with generated messages. (FuzzTesting/Sources)
  5. Update Documentation/API.md with usage examples and format specification. (Documentation/API.md)

Add a new code generation option (e.g., --swift_opt=naming_convention=snake_case)

  1. Define the option struct in Sources/protoc-gen-swift that parses --swift_opt command-line arguments. (Sources/protoc-gen-swift)
  2. Implement option handling in the code generator to branch on the new flag during field/method name generation. (Sources/protoc-gen-swift)
  3. Create a compile test in CompileTests to verify the generated code uses the correct naming convention. (CompileTests/InternalImportsByDefault/Sources/InternalImportsByDefault/Protos)
  4. Document the new option in Documentation/PLUGIN.md with examples. (Documentation/PLUGIN.md)

Fix a serialization bug found in conformance tests

  1. Locate the failing format handler (binary, JSON, or text) in Sources/SwiftProtobuf (e.g., BinaryEncoding.swift for binary issues). (Sources/SwiftProtobuf)
  2. Add a minimal test case to FuzzTesting/FailCases or create a new test in Sources/SwiftProtobufTests. (FuzzTesting/FailCases)
  3. Implement the fix in the encoding/decoding logic. (Sources/SwiftProtobuf)
  4. Run conformance tests locally via .github/workflows/head_conformance.yml logic to verify the fix passes upstream tests. (.github/workflows/head_conformance.yml)

🔧Why these technologies

  • Swift — Type-safe, high-performance compiled language with strong value semantics ideal for data serialization; direct alignment with protobuf's philosophy.
  • protoc plugin architecture — Leverages Google's official protoc tool and descriptor format; enables instant support for new proto3 features without reimplementation.
  • Swift Package Manager — Native Swift dependency management; simplifies integration for Swift iOS/macOS/server projects; enables transitive dependency resolution.
  • Multiple serialization formats (Binary, JSON, Text) — Supports all official protobuf formats; JSON enables API/logging, Text enables debugging, Binary is production-grade performance.

⚖️Trade-offs already made

  • Code generation via protoc plugin vs. runtime reflection

    • Why: Code generation is more complex to implement and maintain but provides compile-time type safety, zero-cost abstractions, and static optimization opportunities.
    • Consequence: Users must regenerate code when .proto files change; no dynamic message creation from runtime descriptors (unlike Java protobuf).
  • Immutable generated message structures (with builder pattern for mutability where needed)

    • Why: Aligns with Swift's value semantics and thread safety; prevents accidental mutations in concurrent code.
    • Consequence: Slightly more verbose code when building messages vs. Java's mutability model; requires explicit copying for modifications.
  • Manual encoder/decoder implementations vs. code-generated serialization logic

    • Why: Centralized runtime handlers reduce generated code size and enable format-wide bug fixes; simpler to understand and maintain.
    • Consequence: Runtime dispatch cost for encoding/decoding (negligible for most workloads); less inlining opportunity vs. fully generated serializers.
  • Support for both modern Swift Package Manager and legacy CMake builds

    • Why: Maximize adoption across different Swift integration scenarios (iOS/macOS frameworks, server, C++ interop).
    • Consequence: Dual build system maintenance overhead; version skew risk between build targets.

🚫Non-goals (don't propose these)

  • Does not provide gRPC implementation—only message serialization (gRPC support is a separate library, grpc-swift).
  • Does not support proto1 or earlier proto2 obscure features; targets proto2 and proto3 standards.
  • Does not guarantee binary stability across major version releases of swift-protobuf.
  • Not a Protobuf compiler replacement; depends on protoc binary for descriptor generation.

🪤Traps & gotchas

  1. Protoc version lock: the plugin must run with the protoc version it was built against; mismatches cause descriptor parsing failures. Check protoc --version matches the repo's declared minimum. 2. Module visibility in multi-file protos: CompileTests/MultiModule/ shows that public imports require special config in swift-protobuf-config.json or codegen errors occur. 3. Copy-on-write semantics: generated structs are not ARC-simple; modifying nested messages creates copies; understand this before performance-tuning. 4. JSON field naming: proto snake_case fields become camelCase in JSON by default; custom naming in .proto requires json_name option or serialization breaks.

🏗️Architecture

💡Concepts to learn

  • grpc/grpc-swift — gRPC runtime for Swift; uses swift-protobuf for service stub generation and message serialization
  • google/protobuf — The canonical protobuf compiler and language spec; swift-protobuf implements the same wire format and passes its conformance tests
  • protobuf-go/protobuf-go — Reference implementation for Go; mirrors swift-protobuf's architecture (plugin + runtime) and conformance test validation
  • bufbuild/buf — Modern protobuf linter and code generator orchestrator; works with swift-protobuf as the Swift code generation backend
  • apple/swift — Swift language repo; swift-protobuf tracks language releases and contributes compatibility patches

🪄PR ideas

To work on one of these in Claude Code or Cursor, paste: Implement the "<title>" PR idea from CLAUDE.md, working through the checklist as the task list.

Add comprehensive fuzzing test suite for JSON parsing edge cases

The FuzzTesting/FailCases directory contains 10+ known failure cases for JSON and TextFormat parsing (JSON-malformed-utf8, JSON-Any, TextFormat-map-loops-forever, etc.), but there's no corresponding automated fuzzing harness in the CI/CD pipeline. Adding libFuzzer integration to the build.yml workflow would catch regressions early and expand the failure case corpus systematically.

  • [ ] Create FuzzTesting/Sources/FuzzJSON.swift and FuzzTextFormat.swift harnesses using Swift's LibFuzzer support
  • [ ] Add a new GitHub Actions workflow step in .github/workflows/build.yml to build and run fuzzing targets
  • [ ] Document the process in Documentation/CONFORMANCE_TESTS.md for running fuzzing locally
  • [ ] Integrate the existing FailCases into the fuzzer as seed inputs

Add missing integration test for proto3 syntax validation and feature compatibility

The CompileTests directory has MultiModule and InternalImportsByDefault tests, but there's no dedicated test suite validating proto3-specific features (optional fields, map types, JSON mapping rules) against the runtime. The .github/workflows/check_upstream_protos.yml suggests version checking, but no test validates that generated Swift code correctly implements proto3 semantics.

  • [ ] Create CompileTests/Proto3Features/Package.swift with test protos using oneof, maps, and optional fields
  • [ ] Add test .proto files in CompileTests/Proto3Features/Sources/Protos/ covering proto3-only semantics
  • [ ] Create unit tests in CompileTests/Proto3Features/Tests/ validating serialization/deserialization behavior
  • [ ] Document the test in CompileTests/Proto3Features/README.md

Add missing documentation for the swift-protobuf-config.json configuration format

The file structure shows swift-protobuf-config.json exists in CompileTests/InternalImportsByDefault/Sources/InternalImportsByDefault/, indicating this is a real configuration mechanism, but there's no documentation in Documentation/ explaining its schema, supported options, or how users should structure it for their projects. The PLUGIN.md mentions code generation but doesn't detail configuration options.

  • [ ] Create Documentation/CONFIG.md documenting the swift-protobuf-config.json schema
  • [ ] Add JSON schema definition (or reference) for IDE autocomplete support
  • [ ] Update Documentation/PLUGIN.md with a link to configuration options
  • [ ] Add example configurations for common scenarios (monorepo setup, visibility control, custom message options)

🌿Good first issues

  • Add exhaustive test coverage for BinaryDecoding.swift error paths (malformed varint, truncated message, invalid field numbers). Current test suite in Tests/SwiftProtobufTests/ lacks negative cases for decoder robustness.
  • Document the proto-to-Swift naming conventions (snake_case → camelCase, reserved keyword escaping) with examples in Documentation/API.md. Currently only mentioned in inline code comments.
  • Extend CompileTests/InternalImportsByDefault/ to verify Swift 5.9+ strict concurrency mode (add @send and Sendable conformance tests). Repo tracks Swift versions but no explicit concurrency audit visible.

Top contributors

Click to expand

📝Recent commits

Click to expand
  • f944413 — Flip the order of the diff in test-plugin (#2059) (thomasvl)
  • e45184e — Drop Swift 6 support (#2056) (glbrntt)
  • 3c93acf — Support well known proto types in Swift PM plugin (#2044) (FranzBusch)
  • 3c8b010 — Use the fuzz options support to control encoding options. (#2049) (thomasvl)
  • 19ff62e — Update protos from upstream. (#2047) (thomasvl)
  • c181762 — Update FuzzTesting Package.swift. (#2037) (thomasvl)
  • 175311d — Update proto files from upstream. (#2045) (thomasvl)
  • 8155827 — Updated vendored dependencies (#2026) (thomasvl)
  • 23627a7 — Version bump for a release. (#2024) (thomasvl)
  • 5ec9b50 — Add a cache for the recursive check to help improve performance. (#2034) (thomasvl)

🔒Security observations

The apple/swift-protobuf repository demonstrates a generally strong security posture. As a protocol buffer code generation and runtime library project, it focuses on core functionality with minimal external dependencies. The codebase includes comprehensive fuzzing test coverage with documented failure cases, indicating mature security testing practices. No hardcoded secrets, SQL injection risks, or obvious misconfigurations were identified in the provided file structure. The primary concerns are the presence of known fuzz failure cases (expected for a fuzzing-heavy project) and incomplete visibility into the full dependency chain. The project's organization under Apple and active CI/CD pipeline (GitHub Actions workflows for building and testing) suggest good security governance practices.

  • Low · Fuzz Testing Failure Cases in Repository — FuzzTesting/FailCases/. The repository contains numerous fuzz testing failure cases in the FuzzTesting/FailCases directory. While these are intentionally included for regression testing, they represent known edge cases that could potentially trigger unexpected behavior or crashes in the protobuf parser when processing malformed inputs. Fix: Ensure all identified failure cases have corresponding fixes or defensive validations in the codebase. Regularly review and update fuzzing test cases to match current security patches.
  • Low · Incomplete Dependency Information — Root directory - missing dependency manifests. The provided file structure shows no Package.swift, package.json, Gemfile, requirements.txt, or other explicit dependency manifest files in the root directory. This makes it difficult to assess the security posture of declared dependencies and identify potentially vulnerable transitive dependencies. Fix: Verify and analyze the actual Swift Package definition. Run 'swift package show-dependencies' and implement dependency auditing with tools like 'swift package resolve' with security scanning. Maintain an updated SBOM (Software Bill of Materials).

LLM-derived; treat as a starting point, not a security audit.


Generated by RepoPilot. Verdict based on maintenance signals — see the live page for receipts. Re-run on a new commit to refresh.

Healthy signals · apple/swift-protobuf — RepoPilot