diff options
Diffstat (limited to 'src/main/java/com/google/devtools')
9 files changed, 82 insertions, 22 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleWatchExtensionBinary.java b/src/main/java/com/google/devtools/build/lib/rules/objc/AppleWatchExtensionBinary.java index 675c82a0d7..6ffbaec894 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleWatchExtensionBinary.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/AppleWatchExtensionBinary.java @@ -23,7 +23,7 @@ import com.google.devtools.build.lib.rules.objc.CompilationSupport.ExtraLinkArgs public class AppleWatchExtensionBinary extends BinaryLinkingTargetFactory { public AppleWatchExtensionBinary() { - super(HasReleaseBundlingSupport.NO, XcodeProductType.LIBRARY_STATIC); + super(HasReleaseBundlingSupport.NO, XcodeProductType.LIBRARY_STATIC, UsesCrosstool.NO); } @Override diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/BinaryLinkingTargetFactory.java b/src/main/java/com/google/devtools/build/lib/rules/objc/BinaryLinkingTargetFactory.java index 9e72c42549..2af307fd94 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/BinaryLinkingTargetFactory.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/BinaryLinkingTargetFactory.java @@ -27,6 +27,7 @@ import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode; import com.google.devtools.build.lib.analysis.RuleConfiguredTargetBuilder; import com.google.devtools.build.lib.analysis.RuleContext; import com.google.devtools.build.lib.analysis.RunfilesSupport; +import com.google.devtools.build.lib.analysis.TransitiveInfoProviderMap; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory; import com.google.devtools.build.lib.rules.apple.AppleConfiguration; @@ -47,13 +48,23 @@ abstract class BinaryLinkingTargetFactory implements RuleConfiguredTargetFactory YES, NO; } + /** Indicates whether this binary uses the c++ rules backend, including the crosstool. */ + enum UsesCrosstool { + EXPERIMENTAL, // use the crosstool if --experimental_use_crosstool_for_binary is given + NO; + } + private final HasReleaseBundlingSupport hasReleaseBundlingSupport; private final XcodeProductType productType; + private final UsesCrosstool usesCrosstool; - protected BinaryLinkingTargetFactory(HasReleaseBundlingSupport hasReleaseBundlingSupport, - XcodeProductType productType) { + protected BinaryLinkingTargetFactory( + HasReleaseBundlingSupport hasReleaseBundlingSupport, + XcodeProductType productType, + UsesCrosstool usesCrosstool) { this.hasReleaseBundlingSupport = hasReleaseBundlingSupport; this.productType = productType; + this.usesCrosstool = usesCrosstool; } /** @@ -107,9 +118,6 @@ abstract class BinaryLinkingTargetFactory implements RuleConfiguredTargetFactory CompilationSupport compilationSupport = new CompilationSupport(ruleContext) - .registerCompileAndArchiveActions(common) - .registerFullyLinkAction(common.getObjcProvider(), - ruleContext.getImplicitOutputArtifact(CompilationSupport.FULLY_LINKED_LIB)) .addXcodeSettings(xcodeProviderBuilder, common) .registerLinkActions( objcProvider, @@ -120,6 +128,27 @@ abstract class BinaryLinkingTargetFactory implements RuleConfiguredTargetFactory DsymOutputType.APP) .validateAttributes(); + TransitiveInfoProviderMap compilationProviders; + if (usesCrosstool == UsesCrosstool.EXPERIMENTAL + && ruleContext.getFragment(ObjcConfiguration.class).useCrosstoolForBinary()) { + CrosstoolSupport crosstoolSupport = new CrosstoolSupport(ruleContext, objcProvider); + CompilationArtifacts compilationArtifacts = + CompilationSupport.compilationArtifacts(ruleContext); + if (compilationArtifacts.getArchive().isPresent()) { + compilationProviders = crosstoolSupport.registerCompileAndArchiveActions(common); + } else { + compilationProviders = crosstoolSupport.registerCompileActions(common); + } + crosstoolSupport.registerFullyLinkAction(common); + } else { + compilationProviders = null; + compilationSupport + .registerCompileAndArchiveActions(common) + .registerFullyLinkAction( + common.getObjcProvider(), + ruleContext.getImplicitOutputArtifact(CompilationSupport.FULLY_LINKED_LIB)); + } + Optional<XcTestAppProvider> xcTestAppProvider; Optional<RunfilesSupport> maybeRunfilesSupport = Optional.absent(); switch (hasReleaseBundlingSupport) { @@ -188,6 +217,9 @@ abstract class BinaryLinkingTargetFactory implements RuleConfiguredTargetFactory RunfilesSupport runfilesSupport = maybeRunfilesSupport.get(); targetBuilder.setRunfilesSupport(runfilesSupport, runfilesSupport.getExecutable()); } + if (compilationProviders != null) { + targetBuilder.addProviders(compilationProviders); + } configureTarget(targetBuilder, ruleContext); return targetBuilder.build(); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/CrosstoolSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/CrosstoolSupport.java index a01e15e49e..2b92e754d5 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/CrosstoolSupport.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/CrosstoolSupport.java @@ -130,6 +130,7 @@ public class CrosstoolSupport { * * @param common the common instance that hsould be queried in the construction of a fully link * action + * @return providers that should be exported by the calling rule implementation */ public void registerFullyLinkAction(ObjcCommon common) throws InterruptedException { Artifact fullyLinkedArchive = @@ -178,7 +179,7 @@ public class CrosstoolSupport { if (ruleContext.getPrerequisiteArtifact("pch", Mode.TARGET) != null) { activatedCrosstoolSelectables.add("pch"); } - + return toolchain.getFeatures().getFeatureConfiguration(activatedCrosstoolSelectables.build()); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IosExtensionBinary.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IosExtensionBinary.java index 02b96ae7b1..b5dde4fe73 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/IosExtensionBinary.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/IosExtensionBinary.java @@ -22,7 +22,7 @@ import com.google.devtools.build.lib.rules.objc.CompilationSupport.ExtraLinkArgs */ public class IosExtensionBinary extends BinaryLinkingTargetFactory { public IosExtensionBinary() { - super(HasReleaseBundlingSupport.NO, XcodeProductType.LIBRARY_STATIC); + super(HasReleaseBundlingSupport.NO, XcodeProductType.LIBRARY_STATIC, UsesCrosstool.NO); } @Override diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/IosFrameworkBinary.java b/src/main/java/com/google/devtools/build/lib/rules/objc/IosFrameworkBinary.java index e9d21f2f97..fb9cfd6919 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/IosFrameworkBinary.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/IosFrameworkBinary.java @@ -23,7 +23,7 @@ import com.google.devtools.build.lib.rules.objc.CompilationSupport.ExtraLinkArgs */ public class IosFrameworkBinary extends BinaryLinkingTargetFactory { public IosFrameworkBinary() { - super(HasReleaseBundlingSupport.NO, XcodeProductType.LIBRARY_STATIC); + super(HasReleaseBundlingSupport.NO, XcodeProductType.LIBRARY_STATIC, UsesCrosstool.NO); } @Override diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBinary.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBinary.java index 3fcf7dbd3d..49a99db5da 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBinary.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBinary.java @@ -14,9 +14,7 @@ package com.google.devtools.build.lib.rules.objc; -/** - * Implementation for the "objc_binary" rule. - */ +/** Implementation for the "objc_binary" rule. */ public class ObjcBinary extends BinaryLinkingTargetFactory { public ObjcBinary() { super( @@ -26,6 +24,9 @@ public class ObjcBinary extends BinaryLinkingTargetFactory { // TODO(bazel-team): Use LIBRARY_STATIC as parameter instead of APPLICATION once objc_binary // no longer creates an application bundle - XcodeProductType.APPLICATION); + XcodeProductType.APPLICATION, + + // If --experimental_objc_binary is set + UsesCrosstool.EXPERIMENTAL); } } diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBinaryRule.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBinaryRule.java index cc21048f40..313defc35a 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBinaryRule.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcBinaryRule.java @@ -26,6 +26,7 @@ import com.google.devtools.build.lib.packages.ImplicitOutputsFunction; import com.google.devtools.build.lib.packages.RuleClass; import com.google.devtools.build.lib.packages.RuleClass.Builder; import com.google.devtools.build.lib.rules.apple.AppleConfiguration; +import com.google.devtools.build.lib.rules.cpp.CppConfiguration; /** * Rule definition for objc_binary. @@ -36,8 +37,11 @@ public class ObjcBinaryRule implements RuleDefinition { @Override public RuleClass build(Builder builder, RuleDefinitionEnvironment env) { return builder - .requiresConfigurationFragments(ObjcConfiguration.class, J2ObjcConfiguration.class, - AppleConfiguration.class) + .requiresConfigurationFragments( + ObjcConfiguration.class, + J2ObjcConfiguration.class, + AppleConfiguration.class, + CppConfiguration.class) /*<!-- #BLAZE_RULE(objc_binary).IMPLICIT_OUTPUTS --> <ul> <li><code><var>name</var>.ipa</code>: the application bundle as an <code>.ipa</code> @@ -49,10 +53,14 @@ public class ObjcBinaryRule implements RuleDefinition { .setImplicitOutputsFunction( ImplicitOutputsFunction.fromFunctions(ReleaseBundlingSupport.IPA, XcodeSupport.PBXPROJ)) // TODO(bazel-team): Remove these when this rule no longer produces a bundle. - .add(attr("$runner_script_template", LABEL).cfg(HOST) - .value(env.getToolsLabel("//tools/objc:ios_runner.sh.mac_template"))) - .add(attr("$is_executable", BOOLEAN).value(true) - .nonconfigurable("Called from RunCommand.isExecutable, which takes a Target")) + .add( + attr("$runner_script_template", LABEL) + .cfg(HOST) + .value(env.getToolsLabel("//tools/objc:ios_runner.sh.mac_template"))) + .add( + attr("$is_executable", BOOLEAN) + .value(true) + .nonconfigurable("Called from RunCommand.isExecutable, which takes a Target")) .build(); } @@ -61,9 +69,13 @@ public class ObjcBinaryRule implements RuleDefinition { return RuleDefinition.Metadata.builder() .name("objc_binary") .factoryClass(ObjcBinary.class) - .ancestors(BaseRuleClasses.BaseRule.class, ObjcRuleClasses.LinkingRule.class, - ObjcRuleClasses.XcodegenRule.class, ObjcRuleClasses.ReleaseBundlingRule.class, - ObjcRuleClasses.SimulatorRule.class) + .ancestors( + BaseRuleClasses.BaseRule.class, + ObjcRuleClasses.LinkingRule.class, + ObjcRuleClasses.XcodegenRule.class, + ObjcRuleClasses.ReleaseBundlingRule.class, + ObjcRuleClasses.SimulatorRule.class, + ObjcRuleClasses.CrosstoolRule.class) .build(); } } 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 ab1e96bd1b..3a9a49b9c9 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 @@ -222,6 +222,13 @@ public class ObjcCommandLineOptions extends FragmentOptions { public boolean experimentalObjcLibrary; @Option( + name = "experimental_objc_use_crosstool_for_binary", + defaultValue = "false", + category = "undocumented" + ) + public boolean experimentalUseCrosstoolForBinary; + + @Option( name = "objc_use_dotd_pruning", defaultValue = "false", category = "flags", 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 b773269a97..e0e26a8e3b 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 @@ -76,6 +76,7 @@ public class ObjcConfiguration extends BuildConfiguration.Fragment { @Nullable private final Label extraEntitlements; private final boolean deviceDebugEntitlements; private final boolean experimentalObjcLibrary; + private final boolean experimentalUseCrosstoolForBinary; private final HeaderDiscovery.DotdPruningMode dotdPruningPlan; ObjcConfiguration(ObjcCommandLineOptions objcOptions, BuildConfiguration.Options options, @@ -109,6 +110,7 @@ public class ObjcConfiguration extends BuildConfiguration.Fragment { this.extraEntitlements = objcOptions.extraEntitlements; this.deviceDebugEntitlements = objcOptions.deviceDebugEntitlements; this.experimentalObjcLibrary = objcOptions.experimentalObjcLibrary; + this.experimentalUseCrosstoolForBinary = objcOptions.experimentalUseCrosstoolForBinary; this.dotdPruningPlan = objcOptions.useDotdPruning ? HeaderDiscovery.DotdPruningMode.USE @@ -334,6 +336,11 @@ public class ObjcConfiguration extends BuildConfiguration.Fragment { return experimentalObjcLibrary; } + /** Returns true if objc_binary targets should use the crosstool for compiling and archiving. */ + public boolean useCrosstoolForBinary() { + return experimentalUseCrosstoolForBinary; + } + /** Returns the DotdPruningPlan for compiles in this build. */ public HeaderDiscovery.DotdPruningMode getDotdPruningPlan() { return dotdPruningPlan; |