Skip to content

Commit

Permalink
Adds the repository rule xcode_sdk_frameworks
Browse files Browse the repository at this point in the history
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, and
  2) finds all frameworks under the xcode SDK path,
  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.

Next steps:
 The dependency among swift_module_alias and sdk_clang_module doesn't work yet. We need to fix that.
  • Loading branch information
congt committed Aug 20, 2024
1 parent b13aef1 commit e42df52
Show file tree
Hide file tree
Showing 4 changed files with 460 additions and 0 deletions.
1 change: 1 addition & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ build:remote_cache --remote_timeout=3600
# Configure for explicit module compilation
build:explicit_modules --features=swift.use_c_modules
build:explicit_modules --features=swift.emit_c_module
build:explicit_modules --repo_env=EXPLICIT_MODULES=1

# By default don't upload local results to remote cache, only CI does this.
build --noremote_upload_local_results
Expand Down
9 changes: 9 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,12 @@ use_repo(
apple_non_module_deps,
"xctestrunner",
)

# Load xcode_sdk_frameworks
xcode_sdk_frameworks = use_repo_rule(
"//rules:xcode_sdk_frameworks.bzl",
"xcode_sdk_frameworks",
)
xcode_sdk_frameworks(
name = "xcode_sdk_frameworks",
)
7 changes: 7 additions & 0 deletions rules/explicit_module/sdk_clang_module.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@build_bazel_rules_swift//swift/internal:feature_names.bzl", "SWIFT_FEATURE_SYSTEM_MODULE")
load("@build_bazel_rules_swift//swift/internal:providers.bzl", "create_swift_info")
load("@build_bazel_rules_swift//swift/internal:swift_common.bzl", "swift_common")

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

sdk_clang_module = rule(
attrs = {
"deps": attr.label_list(
doc = "The deps of the SDK clang module",
),
"module_map": attr.string(
doc = """\
The path to a SDK framework module map.
Expand Down
Loading

0 comments on commit e42df52

Please sign in to comment.