Search in sources :

Example 1 with CxxLink

use of com.facebook.buck.cxx.CxxLink in project buck by facebook.

the class MultiarchFile method copyLinkMaps.

private void copyLinkMaps(BuildableContext buildableContext, ImmutableList.Builder<Step> steps) {
    Path linkMapDir = Paths.get(output + "-LinkMap");
    steps.add(new MakeCleanDirectoryStep(getProjectFilesystem(), linkMapDir));
    for (SourcePath thinBinary : thinBinaries) {
        Optional<BuildRule> maybeRule = ruleFinder.getRule(thinBinary);
        if (maybeRule.isPresent()) {
            BuildRule rule = maybeRule.get();
            if (rule instanceof CxxBinary) {
                rule = ((CxxBinary) rule).getLinkRule();
            }
            if (rule instanceof CxxLink && !rule.getBuildTarget().getFlavors().contains(LinkerMapMode.NO_LINKER_MAP.getFlavor())) {
                Optional<Path> maybeLinkerMapPath = ((CxxLink) rule).getLinkerMapPath();
                if (maybeLinkerMapPath.isPresent()) {
                    Path source = maybeLinkerMapPath.get();
                    Path dest = linkMapDir.resolve(source.getFileName());
                    steps.add(CopyStep.forFile(getProjectFilesystem(), source, dest));
                    buildableContext.recordArtifact(dest);
                }
            }
        }
    }
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) CxxBinary(com.facebook.buck.cxx.CxxBinary) MakeCleanDirectoryStep(com.facebook.buck.step.fs.MakeCleanDirectoryStep) BuildRule(com.facebook.buck.rules.BuildRule) AbstractBuildRule(com.facebook.buck.rules.AbstractBuildRule) CxxLink(com.facebook.buck.cxx.CxxLink)

Example 2 with CxxLink

use of com.facebook.buck.cxx.CxxLink in project buck by facebook.

the class AbstractNativeExecutableStarter method build.

@Override
public SourcePath build() throws NoSuchBuildTargetException {
    BuildTarget linkTarget = getTarget();
    CxxLink linkRule = getRuleResolver().addToIndex(CxxLinkableEnhancer.createCxxLinkableBuildRule(getCxxBuckConfig(), getCxxPlatform(), getBaseParams(), getRuleResolver(), getPathResolver(), getRuleFinder(), linkTarget, Linker.LinkType.EXECUTABLE, Optional.empty(), getOutput(), Linker.LinkableDepType.SHARED, getNativeStarterDeps(), Optional.empty(), Optional.empty(), ImmutableSet.of(), getNativeLinkableInput()));
    return linkRule.getSourcePathToOutput();
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) CxxLink(com.facebook.buck.cxx.CxxLink)

Example 3 with CxxLink

use of com.facebook.buck.cxx.CxxLink in project buck by facebook.

the class NativeRelinker method makeRelinkerRule.

private RelinkerRule makeRelinkerRule(TargetCpuType cpuType, SourcePath source, ImmutableList<RelinkerRule> relinkerDeps) {
    Function<RelinkerRule, SourcePath> getSymbolsNeeded = RelinkerRule::getSymbolsNeededPath;
    String libname = resolver.getAbsolutePath(source).getFileName().toString();
    BuildRuleParams relinkerParams = buildRuleParams.withAppendedFlavor(InternalFlavor.of("xdso-dce")).withAppendedFlavor(InternalFlavor.of(Flavor.replaceInvalidCharacters(cpuType.toString()))).withAppendedFlavor(InternalFlavor.of(Flavor.replaceInvalidCharacters(libname))).copyAppendingExtraDeps(relinkerDeps);
    BuildRule baseRule = ruleFinder.getRule(source).orElse(null);
    ImmutableList<Arg> linkerArgs = ImmutableList.of();
    Linker linker = null;
    if (baseRule != null && baseRule instanceof CxxLink) {
        CxxLink link = (CxxLink) baseRule;
        linkerArgs = link.getArgs();
        linker = link.getLinker();
    }
    return new RelinkerRule(relinkerParams, resolver, ruleFinder, ImmutableSortedSet.copyOf(Lists.transform(relinkerDeps, getSymbolsNeeded)), cpuType, Preconditions.checkNotNull(nativePlatforms.get(cpuType)).getObjdump(), cxxBuckConfig, source, linker, linkerArgs);
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) Arg(com.facebook.buck.rules.args.Arg) BuildRule(com.facebook.buck.rules.BuildRule) CxxLink(com.facebook.buck.cxx.CxxLink) Linker(com.facebook.buck.cxx.Linker)

Example 4 with CxxLink

use of com.facebook.buck.cxx.CxxLink in project buck by facebook.

the class DBinaryDescription method createBuildRule.

@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver buildRuleResolver, A args) throws NoSuchBuildTargetException {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(buildRuleResolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    SymlinkTree sourceTree = buildRuleResolver.addToIndex(DDescriptionUtils.createSourceSymlinkTree(DDescriptionUtils.getSymlinkTreeTarget(params.getBuildTarget()), params, ruleFinder, pathResolver, args.srcs));
    // Create a rule that actually builds the binary, and add that
    // rule to the index.
    CxxLink nativeLinkable = DDescriptionUtils.createNativeLinkable(params.withAppendedFlavor(BINARY_FLAVOR), buildRuleResolver, cxxPlatform, dBuckConfig, cxxBuckConfig, /* compilerFlags */
    ImmutableList.of(), args.srcs, args.linkerFlags, DIncludes.builder().setLinkTree(sourceTree.getSourcePathToOutput()).addAllSources(args.srcs.getPaths()).build());
    buildRuleResolver.addToIndex(nativeLinkable);
    // Create a Tool for the executable.
    CommandTool.Builder executableBuilder = new CommandTool.Builder();
    executableBuilder.addArg(SourcePathArg.of(nativeLinkable.getSourcePathToOutput()));
    // with buck run etc.
    return new DBinary(params.copyReplacingExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of(nativeLinkable))), ruleFinder, executableBuilder.build(), nativeLinkable.getSourcePathToOutput());
}
Also used : SymlinkTree(com.facebook.buck.rules.SymlinkTree) CommandTool(com.facebook.buck.rules.CommandTool) CxxLink(com.facebook.buck.cxx.CxxLink) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver)

Example 5 with CxxLink

use of com.facebook.buck.cxx.CxxLink in project buck by facebook.

the class SwiftLibrary method getNativeLinkableInput.

@Override
public NativeLinkableInput getNativeLinkableInput(CxxPlatform cxxPlatform, Linker.LinkableDepType type) throws NoSuchBuildTargetException {
    SwiftCompile rule = requireSwiftCompileRule(cxxPlatform.getFlavor());
    NativeLinkableInput.Builder inputBuilder = NativeLinkableInput.builder();
    inputBuilder.addAllArgs(rule.getAstLinkArgs()).addAllFrameworks(frameworks).addAllLibraries(libraries);
    boolean isDynamic;
    Linkage preferredLinkage = getPreferredLinkage(cxxPlatform);
    switch(preferredLinkage) {
        case STATIC:
            isDynamic = false;
            break;
        case SHARED:
            isDynamic = true;
            break;
        case ANY:
            isDynamic = type == Linker.LinkableDepType.SHARED;
            break;
        default:
            throw new IllegalStateException("unhandled linkage type: " + preferredLinkage);
    }
    if (isDynamic) {
        CxxLink swiftLinkRule = requireSwiftLinkRule(cxxPlatform.getFlavor());
        inputBuilder.addArgs(FileListableLinkerInputArg.withSourcePathArg(SourcePathArg.of(swiftLinkRule.getSourcePathToOutput())));
    } else {
        inputBuilder.addArgs(rule.getFileListLinkArg());
    }
    return inputBuilder.build();
}
Also used : NativeLinkableInput(com.facebook.buck.cxx.NativeLinkableInput) CxxLink(com.facebook.buck.cxx.CxxLink)

Aggregations

CxxLink (com.facebook.buck.cxx.CxxLink)13 BuildTarget (com.facebook.buck.model.BuildTarget)6 BuildRule (com.facebook.buck.rules.BuildRule)6 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)6 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)6 Test (org.junit.Test)6 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)5 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)5 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)3 SourcePath (com.facebook.buck.rules.SourcePath)3 Arg (com.facebook.buck.rules.args.Arg)3 Genrule (com.facebook.buck.shell.Genrule)3 CxxBinary (com.facebook.buck.cxx.CxxBinary)2 PrebuiltCxxLibraryBuilder (com.facebook.buck.cxx.PrebuiltCxxLibraryBuilder)2 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)2 BuildTargetSourcePath (com.facebook.buck.rules.BuildTargetSourcePath)2 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)2 TargetGraph (com.facebook.buck.rules.TargetGraph)2 StringArg (com.facebook.buck.rules.args.StringArg)2 MakeCleanDirectoryStep (com.facebook.buck.step.fs.MakeCleanDirectoryStep)2