Clang Modules and Bazel, From First Principles
50 minutes read •
This write-up was distilled from a real migration session: enabling explicit Clang modules (swift.use_c_modules) in a large iOS monorepo, debugged end-to-end with an AI agent. One build flag flipped; nine builds failed; none of the failing code had changed. The document below builds every concept needed to understand why — header resolution, module maps, PCMs, Bazel’s action model, aspects — and then walks through each failure as a case study. Prerequisites: you can read Swift/Objective-C and know Bazel has “rules”. Nothing more is assumed.
Part 1 — How a header import is resolved
Everything in this document reduces to one question: given an #import line, where does the compiler look for the file? There are two import forms and three search mechanisms.
Textual inclusion
#import "X.h" and #import <Y/Y.h> are preprocessor directives. By default the preprocessor replaces the line with the full text of the file, recursively. A translation unit (one .m file) expands to itself plus every header it transitively includes — frequently 100k+ lines — re-parsed for every translation unit.
Quote include: #import "X.h"
Resolution order:
- The directory of the including file ("includer-relative").
"../Shared/X.h"resolves here without any flags. - Then each directory passed with
-I, in order.
A quote include naming a file in a different directory only works if some -I flag points there. This is the root cause of case 6.
Angle include: #import <Y/Z.h>
Resolution order:
- Each
-Idirectory: looks for<dir>/Y/Z.h. - Each
-Fdirectory (framework search path): looks for<dir>/Y.framework/Headers/Z.h. - System/SDK paths.
#import <FBSDKCoreKit_Basics/FBSDKCoreKit_Basics.h> requires a -F flag pointing at the directory containing FBSDKCoreKit_Basics.framework. Root cause of case 1.
Framework layout
A built framework is a directory with fixed structure:
FBSDKCoreKit.framework/
├── FBSDKCoreKit (binary)
├── Headers/ (public headers)
│ └── FBSDKCoreKit.h
└── Modules/
└── module.modulemap (Part 2)An xcframework is a wrapper directory holding one such framework per platform slice (device, simulator, …).
Resolution is just this walk down a list of locations. The green steps need no target-private flags; every other step depends on a -I or -F that must be present in the running compilation — which is exactly what changes when a module is compiled in isolation (Parts 4–5).
The consequence that matters
Header resolution is governed entirely by which flags are on the command line of the compilation currently running. The same header can resolve in one compilation and fail in another with no change to any file — only the flag set differs. The entire migration is about which compilation parses each header, and therefore which flags are in effect.
Part 2 — Module maps and PCMs
Textual inclusion has two structural problems: cost (every consumer re-parses every header) and fragility (a header's meaning depends on whatever macros and flags the consumer happens to have). Clang modules address both.
The module map
A module.modulemap file declares that a set of headers forms a named unit:
framework module FBSDKCoreKit {
umbrella header "FBSDKCoreKit.h" // this header (and its includes) define the module's contents
export * // importers also see what this module's headers import
module * { export * } // one submodule per header under the umbrella
}- umbrella header — a header that includes all other public headers; the module's contents are whatever it declares.
- framework module — header paths resolve inside the framework's
Headers/directory. - Non-framework module maps list headers explicitly:
module LookinServer { header "A.h" header "B.h" }.
The PCM (precompiled module)
To "build a module," the compiler parses the headers named by the module map — in a compilation of its own, with its own flag set — and serializes the resulting AST to a binary .pcm file. Importers deserialize the PCM instead of re-parsing headers. Analogous to .c → .o: parse once, reuse many times.
How imports change
@import FBSDKCoreKit; (ObjC) and import FBSDKCoreKit (Swift) load the module by name. With modules enabled, even a textual-looking #import <FBSDKCoreKit/FBSDKCoreKit.h> is remapped to a module import when a module map claims that header. Swift has no headers at all — every ObjC dependency reaches Swift through a module, which is why module correctness is non-negotiable in a mixed codebase.
Module-level dependencies
Building module A's PCM may itself encounter #import <B/B.h>. If B is covered by a module map, A's PCM records a dependency on module B, and B's PCM must be available. Modules therefore form a dependency graph of their own, parallel to the build system's target graph. The migration's central problem: these two graphs must agree, and under the old mode nothing checked that they did.
The two open questions
The module map says nothing about when the PCM is built or which flags that build sees. Two strategies exist:
- Implicit — the compiler builds PCMs on demand, mid-compilation (Part 4, left panel).
- Explicit — the build system builds every PCM as a scheduled step (Part 4, right panel).
The migration is the switch from the first to the second.
The umbrella header creates a module-graph edge, but RSPM generated the binary target with deps = [], so the matching target-graph edge is missing. Implicit mode never compared the two; explicit mode compiles each module in isolation and the gap becomes case 1's file not found.
Part 3 — Bazel: the minimum working model
Six concepts are sufficient to read everything that follows.
1 · Targets and labels
A target is a named buildable unit declared in a BUILD file, addressed by a label: //Modules/Networking:Networking means "target Networking in package Modules/Networking". Labels starting with @ address targets in external repositories — downloaded dependencies, e.g. @swiftpkg_facebook_ios_sdk//:FacebookCore.
2 · Rules and attributes
Each target is an instance of a rule (swift_library, objc_library, apple_dynamic_xcframework_import) with attributes:
srcs,hdrs— source and header files.deps— labels of targets this target depends on. This is the build graph.copts— extra compiler flags, private to this target's own compilations.includes— header search dirs that propagate: dependents get them automatically.features— named toolchain behaviors;"x"enables,"-x"disables, per target or globally.
3 · Actions and sandboxing
Building a target produces actions: concrete command lines (one compiler invocation each) with declared inputs and outputs. Actions run sandboxed — the command can only read files declared as inputs. An undeclared file is absent, not merely discouraged. Actions are cacheable (locally and remotely) and reproducible precisely because their inputs are closed.
4 · Providers
Targets pass structured data to dependents through providers. Two matter here:
CcInfo— C-family compilation context: headers, defines,-I/-Fsearch paths. A target'scoptsare not in CcInfo;includesare.SwiftInfo— Swift modules and, under explicit compilation, the Clang modules (module map + PCM) a target exposes.
"X propagates to dependents" always means "X travels in a provider along deps edges."
5 · Aspects
An aspect walks the dependency graph and attaches additional actions and providers to existing targets without editing their BUILD files. The relevant one is rules_swift's swift_clang_module_aspect: it visits every target reachable through deps, and for each target that owns a module map, registers a SwiftPrecompileCModule action that builds the PCM. Error messages name it explicitly: "from aspects [swift_clang_module_aspect] on objc_library rule target …".
6 · Generated external repos (RSPM)
Swift Package Manager dependencies are integrated by rules_swift_package_manager (RSPM): it downloads each package, reads its manifest, and generates a BUILD file — one target per SPM target. A binary SPM target (binaryTarget, a prebuilt xcframework) becomes an apple_*_xcframework_import target. Critical limitation: SPM's manifest format gives binary targets no dependency list, so RSPM generates them with deps = []. RSPM ≥ 1.17 adds configure_package(target_deps = {...}) to inject edges into the generated BUILD by hand.
Part 4 — Implicit vs. explicit compilation
Same sources, same module maps. The difference is who schedules PCM compilation and which flags it sees. The migration enables two features in .bazelrc: swift.emit_c_module and swift.use_c_modules.
-F facebook -F braze -F zendesk -F sentry -F firebase -I lookin/Shared … one command line, everything visible
import FBSDKCoreKit and no PCM exists yetresolves— this parse runs INSIDE the consumer's compilation and inherits its full flag set (Part 1: resolution = current flags).
The PCM lands in a compiler-private cache, outside Bazel: ~/…/ModuleCache/<hash>/FBSDKCoreKit-<hash>.pcm
Properties of implicit compilation. (1) PCM builds are not Bazel actions: invisible to the action graph, excluded from remote caching, re-done per machine and per flag-hash. (2) The flag set used to build a PCM is whatever the first importer had — module content can vary by import order and configuration. (3) Header resolution inside a module build borrows the consumer's search paths, so a module's undeclared dependency on a sibling resolves successfully whenever any consumer's flags cover it. No mechanism verifies that the module graph matches the target graph.
→ no -F path to the sibling in this sandbox
#import <FBSDKCoreKit_Basics/…> → file not found
Each PCM is an ordinary Bazel action: sandboxed, deterministic per configuration, remote-cacheable, shared across machines.
Properties of explicit compilation. (1) Every module map reachable through deps is precompiled — whether or not any source imports it (relevant in case 2). (2) Each PCM build sees only declared inputs; an undeclared dependency is a hard error rather than a silent borrow. (3) PCM actions are cached and shared org-wide, and run in parallel ahead of Swift compiles. The cost: every assumption the implicit mode silently absorbed must now hold explicitly. The nine case studies are exactly those assumptions.
Part 5 — The governing invariant
Under explicit compilation, each module map is compiled in an isolated, sandboxed action whose visible inputs are the owning target's files plus its declared dependencies' providers. Consumer search paths do not exist inside that sandbox.
Corollary (root cause of cases 6 and 8): when the aspect constructs a PCM action for a target, it takes the compilation context from CcInfo — and forwards only -D defines from the target's copts. Since copts never enter CcInfo (Part 3 §4), any -I search path supplied via copts is absent from the PCM compile. Search paths reach a PCM action only through the includes attribute or a dependency's CcInfo.
Same import, two worlds. The consumer compile sees every dependency's search paths merged together, so a sibling resolves incidentally; the isolated PCM action sees only declared inputs, so the identical line fails. That difference is the entire migration.
Part 6 — Case studies: nine failures, in build order
Each entry names the failing action, explains why the same code compiled under implicit mode, derives the root cause from Parts 1–5, and documents the fix. Failing action PCM precompile of Why it compiled under implicit mode The PCM was built inside a consumer's compilation, which had every Facebook framework's Root cause SPM binary targets carry no dependency list, so RSPM generated Fix Upgraded RSPM 1.13.0 → 1.19.0 (the With the edges declared, the sibling's framework directory becomes a sandbox input and its CcInfo supplies the Failing action PCM precompile of GoogleAppMeasurement. The framework ships a module map whose Why it compiled under implicit mode It never compiled — and never needed to. No source imports this module; the framework is link-only. Implicit PCM builds are triggered by imports (Part 4), so an unimported module map is never parsed. The defect was inert. Root cause Explicit-mode property (1): the aspect precompiles every module map reachable in the graph, imported or not. Invalid metadata that implicit mode never evaluated now fails a scheduled action. Fix A patch to rules_apple's xcframework import rules: when the imported framework ships no headers, do not create the Swift interop provider, so the aspect schedules no PCM action for it. Correct because a headerless framework has no importable surface; linking information is unaffected. Failing actions Two kinds. (a) PCM precompile of MessagingSDK: binary frameworks containing Swift code ship a generated ObjC header ( Root cause Identical to case 1 — binary targets, no declared edges — extended across package boundaries. The required modules live in other generated external repositories (Part 3 §6). Implementation notes ① A binary framework's true dependency set spans three file types: ObjC headers, the generated Failing action PCM precompile of the Why target_deps does not apply The build graph already contains the reverse edge: Fix A source patch (RSPM Failing action PCM precompile of ObjC keeps class and protocol names in separate namespaces. When the protocol exists, Root cause The isolated PCM action has no path to Fix Declare the edge so the primary branch is selected. One subtlety: RSPM splits a mixed target into a parent plus per-language child targets; the failing action belongs to the generated clang child Failing action PCM precompile of LookinServer (a debug-tooling package; the module is imported from Swift, so it cannot be suppressed). Its public headers use quote includes such as Why it compiled under implicit mode RSPM emits the package's internal header search dirs as Root cause The corollary from Part 5, verbatim: the PCM action takes its search paths from CcInfo, and copts Fix A package patch rewriting the 24 cross-directory quote includes (15 headers) to includer-relative paths, e.g. Failing action PCM precompile of a first-party vendored xcframework. Under explicit mode the build system must name the module it is building: rules_apple derives that name from the xcframework's library name ( Why it compiled under implicit mode Implicit lookup works in the opposite direction: the compiler scans available module maps for one declaring the name used at the import site ( Fix First-party files, so no patch machinery: renamed the module to Failing action The Swift compile of a tracking module's Swift half. The target is one half of a mixed-language module: ObjC and Swift halves sharing one module name. The Swift half sees the ObjC half via two hand-written copts: Root cause That module map is referenced only from copts — it is not owned by any target the aspect visits, so no PCM action is scheduled for it (Part 3 §5: the aspect attaches actions to targets). Under implicit mode the compiler would simply build it on the fly; under explicit mode on-the-fly compilation is disabled, the underlying module fails to load, and every ObjC declaration is absent from the Swift compilation. The error is a symptom two layers removed from the cause. Fix This was the only target in the repository using the pattern. Applied a per-target feature opt-out (Part 3 §2): The rest of the graph remains explicit. Long-term resolution: extract the ObjC half into its own named module and replace Failing actions PCM precompiles of two first-party legacy targets whose include paths contain directories with spaces ( Why it compiled under implicit mode The pre-existing compile actions quoted these arguments correctly. The failure is specific to argument handling in the SwiftPrecompileCModule path — the paths themselves were always hazardous, but no prior code path mishandled them. Fix Renamed the four directories to CamelCase and updated the references in the build macro that declares these targets. Renaming removes the failure class; quoting workarounds would leave the hazard for the next tool.01Facebook SDK —
'FBSDKCoreKit_Basics.h' file not foundUndeclared edges between sibling binary frameworks · fixed via RSPM target_depsFBSDKCoreKit. Its umbrella header contains an angle include of a sibling framework, #import <FBSDKCoreKit_Basics/FBSDKCoreKit_Basics.h>, which requires a -F path to the directory containing FBSDKCoreKit_Basics.framework (Part 1).-F path merged from its many deps (Part 4, implicit panel, step 2).deps = [] (Part 3 §6). The isolated PCM action's sandbox contains only FBSDKCoreKit's own files — the sibling framework is not an input, so its headers do not exist there (Part 3 §3).target_deps API landed in 1.17.0) and declared the SDK's internal layering in MODULE.bazel:swift_deps.configure_package(
name = "facebook-ios-sdk",
target_deps = {
"FBSDKCoreKit": ["FBAEMKit", "FBSDKCoreKit_Basics"],
"FBAEMKit": ["FBSDKCoreKit_Basics"],
"FBSDKLoginKit": ["FBSDKCoreKit"],
"FBSDKShareKit": ["FBSDKCoreKit"],
"FBSDKGamingServicesKit": ["FBSDKCoreKit", "FBSDKShareKit"],
},
)-F path; the dependency PCM is also built first, in topological order.deps). Implicit mode never checked this; explicit mode enforces it.02GoogleAppMeasurement —
umbrella header not foundModule map present, headers absent · fixed via rules_apple patchumbrella header directive names GoogleAppMeasurement-umbrella.h — but the framework contains no Headers/ directory at all. The referenced file does not exist in the vendor's artifact.03Zendesk / LiveRamp / Braze —
module 'SDKConfigurations' not foundCross-package edges; imports hidden in -Swift.h and .swiftinterface · fixed via target_deps with public labelsMessagingSDK-Swift.h) that re-exposes their Swift API to ObjC; it is part of the umbrella, and it contains @import SDKConfigurations; — a module import of a module from a different SPM package. (b) Compilation of MessagingAPI's .swiftinterface: frameworks with Swift API ship a textual interface file that rules_apple compiles into a binary swiftmodule, and that compilation must resolve every import statement in the file.-Swift.h, and .swiftinterface files. The initial header-only audit missed the latter two; the complete audit found MessagingSDK → SDKConfigurations + CommonUISDK + MessagingAPI, SupportSDK → five Zendesk modules, BrazeLocation → BrazeKit, LRAtsSDKMediationAdapter → LRAtsSDK + GoogleMobileAds. ② Generated .rspm targets have package-private visibility; cross-package target_deps values must use each repo's public product labels, e.g. @swiftpkg_core_sdk_ios//:ZendeskCoreSDK — referencing the .rspm targets directly fails Bazel's visibility check.-Swift.h, and .swiftinterface imports to determine a binary framework's dependency set. Any one alone is incomplete.04Firebase umbrella —
'FirebaseCore/FirebaseCore.h' file not foundThe required edge would create a cycle · fixed via __has_include source patchFirebase umbrella module — a source target whose only purpose is letting app code write import Firebase. Its header unconditionally angle-includes FirebaseCore's umbrella.FirebaseCore depends on Firebase (it consumes the Firebase_VERSION define from it). Bazel's target graph must be acyclic — adding Firebase → FirebaseCore is rejected at analysis time. This is the one failure where "declare the edge" is structurally impossible.configure_package(patches) applies patches to package sources after download, before BUILD generation) making the include conditional:-#import <FirebaseCore/FirebaseCore.h>
+#if __has_include(<FirebaseCore/FirebaseCore.h>)
+ #import <FirebaseCore/FirebaseCore.h>
+#endif
__has_include evaluates against the current compilation's search paths (Part 1): true in every consumer compile (unchanged behavior), false in the isolated PCM action (import skipped, module compiles near-empty). Acceptable because no source in the repository imports Firebase; the rest of that header already uses the same guard pattern.__has_include instead of modifying the graph.05Sentry —
type argument 'SentrySpan' must be a pointerA never-compiled fallback branch is invalid ObjC · fixed via target_deps on the clang child targetSentryInternal, a source target in sentry-cocoa. The header:#if __has_include(<Sentry/Sentry.h>)
# import <Sentry/Sentry.h> // declares: @protocol SentrySpan
#endif
…
@class SentrySpan; // fallback: forward-declares a CLASS of the same name
@interface SentryTracer : NSObject <SentrySpan>
<SentrySpan> in that position resolves to it — valid. When only the forward-declared class exists, Clang parses NSObject<SentrySpan> as a generic specialization with a non-pointer type argument — the reported diagnostics. The fallback branch is invalid code that no compilation had ever selected.<Sentry/Sentry.h> (no declared edge to the Sentry framework), so __has_include evaluates false for the first time in this codebase's history, selecting the broken branch.SentryInternal.rspm_objc. target_deps keys containing .rspm are matched against generated target names verbatim, allowing the edge to be attached exactly where the action runs: "SentryInternal.rspm_objc": ["Sentry"].__has_include fallback branches are unexercised code paths. The isolated PCM compile is often the first compilation ever to execute them; expect latent invalidity.06LookinServer —
'LookinDefines.h' file not foundHeaders depend on copts -I, which never reaches the PCM action · fixed via include-path rewrite#import "LookinDefines.h" for files located in other directories of the package (Src/Main/Shared/).-I flags in copts. Object-file compilations receive copts, and implicit PCM builds ran inside compilations that had them. Quote includes that fail includer-relative lookup (Part 1) fell through to those -I dirs and resolved.-I flags are not in CcInfo. The PCM compile therefore has includer-relative lookup only, and "LookinDefines.h" is not in the includer's directory.#import "../../Shared/LookinDefines.h". Includer-relative resolution needs no flags at all (Part 1), so both the PCM action and ordinary object compilations resolve identically.-I to find its own module's files will fail explicit compilation.07RudderFirebase —
no module named 'RudderFirebase' declared in module mapDeclared module name diverges from framework name · fixed by renaming the moduleRudderFirebase) and instructs Clang to build that module from the map. The map declares module Rudder_Firebase — the requested module is not defined in it.import Rudder_Firebase) and finds it. No component ever compared the declared name against the framework name.RudderFirebase in both platform slices' module maps and updated the single import statement. A sweep of all other vendored xcframeworks found no further mismatches.08Mixed-language module —
cannot find 'RudderBrazeFactory' in scope-import-underlying-module is invisible to the aspect · fixed via per-target opt-out-import-underlying-module ("load the Clang module with my own name") and -Xcc -fmodule-map-file=… (pointing at a hand-maintained module map).features = ["-swift.use_c_modules"] # this target compiles with implicit modules-import-underlying-module with an ordinary import.-feature disabling scopes exceptions without blocking a migration.09Legacy app targets —
duplicate input file 'Support''Whitespace in include paths splits params-file arguments · fixed by renaming directoriesArchive Support, Report User, Mark as sold process, Seller review — names inherited from Xcode group structure). Long command lines are passed via a params file (a file of arguments referenced as @file.params); the new precompile code path splits these entries on whitespace, turning -I…/Archive Support into two invalid tokens, reported as duplicate / unopenable input files.
Part 7 — Root-cause classification
The nine failures reduce to four categories, each with a distinct diagnostic signature and fix mechanism.
- Missing dependency edges — 3Cases 1, 3, 5. Header-level imports with no corresponding deps edge. Fix: target_deps.
- Invalid vendor metadata — 3Cases 2, 4, 7. Module maps and headers that were wrong but never compiled. Fix: rules patch, source patch, rename.
- Toolchain coverage gaps — 2Cases 6, 8. Inputs carried in copts or flags that the aspect cannot see. Fix: include rewrite, per-target opt-out.
- Path hygiene — 1Case 9. Whitespace in paths mishandled by the new action's params files. Fix: rename.
Part 8 — Diagnostic reference
Lookup table for future SwiftPrecompileCModule failures.
| Diagnostic | Fix mechanism |
|---|---|
| Binary framework header cannot resolve a sibling framework's header | swift_deps.configure_package(target_deps = {…}). Bare names for same-package targets; public product labels for cross-package. |
| Module map references nonexistent headers (headerless framework) | rules_apple patch: skip SwiftInteropInfo when the imported framework ships no headers. |
| Required dep edge would create a cycle | Source patch: guard the import with __has_include. |
Quote includes resolvable only via copts -I | Rewrite to includer-relative paths, or move the dirs to the includes attribute. copts -I does not reach the PCM action. |
Mixed module using -import-underlying-module | Per-target features = ["-swift.use_c_modules"]; restructure into separate modules later. |
no module named X declared in module map | Align the declared module name with the framework/library name; update import statements. |
Malformed argument errors (e.g. duplicate input file 'Support'') | A path containing whitespace is being split in the params file. Rename the directory. |
| Determining a binary framework's full dependency set | Audit three sources: ObjC headers, generated -Swift.h, and .swiftinterface imports. |
Constraint on patches: configure_package(patches) are applied to package sources after clone but before binary artifacts are downloaded. They can modify source files (case 4) but can never modify xcframework contents — which is why case 2 required a rules-level patch instead.
Part 9 — FAQ
A PCM precompile fails with "file not found", but the same import compiles inside the app target. What does this indicate?
A missing dependency edge. The app compile succeeds because its merged search paths (all deps' CcInfo) cover the header; the isolated PCM action sees only the owning target's declared deps. Identify which target owns the missing header and declare the edge — for SPM binary targets, via target_deps.
Does adding -IPath/To/Headers to a target's copts fix a precompile resolution error?
No. copts never enter CcInfo, and the aspect builds the PCM action's command from CcInfo — forwarding only -D defines from copts. Use the includes attribute, a dependency whose CcInfo carries the path, or includer-relative includes in the headers.
A vendor header produces diagnostics inconsistent with code that demonstrably works elsewhere. What is the likely cause?
An __has_include fallback branch is being compiled for the first time. The isolated PCM action cannot see a header that all prior compilations could, so the preprocessor selects a branch never previously compiled — which may be invalid. Make the primary branch's header reachable in the PCM action (declare the edge).
Why is the error attributed to an "aspect" rather than to my target?
PCM actions are not declared by the failing target's rule; they are attached by swift_clang_module_aspect as it walks the deps graph. The message "from aspects […] on objc_library rule target X" means: the aspect, visiting target X, registered this precompile action, and the action failed. The target to fix is X (or its missing dependency), not the top-level target you asked Bazel to build.
What does explicit module compilation provide over implicit?
PCM compilations become declared Bazel actions: remote-cacheable (one compilation per module per configuration, shared across all machines and CI), deterministic (independent of import order and consumer flags), schedulable in parallel ahead of Swift compiles, and validating (undeclared dependencies fail instead of resolving incidentally). Every failure in Part 6 corresponds to a defect that implicit compilation masked.
Part 10 — Glossary
- module map
- File (
module.modulemap) declaring that a set of headers forms a named Clang module. Framework modules resolve headers inHeaders/; an umbrella header defines contents by transitive inclusion. - PCM
- Precompiled module — serialized binary AST produced by compiling a module map's headers once. Importers deserialize it instead of re-parsing headers.
- implicit modules
- Compilation mode in which the compiler builds needed PCMs on demand, inside whichever compilation first imports them, inheriting that compilation's flags. PCMs live in a compiler-private cache outside the build system.
- explicit modules
- Compilation mode in which the build system schedules a dedicated, sandboxed action per module map (
SwiftPrecompileCModule) and passes finished PCMs to consumers via-fmodule-file=. Enabled in rules_swift byswift.emit_c_module+swift.use_c_modules. - -I / -F
- Header search path flags:
-I dirfor plain includes,-F dirfor framework-style includes (<Name/Header.h>→dir/Name.framework/Headers/Header.h). - quote vs. angle include
"X.h"searches the includer's directory first, then-Idirs.<Y/Z.h>searches-I, then-F, then system paths.- __has_include
- Preprocessor operator testing whether a header is resolvable under the current compilation's search paths. Evaluates differently per compilation; guards become first-compiled code paths under explicit modules.
- target / label / deps
- Bazel's unit of build, its address (
//pkg:name, external:@repo//pkg:name), and the attribute forming the dependency graph. - action
- A concrete command with declared inputs/outputs, run in a sandbox containing only declared inputs. Unit of caching and parallelism.
- CcInfo / SwiftInfo
- Providers carrying compilation context along deps edges. CcInfo: headers, defines, search paths (from
includes, notcopts). SwiftInfo: Swift modules and, under explicit mode, Clang module artifacts. - aspect
- A graph traversal attaching extra actions/providers to existing targets.
swift_clang_module_aspectattaches PCM precompile actions to every module-map-owning target reachable through deps. - copts vs. includes
copts: private flags for the target's own object compilations; not propagated, not visible to PCM actions (except-D).includes: search dirs entering CcInfo, visible to dependents and PCM actions.- xcframework
- Distribution bundle containing one prebuilt framework per platform slice. Imported into Bazel by
apple_static_xcframework_import/apple_dynamic_xcframework_import. - RSPM / target_deps
- rules_swift_package_manager: generates Bazel BUILD files for SPM packages.
configure_package(target_deps)(≥1.17) injects dependency edges into generated targets — required for binary targets, which SPM manifests cannot give deps. - -Swift.h
- Generated ObjC header exposing a framework's Swift API to ObjC. Part of the umbrella; may contain
@importof other modules, contributing to the module dependency set. - .swiftinterface
- Textual Swift module interface shipped in binary frameworks; compiled by the build into a binary swiftmodule. Its
importstatements must all be resolvable, contributing to the dependency set. - -import-underlying-module
- Swift flag loading the Clang module with the same name as the module being compiled — the mixed-language module pattern. The module map involved is supplied by flags, not owned by a target, making it invisible to aspects.
- params file
- File holding a long argument list, passed to a tool as
@file.paramsto avoid OS command-length limits. Argument splitting bugs in params handling surface as malformed-path errors.
Summary
Header resolution is a function of the running compilation's flags. Implicit mode builds modules inside consumer compilations, so undeclared dependencies resolve through borrowed flags. Explicit mode builds each module in a sandboxed action with only declared inputs, so the module graph and the target graph must agree. Each of the nine failures was a point of disagreement: an undeclared edge, invalid metadata never previously evaluated, an input invisible to the aspect, or a path hazard exercised by the new action type.
App target green with swift.use_c_modules · June 2026