diff options
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/nativedeps/NativeDepsHelper.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/nativedeps/NativeDepsHelper.java | 102 |
1 files changed, 67 insertions, 35 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/nativedeps/NativeDepsHelper.java b/src/main/java/com/google/devtools/build/lib/rules/nativedeps/NativeDepsHelper.java index 5cd41f3913..496ada0f09 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/nativedeps/NativeDepsHelper.java +++ b/src/main/java/com/google/devtools/build/lib/rules/nativedeps/NativeDepsHelper.java @@ -115,9 +115,15 @@ public abstract class NativeDepsHelper { Artifact nativeDeps = ruleContext.getPackageRelativeArtifact(nativeDepsPath, configuration.getBinDirectory()); - return createNativeDepsAction(ruleContext, linkParams, extraLinkOpts, configuration, - CppHelper.getToolchain(ruleContext), nativeDeps, - ruleContext.getConfiguration().getBinDirectory()); + return createNativeDepsAction( + ruleContext, + linkParams, + extraLinkOpts, + configuration, + CppHelper.getToolchain(ruleContext), + nativeDeps, + ruleContext.getConfiguration().getBinDirectory(), /*useDynamicRuntime*/ + true); } private static final String ANDROID_UNIQUE_DIR = "nativedeps"; @@ -153,15 +159,30 @@ public abstract class NativeDepsHelper { configuration.getBinDirectory()); return createNativeDepsAction( - ruleContext, linkParams, /** extraLinkOpts */ImmutableList.<String>of(), - configuration, toolchain, nativeDeps, configuration.getBinDirectory()).getLibrary(); + ruleContext, + linkParams, /** extraLinkOpts */ + ImmutableList.<String>of(), + configuration, + toolchain, + nativeDeps, + configuration.getBinDirectory(), + /*useDynamicRuntime*/ false) + .getLibrary(); } - private static NativeDepsRunfiles createNativeDepsAction(final RuleContext ruleContext, - CcLinkParams linkParams, Collection<String> extraLinkOpts, BuildConfiguration configuration, - CcToolchainProvider toolchain, Artifact nativeDeps, Root bindirIfShared) { - Preconditions.checkState(ruleContext.isLegalFragment(CppConfiguration.class), - "%s does not have access to CppConfiguration", ruleContext.getRule().getRuleClass()); + private static NativeDepsRunfiles createNativeDepsAction( + final RuleContext ruleContext, + CcLinkParams linkParams, + Collection<String> extraLinkOpts, + BuildConfiguration configuration, + CcToolchainProvider toolchain, + Artifact nativeDeps, + Root bindirIfShared, + boolean useDynamicRuntime) { + Preconditions.checkState( + ruleContext.isLegalFragment(CppConfiguration.class), + "%s does not have access to CppConfiguration", + ruleContext.getRule().getRuleClass()); List<String> linkopts = new ArrayList<>(extraLinkOpts); linkopts.addAll(linkParams.flattenedLinkopts()); @@ -182,38 +203,49 @@ public abstract class NativeDepsHelper { : nativeDeps; CppLinkAction.Builder builder = new CppLinkAction.Builder( ruleContext, sharedLibrary, configuration, toolchain); - builder.setLinkArtifactFactory(SHAREABLE_LINK_ARTIFACT_FACTORY); - CppLinkAction linkAction = builder - .setCrosstoolInputs(toolchain.getLink()) - .addLibraries(linkerInputs) - .setLinkType(LinkTargetType.DYNAMIC_LIBRARY) - .setLinkStaticness(LinkStaticness.MOSTLY_STATIC) - .addLinkopts(linkopts) - .setNativeDeps(true) - .setRuntimeInputs( - toolchain.getDynamicRuntimeLinkMiddleman(), toolchain.getDynamicRuntimeLinkInputs()) - .addLinkstamps(linkstamps) - .build(); + if (useDynamicRuntime) { + builder.setRuntimeInputs( + toolchain.getDynamicRuntimeLinkMiddleman(), toolchain.getDynamicRuntimeLinkInputs()); + } else { + builder.setRuntimeInputs( + toolchain.getStaticRuntimeLinkMiddleman(), toolchain.getStaticRuntimeLinkInputs()); + } + CppLinkAction linkAction = + builder + .setLinkArtifactFactory(SHAREABLE_LINK_ARTIFACT_FACTORY) + .setCrosstoolInputs(toolchain.getLink()) + .addLibraries(linkerInputs) + .setLinkType(LinkTargetType.DYNAMIC_LIBRARY) + .setLinkStaticness(LinkStaticness.MOSTLY_STATIC) + .addLinkopts(linkopts) + .setNativeDeps(true) + .addLinkstamps(linkstamps) + .build(); ruleContext.registerAction(linkAction); - final Artifact linkerOutput = linkAction.getPrimaryOutput(); - - List<Artifact> runtimeSymlinks = new LinkedList<>(); + Artifact linkerOutput = linkAction.getPrimaryOutput(); if (shareNativeDeps) { // Collect dynamic-linker-resolvable symlinks for C++ runtime library dependencies. // Note we only need these symlinks when --share_native_deps is on, as shared native deps // mangle path names such that the library's conventional _solib RPATH entry // no longer resolves (because the target directory's relative depth gets lost). - for (final Artifact runtimeInput : toolchain.getDynamicRuntimeLinkInputs()) { - final Artifact runtimeSymlink = ruleContext.getPackageRelativeArtifact( - getRuntimeLibraryPath(ruleContext, runtimeInput), bindirIfShared); - // Since runtime library symlinks are underneath the target's output directory and - // multiple targets may share the same output directory, we need to make sure this - // symlink's generating action is only set once. - ruleContext.registerAction( - new SymlinkAction(ruleContext.getActionOwner(), runtimeInput, runtimeSymlink, null)); - runtimeSymlinks.add(runtimeSymlink); + List<Artifact> runtimeSymlinks; + if (useDynamicRuntime) { + runtimeSymlinks = new LinkedList<>(); + for (final Artifact runtimeInput : toolchain.getDynamicRuntimeLinkInputs()) { + final Artifact runtimeSymlink = + ruleContext.getPackageRelativeArtifact( + getRuntimeLibraryPath(ruleContext, runtimeInput), bindirIfShared); + // Since runtime library symlinks are underneath the target's output directory and + // multiple targets may share the same output directory, we need to make sure this + // symlink's generating action is only set once. + ruleContext.registerAction( + new SymlinkAction(ruleContext.getActionOwner(), runtimeInput, runtimeSymlink, null)); + runtimeSymlinks.add(runtimeSymlink); + } + } else { + runtimeSymlinks = ImmutableList.of(); } ruleContext.registerAction( @@ -221,7 +253,7 @@ public abstract class NativeDepsHelper { return new NativeDepsRunfiles(nativeDeps, runtimeSymlinks); } - return new NativeDepsRunfiles(linkerOutput, runtimeSymlinks); + return new NativeDepsRunfiles(linkerOutput, ImmutableList.<Artifact>of()); } /** |