Skip to content

Commit b65ce61

Browse files
committed
Support index-import on all Xcode 16.x versions
This PR updates the index-import dependency to include both version 5.8 and 6.1 as the hash algorithm changed in Swift 6.1. To make this change backwards compatible we switch to the 5.8 version on Xcode 16.2 and under. Signed-off-by: Luis Padron <heyluispadron@gmail.com>
1 parent a369447 commit b65ce61

File tree

7 files changed

+100
-27
lines changed

7 files changed

+100
-27
lines changed

MODULE.bazel

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ bazel_dep(name = "bazel_features", version = "1.3.0")
1010
bazel_dep(name = "bazel_skylib", version = "1.3.0")
1111
bazel_dep(
1212
name = "rules_swift",
13-
version = "1.18.0",
13+
version = "2.8.0",
1414
max_compatibility_level = 2,
1515
repo_name = "build_bazel_rules_swift",
1616
)
@@ -27,7 +27,8 @@ use_repo(internal, "rules_xcodeproj_generated")
2727
non_module_deps = use_extension("//xcodeproj:extensions.bzl", "non_module_deps")
2828
use_repo(
2929
non_module_deps,
30-
"rules_xcodeproj_index_import",
30+
"rules_xcodeproj_index_import_5_8",
31+
"rules_xcodeproj_index_import_6_1",
3132
)
3233

3334
# Non-release dependencies
@@ -61,11 +62,6 @@ single_version_override(
6162
version = "1.17.1",
6263
)
6364

64-
single_version_override(
65-
module_name = "rules_swift",
66-
version = "2.3.0",
67-
)
68-
6965
# Some of our deps are forcing a new stardoc on us, so pinning for now
7066
single_version_override(
7167
module_name = "stardoc",

tools/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ _XCSCHEMES = [
176176
# targetIdsFile
177177
"bazel-out/darwin_arm64-dbg/bin/external/_main~internal~rules_xcodeproj_generated/generator/tools/xcodeproj/xcodeproj_target_ids",
178178
# indexImport
179-
"bazel-out/darwin_arm64-opt-exec-2B5CBBC6/bin/external/_main~non_module_deps~rules_xcodeproj_index_import/index-import",
179+
"bazel-out/darwin_arm64-opt-exec-2B5CBBC6/bin/external/_main~non_module_deps~rules_xcodeproj_index_import/index-import_5_8",
180180
# resolvedRepositoriesFile
181181
"bazel-out/darwin_arm64-dbg/bin/external/_main~internal~rules_xcodeproj_generated/generator/tools/generators/xcodeproj/xcodeproj_pbxproj_partials/resolved_repositories",
182182
# minimumXcodeVersion

tools/generators/pbxproj_prefix/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ $ pbxproj_prefix \
3636
/tmp/workspace \
3737
bazel-output-base/rules_xcodeproj.noindex/build_output_base/execroot/_main/bazel-out/darwin_arm64-dbg/bin/external/_main~internal~rules_xcodeproj_generated/generator/tools/generators/xcodeproj/xcodeproj_execution_root_file \
3838
bazel-out/darwin_arm64-dbg/bin/external/_main~internal~rules_xcodeproj_generated/generator/tools/generators/xcodeproj/xcodeproj_target_ids \
39-
bazel-out/darwin_arm64-opt-exec-2B5CBBC6/bin/external/_main~non_module_deps~rules_xcodeproj_index_import/index-import \
39+
bazel-out/darwin_arm64-opt-exec-2B5CBBC6/bin/external/_main~non_module_deps~rules_xcodeproj_index_import/index-import_5_8 \
4040
bazel-out/darwin_arm64-dbg/bin/external/_main~internal~rules_xcodeproj_generated/generator/tools/generators/xcodeproj/xcodeproj_pbxproj_partials/resolved_repositories \
4141
14.0 \
4242
Release \
@@ -216,7 +216,7 @@ Here is an example output:
216216
GCC_OPTIMIZATION_LEVEL = 0;
217217
IMPORT_INDEX_BUILD_INDEXSTORES = YES;
218218
INDEX_DATA_STORE_DIR = "$(INDEX_DATA_STORE_DIR)";
219-
INDEX_IMPORT = "$(BAZEL_OUT)/darwin_arm64-opt-exec-2B5CBBC6/bin/external/_main~non_module_deps~rules_xcodeproj_index_import/index-import";
219+
INDEX_IMPORT = "$(BAZEL_OUT)/darwin_arm64-opt-exec-2B5CBBC6/bin/external/_main~non_module_deps~rules_xcodeproj_index_import/index-import_5_8";
220220
INDEX_FORCE_SCRIPT_EXECUTION = YES;
221221
INSTALL_PATH = "$(BAZEL_PACKAGE_BIN_DIR)/$(TARGET_NAME)/bin";
222222
INTERNAL_DIR = "$(PROJECT_FILE_PATH)/rules_xcodeproj";
@@ -276,7 +276,7 @@ Here is an example output:
276276
GCC_OPTIMIZATION_LEVEL = 0;
277277
IMPORT_INDEX_BUILD_INDEXSTORES = YES;
278278
INDEX_DATA_STORE_DIR = "$(INDEX_DATA_STORE_DIR)";
279-
INDEX_IMPORT = "$(BAZEL_OUT)/darwin_arm64-opt-exec-2B5CBBC6/bin/external/_main~non_module_deps~rules_xcodeproj_index_import/index-import";
279+
INDEX_IMPORT = "$(BAZEL_OUT)/darwin_arm64-opt-exec-2B5CBBC6/bin/external/_main~non_module_deps~rules_xcodeproj_index_import/index-import_5_8";
280280
INDEX_FORCE_SCRIPT_EXECUTION = YES;
281281
INSTALL_PATH = "$(BAZEL_PACKAGE_BIN_DIR)/$(TARGET_NAME)/bin";
282282
INTERNAL_DIR = "$(PROJECT_FILE_PATH)/rules_xcodeproj";
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""Utility functions for working with Xcode versions."""
2+
3+
def is_xcode_at_least_version(xcode_config, desired_version):
4+
"""Returns True if the current Xcode version is at least the given version.
5+
6+
Args:
7+
xcode_config: The Xcode version config.
8+
desired_version: The desired version (e.g. "16.3")
9+
10+
Returns:
11+
True if the current Xcode version is at least the given version, False otherwise.
12+
"""
13+
14+
current_version = xcode_config.xcode_version()
15+
if not current_version:
16+
fail("""\
17+
`xcode_version` not foundin `XcodeVersionConfig`.
18+
19+
Please file a bug report here: \
20+
https://github.com/MobileNativeFoundation/rules_xcodeproj/issues/new?template=bug.md"
21+
""")
22+
23+
desired_version_value = apple_common.dotted_version(desired_version)
24+
return current_version >= desired_version_value

xcodeproj/internal/xcodeproj_incremental_rule.bzl

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ load(
3131
load(":incremental_xcode_targets.bzl", xcode_targets_module = "incremental_xcode_targets")
3232
load(":selected_model_versions.bzl", "write_selected_model_versions_file")
3333
load(":target_id.bzl", "write_target_ids_list")
34+
load(":xcode_version_util.bzl", "is_xcode_at_least_version")
3435
load(":xcodeprojinfo.bzl", "XcodeProjInfo")
3536

3637
# Utility
@@ -622,7 +623,6 @@ Are you using an `alias`? `xcodeproj.focused_targets` and \
622623
actions = ctx.actions
623624
colorize = ctx.attr.colorize
624625
config = ctx.attr.config
625-
index_import = ctx.executable._index_import
626626
install_path = ctx.attr.install_path
627627
is_fixture = ctx.attr._is_fixture
628628
name = ctx.attr.name
@@ -635,6 +635,16 @@ Are you using an `alias`? `xcodeproj.focused_targets` and \
635635
ctx.attr.default_xcode_configuration or xcode_configurations[0]
636636
)
637637

638+
# TODO: Remove once we drop support for Xcode 16.x.
639+
# We set a private environment variable when using a version older than Xcode 16.3
640+
# which comes with Swift 6.1 which changes the hash algorithm for the index-import tool.
641+
# When using an older version we switch to the older version of index-import.
642+
xcode_toolchain_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig]
643+
if not is_xcode_at_least_version(xcode_toolchain_config, "16.3"):
644+
index_import = ctx.executable._index_import_5_8
645+
else:
646+
index_import = ctx.executable._index_import_6_1
647+
638648
# Project contents
639649

640650
(
@@ -871,9 +881,17 @@ def _xcodeproj_incremental_attrs(
871881
),
872882
executable = True,
873883
),
874-
"_index_import": attr.label(
884+
# TODO: we must depend on two versions of index-import to support backwards
885+
# compatibility between Xcode 16.3+ and older versions, we can remove the older
886+
# version once we drop support for Xcode 16.x.
887+
"_index_import_5_8": attr.label(
888+
cfg = "exec",
889+
default = Label("@rules_xcodeproj_index_import_5_8//:index_import"),
890+
executable = True,
891+
),
892+
"_index_import_6_1": attr.label(
875893
cfg = "exec",
876-
default = Label("@rules_xcodeproj_index_import//:index_import"),
894+
default = Label("@rules_xcodeproj_index_import_6_1//:index_import"),
877895
executable = True,
878896
),
879897
"_installer_template": attr.label(

xcodeproj/internal/xcodeproj_legacy_rule.bzl

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ load(":platforms.bzl", "platforms")
3535
load(":project_options.bzl", "project_options_to_dto")
3636
load(":resource_target.bzl", "process_resource_bundles")
3737
load(":target_id.bzl", "write_target_ids_list")
38+
load(":xcode_version_util.bzl", "is_xcode_at_least_version")
3839
load(":xcodeprojinfo.bzl", "XcodeProjInfo")
3940

4041
# Utility
@@ -1584,6 +1585,18 @@ configurations: {}""".format(", ".join(xcode_configurations)))
15841585
if s.id in targets
15851586
]
15861587

1588+
# TODO: Remove once we drop support for Xcode 16.x.
1589+
# We set a private environment variable when using a version older than Xcode 16.3
1590+
# which comes with Swift 6.1 which changes the hash algorithm for the index-import tool.
1591+
# When using an older version we switch to the older version of index-import.
1592+
xcode_toolchain_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig]
1593+
if not is_xcode_at_least_version(xcode_toolchain_config, "16.3"):
1594+
index_import = ctx.executable._index_import_5_8
1595+
index_import_files_to_run = ctx.attr._index_import_5_8[DefaultInfo].files_to_run
1596+
else:
1597+
index_import = ctx.executable._index_import_6_1
1598+
index_import_files_to_run = ctx.attr._index_import_6_1[DefaultInfo].files_to_run
1599+
15871600
spec_files = _write_spec(
15881601
actions = actions,
15891602
args = args,
@@ -1592,7 +1605,7 @@ configurations: {}""".format(", ".join(xcode_configurations)))
15921605
envs = envs,
15931606
extra_files = extra_files,
15941607
extra_folders = extra_folders,
1595-
index_import = ctx.executable._index_import,
1608+
index_import = index_import,
15961609
infos = infos,
15971610
is_fixture = is_fixture,
15981611
minimum_xcode_version = minimum_xcode_version,
@@ -1735,7 +1748,7 @@ done
17351748
execution_root_file = execution_root_file,
17361749
extension_point_identifiers_file = extension_point_identifiers_file,
17371750
generator = ctx.attr._generator[DefaultInfo].files_to_run,
1738-
index_import = ctx.attr._index_import[DefaultInfo].files_to_run,
1751+
index_import = index_import_files_to_run,
17391752
install_path = install_path,
17401753
is_fixture = is_fixture,
17411754
name = name,
@@ -1760,7 +1773,7 @@ done
17601773
input_files_output_groups = input_files.to_output_groups_fields(
17611774
inputs = inputs,
17621775
additional_bwx_generated = additional_bwx_generated,
1763-
index_import = ctx.executable._index_import,
1776+
index_import = index_import,
17641777
)
17651778
output_files_output_groups = {}
17661779
all_targets_files = [
@@ -1773,7 +1786,7 @@ done
17731786
output_files_output_groups = output_files.to_output_groups_fields(
17741787
outputs = provider_outputs,
17751788
additional_bwb_outputs = additional_bwb_outputs,
1776-
index_import = ctx.executable._index_import,
1789+
index_import = index_import,
17771790
)
17781791
all_targets_files = [output_files_output_groups["all_b"]]
17791792

@@ -1891,9 +1904,17 @@ def _xcodeproj_legacy_attrs(
18911904
default = Label("//tools/generators/legacy:universal_generator"),
18921905
executable = True,
18931906
),
1894-
"_index_import": attr.label(
1907+
# TODO: we must depend on two versions of index-import to support backwards
1908+
# compatibility between Xcode 16.3+ and older versions, we can remove the older
1909+
# version once we drop support for Xcode 16.x.
1910+
"_index_import_5_8": attr.label(
1911+
cfg = "exec",
1912+
default = Label("@rules_xcodeproj_index_import_5_8//:index_import"),
1913+
executable = True,
1914+
),
1915+
"_index_import_6_1": attr.label(
18951916
cfg = "exec",
1896-
default = Label("@rules_xcodeproj_index_import//:index_import"),
1917+
default = Label("@rules_xcodeproj_index_import_6_1//:index_import"),
18971918
executable = True,
18981919
),
18991920
"_installer_template": attr.label(

xcodeproj/repositories.bzl

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ def xcodeproj_rules_dependencies(
121121
_maybe(
122122
http_archive,
123123
name = "build_bazel_rules_swift",
124-
sha256 = "bb01097c7c7a1407f8ad49a1a0b1960655cf823c26ad2782d0b7d15b323838e2",
125-
url = "https://github.com/bazelbuild/rules_swift/releases/download/1.18.0/rules_swift.1.18.0.tar.gz",
124+
sha256 = "68290c747eab415d924a3e2a8d2d32a4686dd1e0b091a6b4db4892d1bc0e8308",
125+
url = "https://github.com/bazelbuild/rules_swift/releases/download/2.8.0/rules_swift.2.8.0.tar.gz",
126126
ignore_version_differences = ignore_version_differences,
127127
)
128128

@@ -148,10 +148,10 @@ def xcodeproj_rules_dependencies(
148148
# here in order to reuse it, and in case `rules_swift` stops depending on it
149149
# in the future. We don't though, because we need 5.5.3.1 or higher, and the
150150
# current lowest version of rules_swift we support uses 5.3.2.6.
151-
_maybe(
152-
http_archive,
153-
name = "rules_xcodeproj_index_import",
154-
build_file_content = """\
151+
# TODO: we must depend on two versions of index-import to support backwards
152+
# compatibility between Xcode 16.3+ and older versions, we can remove the older
153+
# version once we drop support for Xcode 16.x.
154+
index_import_build_file_content = """\
155155
load("@bazel_skylib//rules:native_binary.bzl", "native_binary")
156156
157157
native_binary(
@@ -160,11 +160,25 @@ native_binary(
160160
out = "index-import",
161161
visibility = ["//visibility:public"],
162162
)
163-
""",
163+
"""
164+
_maybe(
165+
http_archive,
166+
name = "rules_xcodeproj_index_import_5_8",
167+
build_file_content = index_import_build_file_content,
168+
canonical_id = "index-import-5.8",
164169
sha256 = "28c1ffa39d99e74ed70623899b207b41f79214c498c603915aef55972a851a15",
165170
url = "https://github.com/MobileNativeFoundation/index-import/releases/download/5.8.0.1/index-import.tar.gz",
166171
ignore_version_differences = ignore_version_differences,
167172
)
173+
_maybe(
174+
http_archive,
175+
name = "rules_xcodeproj_index_import_6_1",
176+
build_file_content = index_import_build_file_content,
177+
canonical_id = "index-import-6.1",
178+
sha256 = "54d0477526bba0dc1560189dfc4f02d90aea536e9cb329e911f32b2a564b66f1",
179+
url = "https://github.com/MobileNativeFoundation/index-import/releases/download/6.1.0/index-import.tar.gz",
180+
ignore_version_differences = ignore_version_differences,
181+
)
168182

169183
# Source dependencies
170184
_xcodeproj_rules_source_dependencies(ignore_version_differences)

0 commit comments

Comments
 (0)