We are seeing duplicate builds of the same target in Bazel and wondering what could cause this.
Here is a sample output:
[52,715 / 55,135] 12 action running Bazel package: some-pkg - Target: a_target - Generating files at bazel-out/host/bin/some-pkg/a_target_generate [for host]; 264s remote-cache, processwrapper-sandbox Bazel package: some-pkg - Target: a_target - Generating files at bazel-out/k8-fastbuild/bin/some-pkg/a_target_generate; 264s remote-cache, processwrapper-sandbox ... We have not been able to identify the issue. It looks like this is only happening on Linux but not on Macs.
The target a_target is a custom_rule target. It should be platform independent.
custom_rule = rule( attrs = dict( ... _custom_rule_java_binary = attr.label( cfg = "host", default = Label("//tools/bazel/build/rules/custom-rule:custom_rule_bin"), executable = True, ), _singlejar = attr.label( cfg = "host", default = Label("@bazel_tools//tools/jdk:singlejar"), executable = True, allow_files = True, ), ), implementation = ..., ) custom_rule_bin is defined as follow:
java_library( name = "custom_rule", srcs = glob(["src/main/java/**/*.java"]), deps = [ ..., ], ) java_binary( name = "custom_rule_bin", visibility = ["//visibility:public"], main_class = "...", runtime_deps = [ "@org_slf4j_simple", ":custom_rule", "//some-pkg:some_pkg", # same some-pkg where a_target is built twice ], ) The difference is that one says "for host" and the other doesn't. Anyone knows what the extra "for host" build is?
I do have a feeling that it's somehow related to the cfg attribute on the custom rule. This is likely coming from some example code. We use the same value on all our rules which generate code. This custom rule is special because it requires code from the application being built by Bazel to run and generate additional code.
Any insights appreciated why host would be wrong and what would be the correct value.
Any ideas/tips how to debug this?
