Skip to content

Commit 96cd8d3

Browse files
authored
Adds the repository rule xcode_sdk_frameworks (#898)
### What It scans and configures all SDK frameworks which are required for explicit module builds. Specifically, it 1) uses the bazel_tools//tools/osx:xcode_configure.bzl to fetch all local Xcode infos, 2) finds all frameworks under the xcode SDK path, and 3) uses the swiftc -scan-dependencies mode to fetch the dependency graph among all Swift and Clang SDK modules. We use swift_module_alias to represent a Swift SDK module and sdk_clang_module for a Clang SDK module. This PR is based on the previous attempt to support SDK frameworks: #562 ### Test Runs `bazel build --config=explicit_modules --nobuild @xcode_sdk_frameworks//...` and inspects the generated repository at `$(bazel info output_base)/external/_main~xcode_sdk_frameworks~xcode_sdk_frameworks`. ### Next steps: The dependency among swift_module_alias and sdk_clang_module doesn't work yet. We need to fix that.
1 parent b13aef1 commit 96cd8d3

5 files changed

Lines changed: 474 additions & 0 deletions

File tree

.bazelrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ build:remote_cache --remote_timeout=3600
6565
# Configure for explicit module compilation
6666
build:explicit_modules --features=swift.use_c_modules
6767
build:explicit_modules --features=swift.emit_c_module
68+
build:explicit_modules --repo_env=EXPLICIT_MODULES=1
6869

6970
# By default don't upload local results to remote cache, only CI does this.
7071
build --noremote_upload_local_results

MODULE.bazel

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,14 @@ use_repo(
101101
apple_non_module_deps,
102102
"xctestrunner",
103103
)
104+
105+
# Load xcode_sdk_frameworks
106+
xcode_sdk_frameworks = use_extension(
107+
"//rules:module_extensions.bzl",
108+
"xcode_sdk_frameworks",
109+
dev_dependency = True,
110+
)
111+
use_repo(
112+
xcode_sdk_frameworks,
113+
"xcode_sdk_frameworks",
114+
)

rules/explicit_module/sdk_clang_module.bzl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
load("@build_bazel_rules_swift//swift/internal:feature_names.bzl", "SWIFT_FEATURE_SYSTEM_MODULE")
2+
load("@build_bazel_rules_swift//swift/internal:providers.bzl", "create_swift_info")
23
load("@build_bazel_rules_swift//swift/internal:swift_common.bzl", "swift_common")
34

45
def _sdk_clang_module_impl(ctx):
@@ -11,10 +12,16 @@ def _sdk_clang_module_impl(ctx):
1112
# We need to return CcInfo and its compilation_context. We may also consider to update swift_clang_module_aspect.
1213
# See https://github.com/bazelbuild/rules_swift/blob/d68b21471e4e9d922b75e2b0621082b8ce017d11/swift/internal/swift_clang_module_aspect.bzl#L548
1314
CcInfo(compilation_context = cc_common.create_compilation_context()),
15+
# Required to add sdk_clang_module targets to the deps of swift_module_alias.
16+
# TODO(cshi): create the SwiftInfo correctly
17+
create_swift_info(),
1418
]
1519

1620
sdk_clang_module = rule(
1721
attrs = {
22+
"deps": attr.label_list(
23+
doc = "The deps of the SDK clang module",
24+
),
1825
"module_map": attr.string(
1926
doc = """\
2027
The path to a SDK framework module map.

rules/module_extensions.bzl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ load(
55
"rules_ios_dependencies",
66
"rules_ios_dev_dependencies",
77
)
8+
load(
9+
"//rules:xcode_sdk_frameworks.bzl",
10+
"load_xcode_sdk_frameworks",
11+
)
812
load(
913
"//tools/toolchains/xcode_configure:xcode_configure.bzl",
1014
_xcode_configure = "xcode_configure",
@@ -41,3 +45,8 @@ xcode_configure = module_extension(
4145
),
4246
},
4347
)
48+
49+
def _xcode_sdk_frameworks_impl(_):
50+
load_xcode_sdk_frameworks()
51+
52+
xcode_sdk_frameworks = module_extension(implementation = _xcode_sdk_frameworks_impl)

0 commit comments

Comments
 (0)