use of com.facebook.buck.cxx.CxxBinary 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.CxxBinary in project buck by facebook.
the class AppleBinaryDescriptionTest method linkerFlagsLocationMacro.
@Test
public void linkerFlagsLocationMacro() throws Exception {
assumeThat(Platform.detect(), is(Platform.MACOS));
BuildTarget sandboxTarget = BuildTargetFactory.newInstance("//:rule#sandbox," + FakeAppleRuleDescriptions.DEFAULT_IPHONEOS_I386_PLATFORM.getFlavor());
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraphFactory.newInstance(new AppleBinaryBuilder(sandboxTarget).build()), new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
Genrule dep = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:dep")).setOut("out").build(resolver);
AppleBinaryBuilder builder = new AppleBinaryBuilder(BuildTargetFactory.newInstance("//:rule")).setLinkerFlags(ImmutableList.of(StringWithMacrosUtils.format("--linker-script=%s", LocationMacro.of(dep.getBuildTarget()))));
assertThat(builder.build().getExtraDeps(), Matchers.hasItem(dep.getBuildTarget()));
BuildRule binary = ((CxxBinary) builder.build(resolver)).getLinkRule();
assertThat(binary, Matchers.instanceOf(CxxLink.class));
assertThat(Arg.stringify(((CxxLink) binary).getArgs(), pathResolver), Matchers.hasItem(String.format("--linker-script=%s", dep.getAbsoluteOutputFilePath(pathResolver))));
assertThat(binary.getDeps(), Matchers.hasItem(dep));
}
use of com.facebook.buck.cxx.CxxBinary in project buck by facebook.
the class HalideLibraryDescription method createHalideCompiler.
private CxxBinary createHalideCompiler(BuildRuleParams params, BuildRuleResolver ruleResolver, SourcePathResolver pathResolver, SourcePathRuleFinder ruleFinder, CxxPlatform cxxPlatform, ImmutableSortedSet<SourceWithFlags> halideSources, ImmutableList<String> compilerFlags, PatternMatchedCollection<ImmutableList<String>> platformCompilerFlags, ImmutableMap<CxxSource.Type, ImmutableList<String>> langCompilerFlags, ImmutableList<StringWithMacros> linkerFlags, PatternMatchedCollection<ImmutableList<StringWithMacros>> platformLinkerFlags, ImmutableList<String> includeDirs) throws NoSuchBuildTargetException {
Optional<StripStyle> flavoredStripStyle = StripStyle.FLAVOR_DOMAIN.getValue(params.getBuildTarget());
Optional<LinkerMapMode> flavoredLinkerMapMode = LinkerMapMode.FLAVOR_DOMAIN.getValue(params.getBuildTarget());
params = CxxStrip.removeStripStyleFlavorInParams(params, flavoredStripStyle);
params = LinkerMapMode.removeLinkerMapModeFlavorInParams(params, flavoredLinkerMapMode);
ImmutableMap<String, CxxSource> srcs = CxxDescriptionEnhancer.parseCxxSources(params.getBuildTarget(), ruleResolver, ruleFinder, pathResolver, cxxPlatform, halideSources, PatternMatchedCollection.of());
ImmutableList<String> preprocessorFlags = ImmutableList.of();
PatternMatchedCollection<ImmutableList<String>> platformPreprocessorFlags = PatternMatchedCollection.of();
ImmutableMap<CxxSource.Type, ImmutableList<String>> langPreprocessorFlags = ImmutableMap.of();
ImmutableSortedSet<FrameworkPath> frameworks = ImmutableSortedSet.of();
ImmutableSortedSet<FrameworkPath> libraries = ImmutableSortedSet.of();
Optional<SourcePath> prefixHeader = Optional.empty();
Optional<SourcePath> precompiledHeader = Optional.empty();
Optional<Linker.CxxRuntimeType> cxxRuntimeType = Optional.empty();
CxxLinkAndCompileRules cxxLinkAndCompileRules = CxxDescriptionEnhancer.createBuildRulesForCxxBinary(params, ruleResolver, cxxBuckConfig, cxxPlatform, srcs, /* headers */
ImmutableMap.of(), params.getDeps(), flavoredStripStyle, flavoredLinkerMapMode, Linker.LinkableDepType.STATIC, preprocessorFlags, platformPreprocessorFlags, langPreprocessorFlags, frameworks, libraries, compilerFlags, langCompilerFlags, platformCompilerFlags, prefixHeader, precompiledHeader, linkerFlags, platformLinkerFlags, cxxRuntimeType, includeDirs, Optional.empty());
params = CxxStrip.restoreStripStyleFlavorInParams(params, flavoredStripStyle);
params = LinkerMapMode.restoreLinkerMapModeFlavorInParams(params, flavoredLinkerMapMode);
CxxBinary cxxBinary = new CxxBinary(params.copyAppendingExtraDeps(cxxLinkAndCompileRules.executable.getDeps(ruleFinder)), ruleResolver, ruleFinder, cxxLinkAndCompileRules.getBinaryRule(), cxxLinkAndCompileRules.executable, ImmutableSortedSet.of(), ImmutableSortedSet.of(), params.getBuildTarget().withoutFlavors(cxxPlatforms.getFlavors()));
ruleResolver.addToIndex(cxxBinary);
return cxxBinary;
}
Aggregations