Skip to content

Toolchain auto config error on Windows: name 'arch' is not defined #1614

@stephen-ryan-ansys

Description

@stephen-ryan-ansys

With Bazel 8.4.2, I am trying to add Windows support to an existing Linux C++ project that uses gRPC v1.76.0 as a direct dependency, and therefore rules_swift v3.1.2 as a transitive dependency, and I am getting the Bazel error when compiling my project on Windows x86_64:

ERROR: C:/users/xxxx/_bazel_xxxx/ls3vyc3v/external/rules_swift++non_module_deps+build_bazel_rules_swift_local_config/BUILD:54:58: name 'arch' is not defined
ERROR: package contains errors: : name 'arch' is not defined

My code does not use rules_swift directly, nor do I have any Swift source files.

I see that in the file swift/internal/swift_autoconfiguration.bzl, in the configuration of the windows-swift-toolchain-x86_64, there is a line with target_compatible_with = APPLE_PLATFORMS_CONSTRAINTS[arch]. In other toolchain configs in the file, there seems to be a list comprehension where the arch variable is defined (e.g., for arch in APPLE_PLATFORMS_CONSTRAINTS.keys() ) that is missing for the Windows toolchain. There does not seem to be a suitable value for APPLE_PLATFORMS_CONSTRAINTS for Windows in the configs/platforms.bzl file in the apple_support repo, so I am not sure if this is the correct thing to do here.

I was able to work around the error for my project by adding the following patch file:

diff --git a/swift/internal/swift_autoconfiguration.bzl b/swift/internal/swift_autoconfiguration.bzl
index 46f1f37..27a9965 100644
--- a/swift/internal/swift_autoconfiguration.bzl
+++ b/swift/internal/swift_autoconfiguration.bzl
@@ -364,7 +364,7 @@ toolchain(
         "@platforms//os:windows",
         "@platforms//cpu:x86_64",
     ],
-    target_compatible_with = APPLE_PLATFORMS_CONSTRAINTS[arch],
+    target_compatible_with = [],
     toolchain = ":windows-toolchain",
     toolchain_type = "{toolchain_type}",
     visibility = ["//visibility:public"],

and then using a single_version_override:

single_version_override(
    module_name = "rules_swift",
    version = "3.1.2",
    patches = ["//:fix_missing_arch_definition.patch"],
    patch_strip = 1,
)

Since I am not using Swift directly, I am not quite sure what actually needs to be done here to fix the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions