What’s explicitly built modules?

Generated on 8/2/2024

1 search

Explicitly built modules are a new way of handling module builds in Xcode, introduced to improve the build process for Swift and Clang modules. Here are the key points about explicitly built modules:

  1. Build System Control: Explicitly built modules put the build system in control of module builds. This means that the build system explicitly manages the tasks of scanning, building modules, and compiling the original code, rather than these tasks being implicitly handled by the compiler.

  2. Build Phases: The compilation of each source file is split into three separate phases:

    • Scanning: Xcode scans each source file to build a module graph for the entire project.
    • Building Modules: Modules are compiled as explicit tasks in the build log.
    • Building Original Code: The original source files are compiled, now with the compiled modules they depend on.
  3. Build Logs and Timeline: The build logs now show separate tasks for scanning and module compilation, providing a clearer breakdown of the build process. This helps in better parallelism and clearer error messages if the build fails due to a module issue. The build timeline view also reflects these explicit tasks, making it easier to see where time is being spent.

  4. Efficiency and Reliability: By making the build system aware of modules, it can avoid running tasks that are not ready, leading to more efficient use of execution lanes. This results in more reliable builds with precise dependencies and deterministic build graphs. The build system can also make more informed scheduling choices, reducing the number of module variants that get built.

  5. Debugging Improvements: Explicitly built modules make debugging faster because the debugger can reuse the build outputs when evaluating expressions. This avoids the need for the debugger to build its own version of module files, leading to faster debugging.

  6. Enabling Explicitly Built Modules: In Xcode 16, explicitly built modules are used for all C and Objective-C code and can be enabled as a preview for Swift. This can be done by selecting the project in the project navigator, going to build settings, and setting the "Explicitly Built Modules" option to "Yes".

For more detailed information, you can refer to the session Demystify explicitly built modules (05:55).

Relevant Sessions