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);
}
}
}
}
}
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();
}
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);
}
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());
}
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();
}
Aggregations