bazelbuild / bazel-toolchains

Repository that hosts Bazel toolchain configs for remote execution and related support tools.
Apache License 2.0
186 stars 96 forks source link

rbe_configs_gen: confusing error when custom container contains .bazelrc #978

Open notnarb opened 2 years ago

notnarb commented 2 years ago

Disclaimer: I understand this may be an invalid use case and I am using the tool tool incorrectly 🙃

Background:

My team needs to produce native CPP build for CentOS and CentOS 7 has an older version of glibc so we are using a CentOS-based custom container[1].

I thought I would be clever and define a custom platform within my sandbox container and included a build --host_platform //toolchain:centos in the bazelrc of our container allowing us to use constraints to prevent someone from accidentally building e.g. an RPM on Ubuntu.

Issue

Fast forward to an investigation into using RBE and I got a confusing error when running rbe_configs_gen

ERROR: While resolving toolchains for target @local_config_cc//:cc-compiler-k8: com.google.devtools.build.lib.packages.BuildFileNotFoundException: no such package 'toolchain': BUILD file not found in any of the following directories. Add a BUILD file to a directory to mark it as a package.
 - /workdir/cpp_configs_project/toolchain
ERROR: Analysis of target '@local_config_cc//:cc-compiler-k8' failed; build aborted: com.google.devtools.build.lib.packages.BuildFileNotFoundException: no such package 'toolchain': BUILD file not found in any of the following directories. Add a BUILD file to a directory to mark it as a package.
 - /workdir/cpp_configs_project/toolchain

@local_config_cc// wha? is Bazel somehow broken?

I now now realize this was due to Bazel reading the .bazelrc defined in the container and this is admittedly self-inflicted but it took me quite a while to figure this out. Removing the .bazelrc file from our container solves the problem.

Suggested Solutions

1) Do nothing, hopefully anyone who runs into this issue finds this issue by the keywords I included in this issue

1) add --bazelrc=/dev/null to the bazel commands run by rbe_configs_gen

I think doing nothing is a perfectly acceptable solution, my main reason for raising this issue is making it searchable in case anyone makes the same mistake in the future.


[1] Maybe we would be better served by extending an existing ubuntu rbe base image and installing the desired version of GCC but for now we are exploring making a custom container based on CentOS to try to closely match the target environment.