diff options
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules')
4 files changed, 98 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/apple/AppleCommandLineOptions.java b/src/main/java/com/google/devtools/build/lib/rules/apple/AppleCommandLineOptions.java index b48c5224f3..fbba034669 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/apple/AppleCommandLineOptions.java +++ b/src/main/java/com/google/devtools/build/lib/rules/apple/AppleCommandLineOptions.java @@ -15,12 +15,14 @@ package com.google.devtools.build.lib.rules.apple; import com.google.common.annotations.VisibleForTesting; +import com.google.common.collect.ImmutableList; import com.google.common.collect.Multimap; import com.google.devtools.build.lib.Constants; import com.google.devtools.build.lib.analysis.config.BuildConfiguration.DefaultLabelConverter; import com.google.devtools.build.lib.analysis.config.FragmentOptions; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.common.options.Converters.CommaSeparatedOptionListConverter; +import com.google.devtools.common.options.EnumConverter; import com.google.devtools.common.options.Option; import java.util.List; @@ -99,6 +101,15 @@ public class AppleCommandLineOptions extends FragmentOptions { } } + @Option(name = "apple_bitcode", + converter = AppleBitcodeMode.Converter.class, + // TODO(blaze-team): Default to embedded_markers when fully implemented. + defaultValue = "none", + category = "flags", + help = "Specify the Apple bitcode mode for compile steps. " + + "Values: 'none', 'embedded_markers', 'embedded'.") + public AppleBitcodeMode appleBitcodeMode; + /** Converter for {@code --xcode_version_config}. */ public static class XcodeVersionConfigConverter extends DefaultLabelConverter { public XcodeVersionConfigConverter() { @@ -121,6 +132,61 @@ public class AppleCommandLineOptions extends FragmentOptions { labelMap.put("default_provisioning_profile", defaultProvisioningProfile); } } + + /** + * Represents the Apple Bitcode mode for compilation steps. + * + * <p>Bitcode is an intermediate representation of a compiled program. For many platforms, + * Apple requires app submissions to contain bitcode in order to be uploaded to the app store. + * + * <p>This is a build-wide value, as bitcode mode needs to be consistent among a target and + * its compiled dependencies. + */ + public enum AppleBitcodeMode { + + /** + * Do not compile bitcode. + */ + NONE("none"), + /** + * Compile the minimal set of bitcode markers. This is often the best option for + * developer/debug builds. + */ + EMBEDDED_MARKERS("embedded_markers", "-fembed-bitcode-marker"), + /** + * Fully embed bitcode in compiled files. This is often the best option for release builds. + */ + EMBEDDED("embedded", "-fembed-bitcode"); + + private final String mode; + private final ImmutableList<String> compilerFlags; + + private AppleBitcodeMode(String mode, String... compilerFlags) { + this.mode = mode; + this.compilerFlags = ImmutableList.copyOf(compilerFlags); + } + + @Override + public String toString() { + return mode; + } + + /** + * Returns the flags that should be added to compile actions to use this bitcode setting. + */ + public ImmutableList<String> getCompilerFlags() { + return compilerFlags; + } + + /** + * Converts to {@link AppleBitcodeMode}. + */ + public static class Converter extends EnumConverter<AppleBitcodeMode> { + public Converter() { + super(AppleBitcodeMode.class, "apple bitcode mode"); + } + } + } @Override public FragmentOptions getHost(boolean fallback) { @@ -128,6 +194,7 @@ public class AppleCommandLineOptions extends FragmentOptions { // Set options needed in the host configuration. host.xcodeVersion = xcodeVersion; + host.appleBitcodeMode = appleBitcodeMode; return host; } diff --git a/src/main/java/com/google/devtools/build/lib/rules/apple/AppleConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/apple/AppleConfiguration.java index ae9aceee81..73096ec15a 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/apple/AppleConfiguration.java +++ b/src/main/java/com/google/devtools/build/lib/rules/apple/AppleConfiguration.java @@ -24,6 +24,7 @@ import com.google.devtools.build.lib.analysis.config.ConfigurationFragmentFactor import com.google.devtools.build.lib.analysis.config.FragmentOptions; import com.google.devtools.build.lib.analysis.config.InvalidConfigurationException; import com.google.devtools.build.lib.cmdline.Label; +import com.google.devtools.build.lib.rules.apple.AppleCommandLineOptions.AppleBitcodeMode; import com.google.devtools.build.lib.util.Preconditions; import java.util.List; @@ -51,6 +52,7 @@ public class AppleConfiguration extends BuildConfiguration.Fragment { private final String iosCpu; private final Optional<DottedVersion> xcodeVersionOverride; private final List<String> iosMultiCpus; + private final AppleBitcodeMode bitcodeMode; private final Label xcodeConfigLabel; @Nullable private final Label defaultProvisioningProfileLabel; @@ -59,6 +61,7 @@ public class AppleConfiguration extends BuildConfiguration.Fragment { this.xcodeVersionOverride = Optional.fromNullable(appleOptions.xcodeVersion); this.iosCpu = Preconditions.checkNotNull(appleOptions.iosCpu, "iosCpu"); this.iosMultiCpus = Preconditions.checkNotNull(appleOptions.iosMultiCpus, "iosMultiCpus"); + this.bitcodeMode = appleOptions.appleBitcodeMode; this.xcodeConfigLabel = Preconditions.checkNotNull(appleOptions.xcodeVersionConfig, "xcodeConfigLabel"); this.defaultProvisioningProfileLabel = appleOptions.defaultProvisioningProfile; @@ -169,6 +172,16 @@ public class AppleConfiguration extends BuildConfiguration.Fragment { @Nullable public Label getDefaultProvisioningProfileLabel() { return defaultProvisioningProfileLabel; } + + /** + * Returns the bitcode mode to use for compilation steps. Users can control bitcode + * mode using the {@code apple_bitcode} build flag. + * + * @see AppleBitcodeMode + */ + public AppleBitcodeMode getBitcodeMode() { + return bitcodeMode; + } /** * Returns the label of the xcode_config rule to use for resolving the host system xcode version. diff --git a/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeConfig.java b/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeConfig.java index 9528bdafea..eb789b3c50 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeConfig.java +++ b/src/main/java/com/google/devtools/build/lib/rules/apple/XcodeConfig.java @@ -27,6 +27,7 @@ import com.google.devtools.build.lib.analysis.RuleContext; import com.google.devtools.build.lib.analysis.RunfilesProvider; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory; +import com.google.devtools.build.lib.rules.apple.AppleCommandLineOptions.AppleBitcodeMode; import java.util.Map; @@ -37,6 +38,8 @@ import javax.annotation.Nullable; */ public class XcodeConfig implements RuleConfiguredTargetFactory { + private static final DottedVersion MINIMUM_BITCODE_XCODE_VERSION = DottedVersion.fromString("7"); + @Override public ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException { AppleConfiguration configuration = ruleContext.getFragment(AppleConfiguration.class); @@ -55,12 +58,26 @@ public class XcodeConfig implements RuleConfiguredTargetFactory { xcodeConfigProvider = new XcodeConfigProvider(targetVersion); } + validateXcodeConfig(ruleContext, configuration, xcodeConfigProvider); + return new RuleConfiguredTargetBuilder(ruleContext) .addProvider(RunfilesProvider.class, RunfilesProvider.EMPTY) .addProvider(XcodeConfigProvider.class, xcodeConfigProvider) .build(); } + private void validateXcodeConfig(RuleContext ruleContext, AppleConfiguration config, + XcodeConfigProvider xcodeConfigProvider) { + Optional<DottedVersion> xcodeVersion = xcodeConfigProvider.getXcodeVersion(); + if (config.getBitcodeMode() != AppleBitcodeMode.NONE + && xcodeVersion.isPresent() + && xcodeVersion.get().compareTo(MINIMUM_BITCODE_XCODE_VERSION) < 0) { + ruleContext.ruleError( + String.format("apple_bitcode mode '%s' is unsupported for xcode version '%s'", + config.getBitcodeMode(), xcodeVersion.get())); + } + } + /** * Returns the xcode version number corresponding to the {@code --xcode_version} flag, if there * is an available {@code xcode_version} target which recognizes the flag value as either 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 801e7f7d60..d2458c9b68 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 @@ -1336,6 +1336,7 @@ public final class CompilationSupport { return Iterables.concat( AppleToolchain.DEFAULT_WARNINGS.values(), platformSpecificCompileFlagsForClang(configuration), + configuration.getBitcodeMode().getCompilerFlags(), DEFAULT_COMPILER_FLAGS ); } |