use of com.facebook.buck.cxx.HeaderSymlinkTree in project buck by facebook.
the class CxxLuaExtensionDescription method getExtensionArgs.
private ImmutableList<com.facebook.buck.rules.args.Arg> getExtensionArgs(BuildRuleParams params, BuildRuleResolver ruleResolver, SourcePathResolver pathResolver, SourcePathRuleFinder ruleFinder, CxxPlatform cxxPlatform, Arg args) throws NoSuchBuildTargetException {
// Extract all C/C++ sources from the constructor arg.
ImmutableMap<String, CxxSource> srcs = CxxDescriptionEnhancer.parseCxxSources(params.getBuildTarget(), ruleResolver, ruleFinder, pathResolver, cxxPlatform, args);
ImmutableMap<Path, SourcePath> headers = CxxDescriptionEnhancer.parseHeaders(params.getBuildTarget(), ruleResolver, ruleFinder, pathResolver, Optional.of(cxxPlatform), args);
// Setup the header symlink tree and combine all the preprocessor input from this rule
// and all dependencies.
HeaderSymlinkTree headerSymlinkTree = CxxDescriptionEnhancer.requireHeaderSymlinkTree(params, ruleResolver, cxxPlatform, headers, HeaderVisibility.PRIVATE, true);
Optional<SymlinkTree> sandboxTree = Optional.empty();
if (cxxBuckConfig.sandboxSources()) {
sandboxTree = CxxDescriptionEnhancer.createSandboxTree(params, ruleResolver, cxxPlatform);
}
ImmutableList<CxxPreprocessorInput> cxxPreprocessorInput = CxxDescriptionEnhancer.collectCxxPreprocessorInput(params, cxxPlatform, CxxFlags.getLanguageFlags(args.preprocessorFlags, args.platformPreprocessorFlags, args.langPreprocessorFlags, cxxPlatform), ImmutableList.of(headerSymlinkTree), ImmutableSet.of(), CxxPreprocessables.getTransitiveCxxPreprocessorInput(cxxPlatform, params.getDeps()), args.includeDirs, sandboxTree);
// Generate rule to build the object files.
ImmutableMap<CxxPreprocessAndCompile, SourcePath> picObjects = CxxSourceRuleFactory.requirePreprocessAndCompileRules(params, ruleResolver, pathResolver, ruleFinder, cxxBuckConfig, cxxPlatform, cxxPreprocessorInput, CxxFlags.getLanguageFlags(args.compilerFlags, args.platformCompilerFlags, args.langCompilerFlags, cxxPlatform), args.prefixHeader, args.precompiledHeader, srcs, CxxSourceRuleFactory.PicType.PIC, sandboxTree);
ImmutableList.Builder<com.facebook.buck.rules.args.Arg> argsBuilder = ImmutableList.builder();
argsBuilder.addAll(CxxDescriptionEnhancer.toStringWithMacrosArgs(params.getBuildTarget(), params.getCellRoots(), ruleResolver, cxxPlatform, CxxFlags.getFlagsWithMacrosWithPlatformMacroExpansion(args.linkerFlags, args.platformLinkerFlags, cxxPlatform)));
// Add object files into the args.
argsBuilder.addAll(SourcePathArg.from(picObjects.values()));
return argsBuilder.build();
}
use of com.facebook.buck.cxx.HeaderSymlinkTree in project buck by facebook.
the class HaskellPrebuiltLibraryDescription method createBuildRule.
@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, BuildRuleParams params, BuildRuleResolver resolver, final A args) throws NoSuchBuildTargetException {
return new PrebuiltHaskellLibrary(params) {
private final LoadingCache<CxxPreprocessables.CxxPreprocessorInputCacheKey, ImmutableMap<BuildTarget, CxxPreprocessorInput>> transitiveCxxPreprocessorInputCache = CxxPreprocessables.getTransitiveCxxPreprocessorInputCache(this);
@Override
public HaskellCompileInput getCompileInput(CxxPlatform cxxPlatform, Linker.LinkableDepType depType) throws NoSuchBuildTargetException {
return HaskellCompileInput.builder().addAllFlags(args.exportedCompilerFlags).addPackages(HaskellPackage.builder().setInfo(HaskellPackageInfo.of(getBuildTarget().getShortName(), args.version, args.id.orElse(String.format("%s-%s", getBuildTarget().getShortName(), args.version)))).setPackageDb(args.db).addAllInterfaces(args.importDirs).addAllLibraries(depType == Linker.LinkableDepType.SHARED ? args.sharedLibs.values() : args.staticLibs).build()).build();
}
@Override
public Iterable<? extends NativeLinkable> getNativeLinkableDeps() {
return ImmutableList.of();
}
@Override
public Iterable<? extends NativeLinkable> getNativeLinkableExportedDeps() {
return FluentIterable.from(getDeclaredDeps()).filter(NativeLinkable.class);
}
@Override
public NativeLinkableInput getNativeLinkableInput(CxxPlatform cxxPlatform, Linker.LinkableDepType type) {
NativeLinkableInput.Builder builder = NativeLinkableInput.builder();
builder.addAllArgs(StringArg.from(args.exportedLinkerFlags));
if (type == Linker.LinkableDepType.SHARED) {
builder.addAllArgs(SourcePathArg.from(args.sharedLibs.values()));
} else {
builder.addAllArgs(SourcePathArg.from(args.staticLibs));
}
return builder.build();
}
@Override
public Linkage getPreferredLinkage(CxxPlatform cxxPlatform) {
return Linkage.ANY;
}
@Override
public ImmutableMap<String, SourcePath> getSharedLibraries(CxxPlatform cxxPlatform) {
return args.sharedLibs;
}
@Override
public Iterable<? extends CxxPreprocessorDep> getCxxPreprocessorDeps(CxxPlatform cxxPlatform) {
return FluentIterable.from(getDeps()).filter(CxxPreprocessorDep.class);
}
@Override
public Optional<HeaderSymlinkTree> getExportedHeaderSymlinkTree(CxxPlatform cxxPlatform) {
return Optional.empty();
}
@Override
public CxxPreprocessorInput getCxxPreprocessorInput(CxxPlatform cxxPlatform, HeaderVisibility headerVisibility) throws NoSuchBuildTargetException {
CxxPreprocessorInput.Builder builder = CxxPreprocessorInput.builder();
for (SourcePath headerDir : args.cxxHeaderDirs) {
builder.addIncludes(CxxHeadersDir.of(CxxPreprocessables.IncludeType.SYSTEM, headerDir));
}
return builder.build();
}
@Override
public ImmutableMap<BuildTarget, CxxPreprocessorInput> getTransitiveCxxPreprocessorInput(CxxPlatform cxxPlatform, HeaderVisibility headerVisibility) throws NoSuchBuildTargetException {
return transitiveCxxPreprocessorInputCache.getUnchecked(ImmutableCxxPreprocessorInputCacheKey.of(cxxPlatform, headerVisibility));
}
};
}
use of com.facebook.buck.cxx.HeaderSymlinkTree in project buck by facebook.
the class CxxPythonExtensionDescription method getExtensionArgs.
private ImmutableList<com.facebook.buck.rules.args.Arg> getExtensionArgs(BuildRuleParams params, BuildRuleResolver ruleResolver, SourcePathResolver pathResolver, SourcePathRuleFinder ruleFinder, CxxPlatform cxxPlatform, Arg args) throws NoSuchBuildTargetException {
// Extract all C/C++ sources from the constructor arg.
ImmutableMap<String, CxxSource> srcs = CxxDescriptionEnhancer.parseCxxSources(params.getBuildTarget(), ruleResolver, ruleFinder, pathResolver, cxxPlatform, args);
ImmutableMap<Path, SourcePath> headers = CxxDescriptionEnhancer.parseHeaders(params.getBuildTarget(), ruleResolver, ruleFinder, pathResolver, Optional.of(cxxPlatform), args);
// Setup the header symlink tree and combine all the preprocessor input from this rule
// and all dependencies.
HeaderSymlinkTree headerSymlinkTree = CxxDescriptionEnhancer.requireHeaderSymlinkTree(params, ruleResolver, cxxPlatform, headers, HeaderVisibility.PRIVATE, true);
Optional<SymlinkTree> sandboxTree = Optional.empty();
if (cxxBuckConfig.sandboxSources()) {
sandboxTree = CxxDescriptionEnhancer.createSandboxTree(params, ruleResolver, cxxPlatform);
}
ImmutableList<CxxPreprocessorInput> cxxPreprocessorInput = CxxDescriptionEnhancer.collectCxxPreprocessorInput(params, cxxPlatform, CxxFlags.getLanguageFlags(args.preprocessorFlags, args.platformPreprocessorFlags, args.langPreprocessorFlags, cxxPlatform), ImmutableList.of(headerSymlinkTree), ImmutableSet.of(), CxxPreprocessables.getTransitiveCxxPreprocessorInput(cxxPlatform, params.getDeps()), args.includeDirs, sandboxTree);
// Generate rule to build the object files.
ImmutableMap<CxxPreprocessAndCompile, SourcePath> picObjects = CxxSourceRuleFactory.requirePreprocessAndCompileRules(params, ruleResolver, pathResolver, ruleFinder, cxxBuckConfig, cxxPlatform, cxxPreprocessorInput, CxxFlags.getLanguageFlags(args.compilerFlags, args.platformCompilerFlags, args.langCompilerFlags, cxxPlatform), args.prefixHeader, args.precompiledHeader, srcs, CxxSourceRuleFactory.PicType.PIC, sandboxTree);
ImmutableList.Builder<com.facebook.buck.rules.args.Arg> argsBuilder = ImmutableList.builder();
argsBuilder.addAll(CxxDescriptionEnhancer.toStringWithMacrosArgs(params.getBuildTarget(), params.getCellRoots(), ruleResolver, cxxPlatform, CxxFlags.getFlagsWithMacrosWithPlatformMacroExpansion(args.linkerFlags, args.platformLinkerFlags, cxxPlatform)));
// Embed a origin-relative library path into the binary so it can find the shared libraries.
argsBuilder.addAll(StringArg.from(Linkers.iXlinker("-rpath", String.format("%s/", cxxPlatform.getLd().resolve(ruleResolver).libOrigin()))));
// Add object files into the args.
argsBuilder.addAll(SourcePathArg.from(picObjects.values()));
return argsBuilder.build();
}
Aggregations