Skip to content

Commit 0ae178d

Browse files
Use --@rules_swift//swift:copt instead of --swiftcopt (#3206)
Old way is no longer supported as of Bazel 8. Signed-off-by: Brentley Jones <[email protected]>
1 parent b80558e commit 0ae178d

File tree

6 files changed

+60
-7
lines changed

6 files changed

+60
-7
lines changed

xcodeproj/internal/bazel_integration_files/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ _BASE_FILES = [
22
"calculate_output_groups.py",
33
"copy_dsyms.sh",
44
"create_lldbinit.sh",
5-
"generate_bazel_dependencies.sh",
65
":renamed_import_indexstores",
76
"process_bazel_build_log.py",
87
]

xcodeproj/internal/bazel_integration_files/actions.bzl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,35 @@ def write_bazel_build_script(
5454
)
5555

5656
return output
57+
58+
def write_generate_bazel_dependencies_script(
59+
*,
60+
actions,
61+
generator_label,
62+
template):
63+
"""Writes the `generate_bazel_dependencies.sh` script.
64+
65+
Args:
66+
actions: `ctx.actions`.
67+
generator_label: The `Label` of the `xcodeproj` generator target.
68+
template: `xcodeproj/internal/templates/generate_bazel_dependencies.sh`.
69+
70+
Returns:
71+
The `File` for `generate_bazel_dependencies.sh`.
72+
"""
73+
output = actions.declare_file(
74+
"{}_bazel_integration_files/generate_bazel_dependencies.sh".format(
75+
generator_label.name,
76+
),
77+
)
78+
79+
actions.expand_template(
80+
template = template,
81+
output = output,
82+
is_executable = True,
83+
substitutions = {
84+
"%swiftcopt%": str(Label("@build_bazel_rules_swift//swift:copt")),
85+
},
86+
)
87+
88+
return output

xcodeproj/internal/bazel_integration_files/generate_bazel_dependencies.sh renamed to xcodeproj/internal/templates/generate_bazel_dependencies.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ if [[ $apply_sanitizers -eq 1 ]]; then
141141
--copt=-fno-sanitize-recover=all
142142
--copt=-fsanitize=address
143143
--linkopt=-fsanitize=address
144-
--swiftcopt=-sanitize=address
144+
--%swiftcopt%=-sanitize=address
145145
--copt=-Wno-macro-redefined
146146
--copt=-D_FORTIFY_SOURCE=0
147147
)
@@ -152,7 +152,7 @@ if [[ $apply_sanitizers -eq 1 ]]; then
152152
--copt=-fno-sanitize-recover=all
153153
--copt=-fsanitize=thread
154154
--linkopt=-fsanitize=thread
155-
--swiftcopt=-sanitize=thread
155+
--%swiftcopt%=-sanitize=thread
156156
)
157157
fi
158158
if [ "${ENABLE_UNDEFINED_BEHAVIOR_SANITIZER:-}" == "YES" ]; then

xcodeproj/internal/templates/xcodeproj.bazelrc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ common:rules_xcodeproj_swiftuipreviews --config=rules_xcodeproj
9494
common:rules_xcodeproj_swiftuipreviews --linkopt="-Wl,-rpath,@loader_path/SwiftUIPreviewsFrameworks"
9595

9696
# `swiftc` flags needed for SwiftUI Previews
97-
common:rules_xcodeproj_swiftuipreviews --swiftcopt=-Xfrontend --swiftcopt=-enable-implicit-dynamic
98-
common:rules_xcodeproj_swiftuipreviews --swiftcopt=-Xfrontend --swiftcopt=-enable-private-imports
99-
common:rules_xcodeproj_swiftuipreviews --swiftcopt=-Xfrontend --swiftcopt=-enable-dynamic-replacement-chaining
97+
common:rules_xcodeproj_swiftuipreviews --%swiftcopt%=-Xfrontend --%swiftcopt%=-enable-implicit-dynamic
98+
common:rules_xcodeproj_swiftuipreviews --%swiftcopt%=-Xfrontend --%swiftcopt%=-enable-private-imports
99+
common:rules_xcodeproj_swiftuipreviews --%swiftcopt%=-Xfrontend --%swiftcopt%=-enable-dynamic-replacement-chaining
100100

101101
### `--config=_rules_xcodeproj_build`
102102
#

xcodeproj/internal/xcodeproj_rule.bzl

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ load("//xcodeproj/internal:pbxproj_partials.bzl", "pbxproj_partials")
66
load(
77
"//xcodeproj/internal/bazel_integration_files:actions.bzl",
88
"write_bazel_build_script",
9+
"write_generate_bazel_dependencies_script",
910
)
1011
load("//xcodeproj/internal/files:input_files.bzl", "input_files")
1112
load("//xcodeproj/internal/files:output_files.bzl", "output_groups")
@@ -227,6 +228,7 @@ def _write_bazel_integration_files(
227228
*,
228229
actions,
229230
bazel_build_script_template,
231+
bazel_dependencies_script_template,
230232
bazel_path,
231233
bazel_env,
232234
colorize,
@@ -246,6 +248,12 @@ def _write_bazel_integration_files(
246248
template = bazel_build_script_template,
247249
)
248250

251+
generate_bazel_dependencies_script = write_generate_bazel_dependencies_script(
252+
actions = actions,
253+
generator_label = label,
254+
template = bazel_dependencies_script_template,
255+
)
256+
249257
swift_debug_settings = xcode_targets_module.write_swift_debug_settings(
250258
actions = actions,
251259
colorize = colorize,
@@ -255,7 +263,11 @@ def _write_bazel_integration_files(
255263
tool = swift_debug_settings_generator,
256264
)
257265

258-
return [bazel_build_script] + swift_debug_settings + static_files
266+
return (
267+
[bazel_build_script, generate_bazel_dependencies_script] +
268+
swift_debug_settings +
269+
static_files
270+
)
259271

260272
def _write_installer(
261273
*,
@@ -724,6 +736,9 @@ Are you using an `alias`? `xcodeproj.focused_targets` and \
724736
bazel_integration_files = _write_bazel_integration_files(
725737
actions = actions,
726738
bazel_build_script_template = ctx.file._bazel_build_script_template,
739+
bazel_dependencies_script_template = (
740+
ctx.file._generate_bazel_dependencies_script_template
741+
),
727742
bazel_path = ctx.attr.bazel_path,
728743
bazel_env = ctx.attr.bazel_env,
729744
colorize = colorize,
@@ -858,6 +873,12 @@ def _xcodeproj_attrs(
858873
),
859874
executable = True,
860875
),
876+
"_generate_bazel_dependencies_script_template": attr.label(
877+
allow_single_file = True,
878+
default = Label(
879+
"//xcodeproj/internal/templates:generate_bazel_dependencies.sh",
880+
),
881+
),
861882
"_index_import": attr.label(
862883
cfg = "exec",
863884
default = Label("@rules_xcodeproj_index_import//:index_import"),

xcodeproj/internal/xcodeproj_runner.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ common:_{config}_build --config={config}
6969
output = output,
7070
substitutions = {
7171
"%project_configs%": project_configs,
72+
"%swiftcopt%": str(Label("@build_bazel_rules_swift//swift:copt")),
7273
},
7374
)
7475

0 commit comments

Comments
 (0)