Source:
private static Map<String, NestedSet<Artifact>> addLinkerOutputArtifacts( RuleContext ruleContext, CcToolchainProvider ccToolchain, CppConfiguration cppConfiguration, BuildConfiguration configuration, CcCompilationOutputs ccCompilationOutputs, FeatureConfiguration featureConfiguration) throws RuleErrorException { NestedSetBuilder<Artifact> archiveFile = new NestedSetBuilder<>(Order.STABLE_ORDER); NestedSetBuilder<Artifact> dynamicLibrary = new NestedSetBuilder<>(Order.STABLE_ORDER); ImmutableSortedMap.Builder<String, NestedSet<Artifact>> outputGroups = ImmutableSortedMap.naturalOrder(); if (!ruleContext.attributes().has("alwayslink", Type.BOOLEAN) || !ruleContext.attributes().has("linkstatic", Type.BOOLEAN)) { return outputGroups.build(); } String linkedArtifactNameSuffix = CppHelper.getHashSuffix(ruleContext, cppConfiguration, featureConfiguration); if (ruleContext.attributes().get("alwayslink", Type.BOOLEAN)) { archiveFile.add( CppHelper.getLinkedArtifact( ruleContext, ccToolchain, configuration, Link.LinkTargetType.ALWAYS_LINK_STATIC_LIBRARY, "")); } else { archiveFile.add( CppHelper.getLinkedArtifact( ruleContext, ccToolchain, configuration, Link.LinkTargetType.STATIC_LIBRARY, linkedArtifactNameSuffix)); } if (!ruleContext.attributes().get("linkstatic", Type.BOOLEAN) && !ccCompilationOutputs.isEmpty()) { dynamicLibrary.add( CppHelper.getLinkedArtifact( ruleContext, ccToolchain, configuration, Link.LinkTargetType.NODEPS_DYNAMIC_LIBRARY, linkedArtifactNameSuffix)); if (CppHelper.useInterfaceSharedLibraries( cppConfiguration, ccToolchain, featureConfiguration)) { dynamicLibrary.add( CppHelper.getLinkedArtifact( ruleContext, ccToolchain, configuration, LinkTargetType.INTERFACE_DYNAMIC_LIBRARY, linkedArtifactNameSuffix)); } } outputGroups.put(ARCHIVE_LIBRARY_OUTPUT_GROUP_NAME, archiveFile.build()); outputGroups.put(DYNAMIC_LIBRARY_OUTPUT_GROUP_NAME, dynamicLibrary.build()); return outputGroups.build(); }

Target:
private static Map<String, NestedSet<Artifact>> addLinkerOutputArtifacts( RuleContext ruleContext, CcToolchainProvider ccToolchain, CppConfiguration cppConfiguration, BuildConfiguration configuration, CcCompilationOutputs ccCompilationOutputs, FeatureConfiguration featureConfiguration) throws RuleErrorException { NestedSetBuilder<Artifact> archiveFile = new NestedSetBuilder<>(Order.STABLE_ORDER); NestedSetBuilder<Artifact> dynamicLibrary = new NestedSetBuilder<>(Order.STABLE_ORDER); ImmutableSortedMap.Builder<String, NestedSet<Artifact>> outputGroups = ImmutableSortedMap.naturalOrder(); if (!ruleContext.attributes().has("alwayslink", Type.BOOLEAN) || !ruleContext.attributes().has("linkstatic", Type.BOOLEAN)) { return outputGroups.build(); } if (ruleContext.attributes().get("alwayslink", Type.BOOLEAN)) { archiveFile.add( CppHelper.getLinkedArtifact( ruleContext, ccToolchain, configuration, Link.LinkTargetType.ALWAYS_LINK_STATIC_LIBRARY, "")); } else { archiveFile.add( CppHelper.getLinkedArtifact( ruleContext, ccToolchain, configuration, Link.LinkTargetType.STATIC_LIBRARY, "")); } if (!ruleContext.attributes().get("linkstatic", Type.BOOLEAN) && !ccCompilationOutputs.isEmpty()) { dynamicLibrary.add( CppHelper.getLinkedArtifact( ruleContext, ccToolchain, configuration, Link.LinkTargetType.NODEPS_DYNAMIC_LIBRARY, CppHelper.getDLLHashSuffix(ruleContext, featureConfiguration))); if (CppHelper.useInterfaceSharedLibraries( cppConfiguration, ccToolchain, featureConfiguration)) { dynamicLibrary.add( CppHelper.getLinkedArtifact( ruleContext, ccToolchain, configuration, LinkTargetType.INTERFACE_DYNAMIC_LIBRARY, "")); } } outputGroups.put(ARCHIVE_LIBRARY_OUTPUT_GROUP_NAME, archiveFile.build()); outputGroups.put(DYNAMIC_LIBRARY_OUTPUT_GROUP_NAME, dynamicLibrary.build()); return outputGroups.build(); }