diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java index ae723c99d3aa68..330740c4480174 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java @@ -583,6 +583,13 @@ public static ConfiguredTarget init(CppSemantics semantics, RuleContext ruleCont // logical since all symlinked libraries will be linked anyway and would // not require manual loading but if we do, then we would need to collect // their names and use a different constructor below. + NestedSetBuilder transitiveArtifacts = + NestedSetBuilder.stableOrder() + .addTransitive(filesToBuild) + .addTransitive(extraLinkTimeRuntimeLibraries.build()); + if (featureConfiguration.isEnabled(CppRuleClasses.COPY_DYNAMIC_LIBRARIES_TO_BINARY)) { + transitiveArtifacts.addTransitive(copiedRuntimeDynamicLibraries); + } Runfiles runfiles = collectRunfiles( ruleContext, @@ -593,10 +600,7 @@ public static ConfiguredTarget init(CppSemantics semantics, RuleContext ruleCont ccLinkingOutputs, ccCompilationContext, linkingMode, - NestedSetBuilder.stableOrder() - .addTransitive(filesToBuild) - .addTransitive(extraLinkTimeRuntimeLibraries.build()) - .build(), + transitiveArtifacts.build(), fakeLinkerInputs, fake, compilationHelper.getCompilationUnitSources(), @@ -656,11 +660,6 @@ public static ConfiguredTarget init(CppSemantics semantics, RuleContext ruleCont } if (copiedRuntimeDynamicLibraries != null) { - // When COPY_DYNAMIC_LIBRARIES_TO_BINARY is enabled, runtime dynamic libraries should be - // copied to the binary's directory. Therefore, we add them to HIDDEN_TOP_LEVEL output group - // to make sure they are built for the target and runtime_dynamic_libraries output group - // to make them easier to access. - ruleBuilder.addOutputGroup(OutputGroupInfo.HIDDEN_TOP_LEVEL, copiedRuntimeDynamicLibraries); ruleBuilder.addOutputGroup("runtime_dynamic_libraries", copiedRuntimeDynamicLibraries); }