From e87336f6d97d0b37d1e58be51a716fc20dcc747d Mon Sep 17 00:00:00 2001 From: Googler Date: Fri, 6 May 2016 22:53:22 +0000 Subject: Support alwayslink cc_library dependencies in objc binaries. RELNOTES: Support alwayslink cc_library dependencies in objc binaries. -- MOS_MIGRATED_REVID=121717739 --- .../build/lib/rules/objc/CompilationSupport.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src') diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java index 395a2beaa2..27dc24bdb9 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java @@ -15,6 +15,7 @@ package com.google.devtools.build.lib.rules.objc; import static com.google.devtools.build.lib.packages.ImplicitOutputsFunction.fromTemplates; +import static com.google.devtools.build.lib.rules.cpp.Link.LINK_LIBRARY_FILETYPES; import static com.google.devtools.build.lib.rules.objc.ObjcProvider.DEFINE; import static com.google.devtools.build.lib.rules.objc.ObjcProvider.FORCE_LOAD_LIBRARY; import static com.google.devtools.build.lib.rules.objc.ObjcProvider.FRAMEWORK_DIR; @@ -172,6 +173,17 @@ public final class CompilationSupport { } }; + /** + * Selects cc libraries that have alwayslink=1. + */ + private static final Predicate ALWAYS_LINKED_CC_LIBRARY = + new Predicate() { + @Override + public boolean apply(Artifact input) { + return LINK_LIBRARY_FILETYPES.matches(input.getFilename()); + } + }; + /** * Defines a library that contains the transitive closure of dependencies. */ @@ -1071,9 +1083,13 @@ public final class CompilationSupport { .addExecPaths(ccLibraries); } + Iterable ccLibrariesToForceLoad = + Iterables.filter(ccLibraries, ALWAYS_LINKED_CC_LIBRARY); + commandLine .addExecPath("-o", linkedBinary) .addBeforeEach("-force_load", Artifact.toExecPaths(objcProvider.get(FORCE_LOAD_LIBRARY))) + .addBeforeEach("-force_load", Artifact.toExecPaths(ccLibrariesToForceLoad)) .add(extraLinkArgs) .add(objcProvider.get(ObjcProvider.LINKOPT)); -- cgit v1.2.3