Add toolchain definitions for autoconfigured cc_toolchain entries.
PiperOrigin-RevId: 190611069
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/CcRules.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/CcRules.java
index aeb956c..94aedd9 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/CcRules.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/CcRules.java
@@ -69,9 +69,6 @@
builder.addRuleDefinition(new BazelCcLibraryRule());
builder.addRuleDefinition(new BazelCcImportRule());
builder.addRuleDefinition(new CcIncludeScanningRule());
-
- builder.addWorkspaceFileSuffix(
- "register_toolchains('@bazel_tools//tools/cpp:dummy_cc_toolchain')\n");
}
@Override
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java b/src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java
index a9960b0..9d89a89 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java
@@ -58,7 +58,8 @@
"local_repository(name = 'local_config_xcode', path = '/local_config_xcode')",
"local_repository(name = 'com_google_protobuf', path = '/protobuf')",
"bind(name = 'android/sdk', actual='@bazel_tools//tools/android:sdk')",
- "bind(name = 'tools/python', actual='//tools/python')"));
+ "bind(name = 'tools/python', actual='//tools/python')",
+ "register_toolchains('@bazel_tools//tools/cpp:all')"));
}
@Override
diff --git a/src/test/java/com/google/devtools/build/lib/packages/util/BazelMockCcSupport.java b/src/test/java/com/google/devtools/build/lib/packages/util/BazelMockCcSupport.java
index f9b07d2..ecd0814 100644
--- a/src/test/java/com/google/devtools/build/lib/packages/util/BazelMockCcSupport.java
+++ b/src/test/java/com/google/devtools/build/lib/packages/util/BazelMockCcSupport.java
@@ -102,6 +102,16 @@
" module_map = 'crosstool.cppmap', supports_header_parsing = 1,",
" objcopy_files = ':empty', static_runtime_libs = [':empty'], strip_files = ':empty',",
")",
+ "toolchain(name = 'cc-toolchain-k8',",
+ // Needs to be compatible with all execution environments for tests to work properly.
+ " exec_compatible_with = [],",
+ " target_compatible_with = [",
+ " '@bazel_tools//platforms:x86_64',",
+ " '@bazel_tools//platforms:linux',",
+ " ],",
+ " toolchain = ':cc-compiler-k8',",
+ " toolchain_type = ':toolchain_type',",
+ ")",
"cc_toolchain(name = 'cc-no-dyn-linker-k8', all_files = ':empty', ",
" compiler_files = ':empty', cpu = 'k8', compiler = 'compiler_no_dyn_linker', ",
" libc = 'local', dwp_files = ':empty', dynamic_runtime_libs = [':empty'], ",
@@ -109,6 +119,16 @@
" module_map = 'crosstool.cppmap', supports_header_parsing = 1,",
" objcopy_files = ':empty', static_runtime_libs = [':empty'], strip_files = ':empty',",
")",
+ "toolchain(name = 'cc-toolchain-no-dyn-linker-k8',",
+ // Needs to be compatible with all execution environments for tests to work properly.
+ " exec_compatible_with = [],",
+ " target_compatible_with = [",
+ " '@bazel_tools//platforms:x86_64',",
+ " '@bazel_tools//platforms:linux',",
+ " ],",
+ " toolchain = ':cc-no-dyn-linker-k8',",
+ " toolchain_type = ':toolchain_type',",
+ ")",
"cc_toolchain(name = 'cc-compiler-ppc', all_files = ':empty', compiler_files = ':empty',",
" cpu = 'ppc', compiler = 'compiler', libc = 'local', dwp_files = ':empty',",
" dynamic_runtime_libs = [':empty'], ",
@@ -116,6 +136,16 @@
" module_map = 'crosstool.cppmap', supports_header_parsing = 1,",
" objcopy_files = ':empty', static_runtime_libs = [':empty'], strip_files = ':empty',",
")",
+ "toolchain(name = 'cc-toolchain-ppc',",
+ // Needs to be compatible with all execution environments for tests to work properly.
+ " exec_compatible_with = [],",
+ " target_compatible_with = [",
+ " '@bazel_tools//platforms:ppc',",
+ " '@bazel_tools//platforms:linux',",
+ " ],",
+ " toolchain = ':cc-compiler-ppc',",
+ " toolchain_type = ':toolchain_type',",
+ ")",
"cc_toolchain(name = 'cc-compiler-piii', all_files = ':all-files-piii',",
" compiler_files = ':compiler-files-piii',",
" cpu = 'piii', compiler = 'compiler', libc = 'local', dwp_files = ':empty',",
@@ -124,6 +154,16 @@
" module_map = 'crosstool.cppmap', supports_header_parsing = 1,",
" objcopy_files = ':empty', static_runtime_libs = [':empty'], strip_files = ':empty',",
")",
+ "toolchain(name = 'cc-toolchain-piii',",
+ // Needs to be compatible with all execution environments for tests to work properly.
+ " exec_compatible_with = [],",
+ " target_compatible_with = [",
+ " '@bazel_tools//platforms:x86_32',",
+ " '@bazel_tools//platforms:linux',",
+ " ],",
+ " toolchain = ':cc-compiler-piii',",
+ " toolchain_type = ':toolchain_type',",
+ ")",
"cc_toolchain(name = 'cc-compiler-darwin', all_files = ':empty', ",
" compiler_files = ':empty',",
" cpu = 'darwin', compiler = 'compiler', libc = 'macosx', dwp_files = ':empty',",
@@ -132,6 +172,16 @@
" module_map = 'crosstool.cppmap', supports_header_parsing = 1,",
" objcopy_files = ':empty', static_runtime_libs = [':empty'], strip_files = ':empty',",
")",
+ "toolchain(name = 'cc-toolchain-darwin',",
+ // Needs to be compatible with all execution environments for tests to work properly.
+ " exec_compatible_with = [],",
+ " target_compatible_with = [",
+ " '@bazel_tools//platforms:x86_64',",
+ " '@bazel_tools//platforms:osx',",
+ " ],",
+ " toolchain = ':cc-compiler-darwin',",
+ " toolchain_type = ':toolchain_type',",
+ ")",
"cc_toolchain(name = 'cc-no-dyn-linker-darwin', all_files = ':empty', ",
" compiler_files = ':empty',",
" cpu = 'darwin', compiler = 'compiler_no_dyn_linker', libc = 'macosx', " ,
@@ -140,6 +190,16 @@
" module_map = 'crosstool.cppmap', supports_header_parsing = 1,",
" objcopy_files = ':empty', static_runtime_libs = [':empty'], strip_files = ':empty',",
")",
+ "toolchain(name = 'cc-toolchain-no-dyn-linker-darwin',",
+ // Needs to be compatible with all execution environments for tests to work properly.
+ " exec_compatible_with = [],",
+ " target_compatible_with = [",
+ " '@bazel_tools//platforms:x86_64',",
+ " '@bazel_tools//platforms:osx',",
+ " ],",
+ " toolchain = ':cc-no-dyn-linker-darwin',",
+ " toolchain_type = ':toolchain_type',",
+ ")",
"cc_toolchain(name = 'cc-compiler-ios_x86_64', all_files = ':empty', ",
" compiler_files = ':empty',",
" cpu = 'ios_x86_64', compiler = 'compiler', libc = 'local', dwp_files = ':empty',",
@@ -148,6 +208,16 @@
" module_map = 'crosstool.cppmap', supports_header_parsing = 1,",
" objcopy_files = ':empty', static_runtime_libs = [':empty'], strip_files = ':empty',",
")",
+ "toolchain(name = 'cc-toolchain-ios_x86_64',",
+ // Needs to be compatible with all execution environments for tests to work properly.
+ " exec_compatible_with = [],",
+ " target_compatible_with = [",
+ " '@bazel_tools//platforms:x86_64',",
+ " '@bazel_tools//platforms:ios',",
+ " ],",
+ " toolchain = ':cc-compiler-ios_x86_64',",
+ " toolchain_type = ':toolchain_type',",
+ ")",
"cc_toolchain(name = 'cc-compiler-armeabi-v7a', all_files = ':empty', ",
" compiler_files = ':empty',",
" cpu = 'armeabi-v7a', compiler = 'compiler', libc = 'armeabi-v7a', ",
@@ -157,6 +227,16 @@
" module_map = 'crosstool.cppmap', supports_header_parsing = 1,",
" objcopy_files = ':empty', static_runtime_libs = [':empty'], strip_files = ':empty',",
")",
+ "toolchain(name = 'cc-toolchain-armeabi-v7a',",
+ // Needs to be compatible with all execution environments for tests to work properly.
+ " exec_compatible_with = [],",
+ " target_compatible_with = [",
+ " '@bazel_tools//platforms:arm',",
+ " '@bazel_tools//platforms:android',",
+ " ],",
+ " toolchain = ':cc-compiler-armeabi-v7a',",
+ " toolchain_type = ':toolchain_type',",
+ ")",
"cc_toolchain(name = 'cc-compiler-x64_windows', all_files = ':empty', ",
" compiler_files = ':empty',",
" cpu = 'x64_windows', compiler = 'windows_msys64', libc = 'local', ",
@@ -166,6 +246,16 @@
" module_map = 'crosstool.cppmap', supports_header_parsing = 1,",
" objcopy_files = ':empty', static_runtime_libs = [':empty'], strip_files = ':empty',",
")",
+ "toolchain(name = 'cc-toolchain-x64_windows',",
+ // Needs to be compatible with all execution environments for tests to work properly.
+ " exec_compatible_with = [],",
+ " target_compatible_with = [",
+ " '@bazel_tools//platforms:x86_64',",
+ " '@bazel_tools//platforms:windows',",
+ " ],",
+ " toolchain = ':cc-compiler-x64_windows',",
+ " toolchain_type = ':toolchain_type',",
+ ")",
"cc_toolchain(name = 'cc-no-dyn-linker-x64_windows', all_files = ':empty', ",
" compiler_files = ':empty',",
" cpu = 'x64_windows', compiler = 'compiler_no_dyn_linker', libc = 'local', ",
@@ -175,6 +265,16 @@
" module_map = 'crosstool.cppmap', supports_header_parsing = 1,",
" objcopy_files = ':empty', static_runtime_libs = [':empty'], strip_files = ':empty',",
")",
+ "toolchain(name = 'cc-toolchain-no-dyn-linker-x64_windows',",
+ // Needs to be compatible with all execution environments for tests to work properly.
+ " exec_compatible_with = [],",
+ " target_compatible_with = [",
+ " '@bazel_tools//platforms:x86_64',",
+ " '@bazel_tools//platforms:windows',",
+ " ],",
+ " toolchain = ':cc-no-dyn-linker-x64_windows',",
+ " toolchain_type = ':toolchain_type',",
+ ")",
"filegroup(",
" name = 'interface_library_builder',",
" srcs = ['build_interface_so'],",
@@ -182,26 +282,7 @@
"filegroup(",
" name = 'link_dynamic_library',",
" srcs = ['link_dynamic_library.sh'],",
- ")",
- "toolchain(",
- " name = 'toolchain_cc-compiler-piii',",
- " toolchain_type = ':toolchain_type',",
- " toolchain = '//third_party/crosstool/mock:cc-compiler-piii',",
- " target_compatible_with = [':mock_value'],",
- ")",
- "toolchain(",
- " name = 'dummy_cc_toolchain',",
- " toolchain_type = ':toolchain_type',",
- " toolchain = ':dummy_cc_toolchain_impl',",
- ")",
- "load(':dummy_toolchain.bzl', 'dummy_toolchain')",
- "dummy_toolchain(name = 'dummy_cc_toolchain_impl')");
- config.create(
- "/bazel_tools_workspace/tools/cpp/dummy_toolchain.bzl",
- "def _dummy_toolchain_impl(ctx):",
- " toolchain = platform_common.ToolchainInfo()",
- " return [toolchain]",
- "dummy_toolchain = rule(_dummy_toolchain_impl, attrs = {})");
+ ")");
config.create(
"/bazel_tools_workspace/tools/cpp/CROSSTOOL",
readCrosstoolFile());
diff --git a/src/test/java/com/google/devtools/build/lib/packages/util/MockObjcSupport.java b/src/test/java/com/google/devtools/build/lib/packages/util/MockObjcSupport.java
index 0c4ac80..be5778e 100644
--- a/src/test/java/com/google/devtools/build/lib/packages/util/MockObjcSupport.java
+++ b/src/test/java/com/google/devtools/build/lib/packages/util/MockObjcSupport.java
@@ -244,6 +244,7 @@
Builder<String> crosstoolBuild =
ImmutableList.<String>builder()
.add(
+ "package(default_visibility=['//visibility:public'])",
"exports_files(glob(['**']))",
"cc_toolchain_suite(",
" name = 'crosstool',",
@@ -303,7 +304,20 @@
" static_runtime_libs = [':empty'],",
" strip_files = ':empty',",
" supports_param_files = 0,",
+ ")",
+ "toolchain(name = 'cc-toolchain-" + arch + "',",
+ " exec_compatible_with = [],",
+ " target_compatible_with = [],",
+ " toolchain = ':cc-compiler-" + arch + "',",
+ " toolchain_type = '"
+ + TestConstants.TOOLS_REPOSITORY
+ + "//tools/cpp:toolchain_type'",
")");
+
+ // Add the newly-created toolchain to the WORKSPACE.
+ config.append(
+ "WORKSPACE",
+ "register_toolchains('//" + DEFAULT_OSX_CROSSTOOL_DIR + ":cc-toolchain-" + arch + "')");
}
config.create(DEFAULT_OSX_CROSSTOOL_DIR + "/BUILD",
diff --git a/src/test/java/com/google/devtools/build/lib/packages/util/MockPlatformSupport.java b/src/test/java/com/google/devtools/build/lib/packages/util/MockPlatformSupport.java
index c10bb59..91f525f 100644
--- a/src/test/java/com/google/devtools/build/lib/packages/util/MockPlatformSupport.java
+++ b/src/test/java/com/google/devtools/build/lib/packages/util/MockPlatformSupport.java
@@ -26,13 +26,73 @@
mockToolsConfig.create(
platformsPath + "/BUILD",
"package(default_visibility=['//visibility:public'])",
+ "constraint_setting(name = 'cpu')",
+ "constraint_value(",
+ " name = 'x86_32',",
+ " constraint_setting = ':cpu',",
+ ")",
+ "constraint_value(",
+ " name = 'x86_64',",
+ " constraint_setting = ':cpu',",
+ ")",
+ "constraint_value(",
+ " name = 'ppc',",
+ " constraint_setting = ':cpu',",
+ ")",
+ "constraint_value(",
+ " name = 'arm',",
+ " constraint_setting = ':cpu',",
+ ")",
+ "constraint_setting(name = 'os')",
+ "constraint_value(",
+ " name = 'osx',",
+ " constraint_setting = ':os',",
+ ")",
+ "constraint_value(",
+ " name = 'ios',",
+ " constraint_setting = ':os',",
+ ")",
+ "constraint_value(",
+ " name = 'android',",
+ " constraint_setting = ':os',",
+ ")",
+ "constraint_value(",
+ " name = 'linux',",
+ " constraint_setting = ':os',",
+ ")",
+ "constraint_value(",
+ " name = 'windows',",
+ " constraint_setting = ':os',",
+ ")",
"platform(",
" name = 'target_platform',",
" target_platform = True,",
+ " cpu_constraints = [",
+ " ':x86_32',",
+ " ':x86_64',",
+ " ':ppc',",
+ " ':arm',",
+ " ],",
+ " os_constraints = [",
+ " ':osx',",
+ " ':linux',",
+ " ':windows',",
+ " ],",
")",
"platform(",
" name = 'host_platform',",
" host_platform = True,",
+ " cpu_constraints = [",
+ " ':x86_32',",
+ " ':x86_64',",
+ " ':ppc',",
+ " ':arm',",
+ " ],",
+ " os_constraints = [",
+ " ':osx',",
+ " ':linux',",
+ " ':windows',",
+ " ],",
")");
}
diff --git a/src/test/java/com/google/devtools/build/lib/packages/util/MockToolsConfig.java b/src/test/java/com/google/devtools/build/lib/packages/util/MockToolsConfig.java
index c5f6b31..c4af0c6 100644
--- a/src/test/java/com/google/devtools/build/lib/packages/util/MockToolsConfig.java
+++ b/src/test/java/com/google/devtools/build/lib/packages/util/MockToolsConfig.java
@@ -98,6 +98,16 @@
return create(relativePath, lines);
}
+ public Path append(String relativePath, String... lines) throws IOException {
+ Path path = rootDirectory.getRelative(relativePath);
+ if (!path.exists()) {
+ return create(relativePath, lines);
+ }
+
+ FileSystemUtils.appendIsoLatin1(path, lines);
+ return path;
+ }
+
/**
* Links a tool into the workspace by creating a symbolic link to a real file. The target location
* in the workspace uses the same relative path as the given path to the tool in the runfiles
diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainSelectionTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainSelectionTest.java
index 2a67f8c..09ed5e4 100644
--- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainSelectionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcToolchainSelectionTest.java
@@ -20,7 +20,6 @@
import com.google.common.collect.Iterables;
import com.google.devtools.build.lib.analysis.ConfiguredTarget;
import com.google.devtools.build.lib.analysis.ToolchainContext.ResolvedToolchainProviders;
-import com.google.devtools.build.lib.analysis.platform.ToolchainInfo;
import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
import com.google.devtools.build.lib.analysis.util.ScratchAttributeWriter;
import com.google.devtools.build.lib.cmdline.Label;
@@ -113,21 +112,6 @@
}
@Test
- public void testToolchainSelectionWithoutPlatforms() throws Exception {
- useConfiguration("--experimental_platforms=//mock_platform:mock-piii-platform");
- ConfiguredTarget target =
- ScratchAttributeWriter.fromLabelString(this, "cc_library", "//lib")
- .setList("srcs", "a.cc")
- .write();
- ResolvedToolchainProviders providers =
- (ResolvedToolchainProviders)
- getRuleContext(target).getToolchainContext().getResolvedToolchainProviders();
- ToolchainInfo toolchain =
- providers.getForToolchainType(Label.parseAbsolute(CPP_TOOLCHAIN_TYPE));
- assertThat(toolchain.getFieldNames()).isEmpty();
- }
-
- @Test
public void testCToolchainSelectionFromCcToolchainAttrs() throws Exception {
useConfiguration(
"--enabled_toolchain_types=" + CPP_TOOLCHAIN_TYPE,
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/DefaultToolchainTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/DefaultToolchainTest.java
deleted file mode 100644
index 324ec10..0000000
--- a/src/test/java/com/google/devtools/build/lib/skyframe/DefaultToolchainTest.java
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright 2017 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.lib.skyframe;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import com.google.common.collect.ImmutableList;
-import com.google.devtools.build.lib.analysis.platform.DeclaredToolchainInfo;
-import com.google.devtools.build.lib.cmdline.Label;
-import com.google.devtools.build.lib.rules.platform.ToolchainTestCase;
-import com.google.devtools.build.skyframe.EvaluationResult;
-import com.google.devtools.build.skyframe.SkyKey;
-import java.util.List;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-/** Tests for default toolchains. */
-@RunWith(JUnit4.class)
-public class DefaultToolchainTest extends ToolchainTestCase {
- @Test
- public void testDefaultCcToolchainIsPresent() throws Exception {
- SkyKey toolchainKey = RegisteredToolchainsValue.key(targetConfigKey);
- EvaluationResult<RegisteredToolchainsValue> result =
- requestToolchainsFromSkyframe(toolchainKey);
- ImmutableList<DeclaredToolchainInfo> declaredToolchains =
- result.get(toolchainKey).registeredToolchains();
- List<Label> labels = collectToolchainLabels(declaredToolchains);
- assertThat(
- labels
- .stream()
- .anyMatch(
- toolchainLabel ->
- toolchainLabel.toString().contains("//tools/cpp:dummy_cc_toolchain_impl")))
- .isTrue();
- }
-}
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunctionTest.java
index 311cd5a..7626ce5 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/RegisteredToolchainsFunctionTest.java
@@ -23,6 +23,7 @@
import com.google.devtools.build.lib.rules.platform.ToolchainTestCase;
import com.google.devtools.build.skyframe.EvaluationResult;
import com.google.devtools.build.skyframe.SkyKey;
+import java.util.stream.Collectors;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@@ -41,8 +42,15 @@
assertThatEvaluationResult(result).hasEntryThat(toolchainsKey).isNotNull();
RegisteredToolchainsValue value = result.get(toolchainsKey);
- // We have two registered toolchains, and a default toolchain for C++.
- assertThat(value.registeredToolchains()).hasSize(3);
+
+ // Check that the number of toolchains created for this test is correct.
+ assertThat(
+ value
+ .registeredToolchains()
+ .stream()
+ .filter(toolchain -> toolchain.toolchainType().equals(testToolchainType))
+ .collect(Collectors.toList()))
+ .hasSize(2);
assertThat(
value
diff --git a/tools/cpp/BUILD b/tools/cpp/BUILD
index 4412b14..57007d32 100644
--- a/tools/cpp/BUILD
+++ b/tools/cpp/BUILD
@@ -1,7 +1,52 @@
+# Copyright 2018 The Bazel Authors. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
package(default_visibility = ["//visibility:public"])
licenses(["notice"]) # Apache 2.0
+# The toolchain type used to distinguish cc toolchains.
+cc_toolchain_type(name = "toolchain_type")
+
+# It is frequently necessary to constrain platforms based on the cc compiler type.
+constraint_setting(name = "cc_compiler")
+
+constraint_value(
+ name = "clang",
+ constraint_setting = ":cc_compiler",
+)
+
+constraint_value(
+ name = "gcc",
+ constraint_setting = ":cc_compiler",
+)
+
+constraint_value(
+ name = "msvc",
+ constraint_setting = ":cc_compiler",
+)
+
+constraint_value(
+ name = "mingw",
+ constraint_setting = ":cc_compiler",
+)
+
+constraint_value(
+ name = "msys",
+ constraint_setting = ":cc_compiler",
+)
+
# TODO(lberki): Remove this once cc_toolchain_alias is in a Bazel release
cc_toolchain_alias(name = "current_cc_toolchain")
@@ -67,6 +112,18 @@
supports_param_files = 1,
)
+toolchain(
+ name = "cc-toolchain-local",
+ exec_compatible_with = [
+ "@bazel_tools//platforms:autoconfigured",
+ ],
+ target_compatible_with = [
+ "@bazel_tools//platforms:autoconfigured",
+ ],
+ toolchain = ":cc-compiler-local",
+ toolchain_type = ":toolchain_type",
+)
+
cc_toolchain(
name = "cc-compiler-ppc",
all_files = ":empty",
@@ -81,6 +138,18 @@
supports_param_files = 1,
)
+toolchain(
+ name = "cc-toolchain-ppc",
+ exec_compatible_with = [
+ "@bazel_tools//platforms:ppc",
+ ],
+ target_compatible_with = [
+ "@bazel_tools//platforms:ppc",
+ ],
+ toolchain = ":cc-compiler-ppc",
+ toolchain_type = ":toolchain_type",
+)
+
cc_toolchain(
name = "cc-compiler-armeabi-v7a",
all_files = ":empty",
@@ -95,6 +164,18 @@
supports_param_files = 1,
)
+toolchain(
+ name = "cc-toolchain-armeabi-v7a",
+ exec_compatible_with = [
+ ],
+ target_compatible_with = [
+ "@bazel_tools//platforms:arm",
+ "@bazel_tools//platforms:android",
+ ],
+ toolchain = ":cc-compiler-armeabi-v7a",
+ toolchain_type = ":toolchain_type",
+)
+
cc_toolchain(
name = "cc-compiler-k8",
all_files = ":empty",
@@ -109,6 +190,20 @@
supports_param_files = 1,
)
+toolchain(
+ name = "cc-toolchain-k8",
+ exec_compatible_with = [
+ "@bazel_tools//platforms:x86_64",
+ "@bazel_tools//platforms:linux",
+ ],
+ target_compatible_with = [
+ "@bazel_tools//platforms:x86_64",
+ "@bazel_tools//platforms:linux",
+ ],
+ toolchain = ":cc-compiler-k8",
+ toolchain_type = ":toolchain_type",
+)
+
cc_toolchain(
name = "cc-compiler-darwin",
all_files = ":osx_wrapper",
@@ -123,6 +218,20 @@
supports_param_files = 0,
)
+toolchain(
+ name = "cc-toolchain-darwin",
+ exec_compatible_with = [
+ "@bazel_tools//platforms:x86_64",
+ "@bazel_tools//platforms:osx",
+ ],
+ target_compatible_with = [
+ "@bazel_tools//platforms:x86_64",
+ "@bazel_tools//platforms:osx",
+ ],
+ toolchain = ":cc-compiler-darwin",
+ toolchain_type = ":toolchain_type",
+)
+
cc_toolchain(
name = "cc-compiler-freebsd",
all_files = ":empty",
@@ -137,6 +246,20 @@
supports_param_files = 0,
)
+toolchain(
+ name = "cc-toolchain-freebsd",
+ exec_compatible_with = [
+ "@bazel_tools//platforms:x86_64",
+ "@bazel_tools//platforms:freebsd",
+ ],
+ target_compatible_with = [
+ "@bazel_tools//platforms:x86_64",
+ "@bazel_tools//platforms:freebsd",
+ ],
+ toolchain = ":cc-compiler-freebsd",
+ toolchain_type = ":toolchain_type",
+)
+
cc_toolchain(
name = "cc-compiler-x64_windows",
all_files = ":empty",
@@ -151,6 +274,20 @@
supports_param_files = 0,
)
+toolchain(
+ name = "cc-toolchain-x64_windows",
+ exec_compatible_with = [
+ "@bazel_tools//platforms:x86_64",
+ "@bazel_tools//platforms:windows",
+ ],
+ target_compatible_with = [
+ "@bazel_tools//platforms:x86_64",
+ "@bazel_tools//platforms:windows",
+ ],
+ toolchain = ":cc-compiler-x64_windows",
+ toolchain_type = ":toolchain_type",
+)
+
cc_toolchain(
name = "cc-compiler-x64_windows_msvc",
all_files = ":every-file-x64_windows",
@@ -165,6 +302,21 @@
supports_param_files = 1,
)
+toolchain(
+ name = "cc-toolchain-x64_windows_msvc",
+ exec_compatible_with = [
+ "@bazel_tools//platforms:x86_64",
+ "@bazel_tools//platforms:windows",
+ ":msvc",
+ ],
+ target_compatible_with = [
+ "@bazel_tools//platforms:x86_64",
+ "@bazel_tools//platforms:windows",
+ ],
+ toolchain = ":cc-compiler-x64_windows_msvc",
+ toolchain_type = ":toolchain_type",
+)
+
cc_toolchain(
name = "cc-compiler-ios_x86_64",
all_files = ":empty",
@@ -179,6 +331,18 @@
supports_param_files = 0,
)
+toolchain(
+ name = "cc-toolchain-ios_x86_64",
+ exec_compatible_with = [
+ ],
+ target_compatible_with = [
+ "@bazel_tools//platforms:x86_64",
+ "@bazel_tools//platforms:ios",
+ ],
+ toolchain = ":cc-compiler-ios_x86_64",
+ toolchain_type = ":toolchain_type",
+)
+
filegroup(
name = "every-file-x64_windows",
srcs = [
@@ -228,18 +392,3 @@
name = "crosstool_lib",
srcs = ["crosstool_lib.bzl"],
)
-
-cc_toolchain_type(name = "toolchain_type")
-
-# A dummy toolchain is necessary to satisfy toolchain resolution until platforms
-# are used in c++ by default.
-# TODO(b/64754003): Remove once platforms are used in c++ by default.
-toolchain(
- name = "dummy_cc_toolchain",
- toolchain = "dummy_cc_toolchain_impl",
- toolchain_type = ":toolchain_type",
-)
-
-load(":dummy_toolchain.bzl", "dummy_toolchain")
-
-dummy_toolchain(name = "dummy_cc_toolchain_impl")
diff --git a/tools/cpp/BUILD.static b/tools/cpp/BUILD.static
deleted file mode 100644
index 6175a5a..0000000
--- a/tools/cpp/BUILD.static
+++ /dev/null
@@ -1,146 +0,0 @@
-package(default_visibility = ["//visibility:public"])
-
-cc_library(
- name = "malloc",
-)
-
-cc_library(
- name = "stl",
-)
-
-filegroup(
- name = "empty",
- srcs = [],
-)
-
-# Hardcoded toolchain, legacy behaviour.
-cc_toolchain_suite(
- name = "toolchain",
- toolchains = {
- "armeabi-v7a|compiler": ":cc-compiler-armeabi-v7a",
- "freebsd|compiler": ":cc-compiler-freebsd",
- "x64_windows|msvc-cl": ":cc-compiler-x64_windows",
- "x64_windows|msys-gcc": ":cc-compiler-x64_windows_msys",
- "x64_windows|mingw-gcc": ":cc-compiler-x64_windows_mingw",
- "ios_x86_64|compiler": ":cc-compiler-ios_x86_64",
- },
-)
-
-cc_toolchain(
- name = "cc-compiler-armeabi-v7a",
- all_files = ":empty",
- compiler_files = ":empty",
- cpu = "local",
- dwp_files = ":empty",
- dynamic_runtime_libs = [":empty"],
- linker_files = ":empty",
- objcopy_files = ":empty",
- static_runtime_libs = [":empty"],
- strip_files = ":empty",
- supports_param_files = 1,
-)
-
-cc_toolchain(
- name = "cc-compiler-freebsd",
- all_files = ":empty",
- compiler_files = ":empty",
- cpu = "local",
- dwp_files = ":empty",
- dynamic_runtime_libs = [":empty"],
- linker_files = ":empty",
- objcopy_files = ":empty",
- static_runtime_libs = [":empty"],
- strip_files = ":empty",
- supports_param_files = 0,
-)
-
-cc_toolchain(
- name = "cc-compiler-x64_windows_msys",
- all_files = ":empty",
- compiler_files = ":empty",
- cpu = "local",
- dwp_files = ":empty",
- dynamic_runtime_libs = [":empty"],
- linker_files = ":empty",
- objcopy_files = ":empty",
- static_runtime_libs = [":empty"],
- strip_files = ":empty",
- supports_param_files = 1,
-)
-
-cc_toolchain(
- name = "cc-compiler-x64_windows_mingw",
- all_files = ":empty",
- compiler_files = ":empty",
- cpu = "x64_windows",
- dwp_files = ":empty",
- dynamic_runtime_libs = [":empty"],
- linker_files = ":empty",
- objcopy_files = ":empty",
- static_runtime_libs = [":empty"],
- strip_files = ":empty",
- supports_param_files = 1,
-)
-
-cc_toolchain(
- name = "cc-compiler-x64_windows",
- all_files = ":every-file-x64_windows",
- compiler_files = ":compile-x64_windows",
- cpu = "x64_windows",
- dwp_files = ":empty",
- dynamic_runtime_libs = [":empty"],
- linker_files = ":empty",
- objcopy_files = ":empty",
- static_runtime_libs = [":empty"],
- strip_files = ":empty",
- supports_param_files = 1,
-)
-
-cc_toolchain(
- name = "cc-compiler-ios_x86_64",
- all_files = ":empty",
- compiler_files = ":empty",
- cpu = "local",
- dwp_files = ":empty",
- dynamic_runtime_libs = [":empty"],
- linker_files = ":empty",
- objcopy_files = ":empty",
- static_runtime_libs = [":empty"],
- strip_files = ":empty",
- supports_param_files = 0,
-)
-
-filegroup(
- name = "every-file-x64_windows",
- srcs = [
- ":compile-x64_windows",
- ],
-)
-
-filegroup(
- name = "compile-x64_windows",
- srcs = glob([
- "wrapper/bin/msvc_*",
- "wrapper/bin/pydir/msvc*",
- ]),
-)
-
-filegroup(
- name = "link_dynamic_library",
- srcs = ["link_dynamic_library.sh"],
-)
-
-cc_toolchain_type(name = "toolchain_type")
-
-# A dummy toolchain is necessary to satisfy toolchain resolution until platforms
-# are used in c++ by default.
-# TODO(b/64754003): Remove once platforms are used in c++ by default.
-toolchain(
- name = "dummy_cc_toolchain",
- toolchain = "dummy_cc_toolchain_impl",
- toolchain_type = ":toolchain_type",
-)
-
-load(":dummy_toolchain.bzl", "dummy_toolchain")
-
-dummy_toolchain(name = "dummy_cc_toolchain_impl")
diff --git a/tools/cpp/BUILD.static.freebsd b/tools/cpp/BUILD.static.freebsd
new file mode 100644
index 0000000..4ec5691
--- /dev/null
+++ b/tools/cpp/BUILD.static.freebsd
@@ -0,0 +1,128 @@
+# Copyright 2018 The Bazel Authors. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# This becomes the BUILD file for @local_config_cc// under FreeBSD.
+
+package(default_visibility = ["//visibility:public"])
+
+cc_library(
+ name = "malloc",
+)
+
+cc_library(
+ name = "stl",
+)
+
+filegroup(
+ name = "empty",
+ srcs = [],
+)
+
+# Hardcoded toolchain, legacy behaviour.
+cc_toolchain_suite(
+ name = "toolchain",
+ toolchains = {
+ "armeabi-v7a|compiler": ":cc-compiler-armeabi-v7a",
+ "freebsd|compiler": ":cc-compiler-freebsd",
+ "ios_x86_64|compiler": ":cc-compiler-ios_x86_64",
+ },
+)
+
+cc_toolchain(
+ name = "cc-compiler-freebsd",
+ all_files = ":empty",
+ compiler_files = ":empty",
+ cpu = "local",
+ dwp_files = ":empty",
+ dynamic_runtime_libs = [":empty"],
+ linker_files = ":empty",
+ objcopy_files = ":empty",
+ static_runtime_libs = [":empty"],
+ strip_files = ":empty",
+ supports_param_files = 0,
+)
+
+toolchain(
+ name = "cc-toolchain-freebsd",
+ exec_compatible_with = [
+ "@bazel_tools//platforms:x86_64",
+ "@bazel_tools//platforms:freebsd",
+ ],
+ target_compatible_with = [
+ "@bazel_tools//platforms:x86_64",
+ "@bazel_tools//platforms:freebsd",
+ ],
+ toolchain = ":cc-compiler-freebsd",
+ toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
+)
+
+cc_toolchain(
+ name = "cc-compiler-armeabi-v7a",
+ all_files = ":empty",
+ compiler_files = ":empty",
+ cpu = "local",
+ dwp_files = ":empty",
+ dynamic_runtime_libs = [":empty"],
+ linker_files = ":empty",
+ objcopy_files = ":empty",
+ static_runtime_libs = [":empty"],
+ strip_files = ":empty",
+ supports_param_files = 0,
+)
+
+toolchain(
+ name = "cc-toolchain-armeabi-v7a",
+ exec_compatible_with = [
+ "@bazel_tools//platforms:arm",
+ ],
+ target_compatible_with = [
+ "@bazel_tools//platforms:arm",
+ "@bazel_tools//platforms:android",
+ ],
+ toolchain = ":cc-compiler-armeabi-v7a",
+ toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
+)
+
+cc_toolchain(
+ name = "cc-compiler-ios_x86_64",
+ all_files = ":empty",
+ compiler_files = ":empty",
+ cpu = "local",
+ dwp_files = ":empty",
+ dynamic_runtime_libs = [":empty"],
+ linker_files = ":empty",
+ objcopy_files = ":empty",
+ static_runtime_libs = [":empty"],
+ strip_files = ":empty",
+ supports_param_files = 0,
+)
+
+toolchain(
+ name = "cc-toolchain-ios_x86_64",
+ exec_compatible_with = [
+ "@bazel_tools//platforms:x86_64",
+ "@bazel_tools//platforms:osx",
+ ],
+ target_compatible_with = [
+ "@bazel_tools//platforms:x86_64",
+ "@bazel_tools//platforms:ios",
+ ],
+ toolchain = ":cc-compiler-ios_x86_64",
+ toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
+)
+
+filegroup(
+ name = "link_dynamic_library",
+ srcs = ["link_dynamic_library.sh"],
+)
diff --git a/tools/cpp/BUILD.static.windows b/tools/cpp/BUILD.static.windows
new file mode 100644
index 0000000..6281a05
--- /dev/null
+++ b/tools/cpp/BUILD.static.windows
@@ -0,0 +1,200 @@
+# Copyright 2018 The Bazel Authors. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# This becomes the BUILD file for @local_config_cc// under Windows.
+
+package(default_visibility = ["//visibility:public"])
+
+cc_library(
+ name = "malloc",
+)
+
+cc_library(
+ name = "stl",
+)
+
+filegroup(
+ name = "empty",
+ srcs = [],
+)
+
+# Hardcoded toolchain, legacy behaviour.
+cc_toolchain_suite(
+ name = "toolchain",
+ toolchains = {
+ "armeabi-v7a|compiler": ":cc-compiler-armeabi-v7a",
+ "x64_windows|msvc-cl": ":cc-compiler-x64_windows",
+ "x64_windows|msys-gcc": ":cc-compiler-x64_windows_msys",
+ "x64_windows|mingw-gcc": ":cc-compiler-x64_windows_mingw",
+ "ios_x86_64|compiler": ":cc-compiler-ios_x86_64",
+ },
+)
+
+cc_toolchain(
+ name = "cc-compiler-x64_windows_msys",
+ all_files = ":empty",
+ compiler_files = ":empty",
+ cpu = "local",
+ dwp_files = ":empty",
+ dynamic_runtime_libs = [":empty"],
+ linker_files = ":empty",
+ objcopy_files = ":empty",
+ static_runtime_libs = [":empty"],
+ strip_files = ":empty",
+ supports_param_files = 1,
+)
+
+toolchain(
+ name = "cc-toolchain-x64_windows_msys",
+ exec_compatible_with = [
+ "@bazel_tools//platforms:x86_64",
+ "@bazel_tools//platforms:windows",
+ "@bazel_tools//tools/cpp:msys",
+ ],
+ target_compatible_with = [
+ "@bazel_tools//platforms:x86_64",
+ "@bazel_tools//platforms:windows",
+ ],
+ toolchain = ":cc-compiler-x64_windows_msys",
+ toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
+)
+
+cc_toolchain(
+ name = "cc-compiler-x64_windows_mingw",
+ all_files = ":empty",
+ compiler_files = ":empty",
+ cpu = "x64_windows",
+ dwp_files = ":empty",
+ dynamic_runtime_libs = [":empty"],
+ linker_files = ":empty",
+ objcopy_files = ":empty",
+ static_runtime_libs = [":empty"],
+ strip_files = ":empty",
+ supports_param_files = 0,
+)
+
+toolchain(
+ name = "cc-toolchain-x64_windows_mingw",
+ exec_compatible_with = [
+ "@bazel_tools//platforms:x86_64",
+ "@bazel_tools//platforms:windows",
+ "@bazel_tools//tools/cpp:mingw",
+ ],
+ target_compatible_with = [
+ "@bazel_tools//platforms:x86_64",
+ "@bazel_tools//platforms:windows",
+ ],
+ toolchain = ":cc-compiler-x64_windows_mingw",
+ toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
+)
+
+cc_toolchain(
+ name = "cc-compiler-x64_windows",
+ all_files = ":every-file-x64_windows",
+ compiler_files = ":compile-x64_windows",
+ cpu = "x64_windows",
+ dwp_files = ":empty",
+ dynamic_runtime_libs = [":empty"],
+ linker_files = ":empty",
+ objcopy_files = ":empty",
+ static_runtime_libs = [":empty"],
+ strip_files = ":empty",
+ supports_param_files = 1,
+)
+
+toolchain(
+ name = "cc-toolchain-x64_windows",
+ exec_compatible_with = [
+ "@bazel_tools//platforms:x86_64",
+ "@bazel_tools//platforms:windows",
+ ],
+ target_compatible_with = [
+ "@bazel_tools//platforms:x86_64",
+ "@bazel_tools//platforms:windows",
+ ],
+ toolchain = ":cc-compiler-x64_windows",
+ toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
+)
+
+cc_toolchain(
+ name = "cc-compiler-armeabi-v7a",
+ all_files = ":empty",
+ compiler_files = ":empty",
+ cpu = "local",
+ dwp_files = ":empty",
+ dynamic_runtime_libs = [":empty"],
+ linker_files = ":empty",
+ objcopy_files = ":empty",
+ static_runtime_libs = [":empty"],
+ strip_files = ":empty",
+ supports_param_files = 1,
+)
+
+toolchain(
+ name = "cc-toolchain-armeabi-v7a",
+ exec_compatible_with = [
+ ],
+ target_compatible_with = [
+ "@bazel_tools//platforms:arm",
+ "@bazel_tools//platforms:android",
+ ],
+ toolchain = ":cc-compiler-armeabi-v7a",
+ toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
+)
+
+cc_toolchain(
+ name = "cc-compiler-ios_x86_64",
+ all_files = ":empty",
+ compiler_files = ":empty",
+ cpu = "local",
+ dwp_files = ":empty",
+ dynamic_runtime_libs = [":empty"],
+ linker_files = ":empty",
+ objcopy_files = ":empty",
+ static_runtime_libs = [":empty"],
+ strip_files = ":empty",
+ supports_param_files = 0,
+)
+
+toolchain(
+ name = "cc-toolchain-ios_x86_64",
+ exec_compatible_with = [
+ ],
+ target_compatible_with = [
+ "@bazel_tools//platforms:x86_64",
+ "@bazel_tools//platforms:ios",
+ ],
+ toolchain = ":cc-compiler-ios_x86_64",
+ toolchain_type = "@bazel_tools//tools/cpp: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*",
+ ]),
+)
+
+filegroup(
+ name = "link_dynamic_library",
+ srcs = ["link_dynamic_library.sh"],
+)
diff --git a/tools/cpp/BUILD.tpl b/tools/cpp/BUILD.tpl
index edf2ba6..f2bf8cd 100644
--- a/tools/cpp/BUILD.tpl
+++ b/tools/cpp/BUILD.tpl
@@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+# This becomes the BUILD file for @local_config_cc// under non-FreeBSD unixes.
+
package(default_visibility = ["//visibility:public"])
licenses(["notice"]) # Apache 2.0
@@ -65,6 +67,19 @@
supports_param_files = %{supports_param_files},
)
+toolchain(
+ name = "cc-toolchain-%{name}",
+ exec_compatible_with = [
+ # This toolchain will only work with the local autoconfigured platforms.
+ "@bazel_tools//platforms:autoconfigured",
+ # TODO(katre): add autodiscovered constraints for host CPU and OS.
+ ],
+ target_compatible_with = [
+ # TODO(katre): add autodiscovered constraints for host CPU and OS.
+ ],
+ toolchain = ":cc-compiler-%{name}",
+ toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
+)
# Android tooling requires a default toolchain for the armeabi-v7a cpu.
cc_toolchain(
@@ -81,6 +96,19 @@
supports_param_files = 1,
)
+toolchain(
+ name = "cc-toolchain-armeabi-v7a",
+ exec_compatible_with = [
+ # TODO(katre): add autodiscovered constraints for host CPU and OS.
+ ],
+ target_compatible_with = [
+ "@bazel_tools//platforms:arm",
+ "@bazel_tools//platforms:android",
+ ],
+ toolchain = ":cc-compiler-armabi-v7a",
+ toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
+)
+
# ios crosstool configuration requires a default toolchain for the
# ios_x86_64 cpu.
cc_toolchain(
@@ -97,17 +125,15 @@
supports_param_files = 1,
)
-cc_toolchain_type(name = "toolchain_type")
-
-# A dummy toolchain is necessary to satisfy toolchain resolution until platforms
-# are used in c++ by default.
-# TODO(b/64754003): Remove once platforms are used in c++ by default.
toolchain(
- name = "dummy_cc_toolchain",
- toolchain = "dummy_cc_toolchain_impl",
- toolchain_type = ":toolchain_type",
+ name = "cc-toolchain-ios_x86_64",
+ exec_compatible_with = [
+ # TODO(katre): add autodiscovered constraints for host CPU and OS.
+ ],
+ target_compatible_with = [
+ "@bazel_tools//platforms:x86_64",
+ "@bazel_tools//platforms:ios",
+ ],
+ toolchain = ":cc-compiler-ios_x86_64",
+ toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)
-
-load(":dummy_toolchain.bzl", "dummy_toolchain")
-
-dummy_toolchain(name = "dummy_cc_toolchain_impl")
diff --git a/tools/cpp/cc_configure.bzl b/tools/cpp/cc_configure.bzl
index 858c5bc..925ecbc 100644
--- a/tools/cpp/cc_configure.bzl
+++ b/tools/cpp/cc_configure.bzl
@@ -13,7 +13,6 @@
# limitations under the License.
"""Rules for configuring the C++ toolchain (experimental)."""
-
load("@bazel_tools//tools/cpp:windows_cc_configure.bzl", "configure_windows_toolchain")
load("@bazel_tools//tools/cpp:osx_cc_configure.bzl", "configure_osx_toolchain")
load("@bazel_tools//tools/cpp:unix_cc_configure.bzl", "configure_unix_toolchain")
@@ -30,7 +29,7 @@
# straightforward to add but we cannot run it in a docker container so
# skipping until we have proper tests for FreeBSD.
repository_ctx.symlink(Label("@bazel_tools//tools/cpp:CROSSTOOL"), "CROSSTOOL")
- repository_ctx.symlink(Label("@bazel_tools//tools/cpp:BUILD.static"), "BUILD")
+ repository_ctx.symlink(Label("@bazel_tools//tools/cpp:BUILD.static.freebsd"), "BUILD")
elif cpu_value == "x64_windows":
# TODO(ibiryukov): overriden_tools are only supported in configure_unix_toolchain.
# We might want to add that to Windows too(at least for msys toolchain).
@@ -42,7 +41,6 @@
configure_unix_toolchain(repository_ctx, cpu_value, overriden_tools)
cc_autoconf = repository_rule(
- implementation = cc_autoconf_impl,
environ = [
"ABI_LIBC_VERSION",
"ABI_VERSION",
@@ -72,10 +70,15 @@
"VS100COMNTOOLS",
"VS110COMNTOOLS",
"VS120COMNTOOLS",
- "VS140COMNTOOLS"])
-
+ "VS140COMNTOOLS",
+ ],
+ implementation = cc_autoconf_impl,
+)
def cc_configure():
"""A C++ configuration rules that generate the crosstool file."""
cc_autoconf(name="local_config_cc")
native.bind(name="cc_toolchain", actual="@local_config_cc//:toolchain")
+ native.register_toolchains(
+ # Use register_toolchain's target pattern expansion to register all toolchains in the package.
+ "@local_config_cc//:all")
diff --git a/tools/cpp/windows_cc_configure.bzl b/tools/cpp/windows_cc_configure.bzl
index f7f7df1..605760d 100644
--- a/tools/cpp/windows_cc_configure.bzl
+++ b/tools/cpp/windows_cc_configure.bzl
@@ -27,7 +27,6 @@
"is_cc_configure_debug",
)
-
def _get_escaped_windows_msys_crosstool_content(repository_ctx, use_mingw = False):
"""Return the content of msys crosstool which is still the default CROSSTOOL on Windows."""
bazel_sh = get_env_var(repository_ctx, "BAZEL_SH").replace("\\", "/").lower()
@@ -71,7 +70,6 @@
' feature { name: "targets_windows" implies: "copy_dynamic_libraries_to_binary" enabled: true }' +
' feature { name: "copy_dynamic_libraries_to_binary" }' )
-
def _get_system_root(repository_ctx):
r"""Get System root path on Windows, default is C:\\Windows. Doesn't %-escape the result."""
if "SYSTEMROOT" in repository_ctx.os.environ:
@@ -79,7 +77,6 @@
auto_configure_warning("SYSTEMROOT is not set, using default SYSTEMROOT=C:\\Windows")
return "C:\\Windows"
-
def _find_cuda(repository_ctx):
"""Find out if and where cuda is installed. Doesn't %-escape the result."""
if "CUDA_PATH" in repository_ctx.os.environ:
@@ -89,7 +86,6 @@
return nvcc[:-len("/bin/nvcc.exe")]
return None
-
def _find_python(repository_ctx):
"""Find where is python on Windows. Doesn't %-escape the result."""
if "BAZEL_PYTHON" in repository_ctx.os.environ:
@@ -102,7 +98,6 @@
auto_configure_warning("Python found at %s" % python_binary)
return python_binary
-
def _add_system_root(repository_ctx, env):
r"""Running VCVARSALL.BAT and VCVARSQUERYREGISTRY.BAT need %SYSTEMROOT%\\system32 in PATH."""
if "PATH" not in env:
@@ -110,7 +105,6 @@
env["PATH"] = env["PATH"] + ";" + _get_system_root(repository_ctx) + "\\system32"
return env
-
def find_vc_path(repository_ctx):
"""Find Visual C++ build tools install path. Doesn't %-escape the result."""
# 1. Check if BAZEL_VC or BAZEL_VS is already set by user.
@@ -167,7 +161,6 @@
auto_configure_warning("Visual C++ build tools found at %s" % vc_dir)
return vc_dir
-
def _is_vs_2017(vc_path):
"""Check if the installed VS version is Visual Studio 2017."""
# In VS 2017, the location of VC is like:
@@ -176,7 +169,6 @@
# C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\
return vc_path.find("2017") != -1
-
def _find_vcvarsall_bat_script(repository_ctx, vc_path):
"""Find vcvarsall.bat script. Doesn't %-escape the result."""
if _is_vs_2017(vc_path):
@@ -189,7 +181,6 @@
return vcvarsall
-
def setup_vc_env_vars(repository_ctx, vc_path):
"""Get environment variables set by VCVARSALL.BAT. Doesn't %-escape the result!"""
vcvarsall = _find_vcvarsall_bat_script(repository_ctx, vc_path)
@@ -208,7 +199,6 @@
env_map[key] = escape_string(value.replace("\\", "\\\\"))
return env_map
-
def find_msvc_tool(repository_ctx, vc_path, tool):
"""Find the exact path of a specific build tool in MSVC. Doesn't %-escape the result."""
tool_path = ""
@@ -246,7 +236,6 @@
return missing_tools
-
def _is_support_whole_archive(repository_ctx, vc_path):
"""Run MSVC linker alone to see if it supports /WHOLEARCHIVE."""
env = repository_ctx.os.environ
@@ -256,20 +245,17 @@
result = execute(repository_ctx, [linker], expect_failure = True)
return result.find("/WHOLEARCHIVE") != -1
-
def _is_support_debug_fastlink(repository_ctx, vc_path):
"""Run MSVC linker alone to see if it supports /DEBUG:FASTLINK."""
linker = find_msvc_tool(repository_ctx, vc_path, "link.exe")
result = execute(repository_ctx, [linker], expect_failure = True)
return result.find("/DEBUG[:{FASTLINK|FULL|NONE}]") != -1
-
def _is_use_msvc_wrapper(repository_ctx):
"""Returns True if USE_MSVC_WRAPPER is set to 1."""
env = repository_ctx.os.environ
return "USE_MSVC_WRAPPER" in env and env["USE_MSVC_WRAPPER"] == "1"
-
def _get_compilation_mode_content():
"""Return the content for adding flags for different compilation modes when using MSVC wrapper."""
return "\n".join([
@@ -289,7 +275,6 @@
" linker_flag: '-Xcompilation-mode=opt'",
" }"])
-
def _escaped_cuda_compute_capabilities(repository_ctx):
"""Returns a %-escaped list of strings representing cuda compute capabilities."""
@@ -306,10 +291,9 @@
auto_configure_fail("Invalid compute capability: %s" % capability)
return capabilities
-
def configure_windows_toolchain(repository_ctx):
"""Configure C++ toolchain on Windows."""
- repository_ctx.symlink(Label("@bazel_tools//tools/cpp:BUILD.static"), "BUILD")
+ repository_ctx.symlink(Label("@bazel_tools//tools/cpp:BUILD.static.windows"), "BUILD")
vc_path = find_vc_path(repository_ctx)
missing_tools = None
diff --git a/tools/osx/crosstool/BUILD.tpl b/tools/osx/crosstool/BUILD.tpl
index e82dad2..5215d0f 100644
--- a/tools/osx/crosstool/BUILD.tpl
+++ b/tools/osx/crosstool/BUILD.tpl
@@ -62,3 +62,21 @@
)
for arch in OSX_TOOLS_ARCHS
]
+
+[
+ toolchain(
+ name = "cc-toolchain-" + arch,
+ exec_compatible_with = [
+ # This toolchain will only work with the local autoconfigured
+ # platforms.
+ "@bazel_tools//platforms:autoconfigured",
+ # TODO(katre): add autodiscovered constraints for host CPU and OS.
+ ],
+ target_compatible_with = [
+ # TODO(katre): add autodiscovered constraints for host CPU and OS.
+ ],
+ toolchain = ":cc-compiler-" + arch,
+ toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
+ )
+ for arch in OSX_TOOLS_ARCHS
+]
diff --git a/tools/platforms/BUILD b/tools/platforms/BUILD
index 85bcef9..4323b33 100644
--- a/tools/platforms/BUILD
+++ b/tools/platforms/BUILD
@@ -1,3 +1,5 @@
+# Standard constraint_setting and constraint_values to be used in platforms.
+
package(
default_visibility = ["//visibility:public"],
)
@@ -51,11 +53,21 @@
)
constraint_value(
+ name = "ios",
+ constraint_setting = ":os",
+)
+
+constraint_value(
name = "freebsd",
constraint_setting = ":os",
)
constraint_value(
+ name = "android",
+ constraint_setting = ":os",
+)
+
+constraint_value(
name = "linux",
constraint_setting = ":os",
)
@@ -65,6 +77,21 @@
constraint_setting = ":os",
)
+# A constraint that can only be matched by the autoconfigured platforms.
+constraint_setting(
+ name = "autoconfigure_status",
+ visibility = ["//visibility:private"],
+)
+
+constraint_value(
+ name = "autoconfigured",
+ constraint_setting = ":autoconfigure_status",
+ visibility = [
+ "@bazel_tools//:__subpackages__",
+ "@local_config_cc//:__subpackages__",
+ ],
+)
+
# A default platform with nothing defined.
platform(name = "default_platform")
@@ -72,6 +99,9 @@
# internal build configurations, and so shouldn't be accessed by other packages.
platform(
name = "host_platform",
+ constraint_values = [
+ ":autoconfigured",
+ ],
cpu_constraints = [
":x86_32",
":x86_64",
@@ -90,6 +120,9 @@
platform(
name = "target_platform",
+ constraint_values = [
+ ":autoconfigured",
+ ],
cpu_constraints = [
":x86_32",
":x86_64",
diff --git a/tools/platforms/platforms.BUILD b/tools/platforms/platforms.BUILD
index e2ea57e..5ff4ba8 100644
--- a/tools/platforms/platforms.BUILD
+++ b/tools/platforms/platforms.BUILD
@@ -41,11 +41,21 @@
)
constraint_value(
+ name = "ios",
+ constraint_setting = ":os",
+)
+
+constraint_value(
name = "freebsd",
constraint_setting = ":os",
)
constraint_value(
+ name = "android",
+ constraint_setting = ":os",
+)
+
+constraint_value(
name = "linux",
constraint_setting = ":os",
)
@@ -55,6 +65,21 @@
constraint_setting = ":os",
)
+# A constraint that can only be matched by the autoconfigured platforms.
+constraint_setting(
+ name = "autoconfigure_status",
+ visibility = ["//visibility:private"],
+)
+
+constraint_value(
+ name = "autoconfigured",
+ constraint_setting = ":autoconfigure_status",
+ visibility = [
+ "@bazel_tools//:__subpackages__",
+ "@local_config_cc//:__subpackages__",
+ ],
+)
+
# A default platform with nothing defined.
platform(name = "default_platform")
@@ -62,6 +87,9 @@
# internal build configurations, and so shouldn't be accessed by other packages.
platform(
name = "host_platform",
+ constraint_values = [
+ ":autoconfigured",
+ ],
cpu_constraints = [
":x86_32",
":x86_64",
@@ -80,6 +108,9 @@
platform(
name = "target_platform",
+ constraint_values = [
+ ":autoconfigured",
+ ],
cpu_constraints = [
":x86_32",
":x86_64",