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

0.19.1: @bazel_tools//tools/cpp:cc-compiler-local-k8' is not a cc_toolchain rule #6662

Closed
scottmin0r opened this issue Nov 12, 2018 · 16 comments
Assignees
Labels
P0 This is an emergency and more important than other current work. (Assignee required) team-Rules-CPP Issues for C++ rules type: bug

Comments

@scottmin0r
Copy link

Description of the problem / feature request:

C++ builds fail with:

ERROR: The label '@bazel_tools//tools/cpp:cc-compiler-local-k8' is not a cc_toolchain rule

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

On Linux/amd64, in an otherwise empty workspace with an empty WORKSPACE file, run:

bazel build --crosstool_top=@bazel_tools//tools/cpp:default-toolchain //...

What operating system are you running Bazel on?

Linux (Debian variant)

What's the output of bazel info release?

release 0.19.1

Have you found anything relevant by searching the web?

In the file https://github.com/bazelbuild/bazel/blob/0.19.1/tools/cpp/BUILD:

On the 0.19.0 tag, this line refers to cc-compiler-local, a cc_toolchain rule that exists.

On the 0.19.1 tag, this line refers to cc-compiler-local-k8, a cc_toolchain rule that does not exist.

This appears to be the cause of the issue, although I am not sure why this was changed.

@katre katre added type: bug P0 This is an emergency and more important than other current work. (Assignee required) team-Rules-CPP Issues for C++ rules labels Nov 12, 2018
@katre
Copy link
Member

katre commented Nov 12, 2018

You're right about the cause, I'm not sure what those changed lines are about. Adding @mhlopko and @lberki to try and help figure it out.

@nlopezgi
Copy link
Contributor

#6665 might be related. Perhaps this is also due to 6bc4528 not being included in 0.19.1

@gelrom
Copy link

gelrom commented Nov 13, 2018

Could the following output have the same underlying cause?
...in cc_toolchain rule @local_config_cc//:cc-compiler-k8: Error while selecting cc_toolchain: Toolchain identifier 'local' was not found, valid identifiers are...
This break occurs at 0.19.1. I've been unable to determine if it also occurs at 0.19, but 0.18 was definitely working. Note that this still breaks even if all backward breaking flags that were flipped in 0.19 are set to false.

edit: If this is irrelevant, I can delete this comment and file a separate issue.

@scentini
Copy link
Contributor

@gelrom can you share the build command? Seems close enough, but not quite the same.

@scentini
Copy link
Contributor

@gelrom also, could you please provide the list of valid identifiers in the error message?

@scentini
Copy link
Contributor

@scottminor-google, we've confirmed that @bazel_tools//tools/cpp:default-toolchain is in error.
Why do you need to set --crosstool_top=@bazel_tools//tools/cpp:default-toolchain ? I'm trying to determine the scope of the issue.
Thanks.

@gelrom
Copy link

gelrom commented Nov 13, 2018

@scentini bazel build --crosstool_top=//lib/bazel:toolchain //...
the list of identifiers is of each of our toolchain's toolchain_identifier

@scottmin0r
Copy link
Author

We have a long-ish bazelrc that is explicit about each crosstool_top and host_crosstool_top that is used for each config that we define, to keep the toolchain selection as obvious and understandable as possible. default-toolchain is what we use mostly for host_crosstool_top (although that will change shortly, as we don't want to rely on a user-installed toolchain in any part of the build by default).

Is there a different spelling for the same behavior/toolchain as default-toolchain that works in 0.19.1 and is backwards-compatible to at least 0.18.0 that we should be using instead?

katre added a commit that referenced this issue Nov 13, 2018
…ain_suite.

Fixes #6662.
Closes #6663.

PiperOrigin-RevId: 221271701
@scottmin0r
Copy link
Author

Thanks for the fix! I rebuilt bazel from 94d51fc to test/verify this fix against our codebase. Unfortunately, I'm running into another error:

ERROR: /usr/local/google/home/minors/.cache/bazel/_bazel_minors/32b2ee46dce03a213358bafd92f1c3ce/external/local_config_cc/BUILD:57:1: in cc_toolchain rule @local_config_cc//:cc-compiler-k8: Error while selecting cc_toolchain: Toolchain identifier 'local' was not found, valid identifiers are [stub_armeabi-v7a, local_linux, local_darwin, local_freebsd, local_windows_mingw, local_windows_msys64_mingw64, local_windows_clang, local_windows_msys64, vc_14_0_x64]
ERROR: Analysis of target '//:hello_world' failed; build aborted: Analysis of target '@local_config_cc//:cc-compiler-k8' failed; build aborted

This is reproduced in a workspace with:

  • an empty WORKSPACE file
  • //hello_world.cpp:
    #include <iostream>
    
    int main() {
      std::cout << "Hello, world!" << std::endl;
      return 0;
    }
    
  • //BUILD:
    cc_binary(
        name = "hello_world",
        srcs = ["hello_world.cpp"],
    )
    

Bazel builds successfully when doing:

bazel build //...

but fails with the above error when specifying default-toolchain:

bazel build //... --crosstool_top=@bazel_tools//tools/cpp:default-toolchain

@scottmin0r
Copy link
Author

In our codebase, the error is a little different - it still complains about @local_config_cc//:cc-compiler-k8, but the available toolchain identifiers is one element - the toolchain_identifier specified in our custom CROSSTOOL. I have no idea why that would be interacting with @local_config_cc (or even what that is supposed to be).

Is there anything I can read up on to better understand C/C++ toolchain resolution and what best practices are? I feel woefully uneducated when it comes to this area of Bazel.

@wjywbs
Copy link
Contributor

wjywbs commented Nov 14, 2018

I'm encountering an issue similar to this. I took some time to make a minimal repro in https://github.com/wjywbs/bazel-cc-toolchain-bug, and posted the outputs of bazel 0.18.1, 0.19.0 and 0.19.1 in there.

@scentini
Copy link
Contributor

Thanks for the repro, looking into it.

@katre katre reopened this Nov 14, 2018
katre added a commit to katre/bazel that referenced this issue Nov 14, 2018
Part of bazelbuild#6662.

RELNOTES: cc_toolchains from @local_config_cc are not longer
automatically registered for toolchain resolution. If you need this,
add "register_toolchains('@local_config_cc//:all')" to your WORKSPACE.
@katre
Copy link
Member

katre commented Nov 14, 2018

It looks like cherrypicking 683c302 will fix this (but, it changes how crosstool_top is selected). @scottminor-google, can you add that cherrypick on top of the existing release-0.19.2 branch and let me know if it works?

katre added a commit that referenced this issue Nov 14, 2018
…ain_suite.

Fixes #6662.
Closes #6663.

PiperOrigin-RevId: 221271701
@katre
Copy link
Member

katre commented Nov 14, 2018

I've pushed the cherrypick into the RC, please let me know if there are still issues.

@scottmin0r
Copy link
Author

I built bazel from f2be11dda2 and it successfully builds a C++ target from our codebase with no additional flags. Thanks for the fix!

@katre
Copy link
Member

katre commented Nov 19, 2018

Closing since 0.19.2 will be released shortly.

@katre katre closed this as completed Nov 19, 2018
bazel-io pushed a commit that referenced this issue Nov 19, 2018
Baseline: ac88041

Cherry picks:

   + 9bc3b20:
     Fix the "nojava" platform and enable full presubmit checks for
     the various JDK platforms now that we have enough GCE resources.
   + 54c2572:
     Add openjdk_linux_archive java_toolchain for nojava platform.
   + 20bfdc6:
     Automated rollback of commit
     19a401c.
   + 914b4ce:
     Windows: Fix Precondition check for addDynamicInputLinkOptions
   + 83d406b:
     Windows, test-setup.sh: Setting RUNFILES_MANIFEST_FILE only when
     it exists.
   + e025726:
     Update turbine
   + 5f312dd:
     Fix event id for action_completed BEP events
   + f0c844c:
     Release 0.19.0 (2018-10-29)
   + c3fb1db:
     Do not use CROSSTOOL to select cc_toolchain
   + 8e28083:
     Windows Add tests for msys gcc toolchain and mingw gcc toolchain
   + fd52341:
     update bazel-toolchains pin to latest release Part of changes to
     allow bazelci to use 0.19.0 configs. RBE toolchain configs at or
     before 0.17.0 are not compatible with bazel 0.19.0 or above.
   + eb2af0f:
     Release 0.19.1 (2018-11-12)
   + 6bc4528:
     Also update cc_toolchain.toolchain_identifier when
     CC_TOOLCHAIN_NAME is set
   + f7e5aef:
     Add cc_toolchain targets for the new entries in the default
     cc_toolchain_suite.
   + 683c302:
     Read the CROSSTOOL from the package of the current cc_toolchain,
     not from --crosstool_top

- Fixes regression #6662, by fixing tools/cpp/BUILD
- Fixes regression #6665, by setting the toolchain identifier.
- CROSSTOOL file is now read from the package of cc_toolchain, not from the
  package of cc_toolchain_suite. This is not expected to break anybody since
  cc_toolchain_suite and cc_toolchain are commonly in the same package.
dslomov pushed a commit that referenced this issue Nov 26, 2018
…ain_suite.

Fixes #6662.
Closes #6663.

PiperOrigin-RevId: 221271701
dslomov pushed a commit that referenced this issue Nov 28, 2018
…ain_suite.

Fixes #6662.
Closes #6663.

PiperOrigin-RevId: 221271701
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P0 This is an emergency and more important than other current work. (Assignee required) team-Rules-CPP Issues for C++ rules type: bug
Projects
None yet
Development

No branches or pull requests

9 participants