Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

incompatible_use_cc_configure_from_rules_cc: Use cc_configure from @rules_cc #10134

Open
hlopko opened this issue Oct 30, 2019 · 36 comments
Open
Assignees
Labels
P2 We'll consider working on this in future. (Assignee optional) team-Rules-CPP Issues for C++ rules type: process

Comments

@hlopko
Copy link
Member

hlopko commented Oct 30, 2019

Flag: --incompatible_use_cc_configure_from_rules_cc
Introduced in: 1.2
Will be flipped: not anytime soon AFAIK

Description

We are moving cc_configure, the logic that automatically configures C++ toolchain for the host machine, to @rules_cc.

Migration

TODO

@hlopko hlopko self-assigned this Oct 30, 2019
@hlopko hlopko added P2 We'll consider working on this in future. (Assignee optional) team-Rules-CPP Issues for C++ rules P1 I'll work on this now. (Assignee required) and removed P2 We'll consider working on this in future. (Assignee optional) labels Oct 30, 2019
bazel-io pushed a commit that referenced this issue Nov 11, 2019
…les_cc

Will be used when --incompatible_use_cc_configure_from_rules_cc is implemented.
I'm adding the empty implementation so Bazel release has the symbol so out
internal tests pass when the flag is not flipped.

Progress towards #10134.

PiperOrigin-RevId: 279756806
bazel-io pushed a commit that referenced this issue Nov 12, 2019
This is in preparation for incompatible_use_cc_configure_from_rules_cc (#10134). This PR updates the rules_cc pin in the WORKSPACE file (which also affects which version Bazel bundles in the binary) to get the right files.

Closes #10192.

PiperOrigin-RevId: 279885451
bazel-io pushed a commit that referenced this issue Nov 15, 2019
In this cl only add the flag. Installing the calls to
__do_not_use_fail_with_incompatible_use_cc_configure_from_rules_cc will be done
in a followup cl.

Progress towards #10134.

RELNOTES: None.
PiperOrigin-RevId: 280649623
bazel-io pushed a commit that referenced this issue Nov 15, 2019
…_tools

Progress towards #10134.

RELNOTES: None.
PiperOrigin-RevId: 280654359
@hlopko hlopko added P2 We'll consider working on this in future. (Assignee optional) and removed P1 I'll work on this now. (Assignee required) labels Dec 6, 2019
@smukherj1
Copy link
Contributor

Bazel docs here points to this issue for migration instructions but I don't see any migration instructions here. Any idea when those will be posted?

I encountered this issue in bazelbuild/rules_docker#1354 when attempting to cross compile a Go binary with CGO using rules_go on Linux for Mac.

FYI @jayconrod

freedomtan added a commit to freedomtan/tensorflow that referenced this issue May 6, 2020
make
```
bazel build //tensorflow/tools/pip_package:build_pip_package
````
work again on aarch64 (e.g., EdgeTPU Dev board and Jetson boards)
and arm (e.g, Raspberry Pi 3/4 boards) Linux platforms

without this patch, I saw

```
...
ERROR: While resolving toolchains for target //tensorflow:libtensorflow_framework.so.2.1.0: No matching toolchains found for types @bazel_tools//tools/cpp:toolchain_type. Maybe --incompatible_use_cc_configure_from_rules_cc has been flipped and there is no default C++ toolchain added in the WORKSPACE file? See bazelbuild/bazel#10134 for details and migration instructions.
ERROR: Analysis of target '//tensorflow/tools/pip_package:build_pip_package' failed; build aborted: No matching toolchains found for types @bazel_tools//tools/cpp:toolchain_type. Maybe --incompatible_use_cc_configure_from_rules_cc has been flipped and there is no default C++ toolchain added in the WORKSPACE file? See bazelbuild/bazel#10134 for details and migration instructions.
```
freedomtan added a commit to freedomtan/tensorflow that referenced this issue May 6, 2020
make
```
bazel build //tensorflow/tools/pip_package:build_pip_package
````
work again on aarch64 (e.g., EdgeTPU Dev board and Jetson boards)
and arm (e.g, Raspberry Pi 3/4 boards) Linux platforms

without this patch, I saw

```
...
ERROR: While resolving toolchains for target //tensorflow:libtensorflow_framework.so.2.1.0: No matching toolchains found for types @bazel_tools//tools/cpp:toolchain_type. Maybe --incompatible_use_cc_configure_from_rules_cc has been flipped and there is no default C++ toolchain added in the WORKSPACE file? See bazelbuild/bazel#10134 for details and migration instructions.
ERROR: Analysis of target '//tensorflow/tools/pip_package:build_pip_package' failed; build aborted: No matching toolchains found for types @bazel_tools//tools/cpp:toolchain_type. Maybe --incompatible_use_cc_configure_from_rules_cc has been flipped and there is no default C++ toolchain added in the WORKSPACE file? See bazelbuild/bazel#10134 for details and migration instructions.
```
@meisterT meisterT added untriaged and removed P2 We'll consider working on this in future. (Assignee optional) labels May 12, 2020
@meisterT
Copy link
Member

cc @oquenchil

@oquenchil oquenchil added P3 We're not considering working on this, but happy to review a PR. (No assignee) type: process and removed untriaged labels May 12, 2020
@pcj
Copy link
Member

pcj commented Jul 3, 2020

@hlopko Note the bazel source code refers users to this issue for migration instructions, and as @smukherj1 has pointed out, the migration instructions are still a TODO despite the flag being flipped in 3.0.0.

@oquenchil
Copy link
Contributor

Hi, I'm looking at the code and it seems this wasn't flipped in 3.0.0. The top comment here does say that it will be flipped in 3.0.0 but that did not happen as far as I can tell. Before I update the comment, please let me know if this was really flipped and I'm just not seeing it.

@systemlogic
Copy link

systemlogic commented Sep 20, 2020

Any fix for Mac? On Rhel it works.

Build label: 3.0.0
Build target: bazel-out/darwin-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Mon Apr 6 12:55:48 2020 (1586177748)
Build timestamp: 1586177748
Build timestamp as int: 1586177748
harora37@Harishs-MacBook-Air learn-bazel %      bazel build thirdparty/...
DEBUG: Rule 'com_github_grpc_grpc' indicated that a canonical reproducible form can be obtained by modifying arguments commit = "414bb8322de2411eee1f4e841ff29d887bec7884", shallow_since = "1599598806 -0700" and dropping ["tag"]
DEBUG: Call stack for the definition of repository 'com_github_grpc_grpc' which is a git_repository (rule definition at /private/var/tmp/_bazel_harora37/2a6ebc57f664787b8508faa4e6c82156/external/bazel_tools/tools/build_defs/repo/git.bzl:195:18):
 - <builtin>
 - /Users/harora37/learn-bazel/WORKSPACE:178:1
ERROR: While resolving toolchains for target //thirdparty/bzl/examples/aspect:app: No matching toolchains found for types @bazel_tools//tools/cpp:toolchain_type. Maybe --incompatible_use_cc_configure_from_rules_cc has been flipped and there is no default C++ toolchain added in the WORKSPACE file? See https://github.com/bazelbuild/bazel/issues/10134 for details and migration instructions.
ERROR: Analysis of target '//thirdparty/bzl/examples/aspect:app' failed; build aborted: No matching toolchains found for types @bazel_tools//tools/cpp:toolchain_type. Maybe --incompatible_use_cc_configure_from_rules_cc has been flipped and there is no default C++ toolchain added in the WORKSPACE file? See https://github.com/bazelbuild/bazel/issues/10134 for details and migration instructions.
INFO: Elapsed time: 0.293s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded, 0 targets configured)

please help.
FYI @hlopko @pcj

@oquenchil
Copy link
Contributor

The flag wasn't flipped as far as I can tell nor will it be flipped any time soon.

@oquenchil
Copy link
Contributor

You can ignore this incompatible flag. I believe --all_incompatible_changes will also be removed. @aiuto weren't there plans to do that?

@jwnimmer-tri
Copy link
Contributor

I think the problem is that users have broken their C++ compiler (such that bazel can't find it), and in that case they receive an error message with a hyperlink to this issue, so they assume this is where to find their salvation. It's most likely just a red herring, though.

@cpsauer
Copy link
Contributor

cpsauer commented Jan 14, 2022

For others arriving from the error message and looking to debug:
I eventually found that adding --toolchain_resolution_debug=@bazel_tools//tools/cpp:toolchain_type let me figure out why no toolchains were matching, with very helpful info about why each match had failed.
[Many thanks to whoever built that feature!]


If others landing here find that to be the right next step, maybe we should add it to the error message. Maybe give a 👍🏻 if that's you, so we can gauge usefulness?

@grigoryevandrey
Copy link

If you came here because you trying to build go containers with rules_docker package, add os and arch explicitly to your go_image declaration
go_image( name = "base_image", embed = [":go_default_library"], visibility = ["//visibility:public"], goos = "linux", goarch = "amd64", )

Then you should delete old cache and rebuild

@cpsauer
Copy link
Contributor

cpsauer commented Mar 29, 2022

Hey, all! I tossed up a quick PR (#15135), proposing the changes that it seemed like people wanted above! Andrey's message above brought me back to this issue, and I saw the reacts, above. Would love your help getting it (or an alternative) through!

@kaushik-revefi
Copy link

Any fix for Mac? On Rhel it works.

Build label: 3.0.0
Build target: bazel-out/darwin-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Mon Apr 6 12:55:48 2020 (1586177748)
Build timestamp: 1586177748
Build timestamp as int: 1586177748
harora37@Harishs-MacBook-Air learn-bazel %      bazel build thirdparty/...
DEBUG: Rule 'com_github_grpc_grpc' indicated that a canonical reproducible form can be obtained by modifying arguments commit = "414bb8322de2411eee1f4e841ff29d887bec7884", shallow_since = "1599598806 -0700" and dropping ["tag"]
DEBUG: Call stack for the definition of repository 'com_github_grpc_grpc' which is a git_repository (rule definition at /private/var/tmp/_bazel_harora37/2a6ebc57f664787b8508faa4e6c82156/external/bazel_tools/tools/build_defs/repo/git.bzl:195:18):
 - <builtin>
 - /Users/harora37/learn-bazel/WORKSPACE:178:1
ERROR: While resolving toolchains for target //thirdparty/bzl/examples/aspect:app: No matching toolchains found for types @bazel_tools//tools/cpp:toolchain_type. Maybe --incompatible_use_cc_configure_from_rules_cc has been flipped and there is no default C++ toolchain added in the WORKSPACE file? See https://github.com/bazelbuild/bazel/issues/10134 for details and migration instructions.
ERROR: Analysis of target '//thirdparty/bzl/examples/aspect:app' failed; build aborted: No matching toolchains found for types @bazel_tools//tools/cpp:toolchain_type. Maybe --incompatible_use_cc_configure_from_rules_cc has been flipped and there is no default C++ toolchain added in the WORKSPACE file? See https://github.com/bazelbuild/bazel/issues/10134 for details and migration instructions.
INFO: Elapsed time: 0.293s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded, 0 targets configured)

please help. FYI @hlopko @pcj

Hi @systemlogic,

where you able to solve this issue? I am seeing similar issue with M1.

@gillesmag
Copy link

For anyone running into this issue on an Apple Silicon machine. Here is how I managed to solve it.

WORKSPACE

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# Go (necessary to avoid issue described in this thread)

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "io_bazel_rules_go",
    sha256 = "16e9fca53ed6bd4ff4ad76facc9b7b651a89db1689a2877d6fd7b82aa824e366",
    urls = [
        "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.34.0/rules_go-v0.34.0.zip",
        "https://github.com/bazelbuild/rules_go/releases/download/v0.34.0/rules_go-v0.34.0.zip",
    ],
)

load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")

go_rules_dependencies()

go_register_toolchains(version = "1.18.3")

# Docker (setup as described in rules_docker repo example)

http_archive(
    name = "io_bazel_rules_docker",
    sha256 = "b1e80761a8a8243d03ebca8845e9cc1ba6c82ce7c5179ce2b295cd36f7e394bf",
    urls = ["https://github.com/bazelbuild/rules_docker/releases/download/v0.25.0/rules_docker-v0.25.0.tar.gz"],
)

load(
    "@io_bazel_rules_docker//repositories:repositories.bzl",
    container_repositories = "repositories",
)
container_repositories()

load("@io_bazel_rules_docker//repositories:deps.bzl", container_deps = "deps")

container_deps()

load("@io_bazel_rules_docker//container:container.bzl", "container_pull")

container_pull(
    name = "alpine_linux_arm64",
    digest = "sha256:9b2a28eb47540823042a2ba401386845089bb7b62a9637d55816132c4c3c36eb",
    registry = "index.docker.io",
    repository = "library/alpine",
    # tag field is ignored since digest is set
    tag = "latest",
)

BUILD file example

load("@io_bazel_rules_docker//container:container.bzl", "container_image")

container_image(
    name = "basic_alpine",
    base = "@alpine_linux_arm64//image",
    cmd = ["Hello World!"],
    entrypoint = ["echo"],
)

@harsh04
Copy link

harsh04 commented Jul 28, 2022

This helped solve the issue with go. But now it has spawned another issue with
No matching toolchains found for types @bazel_tools//tools/cpp:toolchain_type.

@stabai
Copy link

stabai commented Aug 12, 2022

rules_go v0.34.0 gave me the error mentioned by harsh, but v0.33.0 worked fine. I've filed bazel-contrib/rules_go#3269 in that repository. However, based on the age of this issue, I'm guessing that some people may have been facing a different root cause.

@rajhlinux
Copy link

I'm getting this error on FreeBSD 13.1 to run "hello world" C++ example:

ERROR: /usr/home/user/.cache/bazel/_bazel_user/dce2e5f5daa25516313b94e75e515765/external/com_google_protobuf/BUILD:515:10: While resolving toolchains for target @com_google_protobuf//:protoc: No matching toolchains found for types @bazel_tools//tools/cpp:toolchain_type. Maybe --incompatible_use_cc_configure_from_rules_cc has been flipped and there is no default C++ toolchain added in the WORKSPACE file? See https://github.com/bazelbuild/bazel/issues/10134 for details and migration instructions.

What is causing the issue?

Thanks.

@stabai
Copy link

stabai commented Sep 12, 2022

Unfortunately, it seems like there are a number of possible root causes for this error. The first thing I would try is to make sure common build tools are installed on your system (e.g. gcc, g++). If I'm not mistaken, Bazel doesn't come packaged with these and relies on them being present in the host environment.

@abhillman
Copy link

Here's a very simple repo on Mac OS X:

WORKSPACE

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "io_bazel_rules_docker",
    sha256 = "b1e80761a8a8243d03ebca8845e9cc1ba6c82ce7c5179ce2b295cd36f7e394bf",
    urls = ["https://github.com/bazelbuild/rules_docker/releases/download/v0.25.0/rules_docker-v0.25.0.tar.gz"],
)

load(
    "@io_bazel_rules_docker//repositories:repositories.bzl",
    container_repositories = "repositories",
)

container_repositories()

load("@io_bazel_rules_docker//repositories:deps.bzl", container_deps = "deps")

container_deps()

BUILD

java_binary(
    name = "hello-world",
    srcs = ["src/fun/aryeh/HelloWorld.java"],
    main_class = "fun.aryeh.HelloWorld",
)

src/fun/aryeh/HelloWorld.java

package fun.aryeh;

class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello!");
    }
}

Error

ahillman@MacBook-Air-3 docker-rule-sh % bazel run //:hello-world
ERROR: /Users/ahillman/Development/docker-rule-sh/BUILD:8:12: While resolving toolchains for target //:hello-world: No matching toolchains found for types @bazel_tools//tools/cpp:toolchain_type. Maybe --incompatible_use_cc_configure_from_rules_cc has been flipped and there is no default C++ toolchain added in the WORKSPACE file? See https://github.com/bazelbuild/bazel/issues/10134 for details and migration instructions.
ERROR: Analysis of target '//:hello-world' failed; build aborted: 
INFO: Elapsed time: 0.097s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (1 packages loaded, 1 target configured)
FAILED: Build did NOT complete successfully (1 packages loaded, 1 target configured)

@rockwotj
Copy link
Contributor

rockwotj commented Nov 21, 2022

If you come to this issue because of trying to build a docker image for language that doesn't have platform specific builds from a non Linux machine (IE java, python, etc) you should add build --@io_bazel_rules_docker//transitions:enable=false to your bazelrc to work around this.

@abhillman I believe this is what you're running into.

@sasha-tkachev
Copy link

sasha-tkachev commented Dec 1, 2022

I solved this issue by registering zig toolchains inspired by this

Under WORKSPACE:

# Setup a CC toolchain using bazel-zig-cc
# https://git.sr.ht/~motiejus/bazel-zig-cc
BAZEL_ZIG_CC_VERSION = "v0.7.3"

http_archive(
    name = "bazel-zig-cc",
    sha256 = "cd2629843fe4ba20cf29e1d73cc02559afba640f884e519b6a194a35627cbbf3",
    strip_prefix = "bazel-zig-cc-{}".format(BAZEL_ZIG_CC_VERSION),
    urls = ["https://git.sr.ht/~motiejus/bazel-zig-cc/archive/{}.tar.gz".format(BAZEL_ZIG_CC_VERSION)],
)

load(
    "@bazel-zig-cc//toolchain:defs.bzl",
    "URL_FORMAT_JAKSTYS",
    "URL_FORMAT_NIGHTLY",
    zig_toolchains = "toolchains",
)

zig_version = "0.10.0-dev.2156+458943e32"

zig_host_platform_sha256 = {
    "linux-aarch64": "43e55632c61833a598aff3dcb134a7967c19eddc6abd28273bb60585bbbf34af",
    "linux-x86_64": "c22f4453ac45256d865defad05bfe0e42c6b73f15dc007e87fdae42f44933485",
    "macos-aarch64": "f786a0d6674f9ec267eb1715de1b6265faedfdfdc7d4d05dedc534644e12224d",
    "macos-x86_64": "7dffe1c995da9145872ae806d770cd2acc38993d3d32aabdece7107177853730",
}

zig_toolchains(
    host_platform_sha256 = zig_host_platform_sha256,
    url_formats = [
        URL_FORMAT_NIGHTLY,
        URL_FORMAT_JAKSTYS,
    ],
    version = zig_version,
)

register_toolchains(
    "@zig_sdk//toolchain:linux_amd64_gnu.2.19",
    "@zig_sdk//toolchain:linux_arm64_gnu.2.28",
    "@zig_sdk//toolchain:darwin_amd64",
    "@zig_sdk//toolchain:darwin_arm64",
)

flyingsilverfin pushed a commit to typedb/typedb that referenced this issue Feb 8, 2023
## What is the goal of this PR?

We downgrade `rules_go` from `0.35.0` to `0.34.0` (in `@vaticle_dependencies`), fixing an issue in C++ toolchain resolution on Apple Silicon. 

## What are the changes implemented in this PR?

`bazel build //...` would fail on Apple Silicon with an error resolving the Go toolchain (for use in `rules_docker`). We tried deleting `rules_go`, which seemed reasonable given we don't use Go anywhere, but this caused a different error in C++ toolchain resolution. (We believe `rules_docker` uses Go for cross-compilation of images.)

The exact cause of this issue remains unclear, but proves quite straightforward to fix: we downgrade `rules_go` from `0.35.0` to `0.34.0` in `@vaticle_dependencies`, following advice from bazelbuild/bazel#10134 (comment) , quoted below: 

For anyone running into this issue on an Apple Silicon machine. Here is how I managed to solve it.

`WORKSPACE`
```bzl
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# Go (necessary to avoid issue described in this thread)

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
    name = "io_bazel_rules_go",
    sha256 = "16e9fca53ed6bd4ff4ad76facc9b7b651a89db1689a2877d6fd7b82aa824e366",
    urls = [
        "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.34.0/rules_go-v0.34.0.zip",
        "https://github.com/bazelbuild/rules_go/releases/download/v0.34.0/rules_go-v0.34.0.zip",
    ],
)

load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")

go_rules_dependencies()

go_register_toolchains(version = "1.18.3")

# Docker (setup as described in rules_docker repo example)

http_archive(
    name = "io_bazel_rules_docker",
    sha256 = "b1e80761a8a8243d03ebca8845e9cc1ba6c82ce7c5179ce2b295cd36f7e394bf",
    urls = ["https://github.com/bazelbuild/rules_docker/releases/download/v0.25.0/rules_docker-v0.25.0.tar.gz"],
)
```

_Originally posted by @gillesmag in bazelbuild/bazel#10134 (comment)
            

This is definitely a workaround more than an actual fix, but it works and is consistent and predictable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 We'll consider working on this in future. (Assignee optional) team-Rules-CPP Issues for C++ rules type: process
Projects
None yet
Development

No branches or pull requests