Search in sources :

Example 1 with CxxSource

use of com.facebook.buck.cxx.CxxSource 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;
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) CxxSource(com.facebook.buck.cxx.CxxSource) LinkerMapMode(com.facebook.buck.cxx.LinkerMapMode) FrameworkPath(com.facebook.buck.rules.coercer.FrameworkPath) SourcePath(com.facebook.buck.rules.SourcePath) ExplicitBuildTargetSourcePath(com.facebook.buck.rules.ExplicitBuildTargetSourcePath) CxxLinkAndCompileRules(com.facebook.buck.cxx.CxxLinkAndCompileRules) StripStyle(com.facebook.buck.cxx.StripStyle) CxxBinary(com.facebook.buck.cxx.CxxBinary)

Example 2 with CxxSource

use of com.facebook.buck.cxx.CxxSource 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();
}
Also used : Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) HeaderSymlinkTree(com.facebook.buck.cxx.HeaderSymlinkTree) CxxPreprocessAndCompile(com.facebook.buck.cxx.CxxPreprocessAndCompile) ImmutableList(com.google.common.collect.ImmutableList) CxxSource(com.facebook.buck.cxx.CxxSource) SourcePath(com.facebook.buck.rules.SourcePath) SymlinkTree(com.facebook.buck.rules.SymlinkTree) HeaderSymlinkTree(com.facebook.buck.cxx.HeaderSymlinkTree) SourcePathArg(com.facebook.buck.rules.args.SourcePathArg) CxxConstructorArg(com.facebook.buck.cxx.CxxConstructorArg) CxxPreprocessorInput(com.facebook.buck.cxx.CxxPreprocessorInput)

Example 3 with CxxSource

use of com.facebook.buck.cxx.CxxSource 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();
}
Also used : Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) HeaderSymlinkTree(com.facebook.buck.cxx.HeaderSymlinkTree) CxxPreprocessAndCompile(com.facebook.buck.cxx.CxxPreprocessAndCompile) ImmutableList(com.google.common.collect.ImmutableList) CxxSource(com.facebook.buck.cxx.CxxSource) SourcePath(com.facebook.buck.rules.SourcePath) SymlinkTree(com.facebook.buck.rules.SymlinkTree) HeaderSymlinkTree(com.facebook.buck.cxx.HeaderSymlinkTree) StringArg(com.facebook.buck.rules.args.StringArg) SourcePathArg(com.facebook.buck.rules.args.SourcePathArg) CxxConstructorArg(com.facebook.buck.cxx.CxxConstructorArg) CxxPreprocessorInput(com.facebook.buck.cxx.CxxPreprocessorInput)

Aggregations

CxxSource (com.facebook.buck.cxx.CxxSource)3 SourcePath (com.facebook.buck.rules.SourcePath)3 ImmutableList (com.google.common.collect.ImmutableList)3 CxxConstructorArg (com.facebook.buck.cxx.CxxConstructorArg)2 CxxPreprocessAndCompile (com.facebook.buck.cxx.CxxPreprocessAndCompile)2 CxxPreprocessorInput (com.facebook.buck.cxx.CxxPreprocessorInput)2 HeaderSymlinkTree (com.facebook.buck.cxx.HeaderSymlinkTree)2 SymlinkTree (com.facebook.buck.rules.SymlinkTree)2 SourcePathArg (com.facebook.buck.rules.args.SourcePathArg)2 Path (java.nio.file.Path)2 CxxBinary (com.facebook.buck.cxx.CxxBinary)1 CxxLinkAndCompileRules (com.facebook.buck.cxx.CxxLinkAndCompileRules)1 LinkerMapMode (com.facebook.buck.cxx.LinkerMapMode)1 StripStyle (com.facebook.buck.cxx.StripStyle)1 ExplicitBuildTargetSourcePath (com.facebook.buck.rules.ExplicitBuildTargetSourcePath)1 StringArg (com.facebook.buck.rules.args.StringArg)1 FrameworkPath (com.facebook.buck.rules.coercer.FrameworkPath)1