Skip to content

Commit

Permalink
Adds the repository rule xcode_sdk_frameworks (#898)
Browse files Browse the repository at this point in the history
### 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.
  • Loading branch information
congt authored Aug 21, 2024
1 parent b13aef1 commit 96cd8d3
Show file tree
Hide file tree
Showing 5 changed files with 474 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
11 changes: 11 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,14 @@ use_repo(
apple_non_module_deps,
"xctestrunner",
)

# Load xcode_sdk_frameworks
xcode_sdk_frameworks = use_extension(
"//rules:module_extensions.bzl",
"xcode_sdk_frameworks",
dev_dependency = True,
)
use_repo(
xcode_sdk_frameworks,
"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
9 changes: 9 additions & 0 deletions rules/module_extensions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ load(
"rules_ios_dependencies",
"rules_ios_dev_dependencies",
)
load(
"//rules:xcode_sdk_frameworks.bzl",
"load_xcode_sdk_frameworks",
)
load(
"//tools/toolchains/xcode_configure:xcode_configure.bzl",
_xcode_configure = "xcode_configure",
Expand Down Expand Up @@ -41,3 +45,8 @@ xcode_configure = module_extension(
),
},
)

def _xcode_sdk_frameworks_impl(_):
load_xcode_sdk_frameworks()

xcode_sdk_frameworks = module_extension(implementation = _xcode_sdk_frameworks_impl)
Loading

0 comments on commit 96cd8d3

Please sign in to comment.