bazel icon indicating copy to clipboard operation
bazel copied to clipboard

C++ host compile actions can conflict when --experimental_platform_in_output_dir is enabled

Open armandomontanez opened this issue 6 months ago • 1 comments

Description of the bug:

When --experimental_platform_in_output_dir is enabled, any C++ compile actions targeting @local_config_platform//:host will conflict with identical actions targeting @platforms//host.

Which category does this issue belong to?

Configurability

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

https://github.com/armandomontanez/bazel_reproducers/tree/main/action_conflicts_with_platform_name_in_out_dir

Summary:

cc_binary(
    name = "data_binary",
    srcs = ["main.cc"],
)

platform_data(
    name = "explicit_host_binary",
    # Note that today the default host platform is @bazel_tools//tools:host_platform
    # which in turn is an alias pointing to @platforms//host.
    platform = "@local_config_platform//:host",
    target = ":data_binary",
)

py_binary(
    name = "main_binary",
    main = "outer.py",
    srcs = ["outer.py"],
    data = [
        ":data_binary",
        ":explicit_host_binary",
    ],
)

Which operating system are you running Bazel on?

macOS/Linux

What is the output of bazel info release?

release 8.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 ?


If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.

No response

Have you found anything relevant by searching the web?

No response

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

Example conflict:

ERROR: file '_objs/data_binary/main.o' is generated by these conflicting actions:
Label: //:data_binary
RuleClass: cc_binary rule
JavaActionClass: class com.google.devtools.build.lib.rules.cpp.CppCompileAction
Configuration: c80e5e0cf4f1be62db5504937d2ca971bc878717f37de07ce0f4f526e6bcd575, 1266988732fa9e033085170afb27b1844ac37e0321fb67d8ec9b375ebfc93f26
Mnemonic: CppCompile
Action key: 7dc6772ccd5192cbc39d0cc9e7e2b47cceb66fe50881d8e5b5904789885b71b5
Progress message: Compiling main.cc
Action describeKey: Compiling main.cc
  Command: external/rules_cc++cc_configure_extension+local_config_cc/cc_wrapper.sh
  Argument: -U_FORTIFY_SOURCE
  Argument: -fstack-protector
  Argument: -Wall
  Argument: -Wthread-safety
  Argument: -Wself-assign
  Argument: -Wunused-but-set-parameter
  Argument: -Wno-free-nonheap-object
  Argument: -fcolor-diagnostics
  Argument: -fno-omit-frame-pointer
  Argument: '-std=c++17'
  Argument: '-frandom-seed=bazel-out/darwin_x86_64-fastbuild/bin/_objs/data_binary/main.o'
  Argument: '-mmacosx-version-min=10.11'
  Argument: -MD
  Argument: -MF
  Argument: bazel-out/darwin_x86_64-fastbuild/bin/_objs/data_binary/main.d
  Argument: -iquote
  Argument: .
  Argument: -iquote
  Argument: bazel-out/darwin_x86_64-fastbuild/bin
  Argument: -iquote
  Argument: external/rules_cc+
  Argument: -iquote
  Argument: bazel-out/darwin_x86_64-fastbuild/bin/external/rules_cc+
  Argument: -iquote
  Argument: external/bazel_tools
  Argument: -iquote
  Argument: bazel-out/darwin_x86_64-fastbuild/bin/external/bazel_tools
  Argument: -c
  Argument: main.cc
  Argument: -o
  Argument: bazel-out/darwin_x86_64-fastbuild/bin/_objs/data_binary/main.o
  Argument: -no-canonical-prefixes
  Argument: -Wno-builtin-macro-redefined
  Argument: '-D__DATE__="redacted"'
  Argument: '-D__TIMESTAMP__="redacted"'
  Argument: '-D__TIME__="redacted"'

PrimaryInput: File:[/Users/amontanez/development/projects/armandomontanez_github/bazel_reproducers/action_conflicts_with_platform_name_in_out_dir[source]]main.cc
PrimaryOutput: File:[[<execution_root>]bazel-out/darwin_x86_64-fastbuild/bin]_objs/data_binary/main.o
Owner information: ConfiguredTargetKey{label=//:data_binary, config=BuildConfigurationKey[c80e5e0cf4f1be62db5504937d2ca971bc878717f37de07ce0f4f526e6bcd575]}, ConfiguredTargetKey{label=//:data_binary, config=BuildConfigurationKey[1266988732fa9e033085170afb27b1844ac37e0321fb67d8ec9b375ebfc93f26]}
MandatoryInputs: are equal
Outputs: are equal
Use --verbose_failures to see the command lines of failed build steps.
ERROR: file '_objs/data_binary/main.o' is generated by these conflicting actions:
Label: //:data_binary
RuleClass: cc_binary rule
JavaActionClass: class com.google.devtools.build.lib.rules.cpp.CppCompileAction
Configuration: c80e5e0cf4f1be62db5504937d2ca971bc878717f37de07ce0f4f526e6bcd575, 1266988732fa9e033085170afb27b1844ac37e0321fb67d8ec9b375ebfc93f26
Mnemonic: CppCompile
Action key: 7dc6772ccd5192cbc39d0cc9e7e2b47cceb66fe50881d8e5b5904789885b71b5
Progress message: Compiling main.cc
Action describeKey: Compiling main.cc
  Command: external/rules_cc++cc_configure_extension+local_config_cc/cc_wrapper.sh
  Argument: -U_FORTIFY_SOURCE
  Argument: -fstack-protector
  Argument: -Wall
  Argument: -Wthread-safety
  Argument: -Wself-assign
  Argument: -Wunused-but-set-parameter
  Argument: -Wno-free-nonheap-object
  Argument: -fcolor-diagnostics
  Argument: -fno-omit-frame-pointer
  Argument: '-std=c++17'
  Argument: '-frandom-seed=bazel-out/darwin_x86_64-fastbuild/bin/_objs/data_binary/main.o'
  Argument: '-mmacosx-version-min=10.11'
  Argument: -MD
  Argument: -MF
  Argument: bazel-out/darwin_x86_64-fastbuild/bin/_objs/data_binary/main.d
  Argument: -iquote
  Argument: .
  Argument: -iquote
  Argument: bazel-out/darwin_x86_64-fastbuild/bin
  Argument: -iquote
  Argument: external/rules_cc+
  Argument: -iquote
  Argument: bazel-out/darwin_x86_64-fastbuild/bin/external/rules_cc+
  Argument: -iquote
  Argument: external/bazel_tools
  Argument: -iquote
  Argument: bazel-out/darwin_x86_64-fastbuild/bin/external/bazel_tools
  Argument: -c
  Argument: main.cc
  Argument: -o
  Argument: bazel-out/darwin_x86_64-fastbuild/bin/_objs/data_binary/main.o
  Argument: -no-canonical-prefixes
  Argument: -Wno-builtin-macro-redefined
  Argument: '-D__DATE__="redacted"'
  Argument: '-D__TIMESTAMP__="redacted"'
  Argument: '-D__TIME__="redacted"'

PrimaryInput: File:[/Users/amontanez/development/projects/armandomontanez_github/bazel_reproducers/action_conflicts_with_platform_name_in_out_dir[source]]main.cc
PrimaryOutput: File:[[<execution_root>]bazel-out/darwin_x86_64-fastbuild/bin]_objs/data_binary/main.o
Owner information: ConfiguredTargetKey{label=//:data_binary, config=BuildConfigurationKey[c80e5e0cf4f1be62db5504937d2ca971bc878717f37de07ce0f4f526e6bcd575]}, ConfiguredTargetKey{label=//:data_binary, config=BuildConfigurationKey[1266988732fa9e033085170afb27b1844ac37e0321fb67d8ec9b375ebfc93f26]}
MandatoryInputs: are equal
Outputs: are equal
INFO: Elapsed time: 0.613s, Critical Path: 0.00s
INFO: 4 processes: 4 action cache hit, 4 internal.
ERROR: Build did NOT complete successfully

armandomontanez avatar Jun 06 '25 22:06 armandomontanez

This also happens if you transition directly to @platforms//host rather than the indirection @bazel_tools//tools:host_platform.

armandomontanez avatar Jun 06 '25 22:06 armandomontanez

@platforms//host should just be an alias for @bazel_tools//tools:host_platform, or the other way around. It's a really unnecessary footgun that these are different platforms!

tpudlik avatar Jul 10 '25 17:07 tpudlik

@tpudlik It is an alias: https://github.com/bazelbuild/bazel/blob/029d01329f8f80c15ef555d2bc31eb370ff8e4d6/tools/BUILD.tools#L7

But the two are still different flag values, hence the potential for configuration conflicts.

@gregestren

fmeum avatar Jul 10 '25 17:07 fmeum