Background
We have a .xcodeproj project with multiple targets, such as:
The source structure is:
Foo/
Foo.swift
Bar/
Bar.swift
Other/
Other.swift
Previous Approach
The previous generation strategy creates BUILD files inside each directory:
Foo/
Foo.swift
BUILD
Bar/
Bar.swift
BUILD
Other/
Other.swift
BUILD
Module.bazel
When Foo depends on files outside its own directory:
Foo -> Bar/Bar.swift
Foo -> Other/Other.swift
The Foo/BUILD becomes:
swift_library(
name = "Foo",
srcs = [
"Foo.swift",
"//Bar:Bar.swift",
"//:Other/Other.swift",
],
)
This requires additional configuration in other BUILD files:
# Bar/BUILD
exports_files(["Bar.swift"])
# root BUILD
exports_files(["Other/Other.swift"])
Problem
This approach introduces several issues:
- Foo's dependency forces changes in other BUILD files
- Tight coupling between targets
- Dependencies are scattered across multiple BUILD files
- High maintenance cost
- Poor scalability as the project grows
Proposed Approach
Generate a separate build output workspace:
$OUTPUT/
BUILD
Module.bazel
Foo/
BUILD
Foo/Foo.swift (link)
Bar/Bar.swift (link)
Other/Other.swift (link)
Corresponding $OUTPUT/Foo/BUILD:
swift_library(
name = "Foo",
srcs = [
"Foo/Foo.swift",
"Bar/Bar.swift",
"Other/Other.swift",
],
)
Improvements
- Each target has a self-contained build context
- No need to modify upstream BUILD files
- Eliminates the need for
exports_files
- Reduces cross-package dependency complexity
- Decouples build configuration from source layout
Core Idea
Shift from cross-package file-level dependencies
to a self-contained, per-target source aggregation model
Background
We have a
.xcodeprojproject with multiple targets, such as:The source structure is:
Previous Approach
The previous generation strategy creates BUILD files inside each directory:
When
Foodepends on files outside its own directory:The
Foo/BUILDbecomes:This requires additional configuration in other BUILD files:
Problem
This approach introduces several issues:
Proposed Approach
Generate a separate build output workspace:
Corresponding
$OUTPUT/Foo/BUILD:Improvements
exports_filesCore Idea