@Override public NativeLinkableInput getNativeLinkableInput( TargetGraph targetGraph, CxxPlatform cxxPlatform, Linker.LinkableDepType type) { if (!isPlatformSupported(cxxPlatform)) { return NativeLinkableInput.of(); } if (headerOnly.apply(cxxPlatform)) { return NativeLinkableInput.of( ImmutableList.<SourcePath>of(), ImmutableList.<String>of(), Preconditions.checkNotNull(frameworks), ImmutableSet.<FrameworkPath>of()); } // Build up the arguments used to link this library. If we're linking the // whole archive, wrap the library argument in the necessary "ld" flags. final Pair<ImmutableList<String>, ImmutableSet<SourcePath>> flagsAndBuildInputs = exportedLinkerFlags.apply(cxxPlatform); ImmutableList.Builder<String> linkerArgsBuilder = ImmutableList.builder(); linkerArgsBuilder.addAll(flagsAndBuildInputs.getFirst()); final BuildRule libraryRule; if (type != Linker.LinkableDepType.SHARED || linkage == Linkage.STATIC) { libraryRule = requireBuildRule( targetGraph, cxxPlatform.getFlavor(), type == Linker.LinkableDepType.STATIC ? CxxDescriptionEnhancer.STATIC_FLAVOR : CxxDescriptionEnhancer.STATIC_PIC_FLAVOR); Path staticLibraryPath = CxxDescriptionEnhancer.getStaticLibraryPath( getBuildTarget(), cxxPlatform.getFlavor(), type == Linker.LinkableDepType.STATIC ? CxxSourceRuleFactory.PicType.PDC : CxxSourceRuleFactory.PicType.PIC); if (linkWhole) { Linker linker = cxxPlatform.getLd(); linkerArgsBuilder.addAll(linker.linkWhole(staticLibraryPath.toString())); } else { linkerArgsBuilder.add(staticLibraryPath.toString()); } } else { String sharedLibrarySoname = soname.or( CxxDescriptionEnhancer.getDefaultSharedLibrarySoname( params.getBuildTarget(), cxxPlatform)); Path sharedLibraryPath = CxxDescriptionEnhancer.getSharedLibraryPath( getBuildTarget(), sharedLibrarySoname, cxxPlatform); libraryRule = requireBuildRule( targetGraph, cxxPlatform.getFlavor(), CxxDescriptionEnhancer.SHARED_FLAVOR); linkerArgsBuilder.add(sharedLibraryPath.toString()); } final ImmutableList<String> linkerArgs = linkerArgsBuilder.build(); return NativeLinkableInput.of( ImmutableList.<SourcePath>builder() .add(new BuildTargetSourcePath(libraryRule.getBuildTarget())) .addAll(flagsAndBuildInputs.getSecond()) .build(), linkerArgs, Preconditions.checkNotNull(frameworks), Preconditions.checkNotNull(libraries)); }