Skip to content

C++ Toolchain configuration on macOS does not allow cross compiling to another arch any more #21768

@redsun82

Description

@redsun82

Description of the bug:

Starting from bazel version 7 the autodetected C++ toolchain seems to have lost arch cross compiling capabilities (i.e. compile for x86_64 when running on M1 arm64).

Which category does this issue belong to?

C++ Rules

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

As an example, the //swift/extractor target in https://github.com/github/codeql can only target x86_64. With bazel 6.4, I was able to compile that (and run it through rosetta) providing --cpu=darwin_x86_64. With bazel 7.0.1 and 7.1.0 that does not work any more, failing at linking, where -arch arm64 is passed.

Which operating system are you running Bazel on?

macOS 13.4.1 (arm64)

What is the output of bazel info release?

release 7.1.0

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse HEAD ?

No response

Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.

Yes, this is a regression. I tried bazelisk --bisect=6.4.0..7.1.0 and it pointed at b5db379, but I think it's a spurious result (the failures bisect were encountering seemed unrelated)

Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

In bazel 6.4.0, external/local_config_cc_toolchains/BUILD is a symlink to embedded_tools/tools/osx/crosstool/BUILD.toolchains and contains toolchains for all sorts of macOS targets:

load("@bazel_tools//tools/osx/crosstool:osx_archs.bzl", "OSX_TOOLS_ARCHS")

package(default_visibility = ["//visibility:public"])

exports_files(["osx_archs.bzl"])

# Target constraints for each arch.
# TODO(apple-rules): Rename osx constraint to macOS.
OSX_TOOLS_CONSTRAINTS = {
    "armeabi-v7a": [
        "@platforms//cpu:armv7",
        "@platforms//os:android",
    ],
    "darwin_arm64": [
        "@platforms//os:osx",
        "@platforms//cpu:arm64",
    ],
    "darwin_arm64e": [
        "@platforms//os:osx",
        "@platforms//cpu:arm64",
    ],
    "darwin_x86_64": [
        "@platforms//os:osx",
        "@platforms//cpu:x86_64",
    ],
    ...
}

OSX_DEVELOPER_PLATFORM_CPUS = [
    "arm64",
    "x86_64",
]

[
    toolchain(
        name = "cc-toolchain-" + arch + "-" + cpu,
        exec_compatible_with = [
            # These only execute on macOS.
            "@platforms//os:osx",
            "@platforms//cpu:" + cpu,
        ],
        target_compatible_with = OSX_TOOLS_CONSTRAINTS[arch],
        toolchain = "@local_config_cc//:cc-compiler-" + arch,
        toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
    )
    for arch in OSX_TOOLS_ARCHS + ["armeabi-v7a"]
    for cpu in OSX_DEVELOPER_PLATFORM_CPUS
]

In 7.1.0, I found this instead:

toolchain(
    name = "cc-toolchain-darwin_arm64",
    exec_compatible_with = HOST_CONSTRAINTS,
    target_compatible_with = HOST_CONSTRAINTS,
    toolchain = "@local_config_cc//:cc-compiler-darwin_arm64",
    toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)

toolchain(
    name = "cc-toolchain-armeabi-v7a",
    exec_compatible_with = HOST_CONSTRAINTS,
    target_compatible_with = [
        "@platforms//cpu:armv7",
        "@platforms//os:android",
    ],
    toolchain = "@local_config_cc//:cc-compiler-armeabi-v7a",
    toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy