iOS Projects with Buck Build Tool

Balraj Singh - Aug 20 - - Dev Community

Summary

At Airbnb, the Mobile Developer Infra team has successfully integrated Buck into their mixed-language iOS project, which combines Swift and Objective-C. This integration has led to a significant improvement in Continuous Integration build times, achieving 50% faster builds and a 30% reduction in app size. The process of adapting Buck for this mixed-language environment presented numerous technical challenges, primarily related to header imports and module management, which were resolved through various updates and workarounds.

Key Points

Introduction to Buck and Its Benefits

  • Buck is a build tool aimed at enhancing developer experience and optimizing mobile app build times.
  • The successful integration of Buck has resulted in notable performance improvements: 50% faster CI builds and a 30% smaller app size for Airbnb's iOS app.

Building Process Overview

  • The typical iOS app build process involves generating machine code (.o) files, creating Swift header files (*-Swift.h), and linking them to produce the final executable.
  • Unlike Xcode, which builds modules as separate, dynamically-linked frameworks, Buck treats them as static libraries, providing optimizations such as reduced binary size and stripping of unused symbols.

Challenges Encountered

  • The -import-underlying-module flag, which allows implicit imports in Swift, does not function with Buck because it lacks the framework structure generated by Xcode.
  • Bridging headers need to be explicitly provided to the Swift tool, leading to issues with header location and visibility.

Solutions Implemented

  • Updates were made to Buck to generate header maps, enabling the swift tool to locate and import Objective-C headers correctly.
  • Buck now correctly handles path issues for bridging headers in generated *-Swift.h files by passing proper compiler arguments.
  • A workaround was introduced for the @import directive limitation by replacing it with #import, facilitated by a dedicated transformation script.

Building Mixed-Language Libraries and CocoaPods

  • Each pod in CocoaPods is treated as an individual library with distinct build rules, using apple_library for source code and different rules for precompiled binaries and frameworks.

Future Development Plans

  • Plans to enable Buck project file generation for Xcode to facilitate local development alongside continuous integration.
  • The team aims to enhance Buck to build libraries as modules for improved interoperability and to optimize the caching mechanism for iOS.
  • Further analysis will be conducted to evaluate the benefits gained from the shift from Xcode to Buck.

Conclusion

  • The integration of Buck into Airbnb's mixed-language iOS project exemplifies the potential for improved efficiency and performance in mobile development, while also highlighting the challenges and solutions that arise when merging different programming languages in a single codebase.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .