Skip to content

Commit cea96e0

Browse files
committed
Implement 'first pass' of index while building V2 (#217)
* Implement 'first pass' of index while building V2 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.
1 parent 55b67af commit cea96e0

File tree

14 files changed

+63
-13
lines changed

14 files changed

+63
-13
lines changed

.bazelrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,10 @@ build --deleted_packages tests/ios/frameworks/sources-with-prebuilt-binaries
2020
# Enable dbg compilation mode in this repo, so we can test xcodeproj-built
2121
# binaries contain debug symbol tables.
2222
build --compilation_mode=dbg
23+
24+
# Use 'worker' strategy for swift compilation
25+
build --strategy=SwiftCompile=worker
26+
27+
# This flips index_while_building_v2 - see docs/index_while_building.md for a
28+
# detailed summary
29+
build --features swift.index_while_building_v2

BUILD.bazel

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Pull buildifer.mac as an http_file, then depend on the file group to make an
2+
# executable
3+
load("@build_bazel_rules_swift//swift/internal:feature_names.bzl", "SWIFT_FEATURE_INDEX_WHILE_BUILDING_V2")
4+
5+
sh_binary(
6+
name = "buildifier",
7+
srcs = ["@buildifier.mac//file"],
8+
)
9+
10+
config_setting(
11+
name = "index_while_building_v2",
12+
values = {
13+
"features": SWIFT_FEATURE_INDEX_WHILE_BUILDING_V2,
14+
},
15+
)

rules/library.bzl

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -582,17 +582,31 @@ def apple_library(name, library_tools = {}, export_private_headers = True, names
582582
lib_names.append(cpp_libname)
583583

584584
additional_objc_copts.append("-I.")
585+
index_while_building_objc_copts = select({
586+
"@build_bazel_rules_ios//:index_while_building_v2": [
587+
# Note: this won't work work for remote caching yet. It uses a
588+
# _different_ global index for objc than so that the BEP grep in
589+
# rules_ios picks this up.
590+
# Checkout the task roadmap for future improvements:
591+
# Docs/index_while_building.md
592+
"-index-store-path",
593+
"bazel-out/rules_ios_global_index_store.indexstore",
594+
],
595+
"//conditions:default": [
596+
"-index-store-path",
597+
"$(GENDIR)/{package}/rules_ios_objc_library_{libname}.indexstore".format(
598+
package = native.package_name(),
599+
libname = objc_libname,
600+
),
601+
],
602+
})
585603

586-
additional_objc_copts.extend(("-index-store-path", "$(GENDIR)/{package}/rules_ios_objc_library_{libname}.indexstore".format(
587-
package = native.package_name(),
588-
libname = objc_libname,
589-
)))
590604
objc_library(
591605
name = objc_libname,
592606
srcs = objc_sources + objc_private_hdrs + objc_non_exported_hdrs,
593607
non_arc_srcs = objc_non_arc_sources,
594608
hdrs = objc_hdrs,
595-
copts = copts_by_build_setting.objc_copts + objc_copts + additional_objc_copts,
609+
copts = copts_by_build_setting.objc_copts + objc_copts + additional_objc_copts + index_while_building_objc_copts,
596610
deps = deps + private_deps + lib_names,
597611
module_map = module_map,
598612
sdk_dylibs = sdk_dylibs,

rules/repositories.bzl

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,15 @@ def rules_ios_dependencies():
5353
sha256 = "1fff3fa1e565111a8f678b4698792101844f57b2e78c5e374431d0ebe97f6b6c",
5454
)
5555

56+
# Note: this ref is a cherry-pick of the rules_swift PR
57+
# https://github.com/bazelbuild/rules_swift/pull/567
5658
_maybe(
5759
github_repo,
5860
name = "build_bazel_rules_swift",
59-
ref = "ed81c15f9b577880c13b987101100cbac03f45c2",
60-
project = "bazelbuild",
61+
ref = "703165622cf87cabe253bf746a8129f8021ec001",
62+
project = "bazel-ios",
6163
repo = "rules_swift",
62-
sha256 = "9527ef2617be16115ed514d442b6d53d8d824054fd97e5b3ab689fb9d978b8ed",
64+
sha256 = "cf553875aae12744846b5e484879098e9c9153883febfc4074aa9305765a923f",
6365
)
6466

6567
_maybe(
@@ -81,9 +83,12 @@ def rules_ios_dependencies():
8183
sha256 = "1c531376ac7e5a180e0237938a2536de0c54d93f5c278634818e0efc952dd56c",
8284
)
8385

86+
# Note: it relies on `index-import` to import indexes. Longer term this
87+
# dependency may be added by rules_swift
88+
# This release is a build of this PR https://github.com/lyft/index-import/pull/53
8489
_maybe(
8590
http_archive,
86-
name = "com_github_lyft_index_import",
91+
name = "build_bazel_rules_swift_index_import",
8792
build_file_content = """\
8893
load("@bazel_skylib//rules:native_binary.bzl", "native_binary")
8994
@@ -108,9 +113,9 @@ native_binary(
108113
visibility = ["//visibility:public"],
109114
)
110115
""",
111-
canonical_id = "index-import-5.2.1.4",
112-
urls = ["https://github.com/lyft/index-import/releases/download/5.2.1.4/index-import.zip"],
113-
sha256 = "62f42816baf3b690682b5d6fe543a3c5a4a6ea7499ce1f4e8326c7bd2175989a",
116+
canonical_id = "index-import-5.3.2.5",
117+
urls = ["https://github.com/bazel-ios/index-import/releases/download/5.3.2.5/index-import.zip"],
118+
sha256 = "79e9b2cd3e988155b86668c56d95705e1a4a7c7b6d702ff5ded3a18d1291a39a",
114119
)
115120

116121
_maybe(

rules/xcodeproj.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ https://www.rubydoc.info/github/CocoaPods/Xcodeproj/Xcodeproj/Constants
837837
"_workspace_checks": attr.label(executable = False, default = Label("//tools/xcodeproj_shims:IDEWorkspaceChecks.plist"), allow_single_file = ["plist"]),
838838
"output_processor": attr.label(executable = True, default = Label("//tools/xcodeproj_shims:output-processor.rb"), cfg = "host", allow_single_file = True),
839839
"_xcodegen": attr.label(executable = True, default = Label("@com_github_yonaskolb_xcodegen//:xcodegen"), cfg = "host"),
840-
"index_import": attr.label(executable = True, default = Label("@com_github_lyft_index_import//:index_import"), cfg = "host"),
840+
"index_import": attr.label(executable = True, default = Label("@build_bazel_rules_swift_index_import//:index_import"), cfg = "host"),
841841
"clang_stub": attr.label(executable = True, default = Label("//tools/xcodeproj_shims:clang-stub"), cfg = "host"),
842842
"ld_stub": attr.label(executable = True, default = Label("//tools/xcodeproj_shims:ld-stub"), cfg = "host"),
843843
"swiftc_stub": attr.label(executable = True, default = Label("//tools/xcodeproj_shims:swiftc-stub"), cfg = "host"),

tests/ios/xcodeproj/Single-Static-Framework-Project.xcodeproj/bazelinstallers/_indexstore.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ readonly xcode_external="$BAZEL_WORKSPACE_ROOT/bazel-$(basename "$SRCROOT")/exte
3232

3333

3434
$BAZEL_INSTALLERS_DIR/index-import \
35+
-incremental \
3536
-remap "$bazel_module=$xcode_module" \
3637
-remap "$bazel_swift_object=$xcode_object" \
3738
-remap "$bazel_objc_object=$xcode_object" \

tests/ios/xcodeproj/Test-Imports-App-Project.xcodeproj/bazelinstallers/_indexstore.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ readonly xcode_external="$BAZEL_WORKSPACE_ROOT/bazel-$(basename "$SRCROOT")/exte
3232

3333

3434
$BAZEL_INSTALLERS_DIR/index-import \
35+
-incremental \
3536
-remap "$bazel_module=$xcode_module" \
3637
-remap "$bazel_swift_object=$xcode_object" \
3738
-remap "$bazel_objc_object=$xcode_object" \

tests/ios/xcodeproj/Test-MultipleConfigs-Project-WithTransitiveFlag.xcodeproj/bazelinstallers/_indexstore.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ readonly xcode_external="$BAZEL_WORKSPACE_ROOT/bazel-$(basename "$SRCROOT")/exte
3232

3333

3434
$BAZEL_INSTALLERS_DIR/index-import \
35+
-incremental \
3536
-remap "$bazel_module=$xcode_module" \
3637
-remap "$bazel_swift_object=$xcode_object" \
3738
-remap "$bazel_objc_object=$xcode_object" \

tests/ios/xcodeproj/Test-MultipleConfigs-Project.xcodeproj/bazelinstallers/_indexstore.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ readonly xcode_external="$BAZEL_WORKSPACE_ROOT/bazel-$(basename "$SRCROOT")/exte
3232

3333

3434
$BAZEL_INSTALLERS_DIR/index-import \
35+
-incremental \
3536
-remap "$bazel_module=$xcode_module" \
3637
-remap "$bazel_swift_object=$xcode_object" \
3738
-remap "$bazel_objc_object=$xcode_object" \

tests/ios/xcodeproj/TestWithHostApp.xcodeproj/bazelinstallers/_indexstore.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ readonly xcode_external="$BAZEL_WORKSPACE_ROOT/bazel-$(basename "$SRCROOT")/exte
3232

3333

3434
$BAZEL_INSTALLERS_DIR/index-import \
35+
-incremental \
3536
-remap "$bazel_module=$xcode_module" \
3637
-remap "$bazel_swift_object=$xcode_object" \
3738
-remap "$bazel_objc_object=$xcode_object" \

tests/macos/xcodeproj/Single-Application-Project-AllTargets.xcodeproj/bazelinstallers/_indexstore.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ readonly xcode_external="$BAZEL_WORKSPACE_ROOT/bazel-$(basename "$SRCROOT")/exte
3232

3333

3434
$BAZEL_INSTALLERS_DIR/index-import \
35+
-incremental \
3536
-remap "$bazel_module=$xcode_module" \
3637
-remap "$bazel_swift_object=$xcode_object" \
3738
-remap "$bazel_objc_object=$xcode_object" \

tests/macos/xcodeproj/Single-Application-Project-DirectTargetsOnly.xcodeproj/bazelinstallers/_indexstore.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ readonly xcode_external="$BAZEL_WORKSPACE_ROOT/bazel-$(basename "$SRCROOT")/exte
3232

3333

3434
$BAZEL_INSTALLERS_DIR/index-import \
35+
-incremental \
3536
-remap "$bazel_module=$xcode_module" \
3637
-remap "$bazel_swift_object=$xcode_object" \
3738
-remap "$bazel_objc_object=$xcode_object" \

tests/macos/xcodeproj/Test-Target-With-Test-Host-Project.xcodeproj/bazelinstallers/_indexstore.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ readonly xcode_external="$BAZEL_WORKSPACE_ROOT/bazel-$(basename "$SRCROOT")/exte
3232

3333

3434
$BAZEL_INSTALLERS_DIR/index-import \
35+
-incremental \
3536
-remap "$bazel_module=$xcode_module" \
3637
-remap "$bazel_swift_object=$xcode_object" \
3738
-remap "$bazel_objc_object=$xcode_object" \

tools/xcodeproj_shims/installers/_indexstore.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ readonly xcode_external="$BAZEL_WORKSPACE_ROOT/bazel-$(basename "$SRCROOT")/exte
3232

3333

3434
$BAZEL_INSTALLERS_DIR/index-import \
35+
-incremental \
3536
-remap "$bazel_module=$xcode_module" \
3637
-remap "$bazel_swift_object=$xcode_object" \
3738
-remap "$bazel_objc_object=$xcode_object" \

0 commit comments

Comments
 (0)