Damien Martin-Guillerez | 8fa5ae6 | 2016-03-02 16:24:13 +0000 | [diff] [blame] | 1 | # 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 Peng | 65cda4f | 2017-06-22 11:06:11 +0200 | [diff] [blame] | 16 | load("@bazel_tools//tools/cpp:windows_cc_configure.bzl", "configure_windows_toolchain") |
| 17 | load("@bazel_tools//tools/cpp:osx_cc_configure.bzl", "configure_osx_toolchain") |
| 18 | load("@bazel_tools//tools/cpp:unix_cc_configure.bzl", "configure_unix_toolchain") |
jmmv | 5b02559 | 2018-05-29 12:03:21 -0700 | [diff] [blame] | 19 | load( |
| 20 | "@bazel_tools//tools/cpp:lib_cc_configure.bzl", |
| 21 | "get_cpu_value", |
| 22 | "resolve_labels", |
| 23 | ) |
hlopko | 0f0ccc4 | 2017-05-10 04:15:26 -0400 | [diff] [blame] | 24 | |
Ilya Biryukov | 12471a7 | 2017-12-20 05:46:44 -0800 | [diff] [blame] | 25 | def cc_autoconf_impl(repository_ctx, overriden_tools = dict()): |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 26 | 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 | ]) |
jmmv | 5b02559 | 2018-05-29 12:03:21 -0700 | [diff] [blame] | 31 | |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 32 | 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-Guillerez | 8fa5ae6 | 2016-03-02 16:24:13 +0000 | [diff] [blame] | 57 | |
Damien Martin-Guillerez | ac29b78 | 2017-02-15 14:50:39 +0000 | [diff] [blame] | 58 | cc_autoconf = repository_rule( |
Damien Martin-Guillerez | ac29b78 | 2017-02-15 14:50:39 +0000 | [diff] [blame] | 59 | environ = [ |
Nicolas Lopez | bcbdb87 | 2017-03-28 08:08:50 +0000 | [diff] [blame] | 60 | "ABI_LIBC_VERSION", |
| 61 | "ABI_VERSION", |
| 62 | "BAZEL_COMPILER", |
| 63 | "BAZEL_HOST_SYSTEM", |
hlopko | 19c6428 | 2018-02-27 07:28:40 -0800 | [diff] [blame] | 64 | "BAZEL_LINKOPTS", |
Nicolas Lopez | bcbdb87 | 2017-03-28 08:08:50 +0000 | [diff] [blame] | 65 | "BAZEL_PYTHON", |
| 66 | "BAZEL_SH", |
| 67 | "BAZEL_TARGET_CPU", |
| 68 | "BAZEL_TARGET_LIBC", |
| 69 | "BAZEL_TARGET_SYSTEM", |
hlopko | 209a975 | 2017-12-12 04:34:41 -0800 | [diff] [blame] | 70 | "BAZEL_USE_CPP_ONLY_TOOLCHAIN", |
hlopko | 57bc201 | 2018-05-16 02:15:04 -0700 | [diff] [blame] | 71 | "BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN", |
Ulf Adams | 1441a3a | 2018-04-26 00:39:43 -0700 | [diff] [blame] | 72 | "BAZEL_USE_LLVM_NATIVE_COVERAGE", |
Damien Martin-Guillerez | ac29b78 | 2017-02-15 14:50:39 +0000 | [diff] [blame] | 73 | "BAZEL_VC", |
| 74 | "BAZEL_VS", |
Nicolas Lopez | bcbdb87 | 2017-03-28 08:08:50 +0000 | [diff] [blame] | 75 | "CC", |
Yun Peng | a6f0f13 | 2017-06-28 14:55:37 +0200 | [diff] [blame] | 76 | "CC_CONFIGURE_DEBUG", |
Nicolas Lopez | bcbdb87 | 2017-03-28 08:08:50 +0000 | [diff] [blame] | 77 | "CC_TOOLCHAIN_NAME", |
Nicolas Lopez | 6326f98 | 2017-04-04 16:22:30 +0000 | [diff] [blame] | 78 | "CPLUS_INCLUDE_PATH", |
Ulf Adams | 9566f67 | 2018-04-19 02:55:15 -0700 | [diff] [blame] | 79 | "GCOV", |
Nicolas Lopez | 6326f98 | 2017-04-04 16:22:30 +0000 | [diff] [blame] | 80 | "HOMEBREW_RUBY_PATH", |
Ulf Adams | 1441a3a | 2018-04-26 00:39:43 -0700 | [diff] [blame] | 81 | "SYSTEMROOT", |
Nicolas Lopez | 6326f98 | 2017-04-04 16:22:30 +0000 | [diff] [blame] | 82 | "VS90COMNTOOLS", |
| 83 | "VS100COMNTOOLS", |
| 84 | "VS110COMNTOOLS", |
| 85 | "VS120COMNTOOLS", |
jcater | f5c8c0b | 2018-03-27 07:22:35 -0700 | [diff] [blame] | 86 | "VS140COMNTOOLS", |
| 87 | ], |
| 88 | implementation = cc_autoconf_impl, |
| 89 | ) |
Damien Martin-Guillerez | 8fa5ae6 | 2016-03-02 16:24:13 +0000 | [diff] [blame] | 90 | |
| 91 | def cc_configure(): |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 92 | """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 | ) |