Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds the repository rule xcode_sdk_frameworks #898

Merged
merged 1 commit into from
Aug 21, 2024

Conversation

congt
Copy link
Contributor

@congt congt commented Aug 20, 2024

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.

@congt congt requested a review from gyfelton August 20, 2024 23:47
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.

Next steps:
 The dependency among swift_module_alias and sdk_clang_module doesn't work yet. We need to fix that.
Copy link
Contributor

@gyfelton gyfelton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

having trouble getting bazel build --config=explicit_modules --nobuild @xcode_sdk_frameworks//... build locally without some changes listed here

return

# Locates all local xcodes
xcode_toolchains, error = run_xcode_locator(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to target at one version only for example? right now me running bazel build --config=explicit_modules --nobuild @xcode_sdk_frameworks//... fails locally with

		targets.append(_target_for_module(
	File "/Users/yuanfeng/Development/rules_ios/rules/xcode_sdk_frameworks.bzl", line 182, column 13, in _target_for_module
		fail("Expect module name by type, but got {}".format(module_name_by_type))
Error in fail: Expect module name by type, but got {"swiftPrebuiltExternal": "_SceneKit_SwiftUI"}

and it seems to happen with xcode 16. Which means we might penalize someone in future just because they installed the new Xcode version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can fix it for new xcode versions

ROOT_ALIAS_TMPL = """
alias(
name = "{target}",
actual = select({{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i got error here on

ERROR: /private/var/tmp/_bazel_yuanfeng/8f12d9050b931ac3050ca4cf9fc59845/external/_main~xcode_sdk_frameworks~xcode_sdk_frameworks/BUILD.bazel:38:6: configurable attribute "actual" in @@_main~xcode_sdk_frameworks~xcode_sdk_frameworks//:xcode_sdk_frameworks doesn't match this configuration. Would a default condition help?

Conditions checked:
 @@_main~xcode_sdk_frameworks~xcode_sdk_frameworks//:xcode_15_4_0_15F31d

To see a condition's definition, run: bazel query --output=build <condition label>.

i tested by adding "//conditions:default": "//version15_4_0_15F31d:xcode_sdk_frameworks", here and the build now succeed. So why you don't hit it and it sounds like we need to ask for a default xcode version or sth?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's because the repo is pinned to 15.2 while you don't have 15.2 installed. You can update the xcode version in .bazelrc to build --xcode_version=15.4.0.15F31d

# Configures SDK frameworks for each xcode version.
for xcode_toolchain in xcode_toolchains:
xcode_version_name = "version{}".format(xcode_toolchain.version.replace(".", "_"))
_create_xcode_framework_targets(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how many xcode versions do you have locally? so far i got it green with 15.4 only via:

        if not xcode_version_name.startswith("version15_4"):
            continue

with 15.1 or 15.2 i got:

ERROR: /private/var/tmp/_bazel_yuanfeng/8f12d9050b931ac3050ca4cf9fc59845/external/_main~xcode_sdk_frameworks~xcode_sdk_frameworks/version15_1_0_15C65/iPhoneOS/BUILD.bazel:7:19: Label '@@_main~xcode_sdk_frameworks~xcode_sdk_frameworks//version15_1_0_15C65/iPhoneOS:CoreMotion_swift' is duplicated in the 'deps' attribute of rule 'bazel_xcode_imports_swift'
ERROR: /private/var/tmp/_bazel_yuanfeng/8f12d9050b931ac3050ca4cf9fc59845/external/_main~xcode_sdk_frameworks~xcode_sdk_frameworks/version15_1_0_15C65/iPhoneOS/BUILD.bazel:7:19: Label '@@_main~xcode_sdk_frameworks~xcode_sdk_frameworks//version15_1_0_15C65/iPhoneOS:CoreAudio_swift' is duplicated in the 'deps' attribute of rule 'bazel_xcode_imports_swift'
ERROR: package contains errors: version15_1_0_15C65/MacOSX
ERROR: package contains errors: version15_1_0_15C65/iPhoneOS

and i cannot build with xcode 16 due to the error above....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't test it on 15.1 or 15.2. Thanks for the heads up! We can address the issue with different xcode versions later.

@congt congt merged commit 96cd8d3 into prototype/explicit-module-build Aug 21, 2024
9 checks passed
@congt congt deleted the cshi/fetch-sdk-frameworks branch August 21, 2024 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants