@@ -635,12 +635,6 @@ public LibraryToLink createLibraryLinkerInput(
635635 "If you pass '%s_library', you must also pass a 'feature_configuration'" , library );
636636 }
637637 }
638- if (nopicObjects != null && staticLibrary == null ) {
639- throw Starlark .errorf ("If you pass 'objects' you must also pass a 'static_library'" );
640- }
641- if (picObjects != null && picStaticLibrary == null ) {
642- throw Starlark .errorf ("If you pass 'pic_objects' you must also pass a 'pic_static_library'" );
643- }
644638 if (notNullArtifactForIdentifier == null ) {
645639 throw Starlark .errorf ("Must pass at least one artifact" );
646640 }
@@ -1804,7 +1798,7 @@ public Tuple createLinkingContextFromCompilationOutputs(
18041798 CcToolchainProvider starlarkCcToolchainProvider ,
18051799 CcCompilationOutputs compilationOutputs ,
18061800 Sequence <?> userLinkFlags , // <String> expected
1807- Sequence <?> linkingContexts , // <CcLinkingContext> expected
1801+ Sequence <?> linkingContextsObjects , // <CcLinkingContext> expected
18081802 String name ,
18091803 String languageString ,
18101804 boolean alwayslink ,
@@ -1814,9 +1808,11 @@ public Tuple createLinkingContextFromCompilationOutputs(
18141808 Object grepIncludes ,
18151809 Object variablesExtension ,
18161810 Object stamp ,
1811+ Object linkedDllNameSuffix ,
1812+ Object winDefFile ,
18171813 StarlarkThread thread )
18181814 throws InterruptedException , EvalException {
1819- if (checkObjectsBound (stamp )) {
1815+ if (checkObjectsBound (stamp , linkedDllNameSuffix , winDefFile )) {
18201816 CcModule .checkPrivateStarlarkificationAllowlist (thread );
18211817 }
18221818 Language language = parseLanguage (languageString );
@@ -1845,6 +1841,8 @@ public Tuple createLinkingContextFromCompilationOutputs(
18451841 } else {
18461842 staticLinkTargetType = LinkTargetType .OBJC_ARCHIVE ;
18471843 }
1844+ List <CcLinkingContext > ccLinkingContexts =
1845+ Sequence .cast (linkingContextsObjects , CcLinkingContext .class , "linking_contexts" );
18481846 CcLinkingHelper helper =
18491847 new CcLinkingHelper (
18501848 actions .getActionConstructionContext ().getRuleErrorConsumer (),
@@ -1868,43 +1866,42 @@ public Tuple createLinkingContextFromCompilationOutputs(
18681866 .addNonCodeLinkerInputs (
18691867 Sequence .cast (additionalInputs , Artifact .class , "additional_inputs" ))
18701868 .setShouldCreateStaticLibraries (!disallowStaticLibraries )
1869+ .addCcLinkingContexts (ccLinkingContexts )
18711870 .setShouldCreateDynamicLibrary (
18721871 !disallowDynamicLibraries
1873- && !featureConfiguration
1874- .getFeatureConfiguration ()
1875- .isEnabled (CppRuleClasses .TARGETS_WINDOWS ))
1872+ && (!featureConfiguration
1873+ .getFeatureConfiguration ()
1874+ .isEnabled (CppRuleClasses .TARGETS_WINDOWS )
1875+ || winDefFile != null ))
18761876 .setStaticLinkType (staticLinkTargetType )
18771877 .setDynamicLinkType (LinkTargetType .NODEPS_DYNAMIC_LIBRARY )
18781878 .emitInterfaceSharedLibraries (true )
1879+ .setLinkedDLLNameSuffix (
1880+ convertFromNoneable (linkedDllNameSuffix , /* defaultValue= */ "" ))
1881+ .setDefFile (convertFromNoneable (winDefFile , /* defaultValue= */ null ))
18791882 .setIsStampingEnabled (isStampingEnabled )
18801883 .addLinkopts (Sequence .cast (userLinkFlags , String .class , "user_link_flags" ));
18811884 if (!asDict (variablesExtension ).isEmpty ()) {
18821885 helper .addVariableExtension (new UserVariablesExtension (asDict (variablesExtension )));
18831886 }
18841887 try {
1885- CcLinkingOutputs ccLinkingOutputs = CcLinkingOutputs .EMPTY ;
18861888 ImmutableList <LibraryToLink > libraryToLink = ImmutableList .of ();
1887- if (!compilationOutputs .isEmpty ()) {
1888- ccLinkingOutputs = helper .link (compilationOutputs );
1889- if (!ccLinkingOutputs .isEmpty ()) {
1890- libraryToLink =
1891- ImmutableList .of (
1892- ccLinkingOutputs .getLibraryToLink ().toBuilder ()
1893- .setAlwayslink (alwayslink )
1894- .build ());
1895- }
1889+ CcLinkingOutputs ccLinkingOutputs = helper .link (compilationOutputs );
1890+ if (!ccLinkingOutputs .isEmpty ()) {
1891+ LibraryToLink rewrappedForAlwaysLink =
1892+ ccLinkingOutputs .getLibraryToLink ().toBuilder ().setAlwayslink (alwayslink ).build ();
1893+ ccLinkingOutputs =
1894+ CcLinkingOutputs .builder ()
1895+ .setExecutable (ccLinkingOutputs .getExecutable ())
1896+ .setLibraryToLink (rewrappedForAlwaysLink )
1897+ .addAllLtoArtifacts (ccLinkingOutputs .getAllLtoArtifacts ())
1898+ .build ();
1899+ libraryToLink = ImmutableList .of (rewrappedForAlwaysLink );
18961900 }
18971901 CcLinkingContext linkingContext =
18981902 helper .buildCcLinkingContextFromLibrariesToLink (
18991903 libraryToLink , CcCompilationContext .EMPTY );
1900- return Tuple .of (
1901- CcLinkingContext .merge (
1902- ImmutableList .<CcLinkingContext >builder ()
1903- .add (linkingContext )
1904- .addAll (
1905- Sequence .cast (linkingContexts , CcLinkingContext .class , "linking_contexts" ))
1906- .build ()),
1907- ccLinkingOutputs );
1904+ return Tuple .of (linkingContext , ccLinkingOutputs );
19081905 } catch (RuleErrorException e ) {
19091906 throw Starlark .errorf ("%s" , e .getMessage ());
19101907 }
@@ -2002,7 +1999,7 @@ protected Tuple compile(
20021999 Object textualHeadersStarlarkObject ,
20032000 Object additionalExportedHeadersObject ,
20042001 Sequence <?> includes , // <String> expected
2005- Object starlarkIncludes ,
2002+ Object starlarkLooseIncludes ,
20062003 Sequence <?> quoteIncludes , // <String> expected
20072004 Sequence <?> systemIncludes , // <String> expected
20082005 Sequence <?> frameworkIncludes , // <String> expected
@@ -2042,15 +2039,15 @@ protected Tuple compile(
20422039 hdrsCheckingModeObject ,
20432040 implementationCcCompilationContextsObject ,
20442041 coptsFilterObject ,
2045- starlarkIncludes )) {
2042+ starlarkLooseIncludes )) {
20462043 CcModule .checkPrivateStarlarkificationAllowlist (thread );
20472044 }
20482045
20492046 StarlarkActionFactory actions = starlarkActionFactoryApi ;
20502047 CcToolchainProvider ccToolchainProvider =
20512048 convertFromNoneable (starlarkCcToolchainProvider , null );
20522049
2053- ImmutableList <String > looseIncludes = asClassImmutableList (starlarkIncludes );
2050+ ImmutableList <String > looseIncludes = asClassImmutableList (starlarkLooseIncludes );
20542051 CppModuleMap moduleMap = convertFromNoneable (moduleMapNoneable , /* defaultValue= */ null );
20552052 ImmutableList <CppModuleMap > additionalModuleMaps =
20562053 asClassImmutableList (additionalModuleMapsNoneable );
0 commit comments