diff options
Diffstat (limited to 'src/main')
12 files changed, 176 insertions, 192 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java index 008a9cd5d9..7b9a461c15 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java @@ -179,7 +179,6 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory { .addPicIndependentObjectFiles(common.getLinkerScripts()) .addDeps(ruleContext.getPrerequisites("deps", Mode.TARGET)) .addDeps(ImmutableList.of(CppHelper.mallocForTarget(ruleContext))) - .setEnableLayeringCheck(ruleContext.getFeatures().contains(CppRuleClasses.LAYERING_CHECK)) .addSystemIncludeDirs(common.getSystemIncludeDirs()) .addIncludeDirs(common.getIncludeDirs()) .addLooseIncludeDirs(common.getLooseIncludeDirs()) diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java index afda3b6034..295640f2f1 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcCommon.java @@ -234,17 +234,8 @@ public final class CcCommon { } private boolean shouldProcessHeaders() { - if (featureConfiguration.isEnabled(CppRuleClasses.PREPROCESS_HEADERS) - || featureConfiguration.isEnabled(CppRuleClasses.PARSE_HEADERS)) { - return true; - } - // TODO(bazel-team): Remove once header processing is configured via the feature configuration - // in all toolchains. - boolean crosstoolSupportsHeaderParsing = - CppHelper.getToolchain(ruleContext).supportsHeaderParsing(); - return crosstoolSupportsHeaderParsing && ( - ruleContext.getFeatures().contains(CppRuleClasses.PREPROCESS_HEADERS) - || ruleContext.getFeatures().contains(CppRuleClasses.PARSE_HEADERS)); + return featureConfiguration.isEnabled(CppRuleClasses.PREPROCESS_HEADERS) + || featureConfiguration.isEnabled(CppRuleClasses.PARSE_HEADERS); } private ImmutableList<Pair<Artifact, Label>> collectCAndCppSources() { @@ -670,9 +661,18 @@ public final class CcCommon { Set<String> ruleSpecificRequestedFeatures, Set<String> ruleSpecificUnsupportedFeatures) { CcToolchainProvider toolchain = CppHelper.getToolchain(ruleContext); + ImmutableSet.Builder<String> unsupportedFeaturesBuilder = ImmutableSet.builder(); + unsupportedFeaturesBuilder.addAll(ruleSpecificUnsupportedFeatures); + if (!toolchain.supportsHeaderParsing()) { + // TODO(bazel-team): Remove once supports_header_parsing has been removed from the + // cc_toolchain rule. + unsupportedFeaturesBuilder.add(CppRuleClasses.PARSE_HEADERS); + unsupportedFeaturesBuilder.add(CppRuleClasses.PREPROCESS_HEADERS); + } + Set<String> unsupportedFeatures = unsupportedFeaturesBuilder.build(); ImmutableSet.Builder<String> requestedFeatures = ImmutableSet.builder(); for (String feature : Iterables.concat(DEFAULT_FEATURES, ruleContext.getFeatures())) { - if (!ruleSpecificUnsupportedFeatures.contains(feature)) { + if (!unsupportedFeatures.contains(feature)) { requestedFeatures.add(feature); } } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java index 37a800494f..81cd014650 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcLibrary.java @@ -144,8 +144,6 @@ public abstract class CcLibrary implements RuleConfiguredTargetFactory { .addPicObjectFiles(common.getObjectFilesFromSrcs(true)) .addPicIndependentObjectFiles(common.getLinkerScripts()) .addDeps(ruleContext.getPrerequisites("deps", Mode.TARGET)) - .setEnableLayeringCheck(ruleContext.getFeatures().contains(CppRuleClasses.LAYERING_CHECK)) - .setCompileHeaderModules(ruleContext.getFeatures().contains(CppRuleClasses.HEADER_MODULES)) .addSystemIncludeDirs(common.getSystemIncludeDirs()) .addIncludeDirs(common.getIncludeDirs()) .addLooseIncludeDirs(common.getLooseIncludeDirs()) 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 4084d28d60..cc36586067 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 @@ -171,11 +171,6 @@ public final class CcLibraryHelper { private final List<LibraryToLink> picStaticLibraries = new ArrayList<>(); private final List<LibraryToLink> dynamicLibraries = new ArrayList<>(); - // TODO(bazel-team): Remove flags that affect toolchain features after migrating their uses to - // requestedFeatures / unsupportedFeatures. - private boolean emitCppModuleMaps = true; - private boolean enableLayeringCheck; - private boolean compileHeaderModules; private boolean emitCompileActionsIfEmpty = true; private boolean emitCcNativeLibrariesProvider; private boolean emitCcSpecificLinkParamsProvider; @@ -503,40 +498,6 @@ public final class CcLibraryHelper { } /** - * This disables C++ module map generation for the current rule. Don't call this unless you know - * what you are doing. - * - * <p>TODO(bazel-team): Replace with {@code addUnsupportedFeature()}. - */ - public CcLibraryHelper disableCppModuleMapGeneration() { - this.emitCppModuleMaps = false; - return this; - } - - /** - * This enables or disables use of module maps during compilation, i.e., layering checks. - * - * <p>TODO(bazel-team): Replace with {@code addRequestedFeature()}. - */ - public CcLibraryHelper setEnableLayeringCheck(boolean enableLayeringCheck) { - this.enableLayeringCheck = enableLayeringCheck; - return this; - } - - /** - * This enabled or disables compilation of C++ header modules. - * TODO(bazel-team): Add a cc_toolchain flag that allows fully disabling this feature and document - * this feature. - * See http://clang.llvm.org/docs/Modules.html. - * - * <p>TODO(bazel-team): Replace with {@code addRequestedFeature()}. - */ - public CcLibraryHelper setCompileHeaderModules(boolean compileHeaderModules) { - this.compileHeaderModules = compileHeaderModules; - return this; - } - - /** * Enables or disables generation of compile actions if there are no sources. Some rules declare a * .a or .so implicit output, which requires that these files are created even if there are no * source files, so be careful when calling this. @@ -627,8 +588,6 @@ public final class CcLibraryHelper { // Note: this doesn't actually save the temps, it just makes the CppModel use the // configurations --save_temps setting to decide whether to actually save the temps. .setSaveTemps(true) - .setEnableLayeringCheck(enableLayeringCheck) - .setCompileHeaderModules(compileHeaderModules) .setNoCopts(nocopts) .setDynamicLibraryPath(dynamicLibraryPath) .addLinkopts(linkopts) @@ -636,6 +595,7 @@ public final class CcLibraryHelper { CppCompilationContext cppCompilationContext = initializeCppCompilationContext(model, featureConfiguration); model.setContext(cppCompilationContext); + boolean compileHeaderModules = featureConfiguration.isEnabled(CppRuleClasses.HEADER_MODULES); if (emitCompileActionsIfEmpty || !sources.isEmpty() || compileHeaderModules) { Preconditions.checkState( !compileHeaderModules || cppCompilationContext.getCppModuleMap() != null, @@ -766,7 +726,7 @@ public final class CcLibraryHelper { } } - if (emitCppModuleMaps) { + if (featureConfiguration.isEnabled(CppRuleClasses.MODULE_MAPS)) { CppModuleMap cppModuleMap = CppHelper.addCppModuleMapToContext(ruleContext, contextBuilder); // TODO(bazel-team): addCppModuleMapToContext second-guesses whether module maps should // actually be enabled, so we need to double-check here. Who would write code like this? @@ -777,7 +737,7 @@ public final class CcLibraryHelper { publicHeaders, collectModuleMaps(), additionalExportedHeaders, - compileHeaderModules, + featureConfiguration.isEnabled(CppRuleClasses.HEADER_MODULES), featureConfiguration.isEnabled(CppRuleClasses.MODULE_MAP_HOME_CWD)); ruleContext.registerAction(action); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java index 02c4ddbaba..d963dda924 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java @@ -146,8 +146,6 @@ public class CppCompileAction extends AbstractAction implements IncludeScannable private final Collection<PathFragment> extraSystemIncludePrefixes; private final Iterable<IncludeScannable> lipoScannables; private final CppCompileCommandLine cppCompileCommandLine; - private final boolean enableLayeringCheck; - private final boolean compileHeaderModules; private final boolean usePic; @VisibleForTesting @@ -194,7 +192,6 @@ public class CppCompileAction extends AbstractAction implements IncludeScannable * @param context the compilation context * @param copts options for the compiler * @param coptsFilter regular expression to remove options from {@code copts} - * @param compileHeaderModules whether to compile C++ header modules */ protected CppCompileAction(ActionOwner owner, // TODO(bazel-team): Eventually we will remove 'features'; all functionality in 'features' @@ -217,12 +214,10 @@ public class CppCompileAction extends AbstractAction implements IncludeScannable ImmutableList<String> pluginOpts, Predicate<String> coptsFilter, ImmutableList<PathFragment> extraSystemIncludePrefixes, - boolean enableLayeringCheck, @Nullable String fdoBuildStamp, IncludeResolver includeResolver, Iterable<IncludeScannable> lipoScannables, UUID actionClassId, - boolean compileHeaderModules, boolean usePic) { // getInputs() method is overridden in this class so we pass a dummy empty // list to the AbstractAction constructor in place of a real input collection. @@ -237,7 +232,6 @@ public class CppCompileAction extends AbstractAction implements IncludeScannable this.optionalSourceFile = optionalSourceFile; this.context = context; this.extraSystemIncludePrefixes = extraSystemIncludePrefixes; - this.enableLayeringCheck = enableLayeringCheck; this.includeResolver = includeResolver; this.cppConfiguration = cppConfiguration; if (cppConfiguration != null && !cppConfiguration.shouldScanIncludes()) { @@ -249,7 +243,6 @@ public class CppCompileAction extends AbstractAction implements IncludeScannable this.actionContext = actionContext; this.lipoScannables = lipoScannables; this.actionClassId = actionClassId; - this.compileHeaderModules = compileHeaderModules; this.usePic = usePic; // We do not need to include the middleman artifact since it is a generated @@ -1135,12 +1128,9 @@ public class CppCompileAction extends AbstractAction implements IncludeScannable return CPP_MODULE_COMPILE; } else if (CppFileTypes.CPP_HEADER.matches(sourcePath)) { // TODO(bazel-team): Handle C headers that probably don't work in C++ mode. - // TODO(bazel-team): Replace use of features.contains with featureConfiguration.isEnabled - // here (the other instances will need to stay with the current feature selection process - // until all crosstool configurations have been converted). - if (features.contains(CppRuleClasses.PARSE_HEADERS)) { + if (featureConfiguration.isEnabled(CppRuleClasses.PARSE_HEADERS)) { return CPP_HEADER_PARSING; - } else if (features.contains(CppRuleClasses.PREPROCESS_HEADERS)) { + } else if (featureConfiguration.isEnabled(CppRuleClasses.PREPROCESS_HEADERS)) { return CPP_HEADER_PREPROCESSING; } else { // CcCommon.collectCAndCppSources() ensures we do not add headers to @@ -1162,39 +1152,6 @@ public class CppCompileAction extends AbstractAction implements IncludeScannable public List<String> getCompilerOptions() { List<String> options = new ArrayList<>(); - // TODO(bazel-team): Extract combinations of options into sections in the CROSSTOOL file. - if (CppFileTypes.CPP_MODULE_MAP.matches(sourceFile.getExecPath())) { - if (!featureConfiguration.isEnabled(CppRuleClasses.HEADER_MODULES)) { - options.add("-x"); - options.add("c++"); - options.add("-Xclang=-emit-module"); - options.add("-Xcrosstool-module-compilation"); - } - } else if (CppFileTypes.CPP_HEADER.matches(sourceFile.getExecPath())) { - // TODO(bazel-team): Read the compiler flag settings out of the CROSSTOOL file. - // TODO(bazel-team): Handle C headers that probably don't work in C++ mode. - if (features.contains(CppRuleClasses.PARSE_HEADERS)) { - if (!featureConfiguration.isEnabled(CppRuleClasses.PARSE_HEADERS)) { - options.add("-x"); - options.add("c++-header"); - // Specifying -x c++-header will make clang/gcc create precompiled - // headers, which we suppress with -fsyntax-only. - options.add("-fsyntax-only"); - } - } else if (features.contains(CppRuleClasses.PREPROCESS_HEADERS)) { - if (!featureConfiguration.isEnabled(CppRuleClasses.PREPROCESS_HEADERS)) { - options.add("-E"); - options.add("-x"); - options.add("c++"); - } - } else { - // CcCommon.collectCAndCppSources() ensures we do not add headers to - // the compilation artifacts unless either 'parse_headers' or - // 'preprocess_headers' is set. - throw new IllegalStateException(); - } - } - for (PathFragment quoteIncludePath : context.getQuoteIncludeDirs()) { // "-iquote" is a gcc-specific option. For C compilers that don't support "-iquote", // we should instead use "-I". @@ -1280,30 +1237,6 @@ public class CppCompileAction extends AbstractAction implements IncludeScannable options.add(dotdFile.getSafeExecPath().getPathString()); } - if (cppModuleMap != null && (compileHeaderModules || enableLayeringCheck)) { - if (!featureConfiguration.isEnabled(CppRuleClasses.MODULE_MAPS)) { - // TODO(bazel-team): Remove this path once all toolchains that support module map have - // their configuration updated; in that case, we do not need to add the flags here, as - // they will be added through the corresponding crosstool feature configuration. - options.add("-Xclang-only=-fmodule-maps"); - options.add("-Xclang-only=-fmodule-name=" + cppModuleMap.getName()); - options.add("-Xclang-only=-fmodule-map-file=" - + cppModuleMap.getArtifact().getExecPathString()); - options.add("-Xclang=-fno-modules-implicit-maps"); - } - - if (compileHeaderModules - && !featureConfiguration.isEnabled(CppRuleClasses.HEADER_MODULES)) { - options.add("-Xclang-only=-fmodules"); - for (String headerModulePath : getHeaderModulePaths()) { - options.add("-Xclang=-fmodule-file=" + headerModulePath); - } - } - if (enableLayeringCheck && !featureConfiguration.isEnabled(CppRuleClasses.LAYERING_CHECK)) { - options.add("-Xclang-only=-fmodules-strict-decluse"); - } - } - if (FileType.contains(outputFile, CppFileTypes.ASSEMBLER, CppFileTypes.PIC_ASSEMBLER)) { options.add("-S"); } else if (FileType.contains(outputFile, CppFileTypes.PREPROCESSED_C, diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java index 5c1a5e9faf..ad88747061 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileActionBuilder.java @@ -70,8 +70,6 @@ public class CppCompileActionBuilder { private final List<Pattern> nocopts = new ArrayList<>(); private AnalysisEnvironment analysisEnvironment; private ImmutableList<PathFragment> extraSystemIncludePrefixes = ImmutableList.of(); - private boolean enableLayeringCheck; - private boolean compileHeaderModules; private String fdoBuildStamp; private boolean usePic; private IncludeResolver includeResolver = CppCompileAction.VOID_INCLUDE_RESOLVER; @@ -154,8 +152,6 @@ public class CppCompileActionBuilder { this.nocopts.addAll(other.nocopts); this.analysisEnvironment = other.analysisEnvironment; this.extraSystemIncludePrefixes = ImmutableList.copyOf(other.extraSystemIncludePrefixes); - this.enableLayeringCheck = other.enableLayeringCheck; - this.compileHeaderModules = other.compileHeaderModules; this.includeResolver = other.includeResolver; this.actionClassId = other.actionClassId; this.actionContext = other.actionContext; @@ -261,7 +257,7 @@ public class CppCompileActionBuilder { sourceFile, sourceLabel, realMandatoryInputsBuilder.build(), outputFile, tempOutputFile, dotdFile, configuration, cppConfiguration, context, ImmutableList.copyOf(copts), ImmutableList.copyOf(pluginOpts), getNocoptPredicate(nocopts), - extraSystemIncludePrefixes, enableLayeringCheck, fdoBuildStamp); + extraSystemIncludePrefixes, fdoBuildStamp); } else { NestedSet<Artifact> realMandatoryInputs = realMandatoryInputsBuilder.build(); @@ -272,9 +268,9 @@ public class CppCompileActionBuilder { actionContext, ImmutableList.copyOf(copts), ImmutableList.copyOf(pluginOpts), getNocoptPredicate(nocopts), - extraSystemIncludePrefixes, enableLayeringCheck, fdoBuildStamp, + extraSystemIncludePrefixes, fdoBuildStamp, includeResolver, getLipoScannables(realMandatoryInputs), actionClassId, - compileHeaderModules, usePic); + usePic); } } @@ -423,19 +419,6 @@ public class CppCompileActionBuilder { return this; } - public CppCompileActionBuilder setEnableLayeringCheck(boolean enableLayeringCheck) { - this.enableLayeringCheck = enableLayeringCheck; - return this; - } - - /** - * Sets whether the CompileAction should use header modules for its compilation. - */ - public CppCompileActionBuilder setCompileHeaderModules(boolean compileHeaderModules) { - this.compileHeaderModules = compileHeaderModules; - return this; - } - public CppCompileActionBuilder setFdoBuildStamp(String fdoBuildStamp) { this.fdoBuildStamp = fdoBuildStamp; return this; diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java index c5cc9a57fc..5bad2e6043 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java @@ -21,6 +21,7 @@ import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; +import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.common.collect.ListMultimap; import com.google.common.collect.Maps; @@ -48,10 +49,13 @@ import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig; +import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.CToolchain; import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.LinkingModeFlags; import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.LipoMode; import com.google.devtools.build.skyframe.SkyFunction.Environment; import com.google.devtools.common.options.OptionsParsingException; +import com.google.protobuf.TextFormat; +import com.google.protobuf.TextFormat.ParseException; import java.io.IOException; import java.io.Serializable; @@ -62,6 +66,7 @@ import java.util.EnumSet; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.zip.ZipException; /** @@ -398,6 +403,7 @@ public class CppConfiguration extends BuildConfiguration.Fragment { this.cacheKey = this + ":" + crosstoolTop + ":" + params.cacheKeySuffix + ":" + lipoContextCollector; + toolchain = addLegacyFeatures(toolchain); this.toolchainFeatures = new CcToolchainFeatures(toolchain); this.supportsGoldLinker = toolchain.getSupportsGoldLinker(); this.supportsThinArchives = toolchain.getSupportsThinArchives(); @@ -656,6 +662,141 @@ public class CppConfiguration extends BuildConfiguration.Fragment { return result; } + + private CToolchain addLegacyFeatures(CToolchain toolchain) { + CToolchain.Builder toolchainBuilder = CToolchain.newBuilder(); + ImmutableSet.Builder<String> featuresBuilder = ImmutableSet.builder(); + for (CToolchain.Feature feature : toolchain.getFeatureList()) { + featuresBuilder.add(feature.getName()); + } + Set<String> features = featuresBuilder.build(); + if (features.contains(CppRuleClasses.NO_LEGACY_FEATURES)) { + // The toolchain requested to not get any legacy features enabled. + return toolchain; + } + try { + if (!features.contains("use_header_modules")) { + TextFormat.merge("" + + "feature {" + + " name: 'use_header_modules'" + + " implies: 'use_module_maps'" + + " requires { feature: 'layering_check' }" + + " requires { feature: 'header_modules' }" + + " flag_set {" + + " action: 'c-compile'" + + " action: 'c++-compile'" + + " action: 'c++-header-parsing'" + + " action: 'c++-header-preprocessing'" + + " action: 'c++-module-compile'" + + " flag_group {" + + " flag: '-Xclang-only=-fmodules'" + + " flag: '-Xclang-only=-fmodules-decluse'" + + " }" + + " flag_group {" + + " flag: '-Xclang=-fmodule-file=%{module_files}'" + + " }" + + " }" + + "}", + toolchainBuilder); + } + if (!features.contains("module_maps")) { + TextFormat.merge("" + + "feature { name: 'module_maps' }", + toolchainBuilder); + } + if (!features.contains("use_module_maps")) { + TextFormat.merge("" + + "feature {" + + " name: 'use_module_maps'" + + " implies: 'module_maps'" + + " flag_set {" + + " action: 'c-compile'" + + " action: 'c++-compile'" + + " action: 'c++-header-parsing'" + + " action: 'c++-header-preprocessing'" + + " action: 'c++-module-compile'" + + " flag_group {" + + " flag: '-Xclang-only=-fmodule-maps'" + + " flag: '-Xclang-only=-fmodule-name=%{module_name}'" + + " flag: '-Xclang-only=-fmodule-map-file=%{module_map_file}'" + + " flag: '-Xclang=-fno-modules-implicit-maps'" + + " }" + + " }" + + "}", + toolchainBuilder); + } + if (!features.contains("header_modules")) { + TextFormat.merge("" + + "feature {" + + " name: 'header_modules'" + + " implies: 'use_header_modules'" + + " flag_set {" + + " action: 'c++-module-compile'" + + " flag_group {" + + " flag: '-x'" + + " flag: 'c++'" + + " flag: '-Xclang=-emit-module'" + + " flag: '-Xcrosstool-module-compilation'" + + " }" + + " }" + + "}", + toolchainBuilder); + } + if (!features.contains("layering_check")) { + TextFormat.merge("" + + "feature {" + + " name: 'layering_check'" + + " implies: 'use_module_maps'" + + " flag_set {" + + " action: 'c-compile'" + + " action: 'c++-compile'" + + " action: 'c++-header-parsing'" + + " action: 'c++-header-preprocessing'" + + " action: 'c++-module-compile'" + + " flag_group {" + + " flag: '-Xclang-only=-fmodules-strict-decluse'" + + " }" + + " }" + + "}", + toolchainBuilder); + } + if (!features.contains("parse_headers")) { + TextFormat.merge("" + + "feature {" + + " name: 'parse_headers'" + + " flag_set {" + + " action: 'c++-header-parsing'" + + " flag_group {" + + " flag: '-x'" + + " flag: 'c++-header'" + + " flag: '-fsyntax-only'" + + " }" + + " }" + + "}", + toolchainBuilder); + } + if (!features.contains("preprocess_headers")) { + TextFormat.merge("" + + "feature {" + + " name: 'preprocess_headers'" + + " flag_set {" + + " action: 'c++-header-preprocessing'" + + " flag_group {" + + " flag: '-x'" + + " flag: 'c++'" + + " flag: '-E'" + + " }" + + " }" + + "}", + toolchainBuilder); + } + } catch (ParseException e) { + // Can only happen if we change the proto definition without changing our configuration above. + throw new RuntimeException(e); + } + toolchainBuilder.mergeFrom(toolchain); + return toolchainBuilder.build(); + } private static ImmutableList<String> copyOrDefaultIfEmpty(List<String> list, String defaultValue) { @@ -1300,10 +1441,6 @@ public class CppConfiguration extends BuildConfiguration.Fragment { return cppOptions.extractInclusions; } - public boolean createCppModuleMaps() { - return cppOptions.cppModuleMaps; - } - /** * Returns true if shared libraries must be compiled with position independent code * on this platform or in this configuration. diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java index 5bc1363072..62c7f1fdcc 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppHelper.java @@ -398,12 +398,6 @@ public class CppHelper { // Creates CppModuleMap object, and adds it to C++ compilation context. public static CppModuleMap addCppModuleMapToContext(RuleContext ruleContext, CppCompilationContext.Builder contextBuilder) { - if (!ruleContext.getFragment(CppConfiguration.class).createCppModuleMaps()) { - return null; - } - if (getToolchain(ruleContext).getCppCompilationContext().getCppModuleMap() == null) { - return null; - } // Create the module map artifact as a genfile. PathFragment mapPath = FileSystemUtils.appendExtension(ruleContext.getLabel().toPathFragment(), Iterables.getOnlyElement(CppFileTypes.CPP_MODULE_MAP.getExtensions())); diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppModel.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppModel.java index f77a99c287..ef0574ad63 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppModel.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppModel.java @@ -66,8 +66,6 @@ public final class CppModel { private boolean maySaveTemps; private boolean onlySingleOutput; private CcCompilationOutputs compilationOutputs; - private boolean enableLayeringCheck; - private boolean compileHeaderModules; // link model private final List<String> linkopts = new ArrayList<>(); @@ -106,23 +104,6 @@ public final class CppModel { } /** - * If set, use compiler flags to enable compiler based layering checks. - */ - public CppModel setEnableLayeringCheck(boolean enableLayeringCheck) { - this.enableLayeringCheck = enableLayeringCheck; - return this; - } - - /** - * If set, add actions that compile header modules to the build. - * See http://clang.llvm.org/docs/Modules.html for more information. - */ - public CppModel setCompileHeaderModules(boolean compileHeaderModules) { - this.compileHeaderModules = compileHeaderModules; - return this; - } - - /** * Whether to create actions for temps. This defaults to false. */ public CppModel setSaveTemps(boolean maySaveTemps) { @@ -279,14 +260,16 @@ public final class CppModel { */ public boolean getGeneratesPicHeaderModule() { // TODO(bazel-team): Make sure cc_fake_binary works with header module support. - return compileHeaderModules && !fake && getGeneratePicActions(); + return featureConfiguration.isEnabled(CppRuleClasses.HEADER_MODULES) && !fake + && getGeneratePicActions(); } /** * @return whether this target needs to generate a non-pic header module. */ public boolean getGeratesNoPicHeaderModule() { - return compileHeaderModules && !fake && getGenerateNoPicActions(); + return featureConfiguration.isEnabled(CppRuleClasses.HEADER_MODULES) && !fake + && getGenerateNoPicActions(); } /** @@ -300,8 +283,6 @@ public final class CppModel { builder.addNocopts(nocopts); } - builder.setEnableLayeringCheck(enableLayeringCheck); - builder.setCompileHeaderModules(compileHeaderModules); builder.setExtraSystemIncludePrefixes(additionalIncludes); builder.setFdoBuildStamp(CppHelper.getFdoBuildStamp(cppConfiguration)); builder.setFeatureConfiguration(featureConfiguration); @@ -319,7 +300,7 @@ public final class CppModel { AnalysisEnvironment env = ruleContext.getAnalysisEnvironment(); PathFragment objectDir = CppHelper.getObjDirectory(ruleContext.getLabel()); - if (compileHeaderModules) { + if (featureConfiguration.isEnabled(CppRuleClasses.HEADER_MODULES)) { Artifact moduleMapArtifact = context.getCppModuleMap().getArtifact(); Label moduleMapLabel = Label.parseAbsoluteUnchecked(context.getCppModuleMap().getName()); PathFragment outputName = getObjectOutputPath(moduleMapArtifact, objectDir); diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java index b0f2e820a5..d23c604fe5 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java @@ -354,13 +354,6 @@ public class CppOptions extends FragmentOptions { converter = LabelConverter.class) public Label customMalloc; - @Option(name = "cpp_module_maps", - defaultValue = "true", - category = "flags", - help = "If true then C++ targets create a module map based on BUILD files, and " - + "pass them to the compiler.") - public boolean cppModuleMaps; - @Option(name = "legacy_whole_archive", defaultValue = "true", category = "semantics", @@ -569,7 +562,6 @@ public class CppOptions extends FragmentOptions { host.lipoMode = LipoMode.OFF; host.scanIncludes = scanIncludes; host.inmemoryDotdFiles = inmemoryDotdFiles; - host.cppModuleMaps = cppModuleMaps; return host; } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java index bde769a3b3..34b4f1840e 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java @@ -122,4 +122,12 @@ public class CppRuleClasses { */ public static final String HEADER_MODULE_INCLUDES_DEPENDENCIES = "header_module_includes_dependencies"; + + /** + * A string constant for the no_legacy_features feature. + * + * </p>If this feature is enabled, Bazel will not extend the crosstool configuration with the + * default legacy feature set. + */ + public static final String NO_LEGACY_FEATURES = "no_legacy_features"; } diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/FakeCppCompileAction.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/FakeCppCompileAction.java index 0f8ab42fb2..17fa62e609 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/FakeCppCompileAction.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/FakeCppCompileAction.java @@ -74,7 +74,6 @@ public class FakeCppCompileAction extends CppCompileAction { ImmutableList<String> pluginOpts, Predicate<String> nocopts, ImmutableList<PathFragment> extraSystemIncludePrefixes, - boolean enableLayeringCheck, @Nullable String fdoBuildStamp) { super(owner, features, featureConfiguration, sourceFile, sourceLabel, mandatoryInputs, outputFile, dotdFile, null, null, null, @@ -87,9 +86,9 @@ public class FakeCppCompileAction extends CppCompileAction { // the cc_fake_binary, and the runfiles must be determined at analysis // time, so they can't depend on the contents of the ".d" file.) CppCompilationContext.disallowUndeclaredHeaders(context), null, copts, pluginOpts, nocopts, - extraSystemIncludePrefixes, enableLayeringCheck, fdoBuildStamp, VOID_INCLUDE_RESOLVER, + extraSystemIncludePrefixes, fdoBuildStamp, VOID_INCLUDE_RESOLVER, ImmutableList.<IncludeScannable>of(), - GUID, /*compileHeaderModules=*/false, /*usePic=*/false); + GUID, /*usePic=*/false); this.tempOutputFile = Preconditions.checkNotNull(tempOutputFile); } |