Search in sources :

Example 16 with NativeLinkableInput

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

the class SwiftRuntimeNativeLinkable method getNativeLinkableInput.

@Override
public NativeLinkableInput getNativeLinkableInput(CxxPlatform cxxPlatform, Linker.LinkableDepType type) throws NoSuchBuildTargetException {
    NativeLinkableInput.Builder inputBuilder = NativeLinkableInput.builder();
    ImmutableSet<Path> swiftRuntimePaths = type == Linker.LinkableDepType.SHARED ? ImmutableSet.of() : swiftPlatform.getSwiftStaticRuntimePaths();
    // Fall back to shared if static isn't supported on this platform.
    if (type == Linker.LinkableDepType.SHARED || swiftRuntimePaths.isEmpty()) {
        inputBuilder.addAllArgs(StringArg.from("-Xlinker", "-rpath", "-Xlinker", "@executable_path/Frameworks", "-Xlinker", "-rpath", "-Xlinker", "@loader_path/Frameworks"));
        swiftRuntimePaths = swiftPlatform.getSwiftRuntimePaths();
    } else {
        // Static linking requires force-loading Swift libs, since the dependency
        // discovery mechanism is disabled otherwise.
        inputBuilder.addAllArgs(StringArg.from("-Xlinker", "-force_load_swift_libs"));
    }
    for (Path swiftRuntimePath : swiftRuntimePaths) {
        inputBuilder.addAllArgs(StringArg.from("-L", swiftRuntimePath.toString()));
    }
    return inputBuilder.build();
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) NativeLinkableInput(com.facebook.buck.cxx.NativeLinkableInput)

Example 17 with NativeLinkableInput

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

the class HaskellLibraryDescriptionTest method linkWhole.

@Test
public void linkWhole() throws Exception {
    BuildTarget target = BuildTargetFactory.newInstance("//:rule");
    HaskellLibraryBuilder builder = new HaskellLibraryBuilder(target).setLinkWhole(true);
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraphFactory.newInstance(builder.build()), new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    HaskellLibrary library = builder.build(resolver);
    // Lookup the link whole flags.
    Linker linker = CxxPlatformUtils.DEFAULT_PLATFORM.getLd().resolve(resolver);
    ImmutableList<String> linkWholeFlags = FluentIterable.from(linker.linkWhole(StringArg.of("sentinel"))).transformAndConcat((input) -> Arg.stringifyList(input, pathResolver)).filter(Predicates.not("sentinel"::equals)).toList();
    // Test static dep type.
    NativeLinkableInput staticInput = library.getNativeLinkableInput(CxxPlatformUtils.DEFAULT_PLATFORM, Linker.LinkableDepType.STATIC);
    assertThat(Arg.stringify(staticInput.getArgs(), pathResolver), hasItems(linkWholeFlags.toArray(new String[linkWholeFlags.size()])));
    // Test static-pic dep type.
    NativeLinkableInput staticPicInput = library.getNativeLinkableInput(CxxPlatformUtils.DEFAULT_PLATFORM, Linker.LinkableDepType.STATIC_PIC);
    assertThat(Arg.stringify(staticPicInput.getArgs(), pathResolver), hasItems(linkWholeFlags.toArray(new String[linkWholeFlags.size()])));
    // Test shared dep type.
    NativeLinkableInput sharedInput = library.getNativeLinkableInput(CxxPlatformUtils.DEFAULT_PLATFORM, Linker.LinkableDepType.SHARED);
    assertThat(Arg.stringify(sharedInput.getArgs(), pathResolver), not(hasItems(linkWholeFlags.toArray(new String[linkWholeFlags.size()]))));
}
Also used : NativeLinkableInput(com.facebook.buck.cxx.NativeLinkableInput) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Linker(com.facebook.buck.cxx.Linker) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 18 with NativeLinkableInput

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

the class HaskellPrebuiltLibraryDescriptionTest method sharedLibraries.

@Test
public void sharedLibraries() throws Exception {
    PathSourcePath lib = new FakeSourcePath("libfoo.so");
    BuildTarget target = BuildTargetFactory.newInstance("//:rule");
    PrebuiltHaskellLibraryBuilder builder = new PrebuiltHaskellLibraryBuilder(target).setVersion("1.0.0").setDb(new FakeSourcePath("package.conf.d")).setSharedLibs(ImmutableMap.of("libfoo.so", lib));
    TargetGraph targetGraph = TargetGraphFactory.newInstance(builder.build());
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    PrebuiltHaskellLibrary library = builder.build(resolver, filesystem, targetGraph);
    NativeLinkableInput input = library.getNativeLinkableInput(CxxPlatformUtils.DEFAULT_PLATFORM, Linker.LinkableDepType.SHARED);
    assertThat(RichStream.from(input.getArgs()).flatMap(a -> a.getInputs().stream()).toImmutableSet(), Matchers.contains(lib));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) NativeLinkableInput(com.facebook.buck.cxx.NativeLinkableInput) BuildTarget(com.facebook.buck.model.BuildTarget) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) PathSourcePath(com.facebook.buck.rules.PathSourcePath) TargetGraph(com.facebook.buck.rules.TargetGraph) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Aggregations

NativeLinkableInput (com.facebook.buck.cxx.NativeLinkableInput)18 BuildTarget (com.facebook.buck.model.BuildTarget)10 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)10 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)9 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)9 BuildRule (com.facebook.buck.rules.BuildRule)8 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)8 Test (org.junit.Test)8 Linker (com.facebook.buck.cxx.Linker)6 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)6 SourcePath (com.facebook.buck.rules.SourcePath)6 ImmutableList (com.google.common.collect.ImmutableList)6 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)6 CxxPlatform (com.facebook.buck.cxx.CxxPlatform)5 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)5 TargetGraph (com.facebook.buck.rules.TargetGraph)5 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)5 FluentIterable (com.google.common.collect.FluentIterable)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 Path (java.nio.file.Path)5