Fix conflicting actions for C++20 modules info files in PIC/non-PIC b… (#834) …uilds Fix https://github.com/bazelbuild/rules_cc/issues/833 Closes #834 COPYBARA_INTEGRATE_REVIEW=https://github.com/bazelbuild/rules_cc/pull/834 from PikachuHyA:fix_module_json_conflict 9683f3aa78798665ebdf59aeaa5edfb46b4edffe PiperOrigin-RevId: 962293343 Change-Id: I7c7b13687004126310f004359afc05970e31d506
diff --git a/cc/private/compile/compile.bzl b/cc/private/compile/compile.bzl index d1ca4ad..56b9aed 100644 --- a/cc/private/compile/compile.bzl +++ b/cc/private/compile/compile.bzl
@@ -673,6 +673,17 @@ direct_module_files = [] source_to_module_file_map = {} source_to_ddi_file_map = {} + + # The modules info file must be distinct between PIC and non-PIC builds, + # otherwise the PIC and non-PIC aggregate-ddi actions would both write to + # the same output, causing a conflicting-actions error. + modules_info_output_name = label.name + if use_pic: + modules_info_output_name = _cc_internal.get_artifact_name_for_category( + cc_toolchain = cc_toolchain, + category = artifact_category.PIC_FILE, + output_name = modules_info_output_name, + ) modules_info_file = _get_compile_output_file( action_construction_context, label, @@ -680,7 +691,7 @@ output_name = _cc_internal.get_artifact_name_for_category( cc_toolchain = cc_toolchain, category = artifact_category.CPP_MODULES_INFO, - output_name = label.name, + output_name = modules_info_output_name, ), ) if use_pic: