aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2017-10-21 04:06:39 +0200
committerGravatar Dmitry Lomov <dslomov@google.com>2017-10-23 17:16:18 +0200
commit9cc97513839442ac13fe10ab84e103e127e36987 (patch)
treec3bc0aa44c7df12e85cc857d9d614b9a7ec12d8f /src/main/java/com/google/devtools
parent89d13b8810bfe9216ed1746a28b83d636183c1c7 (diff)
Add support for linker scripts in auto-linked Android native deps
Android's mechanism for automatically linking native deps does not currently support linker scripts. A dependency cc_library can specify the linker script in the linkopts and include it in its deps, but since the artifact is not provided as an input to the generated link action, this results in an error. This change provides the missing inputs and makes this work. RELNOTES: Support for linker scripts in NativeDepsHelper (e.g., android_binary) PiperOrigin-RevId: 172963605
Diffstat (limited to 'src/main/java/com/google/devtools')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java1
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkParams.java56
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/nativedeps/NativeDepsHelper.java9
3 files changed, 55 insertions, 11 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java
index 846e68b19b..6a48bae198 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibraryHelper.java
@@ -1563,6 +1563,7 @@ public final class CcLibraryHelper {
LinkerInputs.toLibraryArtifacts(ccLinkingOutputs.getExecutionDynamicLibraries()));
}
builder.addLinkOpts(linkopts);
+ builder.addNonCodeInputs(nonCodeLinkerInputs);
}
}
};
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkParams.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkParams.java
index b9243fb1cb..731c1f6c99 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkParams.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLinkParams.java
@@ -29,6 +29,7 @@ import com.google.devtools.build.lib.rules.cpp.LinkerInputs.LibraryToLink;
import com.google.devtools.build.lib.util.Preconditions;
import java.util.Collection;
import java.util.Objects;
+import javax.annotation.Nullable;
/**
* Parameters to be passed to the linker.
@@ -70,22 +71,25 @@ public final class CcLinkParams {
private final NestedSet<LibraryToLink> libraries;
private final NestedSet<Artifact> executionDynamicLibraries;
private final ExtraLinkTimeLibraries extraLinkTimeLibraries;
+ private final NestedSet<Artifact> nonCodeInputs;
private CcLinkParams(
NestedSet<LinkOptions> linkOpts,
NestedSet<Linkstamp> linkstamps,
NestedSet<LibraryToLink> libraries,
NestedSet<Artifact> executionDynamicLibraries,
- ExtraLinkTimeLibraries extraLinkTimeLibraries) {
+ ExtraLinkTimeLibraries extraLinkTimeLibraries,
+ NestedSet<Artifact> nonCodeInputs) {
this.linkOpts = linkOpts;
this.linkstamps = linkstamps;
this.libraries = libraries;
this.executionDynamicLibraries = executionDynamicLibraries;
this.extraLinkTimeLibraries = extraLinkTimeLibraries;
+ this.nonCodeInputs = nonCodeInputs;
}
/**
- * @return the linkopts
+ * Returns the linkopts
*/
public NestedSet<LinkOptions> getLinkopts() {
return linkOpts;
@@ -96,20 +100,22 @@ public final class CcLinkParams {
}
/**
- * @return the linkstamps
+ * Returns the linkstamps
*/
public NestedSet<Linkstamp> getLinkstamps() {
return linkstamps;
}
/**
- * @return the libraries
+ * Returns the libraries
*/
public NestedSet<LibraryToLink> getLibraries() {
return libraries;
}
- /** @return the executionDynamicLibraries */
+ /**
+ * Returns the executionDynamicLibraries.
+ */
public NestedSet<Artifact> getExecutionDynamicLibraries() {
return executionDynamicLibraries;
}
@@ -117,18 +123,23 @@ public final class CcLinkParams {
/**
* The extra link time libraries; will be null if there are no such libraries.
*/
- public ExtraLinkTimeLibraries getExtraLinkTimeLibraries() {
+ public @Nullable ExtraLinkTimeLibraries getExtraLinkTimeLibraries() {
return extraLinkTimeLibraries;
}
+ /**
+ * Returns the non-code inputs, e.g. linker scripts; will be null if none.
+ */
+ public @Nullable NestedSet<Artifact> getNonCodeInputs() {
+ return nonCodeInputs;
+ }
+
public static final Builder builder(boolean linkingStatically, boolean linkShared) {
return new Builder(linkingStatically, linkShared);
}
/**
* Builder for {@link CcLinkParams}.
- *
- *
*/
public static final class Builder {
@@ -164,6 +175,8 @@ public final class CcLinkParams {
*/
private ExtraLinkTimeLibraries.Builder extraLinkTimeLibrariesBuilder = null;
+ private NestedSetBuilder<Artifact> nonCodeInputsBuilder = null;
+
private boolean built = false;
private Builder(boolean linkingStatically, boolean linkShared) {
@@ -172,7 +185,7 @@ public final class CcLinkParams {
}
/**
- * Build a {@link CcLinkParams} object.
+ * Builds a {@link CcLinkParams} object.
*/
public CcLinkParams build() {
Preconditions.checkState(!built);
@@ -186,12 +199,17 @@ public final class CcLinkParams {
if (extraLinkTimeLibrariesBuilder != null) {
extraLinkTimeLibraries = extraLinkTimeLibrariesBuilder.build();
}
+ NestedSet<Artifact> nonCodeInputs = null;
+ if (nonCodeInputsBuilder != null) {
+ nonCodeInputs = nonCodeInputsBuilder.build();
+ }
return new CcLinkParams(
linkOptsBuilder.build(),
linkstampsBuilder.build(),
librariesBuilder.build(),
executionDynamicLibrariesBuilder.build(),
- extraLinkTimeLibraries);
+ extraLinkTimeLibraries,
+ nonCodeInputs);
}
public boolean add(CcLinkParamsStore store) {
@@ -284,6 +302,12 @@ public final class CcLinkParams {
}
extraLinkTimeLibrariesBuilder.addTransitive(args.getExtraLinkTimeLibraries());
}
+ if (args.getNonCodeInputs() != null) {
+ if (nonCodeInputsBuilder == null) {
+ nonCodeInputsBuilder = NestedSetBuilder.linkOrder();
+ }
+ nonCodeInputsBuilder.addTransitive(args.getNonCodeInputs());
+ }
return this;
}
@@ -339,6 +363,17 @@ public final class CcLinkParams {
return this;
}
+ /**
+ * Adds a collection of non-code inputs.
+ */
+ public Builder addNonCodeInputs(Iterable<Artifact> nonCodeInputs) {
+ if (nonCodeInputsBuilder == null) {
+ nonCodeInputsBuilder = NestedSetBuilder.linkOrder();
+ }
+ nonCodeInputsBuilder.addAll(nonCodeInputs);
+ return this;
+ }
+
/** Processes typical dependencies of a C/C++ library. */
public Builder addCcLibrary(RuleContext context) {
addTransitiveTargets(
@@ -404,5 +439,6 @@ public final class CcLinkParams {
NestedSetBuilder.<Linkstamp>emptySet(Order.COMPILE_ORDER),
NestedSetBuilder.<LibraryToLink>emptySet(Order.LINK_ORDER),
NestedSetBuilder.<Artifact>emptySet(Order.STABLE_ORDER),
+ null,
null);
}
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 2c8cf58886..83f1be8491 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
@@ -232,6 +232,12 @@ public abstract class NativeDepsHelper {
ltoBitcodeFilesMap.putAll(lib.getLtoBitcodeFiles());
}
}
+
+ Iterable<Artifact> nonCodeInputs = linkParams.getNonCodeInputs();
+ if (nonCodeInputs == null) {
+ nonCodeInputs = ImmutableList.of();
+ }
+
builder
.setLinkArtifactFactory(SHAREABLE_LINK_ARTIFACT_FACTORY)
.setCrosstoolInputs(toolchain.getLink())
@@ -242,7 +248,8 @@ public abstract class NativeDepsHelper {
.addLinkopts(linkopts)
.setNativeDeps(true)
.addLinkstamps(linkstamps)
- .addLtoBitcodeFiles(ltoBitcodeFilesMap.build());
+ .addLtoBitcodeFiles(ltoBitcodeFilesMap.build())
+ .addNonCodeInputs(nonCodeInputs);
if (!builder.getLtoBitcodeFiles().isEmpty()
&& featureConfiguration.isEnabled(CppRuleClasses.THIN_LTO)) {