Repository: bazelbuild/bazel
Issue: incompatible_dont_enable_host_nonhost_crosstool_features: Do not automatically enable "host" and "nonhost" crosstool features
Labels: P1
team-Rules-CPP
incompatible-change

**Flag:** `--incompatible_dont_enable_host_nonhost_crosstool_features`
**Available since:** 0.24 (March 2019 release)
**Will be flipped in:** 0.25 (April 2019 release)
**Tracking issue:** #6516

# Motivation

With the move of C++ rules to use platforms/toolchains (tracked in #6516), we are removing host specific logic. Platforms don't guarantee existence of separate host toolchain, in which case it's not clear which feature to enable, and it can happen that there will be multiple execution platforms, which currently don't have a way to enable a specific feature. My research shows that these Bazel features are actually mostly unused, so instead of coming up with non-trivial solution, we will remove them.

# Migration

With the flag flipped, `host` and `nonhost` features will never be enabled automatically. There are no generally useful migration notes.

Issue comments:
CC @katre 
Seems like the flag wasn't flipped. Changing breaking-change label to 0.26

Pull request review comments:

Patch that resolved the issue:
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 58fd83c8ef7275..abe07496f948ef 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
@@ -726,7 +726,7 @@ public Label getFdoPrefetchHintsLabel() {
 
   @Option(
       name = "incompatible_dont_enable_host_nonhost_crosstool_features",
-      defaultValue = "false",
+      defaultValue = "true",
       documentationCategory = OptionDocumentationCategory.TOOLCHAIN,
       effectTags = {OptionEffectTag.LOADING_AND_ANALYSIS},
       metadataTags = {
diff --git a/tools/cpp/BUILD b/tools/cpp/BUILD
index 34c428999b999e..c5e48ad0d83e87 100644
--- a/tools/cpp/BUILD
+++ b/tools/cpp/BUILD
@@ -357,10 +357,10 @@ toolchain(
 
 cc_toolchain(
     name = "cc-compiler-x64_windows_msvc",
-    all_files = ":every-file-x64_windows",
+    all_files = ":empty",
     ar_files = ":empty",
     as_files = ":empty",
-    compiler_files = ":compile-x64_windows",
+    compiler_files = ":empty",
     dwp_files = ":empty",
     linker_files = ":empty",
     objcopy_files = ":empty",
@@ -391,24 +391,6 @@ toolchain(
     toolchain_type = ":toolchain_type",
 )
 
-filegroup(
-    name = "every-file-x64_windows",
-    srcs = [
-        ":compile-x64_windows",
-    ],
-)
-
-filegroup(
-    name = "compile-x64_windows",
-    srcs = glob(
-        [
-            "wrapper/bin/msvc_*",
-            "wrapper/bin/pydir/msvc*",
-        ],
-        allow_empty = True,
-    ),
-)
-
 filegroup(
     name = "srcs",
     srcs = glob(["**"]) + [


Test patch:
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/mock/cc_toolchain_config.bzl b/src/test/java/com/google/devtools/build/lib/analysis/mock/cc_toolchain_config.bzl
index 656604fd01c85f..9de5293b924356 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/mock/cc_toolchain_config.bzl
+++ b/src/test/java/com/google/devtools/build/lib/analysis/mock/cc_toolchain_config.bzl
@@ -522,7 +522,6 @@ _thin_lto_feature = feature(
             ],
         ),
     ],
-    requires = [feature_set(features = ["nonhost"])],
 )
 
 _simple_thin_lto_feature = feature(
diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java
index 76002e39f04ee3..6f569a68bea112 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcLibraryConfiguredTargetTest.java
@@ -1229,64 +1229,6 @@ public void testCompilationModeFeatures() throws Exception {
     assertThat(flags).containsNoneOf("-fastbuild", "-opt");
   }
 
-  private List<String> getHostAndTargetFlags(boolean useHost, boolean isDisabledByFlag)
-      throws Exception {
-    AnalysisMock.get()
-        .ccSupport()
-        .setupCcToolchainConfig(
-            mockToolsConfig,
-            CcToolchainConfig.builder()
-                .withFeatures(
-                    MockCcSupport.HOST_AND_NONHOST_CONFIGURATION_FEATURES,
-                    CppRuleClasses.SUPPORTS_PIC));
-    scratch.overwriteFile("mode/BUILD", "cc_library(name = 'a', srcs = ['a.cc'])");
-    useConfiguration(
-        "--cpu=k8",
-        isDisabledByFlag
-            ? "--incompatible_dont_enable_host_nonhost_crosstool_features"
-            : "--noincompatible_dont_enable_host_nonhost_crosstool_features");
-    ConfiguredTarget target;
-    String objectPath;
-    if (useHost) {
-      target = getHostConfiguredTarget("//mode:a");
-      objectPath = "_objs/a/a.o";
-    } else {
-      target = getConfiguredTarget("//mode:a");
-      objectPath = "_objs/a/a.pic.o";
-    }
-    Artifact objectArtifact = getBinArtifact(objectPath, target);
-    CppCompileAction action = (CppCompileAction) getGeneratingAction(objectArtifact);
-    assertThat(action).isNotNull();
-    return action.getCompilerOptions();
-  }
-
-  @Test
-  public void testHostAndNonHostFeatures() throws Exception {
-    useConfiguration();
-    List<String> flags;
-
-    flags = getHostAndTargetFlags(/* useHost= */ true, /* isDisabledByFlag= */ false);
-    assertThat(flags).contains("-host");
-    assertThat(flags).doesNotContain("-nonhost");
-
-    flags = getHostAndTargetFlags(/* useHost= */ false, /* isDisabledByFlag= */ false);
-    assertThat(flags).contains("-nonhost");
-    assertThat(flags).doesNotContain("-host");
-  }
-
-  @Test
-  public void testHostAndNonHostFeaturesDisabledByTheFlag() throws Exception {
-    List<String> flags;
-
-    flags = getHostAndTargetFlags(/* useHost= */ true, /* isDisabledByFlag= */ true);
-    assertThat(flags).doesNotContain("-host");
-    assertThat(flags).doesNotContain("-nonhost");
-
-    flags = getHostAndTargetFlags(/* useHost= */ false, /* isDisabledByFlag= */ true);
-    assertThat(flags).doesNotContain("-nonhost");
-    assertThat(flags).doesNotContain("-host");
-  }
-
   @Test
   public void testIncludePathsOutsideExecutionRoot() throws Exception {
     scratchRule(
diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CompileBuildVariablesTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CompileBuildVariablesTest.java
index 96d8c2cb2c7ece..4c508145088c1f 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CompileBuildVariablesTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CompileBuildVariablesTest.java
@@ -220,8 +220,7 @@ public void testPresenceOfIsUsingFissionAndPerDebugObjectFileVariablesWithThinlt
                     "fission_flags_for_lto_backend",
                     CppRuleClasses.PER_OBJECT_DEBUG_INFO,
                     CppRuleClasses.SUPPORTS_START_END_LIB,
-                    CppRuleClasses.THIN_LTO,
-                    MockCcSupport.HOST_AND_NONHOST_CONFIGURATION_FEATURES));
+                    CppRuleClasses.THIN_LTO));
     useConfiguration("--fission=yes", "--features=thin_lto");
 
     scratch.file("x/BUILD", "cc_binary(name = 'bin', srcs = ['bin.cc'])");
diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/LinkBuildVariablesTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/LinkBuildVariablesTest.java
index 706013f82509fd..bcff1372642729 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/cpp/LinkBuildVariablesTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/LinkBuildVariablesTest.java
@@ -217,7 +217,6 @@ public void testNoIfsoBuildingWhenWhenThinLtoIndexing() throws Exception {
                 .withFeatures(
                     CppRuleClasses.THIN_LTO,
                     CppRuleClasses.SUPPORTS_PIC,
-                    MockCcSupport.HOST_AND_NONHOST_CONFIGURATION_FEATURES,
                     CppRuleClasses.SUPPORTS_INTERFACE_SHARED_LIBRARIES,
                     CppRuleClasses.SUPPORTS_DYNAMIC_LINKER,
                     CppRuleClasses.SUPPORTS_START_END_LIB));
@@ -343,7 +342,6 @@ public void testOutputExecpathIsNotExposedWhenThinLtoIndexing() throws Exception
             CcToolchainConfig.builder()
                 .withFeatures(
                     CppRuleClasses.THIN_LTO,
-                    MockCcSupport.HOST_AND_NONHOST_CONFIGURATION_FEATURES,
                     CppRuleClasses.SUPPORTS_DYNAMIC_LINKER,
                     CppRuleClasses.SUPPORTS_PIC,
                     CppRuleClasses.SUPPORTS_INTERFACE_SHARED_LIBRARIES,