Error index out of range for rules_swift with Bazel@HEAD
sgowroji opened this issue · comments
Platform : rules_swift (Current LTS with Head Deps on :mac: (OpenJDK 11, Xcode))
Logs:
ERROR: /private/var/tmp/_bazel_buildkite/3008726644da67aac23702de50cd23cf/external/build_bazel_rules_swift_local_config/BUILD:9:22: in xcode_swift_toolchain rule @build_bazel_rules_swift_local_config//:toolchain:
Traceback (most recent call last):
File "/Users/buildkite/builds/bk-imacpro-4/bazel-downstream-projects/rules_swift/swift/internal/xcode_swift_toolchain.bzl", line 549, column 29, in _xcode_swift_toolchain_impl
target_triples.parse(cc_toolchain.target_gnu_system_name),
File "/Users/buildkite/builds/bk-imacpro-4/bazel-downstream-projects/rules_swift/swift/internal/target_triples.bzl", line 135, column 28, in _parse
vendor = components[1],
Error: index out of range (index is 1, but sequence has 1 elements)
(04:38:04) ERROR: /private/var/tmp/_bazel_buildkite/3008726644da67aac23702de50cd23cf/external/build_bazel_rules_swift_local_config/BUILD:9:22: Analysis of target '@build_bazel_rules_swift_local_config//:toolchain' failed
(04:38:04) ERROR: Analysis of target '//examples/xplatform/grpc:echo_client_test_stubs_swift' failed; build aborted: Analysis failed
(04:38:04) INFO: Elapsed time: 10.181s
(04:38:04) INFO: 0 processes.
(04:38:04) ERROR: Build did NOT complete successfully
Steps:
git clone https://github.com/bazelbuild/rules_swift.git
git reset 22b7ffa244af5f0fa7f65c0a07cd4b83114f6ede --hard
export USE_BAZEL_VERSION=f3aafea59ae021c6a12086cb2cd34c5fa782faf1
bazel build //examples/...
Culprit : bazelbuild/bazel@534e6f8
CC Greenteam @Wyverald
I'm looking into this, I think I have a lead.
I saw this with a different issue. I don't see this locally. Is it still an issue? Looks green now: https://buildkite.com/bazel/bazel-at-head-plus-downstream/builds/3396#018b4087-e481-4b37-b632-42995ca5ca3c
This issue is still happening on my machine for a simple hello-world program.
Environment
- MacBook Pro with M1 Pro
- macOS Sonoma 14.2.1
- Bazel 7.0.0
- Xcode 15.2 (15C500b)
Error message
❯ bazel run :hello
ERROR: /private/var/tmp/_bazel_luangong/9bd49df8365c9c5c2df81d4fe23576da/external/rules_swift~1.14.0~non_module_deps~build_bazel_rules_swift_local_config/BUILD:9:22: in xcode_swift_toolchain rule @@rules_swift~1.14.0~non_module_deps~build_bazel_rules_swift_local_config//:toolchain:
Traceback (most recent call last):
File "/private/var/tmp/_bazel_luangong/9bd49df8365c9c5c2df81d4fe23576da/external/rules_swift~1.14.0/swift/internal/xcode_swift_toolchain.bzl", line 558, column 29, in _xcode_swift_toolchain_impl
target_triples.parse(cc_toolchain.target_gnu_system_name),
File "/private/var/tmp/_bazel_luangong/9bd49df8365c9c5c2df81d4fe23576da/external/rules_swift~1.14.0/swift/internal/target_triples.bzl", line 135, column 28, in _parse
vendor = components[1],
Error: index out of range (index is 1, but sequence has 1 elements)
ERROR: /private/var/tmp/_bazel_luangong/9bd49df8365c9c5c2df81d4fe23576da/external/rules_swift~1.14.0~non_module_deps~build_bazel_rules_swift_local_config/BUILD:9:22: Analysis of target '@@rules_swift~1.14.0~non_module_deps~build_bazel_rules_swift_local_config//:toolchain' failed
ERROR: Analysis of target '//:hello' failed; build aborted: Analysis failed
INFO: Elapsed time: 0.404s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
ERROR: Build did NOT complete successfully
ERROR: Build failed. Not running target
Directory structure
swift-example
├── BUILD.bazel
├── MODULE.bazel
├── MODULE.bazel.lock
└── hello.swift
Contents of MODULE.bazel
module(name = "swift_example")
bazel_dep(name = "rules_swift", version = "1.14.0")
Contents of BUILD.bazel
load("@rules_swift//swift:swift.bzl", "swift_binary")
swift_binary(
name = "hello",
srcs = ["hello.swift"],
)
Contents of hello.swift
print("Hello from Swift!")
The fix here is to include apple_support in your MODULE.bazel as well, so that its toolchain takes precedence over the default toolchain
bazel_dep(name = "apple_support", version = "1.11.1", repo_name = "build_bazel_apple_support")
The fix here is to include apple_support in your MODULE.bazel as well, so that its toolchain takes precedence over the default toolchain
bazel_dep(name = "apple_support", version = "1.11.1", repo_name = "build_bazel_apple_support")
It works! I didn’t know apple_support
existed. And it also fixes issues I encountered when building C++ code with Bazel! Thank you @keith!