@@ -259,6 +259,11 @@ private static RuntimeFiles collectRunfiles(
259
259
.getAllArtifacts ()
260
260
.toList ());
261
261
}
262
+ for (TransitiveInfoCollection transitiveInfoCollection :
263
+ ruleContext .getPrerequisites ("dynamic_deps" )) {
264
+ builder .merge (
265
+ transitiveInfoCollection .getProvider (RunfilesProvider .class ).getDefaultRunfiles ());
266
+ }
262
267
// Add the C++ runtime libraries if linking them dynamically.
263
268
if (linkingMode == Link .LinkingMode .DYNAMIC ) {
264
269
try {
@@ -557,6 +562,7 @@ public static void init(
557
562
Pair <CcLinkingOutputs , CcLauncherInfo > ccLinkingOutputsAndCcLinkingInfo =
558
563
createTransitiveLinkingActions (
559
564
ruleContext ,
565
+ ruleBuilder ,
560
566
ccToolchain ,
561
567
featureConfiguration ,
562
568
fdoContext ,
@@ -741,8 +747,9 @@ public static void init(
741
747
.addNativeDeclaredProvider (ccLauncherInfo );
742
748
}
743
749
744
- public static Pair <CcLinkingOutputs , CcLauncherInfo > createTransitiveLinkingActions (
750
+ private static Pair <CcLinkingOutputs , CcLauncherInfo > createTransitiveLinkingActions (
745
751
RuleContext ruleContext ,
752
+ RuleConfiguredTargetBuilder ruleBuilder ,
746
753
CcToolchainProvider ccToolchain ,
747
754
FeatureConfiguration featureConfiguration ,
748
755
FdoContext fdoContext ,
@@ -869,7 +876,7 @@ public static Pair<CcLinkingOutputs, CcLauncherInfo> createTransitiveLinkingActi
869
876
CcLinkingContext ccLinkingContext =
870
877
ruleContext .attributes ().isAttributeValueExplicitlySpecified ("dynamic_deps" )
871
878
? filterLibrariesThatAreLinkedDynamically (
872
- ruleContext , ccInfo .getCcLinkingContext (), cppSemantics )
879
+ ruleContext , ruleBuilder , ccInfo .getCcLinkingContext (), cppSemantics )
873
880
: ccInfo .getCcLinkingContext ();
874
881
if (ruleContext .hasErrors ()) {
875
882
return null ;
@@ -1426,8 +1433,11 @@ private static ImmutableList<CcLinkingContext.LinkerInput> filterInputs(
1426
1433
graphStructureAspectNodes .add (nodeInfo );
1427
1434
}
1428
1435
}
1429
- graphStructureAspectNodes .add (
1430
- CppHelper .mallocForTarget (ruleContext ).getProvider (GraphNodeInfo .class ));
1436
+ GraphNodeInfo mallocNodeInfo =
1437
+ CppHelper .mallocForTarget (ruleContext ).getProvider (GraphNodeInfo .class );
1438
+ if (mallocNodeInfo != null ) {
1439
+ graphStructureAspectNodes .add (mallocNodeInfo );
1440
+ }
1431
1441
1432
1442
Set <String > canBeLinkedDynamically = new HashSet <>();
1433
1443
for (CcLinkingContext .LinkerInput linkerInput : linkerInputs ) {
@@ -1533,7 +1543,8 @@ public static ImmutableMap<String, String> buildLinkOnceStaticLibsMap(
1533
1543
}
1534
1544
1535
1545
private static CcLinkingContext filterLibrariesThatAreLinkedDynamically (
1536
- RuleContext ruleContext , CcLinkingContext ccLinkingContext , CppSemantics cppSemantics ) {
1546
+ RuleContext ruleContext , RuleConfiguredTargetBuilder ruleBuilder ,
1547
+ CcLinkingContext ccLinkingContext , CppSemantics cppSemantics ) {
1537
1548
ImmutableList <CcSharedLibraryInfo > mergedCcSharedLibraryInfos =
1538
1549
mergeCcSharedLibraryInfos (ruleContext , cppSemantics );
1539
1550
ImmutableList <CcLinkingContext .LinkerInput > preloadedDeps =
@@ -1548,6 +1559,37 @@ private static CcLinkingContext filterLibrariesThatAreLinkedDynamically(
1548
1559
buildExportsMapFromOnlyDynamicDeps (ruleContext , mergedCcSharedLibraryInfos );
1549
1560
ImmutableList <CcLinkingContext .LinkerInput > staticLinkerInputs =
1550
1561
filterInputs (ruleContext , ccLinkingContext , exportsMap , linkOnceStaticLibsMap );
1562
+ if (ruleContext
1563
+ .getConfiguration ()
1564
+ .getFragment (CppConfiguration .class )
1565
+ .experimentalCcSharedLibraryDebug ()) {
1566
+ ImmutableList .Builder <String > debugLinkerInputsFile = ImmutableList .builder ();
1567
+ debugLinkerInputsFile .add ("Owner: " + ruleContext .getLabel ());
1568
+ for (CcLinkingContext .LinkerInput linkerInput :
1569
+ Iterables .concat (staticLinkerInputs , preloadedDeps )) {
1570
+ debugLinkerInputsFile .add (linkerInput .getOwner ().toString ());
1571
+ }
1572
+ Artifact linkOnceStaticLibsDebugFile =
1573
+ ruleContext .getBinArtifact (
1574
+ ruleContext .getLabel ().getName () + "_link_once_static_libs.txt" );
1575
+ ruleContext .registerAction (
1576
+ FileWriteAction .create (
1577
+ ruleContext ,
1578
+ linkOnceStaticLibsDebugFile ,
1579
+ Joiner .on ("\n " ).join (debugLinkerInputsFile .build ()),
1580
+ false ));
1581
+ NestedSetBuilder <Artifact > transitiveDebugFiles = NestedSetBuilder .stableOrder ();
1582
+ for (TransitiveInfoCollection dep : ruleContext .getPrerequisites ("dynamic_deps" )) {
1583
+ transitiveDebugFiles .addTransitive (
1584
+ dep .get (OutputGroupInfo .STARLARK_CONSTRUCTOR ).getOutputGroup ("rule_impl_debug_files" ));
1585
+ }
1586
+ ruleBuilder .addOutputGroup (
1587
+ "rule_impl_debug_files" ,
1588
+ NestedSetBuilder .<Artifact >stableOrder ()
1589
+ .add (linkOnceStaticLibsDebugFile )
1590
+ .addTransitive (transitiveDebugFiles .build ())
1591
+ .build ());
1592
+ }
1551
1593
1552
1594
return createLinkingContextWithDynamicDependencies (
1553
1595
staticLinkerInputs , preloadedDeps , exportsMap .values ());
0 commit comments