Skip to content

Commit

Permalink
Implement 'first pass' of index while building V2
Browse files Browse the repository at this point in the history
This concludes the first step if mitigating perf issues and first PR in
the series for index while building - docs/index_while_building.md.

Hinging on the feature, swift.index_while_building_v2, it moves
rules_ios to use a global index and pulls in the swift PR
bazelbuild/rules_swift#567, and index-import PR
MobileNativeFoundation/index-import#53 .

In hopes of mitigating performance problems of processing the global
index in this way it flips the `-incremental` bit in the latest flag.
Longer term we will not be processing a global index, per
docs/index_while_building.md so this is temporary measure.

This PR implements line items from 'Index while building V2 - first
pass' in the roadmap for this feature defined in
docs/index_while_building.md.
  • Loading branch information
jerrymarino committed Feb 26, 2021
1 parent fb4fffc commit d82b12b
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 13 deletions.
4 changes: 4 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ build --deleted_packages tests/ios/frameworks/sources-with-prebuilt-binaries
# Enable dbg compilation mode in this repo, so we can test xcodeproj-built
# binaries contain debug symbol tables.
build --compilation_mode=dbg

# This flips index_while_building_v2 on
build --features swift.index_while_building_v2

7 changes: 7 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@ sh_binary(
name = "buildifier",
srcs = ["@buildifier.mac//file"],
)

config_setting(
name = "index_while_building_v2",
values = {
"features": "swift.index_while_building_v2",
},
)
24 changes: 19 additions & 5 deletions rules/library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -664,17 +664,31 @@ def apple_library(name, library_tools = {}, export_private_headers = True, names
lib_names.append(cpp_libname)

additional_objc_copts.append("-I.")
index_while_building_objc_copts = select({
"@build_bazel_rules_ios//:index_while_building_v2": [
# Note: this won't work work for remote caching yet. It uses a
# _different_ global index for objc than so that the BEP grep in
# rules_ios picks this up.
# Checkout the task roadmap for future improvements:
# Docs/index_while_building.md
"-index-store-path",
"bazel-out/rules_ios_global_index_store.indexstore",
],
"//conditions:default": [
"-index-store-path",
"$(GENDIR)/{package}/rules_ios_objc_library_{libname}.indexstore".format(
package = native.package_name(),
libname = objc_libname,
),
],
})

additional_objc_copts.extend(("-index-store-path", "$(GENDIR)/{package}/rules_ios_objc_library_{libname}.indexstore".format(
package = native.package_name(),
libname = objc_libname,
)))
objc_library(
name = objc_libname,
srcs = objc_sources + objc_private_hdrs + objc_non_exported_hdrs,
non_arc_srcs = objc_non_arc_sources,
hdrs = objc_hdrs,
copts = copts_by_build_setting.objc_copts + objc_copts + additional_objc_copts,
copts = copts_by_build_setting.objc_copts + objc_copts + additional_objc_copts + index_while_building_objc_copts,
deps = deps + private_deps + lib_names,
module_map = module_map,
sdk_dylibs = sdk_dylibs,
Expand Down
18 changes: 11 additions & 7 deletions rules/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@ def rules_ios_dependencies():
sha256 = "1fff3fa1e565111a8f678b4698792101844f57b2e78c5e374431d0ebe97f6b6c",
)

# Note: this is a branch of the rules_swift PR
# https://github.com/bazelbuild/rules_swift/pull/567
_maybe(
github_repo,
name = "build_bazel_rules_swift",
ref = "ed81c15f9b577880c13b987101100cbac03f45c2",
project = "bazelbuild",
ref = "d8fff1f3ef0b057085c875421c15cfd83fcbee28",
project = "bazel-ios",
repo = "rules_swift",
sha256 = "9527ef2617be16115ed514d442b6d53d8d824054fd97e5b3ab689fb9d978b8ed",
sha256 = "c8768b871e9726efe0245b3b3a60b18f6a41f9735d864bfe97f17bf7d0ae47e9",
)

_maybe(
Expand All @@ -81,9 +83,11 @@ def rules_ios_dependencies():
sha256 = "1c531376ac7e5a180e0237938a2536de0c54d93f5c278634818e0efc952dd56c",
)

# Note: it relies on `index-import` to import indexes. Longer term this
# dependency may be added by rules_swift
_maybe(
http_archive,
name = "com_github_lyft_index_import",
name = "build_bazel_rules_swift_index_import",
build_file_content = """\
load("@bazel_skylib//rules:native_binary.bzl", "native_binary")
Expand All @@ -108,9 +112,9 @@ native_binary(
visibility = ["//visibility:public"],
)
""",
canonical_id = "index-import-5.2.1.4",
urls = ["https://github.com/lyft/index-import/releases/download/5.2.1.4/index-import.zip"],
sha256 = "62f42816baf3b690682b5d6fe543a3c5a4a6ea7499ce1f4e8326c7bd2175989a",
canonical_id = "index-import-5.3.2.5",
urls = ["https://github.com/bazel-ios/index-import/releases/download/5.3.2.5/index-import.zip"],
sha256 = "79e9b2cd3e988155b86668c56d95705e1a4a7c7b6d702ff5ded3a18d1291a39a",
)

_maybe(
Expand Down
2 changes: 1 addition & 1 deletion rules/xcodeproj.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ https://www.rubydoc.info/github/CocoaPods/Xcodeproj/Xcodeproj/Constants
"_workspace_checks": attr.label(executable = False, default = Label("//tools/xcodeproj_shims:IDEWorkspaceChecks.plist"), allow_single_file = ["plist"]),
"output_processor": attr.label(executable = True, default = Label("//tools/xcodeproj_shims:output-processor.rb"), cfg = "host", allow_single_file = True),
"_xcodegen": attr.label(executable = True, default = Label("@com_github_yonaskolb_xcodegen//:xcodegen"), cfg = "host"),
"index_import": attr.label(executable = True, default = Label("@com_github_lyft_index_import//:index_import"), cfg = "host"),
"index_import": attr.label(executable = True, default = Label("@build_bazel_rules_swift_index_import//:index_import"), cfg = "host"),
"clang_stub": attr.label(executable = True, default = Label("//tools/xcodeproj_shims:clang-stub"), cfg = "host"),
"ld_stub": attr.label(executable = True, default = Label("//tools/xcodeproj_shims:ld-stub"), cfg = "host"),
"swiftc_stub": attr.label(executable = True, default = Label("//tools/xcodeproj_shims:swiftc-stub"), cfg = "host"),
Expand Down
1 change: 1 addition & 0 deletions tools/xcodeproj_shims/installers/_indexstore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ readonly xcode_external="$BAZEL_WORKSPACE_ROOT/bazel-$(basename "$SRCROOT")/exte


$BAZEL_INSTALLERS_DIR/index-import \
-incremental \
-remap "$bazel_module=$xcode_module" \
-remap "$bazel_swift_object=$xcode_object" \
-remap "$bazel_objc_object=$xcode_object" \
Expand Down

0 comments on commit d82b12b

Please sign in to comment.