diff options
3 files changed, 33 insertions, 4 deletions
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 f05949c1c0..9fb00d47bf 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 @@ -842,7 +842,8 @@ public final class CompilationSupport { ImmutableList<Artifact> ccLibraries) { ObjcConfiguration objcConfiguration = ObjcRuleClasses.objcConfiguration(ruleContext); AppleConfiguration appleConfiguration = ruleContext.getFragment(AppleConfiguration.class); - + Iterable<String> libraryNames = libraryNames(objcProvider); + CustomCommandLine.Builder commandLine = CustomCommandLine.builder() .addPath(xcrunwrapper(ruleContext).getExecutable().getExecPath()); @@ -861,6 +862,10 @@ public final class CompilationSupport { commandLine.add("-dead_strip").add("-no_dead_strip_inits_and_terms"); } + if (objcConfiguration.shouldPrioritizeSystemLibsOverFrameworks()) { + commandLine.addFormatEach("-l%s", libraryNames); + } + commandLine .add(commonLinkAndCompileFlagsForClang(objcProvider, objcConfiguration, appleConfiguration)) .add("-Xlinker") @@ -870,8 +875,13 @@ public final class CompilationSupport { .add("-fobjc-link-runtime") .add(DEFAULT_LINKER_FLAGS) .addBeforeEach("-framework", frameworkNames(objcProvider)) - .addBeforeEach("-weak_framework", SdkFramework.names(objcProvider.get(WEAK_SDK_FRAMEWORK))) - .addFormatEach("-l%s", libraryNames(objcProvider)) + .addBeforeEach("-weak_framework", SdkFramework.names(objcProvider.get(WEAK_SDK_FRAMEWORK))); + + if (!objcConfiguration.shouldPrioritizeSystemLibsOverFrameworks()) { + commandLine.addFormatEach("-l%s", libraryNames); + } + + commandLine .addExecPath("-o", linkedBinary) .addExecPaths(objcProvider.get(LIBRARY)) .addExecPaths(objcProvider.get(IMPORTED_LIBRARY)) diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommandLineOptions.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommandLineOptions.java index 6c37619b5e..02e9338984 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommandLineOptions.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcCommandLineOptions.java @@ -162,6 +162,16 @@ public class ObjcCommandLineOptions extends FragmentOptions { ) public String xcodeOverrideWorkspaceRoot; + @Option( + name = "objc_includes_prioritize_system_libs", + defaultValue = "false", + category = "flags", + help = + "If set, the linker invocation will contain system library includes before framework" + + " includes." + ) + public boolean prioritizeSystemLibsOverFrameworks; + @VisibleForTesting static final String DEFAULT_MINIMUM_IOS = "7.0"; @Override diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcConfiguration.java index 53a36ab756..4e24f66870 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcConfiguration.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcConfiguration.java @@ -61,7 +61,7 @@ public class ObjcConfiguration extends BuildConfiguration.Fragment { @Nullable private final Path clientWorkspaceRoot; private final String xcodeOverrideWorkspaceRoot; private final boolean useAbsolutePathsForActions; - + private final boolean prioritizeSystemLibsOverFrameworks; ObjcConfiguration(ObjcCommandLineOptions objcOptions, BuildConfiguration.Options options, @Nullable BlazeDirectories directories) { @@ -83,6 +83,7 @@ public class ObjcConfiguration extends BuildConfiguration.Fragment { this.signingCertName = objcOptions.iosSigningCertName; this.xcodeOverrideWorkspaceRoot = objcOptions.xcodeOverrideWorkspaceRoot; this.useAbsolutePathsForActions = objcOptions.useAbsolutePathsForActions; + this.prioritizeSystemLibsOverFrameworks = objcOptions.prioritizeSystemLibsOverFrameworks; } /** @@ -220,4 +221,12 @@ public class ObjcConfiguration extends BuildConfiguration.Fragment { public String getSigningCertName() { return this.signingCertName; } + + /** + * Returns true if the linker invocation should contain system library includes before framework + * includes. + */ + public boolean shouldPrioritizeSystemLibsOverFrameworks() { + return this.prioritizeSystemLibsOverFrameworks; + } } |