Log in
engineering

Debugging the communication between Xcode and XCBBuildService

Learn how to debug the communication between Xcode and XCBBuildService with XCBLoggingBuildService.

Xcode and xcodebuild use an internal service named XCBBuildService to perform build tasks. The contract between Xcode and XCBBuildService has been leveraged by some organizations, such as to proxy calls to other build systems like Bazel. More recently, Apple has utilized it to add support for their new build system, swift-build, which we discussed in this blog post.

As a developer, this is generally not something you need to worry about. However, at Tuist, understanding this system has been on our backlog for some time, as we wanted to explore introducing optimizations and telemetry at a lower layer of the build process. The introduction of swift-build has shifted our focus, as it now makes more sense for us to explore that layer.

While working with one of Tuist's customers, we observed some unusual behaviors, including Xcode projects and xcodebuild processes hanging, without a clear explanation. This prompted us to investigate the communication between Xcode and XCBBuildService and build a small utility to help debug it.

XCBBuildService has been recently open sourced and rebranded as SWBBuildService.

The Format

Xcode spawns XCBBuildService as a system process and communicates with it through standard pipelines. Messages are formatted using MessagePack, a format similar to JSON but smaller and faster.

The types of messages exchanged can be found in the Mobile Native Foundation's XCBBuildServiceProxyKit project or in the SWBProtocol target of swift-build. Among others, you will find messages for:

  • Requesting indexing information
  • Pinging the service
  • Listing the available sessions (since multiple can exist)
  • Starting a build operation
  • Notifying about the completion of a build operation

As mentioned earlier, you do not directly interact with these messages. Xcode and xcodebuild, acting as presentation layers, translate these internals into a debuggable UI or CLI output.

Debugging Messages with XCBLoggingBuildService

To facilitate debugging this communication, we built a new Swift package, XCBLoggingBuildService. It serves as a simple wrapper around XCBBuildService, logging the messages exchanged between Xcode and the service.

You can use it with Xcode or xcodebuild by following these steps:

First, clone and build the project the repository:

git clone https://github.com/tuist/XCBLoggingBuildService swift build

You can then use it with xcodebuild or Xcode

# xcodebuild XCBBUILDSERVICE_PATH=$(pwd)/.build/debug/XCBLoggingBuildService xcodebuild ... # Xcode env XCBBUILDSERVICE_PATH=$(pwd)/.build/debug/XCBLoggingBuildService /Applications/Xcode.app/Contents/MacOS/Xcode

The logs are saved in /tmp/XCBLoggingBuildService.log. You can monitor them in real time using:

tail -f /tmp/XCBLoggingBuildService.log

What's next

In the coming months, we'll explore the internals of swift-build, its extensibility, and the capabilities it offers for Tuist to optimize your projects and enhance telemetry for better decision-making. Of course, we'll document our learnings in this blog.

You might also like

Interview with George Tsifrikas - What led us to modularize Workable's project was high build times
In this interview of apps at scale we interview George Tsifrikas, iOS team lead at Workable. He shares his experience growing their Xcode project into a modular app, how they use reactive programming extensively throughout the app, and the testing strategies that they follow to ship new features with confidence.
Mapping XcodeProj to XcodeGraph
Taking the scenic route through the XcodeGraphMapper.
Interview with Angry Nerds - Project description helpers are a game changer for modular apps
In this blog post we interview Marcel from Angry Nerds, a custom software development company based in Wrocław, Poland. Marcel talks about a wide range of topics which includes their workflows, preferred code patterns and architecture, and their testing strategy.

Supercharge your app development

Get started