-
Notifications
You must be signed in to change notification settings - Fork 93
Add rules for building SDK frameworks for explicit module compilation #562
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
Draft
dierksen
wants to merge
55
commits into
bazel-ios:master
Choose a base branch
from
dierksen:framework_repo_rule
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit
Hold shift + click to select a range
c27f34e
Add rules for building SDK frameworks for explicit module compilation
dierksen e0f837c
Merge branch 'master' into framework_repo_rule
dierksen 567d839
split out repo rule; bump bazel and rules_swift
dierksen 183306e
revert arm64-to-sim tweak
dierksen 399edef
testing some stuff
dierksen 59fe2f4
add umbrella dep under the hood
dierksen b02c8ac
Merge branch 'master' into framework_repo_rule
dierksen 87de123
Merge branch 'framework_repo_rule' into framework_tinkering
dierksen e905fe1
further repo rule cleanup
dierksen 9792e61
change .bazelrc for now
dierksen 0b47395
symlink in xctest framework, pass to testonly swift libraries
dierksen 1b7afe4
cleanup
dierksen ebb38c2
Bump macos image, bazel, and carthage versions
dierksen 90aa093
Merge branch 'xc13' into framework_repo_rule
dierksen 0a92978
gradually trying to fix tests
dierksen c891e65
bump cocoapods to 1.11 to add ruby 3 support
dierksen 55c9710
newest bazel release
dierksen e83f15d
update gemfile.lock
dierksen 901234d
bump checkout action, mark mixed framework test as manual for now
dierksen efc8ff6
disable another one
dierksen fd3db05
Merge branch 'master' into xc13
dierksen 7d01fbe
try newer carthage fix
dierksen a6d85c3
re-enable a couple of tests for now
dierksen 0d11ade
reverts
dierksen 3eee080
Merge branch 'master' into xc13
dierksen 865789c
revert more formatting
dierksen de887dd
update test simulators
dierksen 29dc203
just change the diff
dierksen 8d06a2a
tweak diff
dierksen 5f3bfd0
Merge branch 'xc13' into framework_repo_rule
dierksen ed943d9
tweak repos for testing on github
dierksen 9dc858f
Merge branch 'master' into framework_repo_rule
dierksen b921c35
fix deps array (ugh), fix watch simulator cpu
dierksen c17cbbe
add -k to tests so i can see progress at least
dierksen 8a6de35
Merge branch 'master' into framework_repo_rule
dierksen a076ac1
reverts, test cleanup
dierksen 893bddb
bump rules versions
dierksen 5422ec0
trying to clean up while preserving existing tests
dierksen e09da21
upgrade stardoc due to rules_proto changes :-/
dierksen 5951403
alias XCTest dummy module so it doesn't replace the real one
dierksen fc1b9b3
trying one more thing
dierksen bb6bbf1
more tweaks, getting closer
dierksen a8278b0
Merge branch 'master' into framework_repo_rule
dierksen 82b3662
whitespace revert
dierksen 6346d6d
revert vscode change
dierksen d505eb0
attempting to generate for intel mac, might need to iterate a bit
dierksen 723efe9
this stupid diff test again
dierksen 510bee3
add default mapping to mac to deal with darwin cpu weirdness
dierksen 1504731
one more tweak for intel mac
dierksen 9795596
add frameworks dep to arm64-to-sim
dierksen ebf77f8
make config flag, fix import underlying module flag
dierksen 997b0f9
tweak config setting
dierksen 55f13ec
address lingering nit
dierksen 4e34aec
add -k to tests
dierksen 0e4c235
hopefully green test setup
dierksen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,3 @@ | ||
| { | ||
| "files.exclude": { | ||
| "bazel-*": true | ||
| }, | ||
| "editor.formatOnSave": true, | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
tools/toolchains/xcode_configure/xcode_sdk_frameworks.bzl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| PLATFORM_TUPLES = [ | ||
| ("AppleTVOS", "tvos"), | ||
| ("AppleTVSimulator", "tvos"), | ||
| ("MacOSX", "macos"), | ||
| ("WatchOS", "watchos"), | ||
| ("WatchSimulator", "watchos"), | ||
| ("iPhoneOS", "ios"), | ||
| ("iPhoneSimulator", "ios"), | ||
| ] | ||
|
|
||
| def _find_all_frameworks(sdk_path): | ||
| frameworks_dir = sdk_path.get_child("System").get_child("Library").get_child("Frameworks") | ||
| if not frameworks_dir.exists: | ||
| # Skip things like DriverKit | ||
| return [] | ||
| frameworks = frameworks_dir.readdir() | ||
| return [ | ||
| f.basename.replace(".framework", "") | ||
| for f in frameworks | ||
| if f.basename.endswith(".framework") and not f.basename.startswith("_") | ||
| ] | ||
|
|
||
| def _build_file_header(): | ||
| return """load("@build_bazel_rules_swift//swift:swift.bzl", "swift_module_alias", "swift_c_module") | ||
| package(default_visibility = ["//visibility:public"]) | ||
| """ | ||
|
|
||
| IMPORTS_FILE = "bazel_xcode_imports.swift" | ||
|
|
||
| def _get_dependency_graph(repository_ctx, developer_dir, sdk_path, target_triple): | ||
| frameworks = _find_all_frameworks(sdk_path) | ||
| swift_lib_dir = sdk_path.get_child("usr").get_child("lib").get_child("swift") | ||
| swift_libs = swift_lib_dir.readdir() | ||
| frameworks.extend([s.basename.replace(".swiftmodule", "") for s in swift_libs if s.basename.endswith(".swiftmodule") and not s.basename.startswith("_")]) | ||
dierksen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| import_file_content = "".join(["import {}\n".format(f) for f in frameworks]) | ||
| repository_ctx.file(IMPORTS_FILE, content = import_file_content) | ||
| resource_dir = "{}/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift".format(developer_dir) | ||
|
|
||
| repository_ctx.report_progress("Scanning deps for {}".format(sdk_path)) | ||
| deps_result = repository_ctx.execute( | ||
| [ | ||
| "swiftc", | ||
| "-scan-dependencies", | ||
| "-sdk", | ||
| sdk_path, | ||
| "-resource-dir", | ||
| resource_dir, | ||
| "-target", | ||
| target_triple, | ||
| IMPORTS_FILE, | ||
| ], | ||
| ) | ||
| repository_ctx.delete(IMPORTS_FILE) | ||
| if deps_result.return_code != 0: | ||
| fail("Could not scan dependencies for {}\n{}".format(sdk_path, deps_result.stderr)) | ||
| return json.decode(deps_result.stdout) | ||
|
|
||
| C_MODULE_TMPL = """swift_c_module( | ||
| name = "{name}_c", | ||
| module_name = "{name}", | ||
| system_module_map = "{module_map_file}", | ||
| deps = [ | ||
| {deps} | ||
| ], | ||
| ) | ||
| """ | ||
|
|
||
| SWIFT_MODULE_TMPL = """swift_module_alias( | ||
| name = "{name}_swift", | ||
| deps = [ | ||
| {deps} | ||
| ] | ||
| ) | ||
| """ | ||
|
|
||
| def _sub_bazel_path_vars(path, sdk_path, developer_dir): | ||
| path = path.replace(str(sdk_path), "__BAZEL_XCODE_SDKROOT__") | ||
| path = path.replace(str(developer_dir), "__BAZEL_XCODE_DEVELOPER_DIR__") | ||
| return path | ||
|
|
||
| def _rule_for_pkg(developer_dir, sdk_path, pkg): | ||
| module_path = pkg.get("modulePath", "") | ||
| if not module_path or IMPORTS_FILE in module_path: | ||
dierksen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return "" | ||
| module_name = module_path.replace(".pcm", "").replace(".swiftmodule", "") | ||
|
|
||
| pkg_deps = pkg.get("directDependencies", []) | ||
| deps = ["{}_c".format(d["clang"]) for d in pkg_deps if "clang" in d] | ||
| deps += ["{}_swift".format(d["swift"]) for d in pkg_deps if "swift" in d] | ||
| deps_string = "\n".join(sorted([" \":{}\",".format(d) for d in deps])) | ||
thiagohmcruz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| clang = pkg.get("details", {}).get("clang", {}) | ||
| if clang: | ||
| return C_MODULE_TMPL.format( | ||
| name = module_name, | ||
| module_map_file = _sub_bazel_path_vars(clang["moduleMapPath"], sdk_path, developer_dir), | ||
| deps = deps_string, | ||
| ) | ||
|
|
||
| return SWIFT_MODULE_TMPL.format( | ||
| name = module_name, | ||
| deps = deps_string, | ||
| ) | ||
|
|
||
| def _create_build_file_for_sdk(repository_ctx, developer_dir, sdk_path, output_folder, target_triple): | ||
| scan_deps = _get_dependency_graph(repository_ctx, developer_dir, sdk_path, target_triple) | ||
|
|
||
| build_file = _build_file_header() | ||
|
|
||
| for pkg in scan_deps.get("modules", []): | ||
| build_file += _rule_for_pkg(developer_dir, sdk_path, pkg) | ||
|
|
||
| build_file_path = output_folder.get_child("BUILD.bazel") | ||
| repository_ctx.file(build_file_path, build_file) | ||
|
|
||
| def _platform_target_triple(platform, target_name, version): | ||
| return "{cpu}-apple-{platform}{version}{suffix}".format( | ||
| cpu = "arm64_32" if target_name == "watchos" else "arm64", | ||
| platform = target_name, | ||
| version = version, | ||
| suffix = "-simulator" if platform.endswith("Simulator") else "", | ||
| ) | ||
|
|
||
| def create_xcode_framework_targets(repository_ctx, xcode_version_name, developer_dir, versions): | ||
| """Creates a BUILD file for all the SDK frameworks contained in a given Xcode version.""" | ||
| developer_dir_path = repository_ctx.path(developer_dir) | ||
| platforms_dir = developer_dir_path.get_child("Platforms") | ||
| for platform_name, target_name in PLATFORM_TUPLES: | ||
| platform_dir = platforms_dir.get_child(platform_name + ".platform") | ||
| platform_version = versions[target_name] | ||
dierksen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| sdk_dir = platform_dir.get_child("Developer").get_child("SDKs").get_child("{}.sdk".format(platform_name)) | ||
| target_triple = _platform_target_triple(platform_name, target_name, platform_version) | ||
|
|
||
| output_folder = repository_ctx.path(xcode_version_name).get_child(platform_name) | ||
| _create_build_file_for_sdk(repository_ctx, developer_dir_path, sdk_dir, output_folder, target_triple) | ||
dierksen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.