Cash App Aug 19, 2020

Wire Support For Swift, Part 1

Article Summary

Eric Firestone and Jake Wharton from Square just brought Wire's protocol buffer compiler to Swift, and their opinionated approach throws out some sacred cows. Why build yet another proto compiler when Google already has one?

Square's Wire compiler now supports Swift alongside Java and Kotlin, offering a simpler alternative to Google's official protoc compiler. The team deliberately omits features like default values and dynamic extensions to create cleaner, more idiomatic APIs that scale better for large organizations.

Key Takeaways

Critical Insight

Wire trades protocol buffer feature completeness for dramatically simpler generated code, turning a single optional field from 8 lines of boilerplate into just one nullable property.

Part two promises performance benchmarks and engineering tradeoffs that influenced Square's decision to standardize on Wire across all platforms.

About This Article

Problem

Swift's module system works differently than Java and Kotlin. Instead of fully-qualified package names, Swift defines modules at the compilation unit level rather than through type-level namespacing. Square needed to handle this fundamental difference.

Solution

Wire's team created a manifest-based packaging system using a single YAML file. This file defines modules, their dependencies, content roots, and what to prune. Developers get type-level control over where modules go.

Impact

Generated Swift content now scopes semantically within the proto dependency tree. Wire handles complete dependency resolution automatically and manages edge cases like type nesting and options across multiple modules.