blob: cf4c389bca0f38ef2b52a871b695e1a9aace52d1 [file] [log] [blame]
Damien Martin-Guillerez8fa5ae62016-03-02 16:24:13 +00001# Copyright 2016 The Bazel Authors. All rights reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14"""Rules for configuring the C++ toolchain (experimental)."""
15
Yun Peng65cda4f2017-06-22 11:06:11 +020016load("@bazel_tools//tools/cpp:windows_cc_configure.bzl", "configure_windows_toolchain")
17load("@bazel_tools//tools/cpp:osx_cc_configure.bzl", "configure_osx_toolchain")
18load("@bazel_tools//tools/cpp:unix_cc_configure.bzl", "configure_unix_toolchain")
jmmv5b025592018-05-29 12:03:21 -070019load(
20 "@bazel_tools//tools/cpp:lib_cc_configure.bzl",
21 "get_cpu_value",
22 "resolve_labels",
23)
hlopko0f0ccc42017-05-10 04:15:26 -040024
Ilya Biryukov12471a72017-12-20 05:46:44 -080025def cc_autoconf_impl(repository_ctx, overriden_tools = dict()):
vladmos20a042f2018-06-01 04:51:21 -070026 paths = resolve_labels(repository_ctx, [
27 "@bazel_tools//tools/cpp:BUILD.static.freebsd",
28 "@bazel_tools//tools/cpp:CROSSTOOL",
29 "@bazel_tools//tools/cpp:dummy_toolchain.bzl",
30 ])
jmmv5b025592018-05-29 12:03:21 -070031
vladmos20a042f2018-06-01 04:51:21 -070032 repository_ctx.symlink(
33 paths["@bazel_tools//tools/cpp:dummy_toolchain.bzl"],
34 "dummy_toolchain.bzl",
35 )
36 env = repository_ctx.os.environ
37 cpu_value = get_cpu_value(repository_ctx)
38 if "BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN" in env and env["BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN"] == "1":
39 repository_ctx.symlink(Label("@bazel_tools//tools/cpp:CROSSTOOL.empty"), "CROSSTOOL")
40 repository_ctx.symlink(Label("@bazel_tools//tools/cpp:BUILD.empty"), "BUILD")
41 elif cpu_value == "freebsd":
42 # This is defaulting to the static crosstool, we should eventually
43 # autoconfigure this platform too. Theorically, FreeBSD should be
44 # straightforward to add but we cannot run it in a docker container so
45 # skipping until we have proper tests for FreeBSD.
46 repository_ctx.symlink(paths["@bazel_tools//tools/cpp:CROSSTOOL"], "CROSSTOOL")
47 repository_ctx.symlink(paths["@bazel_tools//tools/cpp:BUILD.static.freebsd"], "BUILD")
48 elif cpu_value == "x64_windows":
49 # TODO(ibiryukov): overriden_tools are only supported in configure_unix_toolchain.
50 # We might want to add that to Windows too(at least for msys toolchain).
51 configure_windows_toolchain(repository_ctx)
52 elif (cpu_value == "darwin" and
53 ("BAZEL_USE_CPP_ONLY_TOOLCHAIN" not in env or env["BAZEL_USE_CPP_ONLY_TOOLCHAIN"] != "1")):
54 configure_osx_toolchain(repository_ctx, overriden_tools)
55 else:
56 configure_unix_toolchain(repository_ctx, cpu_value, overriden_tools)
Damien Martin-Guillerez8fa5ae62016-03-02 16:24:13 +000057
Damien Martin-Guillerezac29b782017-02-15 14:50:39 +000058cc_autoconf = repository_rule(
Damien Martin-Guillerezac29b782017-02-15 14:50:39 +000059 environ = [
Nicolas Lopezbcbdb872017-03-28 08:08:50 +000060 "ABI_LIBC_VERSION",
61 "ABI_VERSION",
62 "BAZEL_COMPILER",
63 "BAZEL_HOST_SYSTEM",
hlopko19c64282018-02-27 07:28:40 -080064 "BAZEL_LINKOPTS",
Nicolas Lopezbcbdb872017-03-28 08:08:50 +000065 "BAZEL_PYTHON",
66 "BAZEL_SH",
67 "BAZEL_TARGET_CPU",
68 "BAZEL_TARGET_LIBC",
69 "BAZEL_TARGET_SYSTEM",
hlopko209a9752017-12-12 04:34:41 -080070 "BAZEL_USE_CPP_ONLY_TOOLCHAIN",
hlopko57bc2012018-05-16 02:15:04 -070071 "BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN",
Ulf Adams1441a3a2018-04-26 00:39:43 -070072 "BAZEL_USE_LLVM_NATIVE_COVERAGE",
Damien Martin-Guillerezac29b782017-02-15 14:50:39 +000073 "BAZEL_VC",
74 "BAZEL_VS",
Nicolas Lopezbcbdb872017-03-28 08:08:50 +000075 "CC",
Yun Penga6f0f132017-06-28 14:55:37 +020076 "CC_CONFIGURE_DEBUG",
Nicolas Lopezbcbdb872017-03-28 08:08:50 +000077 "CC_TOOLCHAIN_NAME",
Nicolas Lopez6326f982017-04-04 16:22:30 +000078 "CPLUS_INCLUDE_PATH",
Ulf Adams9566f672018-04-19 02:55:15 -070079 "GCOV",
Nicolas Lopez6326f982017-04-04 16:22:30 +000080 "HOMEBREW_RUBY_PATH",
Ulf Adams1441a3a2018-04-26 00:39:43 -070081 "SYSTEMROOT",
Nicolas Lopez6326f982017-04-04 16:22:30 +000082 "VS90COMNTOOLS",
83 "VS100COMNTOOLS",
84 "VS110COMNTOOLS",
85 "VS120COMNTOOLS",
jcaterf5c8c0b2018-03-27 07:22:35 -070086 "VS140COMNTOOLS",
87 ],
88 implementation = cc_autoconf_impl,
89)
Damien Martin-Guillerez8fa5ae62016-03-02 16:24:13 +000090
91def cc_configure():
vladmos20a042f2018-06-01 04:51:21 -070092 """A C++ configuration rules that generate the crosstool file."""
93 cc_autoconf(name = "local_config_cc")
94 native.bind(name = "cc_toolchain", actual = "@local_config_cc//:toolchain")
95 native.register_toolchains(
96 # Use register_toolchain's target pattern expansion to register all toolchains in the package.
97 "@local_config_cc//:all",
98 )