apple/swift-protobuf: A Working Guide to the protoc-gen-swift Plugin and Runtime
Plugin and runtime library for using protobuf with Swift
At a glance
- What is it?
- SwiftProtobuf pairs a protoc plugin with a Swift runtime so .proto schemas become generated Swift types. Here is how the pieces fit, how to install the plugin, and where the approach stops being the right one.
- Who is it for?
- Adopt SwiftProtobuf when your team already owns .proto schemas and needs generated Swift types that interoperate with Java, C++, Python or Objective-C code generated from the same files. Skip it when your wire format is JSON you control end to end, because the plugin, the runtime module and a protoc binary become three more things to keep in step.
- Can I use it commercially?
- Yes. Apache-2.0 is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 5 days ago.
- What is it written in?
- Mainly Swift, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on September 29, 2026, and from our analysis. They are not legal advice.
Editorial analysis
The gap SwiftProtobuf fills between .proto files and Swift types
Protocol Buffers is Google's schema language and serialization format. The README describes it as a serialization technology that, like Swift, emphasizes high performance and programmer safety. The problem it leaves open is language support: protoc knows how to emit C++, Java, Python and Objective-C, but Swift is not one of its built-in targets. That is the hole this repository fills. It ships two things that only make sense together. The first is a command-line program, protoc-gen-swift, which plugs into protoc and turns each .proto file into a .pb.swift file. The second is the SwiftProtobuf runtime library, which the generated code imports and calls into. Generating one without linking the other produces a project that does not compile.
The audience is narrower than the repository's visibility suggests. You need a reason to keep a schema file as the source of truth: a service boundary, a mobile client talking to a backend, or a payload that other languages also read. If you are writing a small Swift app that persists its own state, the schema layer is overhead with no payoff. The README is explicit that the same .proto file can generate Java, C++, Python or Objective-C for other platforms, and that those generated types share the same serialization conventions. That cross-language agreement is the actual product. Swift support is the part Apple maintains.
What the plugin generates and what the runtime does at call time
The data flow has three stages. You write a .proto file. You run protoc with the --swift_out flag, and protoc locates protoc-gen-swift on your PATH and hands it the parsed schema. The plugin writes a .pb.swift file next to your other sources. At runtime your code imports SwiftProtobuf, constructs the generated structs, and calls methods on them to serialize.
The README lists the surface of that generated API. .serializedBytes() returns the compact binary form, and init(contiguousBytes:) parses it back. .jsonUTF8Bytes() returns a JSON form, parsed with init(jsonUTF8Bytes:). The generated structs are Hashable and Equatable, so they can go into a Set or a Dictionary. They also carry full Swift copy-on-write value semantics, which matters more than it sounds: passing a generated message around your codebase copies the reference, not the buffer, until something mutates it. The README also notes the generated types are extensible, so you can add your own Swift extensions.
Two design consequences follow. Because the plugin emits plain Swift source, the generated file is checked into your build like any other source, and regenerating it is a build step you own rather than something the runtime does on the fly. And because the runtime is a separate module, upgrading the plugin without upgrading the library, or the reverse, is a real failure mode the project's own Makefile warns about in a different context: it notes that make test does not regenerate, so code-generation changes require a build, a regenerate, another build, then a test.
Installing protoc-gen-swift from source or through Homebrew
The README gives two install paths. The Homebrew one is the shortest: it installs both the protoc compiler and the Swift code generator plugin in one step.
brew install swift-protobufAfter that, protoc is on your PATH and so is the plugin, and you can skip straight to generating code. If you would rather build from source, the README's steps are to clone the repository, list the tags, check out the release you want, and build in release configuration.
git clone https://github.com/apple/swift-protobuf.git
cd swift-protobuf
git tag -l
git checkout tags/[tag_name]
swift build -c releaseThe build leaves a binary named protoc-gen-swift in the .build/release directory. The README's install instruction is to copy that single executable into a directory on your PATH. There is no installer script and no package to register. The README adds a note that the Swift runtime support is now included with macOS, and that older Xcode or older system versions may need --static-swift-stdlib passed to swift build.
Once the plugin is reachable, generation is one command. The README's example writes output into the current directory.
protoc --swift_out=. my.protoEach input file becomes a corresponding .pb.swift file in the output directory. The plugin is found automatically through PATH; you do not pass its location. The remaining step, adding the SwiftProtobuf runtime module to your project, is where the README text is cut off in the documentation available here, and the repository ships a Package.swift and a SwiftProtobuf.podspec, so both Swift Package Manager and CocoaPods are represented in the tree.
Where SwiftProtobuf is the wrong tool
The system requirements are the first hard boundary. The README asks for a Swift 6.1 or later compiler, or Xcode 16.3 or later if you build with Xcode, and states the project is developed and tested against the latest release version of Swift. A team pinned to an older toolchain for App Store reasons is outside that envelope, and the README does not describe a supported path for staying on an older Swift.
The protoc side has its own floor. The README says the SwiftProtobuf tests need a protoc that supports the swift_prefix option, introduced in protoc 3.2.0, and that it may work with earlier versions. That is a soft statement, not a guarantee, and it means your protoc version is part of your build's correctness surface. If your organization ships a pinned protoc from a system package manager, that pin now has a second reason to be maintained.
The wrong-tool case is more common than the toolchain case. If your data never leaves a Swift process, or if your team has already standardized on JSON and has no other language reading the payload, adding a schema compiler and a runtime module buys you nothing that Codable does not already do. The README's own framing assumes you want the same .proto to serve multiple languages. Drop that assumption and the cost side of the ledger has no matching benefit. A second case: if you need the generated code to be shaped by a build plugin that inspects your sources, this is a separate executable you invoke, not something integrated into a Swift build graph by default.
How SwiftProtobuf differs from swift-grpc and hand-written Codable
The closest alternative people reach for is a gRPC stack for Swift, which appears in the search data as Grpc-swift-protobuf and Swift gRPC. The difference is scope, and it is worth being precise about. SwiftProtobuf is a serialization layer: it takes a schema and produces message types with binary and JSON encoders. A gRPC library is a transport layer: it takes a service definition and produces client and server stubs that move messages over HTTP/2. gRPC needs a message serializer underneath it, and SwiftProtobuf is one of the things that can sit there. Choosing between them is a category error; the real question is whether you need the transport at all. If you are writing protobuf payloads to a file or embedding them in an existing HTTP request, you do not.
The other alternative is hand-written Codable conformances over plain Swift structs. The README's argument against that is safety and correctness: it says the code-generation system avoids errors common in hand-built serialization code, and that SwiftProtobuf passes both its own test suite and Google's full conformance test. That conformance suite is the substantive difference. Hand-written Codable gives you JSON that matches your struct, but it does not give you a wire format that a Java service can parse, and it will not tell you when your encoding drifts from the specification. What hand-written Codable gives you instead is control: no plugin to install, no protoc version to pin, no generated file to regenerate, and no runtime module in your dependency graph. For a single-language app, that trade is usually the right one.
Maintenance cadence, licensing and the cost of staying current
The repository is not archived, and the last push was on 2026-09-22. Recent releases are 1.38.1 on 2026-06-23, 1.38.0 on 2026-05-15 and 1.37.0 on 2026-04-20, so the release line has moved three times in roughly five months. That cadence has a direct cost for adopters: a minor version bump can change generated output, and generated output is source you commit. The repository's own Makefile documents the sequence a contributor must follow after touching code generation, and the same shape applies to consumers who upgrade the plugin. You regenerate, you rebuild, and you look at the diff in your .pb.swift files before you commit them. Treating those files as opaque build artifacts and regenerating them silently is how a wire-format change reaches production unnoticed.
The licence is Apache-2.0, and the repository ships LICENSE.txt at the top level. Apache-2.0 is a permissive licence with an explicit patent grant and a requirement to preserve notices. If you vendor the generated code or the runtime into a closed-source product, the practical obligation is attribution and notice retention rather than source disclosure. This is a description of the licence text, not legal advice, and a team with an unusual distribution model should read LICENSE.txt rather than rely on a summary.
The upgrade cost is unevenly distributed. The runtime library is a normal Swift dependency and moves with your package manager. The plugin is a binary on your PATH or a Homebrew formula, and it drifts independently of the runtime. Nothing in the documentation enforces that the two versions match, which makes version skew between plugin and runtime a thing you check yourself rather than a thing the tooling prevents.
Editorial conclusion
Adopt SwiftProtobuf when your team already owns .proto schemas and needs generated Swift types that interoperate with Java, C++, Python or Objective-C code generated from the same files. Skip it when your wire format is JSON you control end to end, because the plugin, the runtime module and a protoc binary become three more things to keep in step. Before committing, verify the Swift 6.1 compiler requirement and the protoc version that supports swift_prefix against your toolchain, and check whether the generated types you need are already covered in Documentation/API.md.
Frequently asked questions
What exactly is apple/swift-protobuf?
It is a command-line program that adds Swift code generation to Google's protoc compiler, plus the runtime library that the generated Swift code needs. The README states that after using the protoc plugin to generate Swift code from your .proto files, you add the library to your project.
Is Protobuf still used?
The README frames protobuf as Google's serialization technology and positions Swift as a complement to it, and this repository is not archived, with releases through 1.38.1 on 2026-06-23. The README also notes the same .proto file can generate Java, C++, Python or Objective-C.
Is protobuf faster than JSON?
The README describes the binary serializer as efficient and says the binary and JSON serializers have been extensively optimized, and it lists efficient binary serialization as a feature. It does not publish a comparison against JSON parsing, so no measured figure is available here.
What exactly is protobuf?
Protocol Buffers is Google's serialization technology, and the README points to Google's protobuf documentation for general information about protocol buffers, the protoc compiler, and how to use them with C++, Java and other languages.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/apple-swift-protobuf)