Yun Peng | 65cda4f | 2017-06-22 11:06:11 +0200 | [diff] [blame] | 1 | # pylint: disable=g-bad-file-header |
| 2 | # Copyright 2016 The Bazel Authors. All rights reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | """Configuring the C++ toolchain on Windows.""" |
| 16 | |
| 17 | load( |
| 18 | "@bazel_tools//tools/cpp:lib_cc_configure.bzl", |
Yun Peng | 65cda4f | 2017-06-22 11:06:11 +0200 | [diff] [blame] | 19 | "auto_configure_fail", |
| 20 | "auto_configure_warning", |
Marcel Hlopko | ff6fa78 | 2019-06-04 05:52:05 -0700 | [diff] [blame] | 21 | "auto_configure_warning_maybe", |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 22 | "escape_string", |
Yun Peng | 65cda4f | 2017-06-22 11:06:11 +0200 | [diff] [blame] | 23 | "execute", |
jmmv | 5b02559 | 2018-05-29 12:03:21 -0700 | [diff] [blame] | 24 | "resolve_labels", |
Yun Peng | 65cda4f | 2017-06-22 11:06:11 +0200 | [diff] [blame] | 25 | ) |
| 26 | |
Laszlo Csomor | 63d4f11 | 2019-05-14 06:40:26 -0700 | [diff] [blame] | 27 | def _get_path_env_var(repository_ctx, name): |
| 28 | """Returns a path from an environment variable. |
| 29 | |
| 30 | Removes quotes, replaces '/' with '\', and strips trailing '\'s.""" |
| 31 | if name in repository_ctx.os.environ: |
| 32 | value = repository_ctx.os.environ[name] |
| 33 | if value[0] == "\"": |
| 34 | if len(value) == 1 or value[-1] != "\"": |
| 35 | auto_configure_fail("'%s' environment variable has no trailing quote" % name) |
| 36 | value = value[1:-1] |
| 37 | if "/" in value: |
| 38 | value = value.replace("/", "\\") |
| 39 | if value[-1] == "\\": |
| 40 | value = value.rstrip("\\") |
| 41 | return value |
| 42 | else: |
| 43 | return None |
| 44 | |
| 45 | def _get_temp_env(repository_ctx): |
Marwan Tammam | 20c8413 | 2019-06-04 07:27:31 -0700 | [diff] [blame] | 46 | """Returns the value of TMP, or TEMP, or if both undefined then C:\\Windows.""" |
Laszlo Csomor | 63d4f11 | 2019-05-14 06:40:26 -0700 | [diff] [blame] | 47 | tmp = _get_path_env_var(repository_ctx, "TMP") |
| 48 | if not tmp: |
| 49 | tmp = _get_path_env_var(repository_ctx, "TEMP") |
| 50 | if not tmp: |
| 51 | tmp = "C:\\Windows\\Temp" |
| 52 | auto_configure_warning( |
| 53 | "neither 'TMP' nor 'TEMP' environment variables are set, using '%s' as default" % tmp, |
| 54 | ) |
| 55 | return tmp |
| 56 | |
rosica | 71bc38f | 2019-02-04 02:39:30 -0800 | [diff] [blame] | 57 | def _get_escaped_windows_msys_starlark_content(repository_ctx, use_mingw = False): |
| 58 | """Return the content of msys cc toolchain rule.""" |
Yun Peng | f66086d | 2018-10-24 08:33:09 -0700 | [diff] [blame] | 59 | msys_root = "" |
Laszlo Csomor | 63d4f11 | 2019-05-14 06:40:26 -0700 | [diff] [blame] | 60 | bazel_sh = _get_path_env_var(repository_ctx, "BAZEL_SH") |
| 61 | if bazel_sh: |
| 62 | bazel_sh = bazel_sh.replace("\\", "/").lower() |
| 63 | tokens = bazel_sh.rsplit("/", 1) |
| 64 | if tokens[0].endswith("/usr/bin"): |
| 65 | msys_root = tokens[0][:len(tokens[0]) - len("usr/bin")] |
| 66 | elif tokens[0].endswith("/bin"): |
| 67 | msys_root = tokens[0][:len(tokens[0]) - len("bin")] |
| 68 | |
Yun Peng | f66086d | 2018-10-24 08:33:09 -0700 | [diff] [blame] | 69 | prefix = "mingw64" if use_mingw else "usr" |
| 70 | tool_path_prefix = escape_string(msys_root) + prefix |
pcloudy | 511fe9b | 2018-11-19 03:27:09 -0800 | [diff] [blame] | 71 | tool_bin_path = tool_path_prefix + "/bin" |
Yun Peng | f66086d | 2018-10-24 08:33:09 -0700 | [diff] [blame] | 72 | tool_path = {} |
| 73 | |
| 74 | for tool in ["ar", "compat-ld", "cpp", "dwp", "gcc", "gcov", "ld", "nm", "objcopy", "objdump", "strip"]: |
| 75 | if msys_root: |
pcloudy | 511fe9b | 2018-11-19 03:27:09 -0800 | [diff] [blame] | 76 | tool_path[tool] = tool_bin_path + "/" + tool |
Yun Peng | f66086d | 2018-10-24 08:33:09 -0700 | [diff] [blame] | 77 | else: |
| 78 | tool_path[tool] = "msys_gcc_installation_error.bat" |
rosica | beaba92 | 2019-05-20 02:36:26 -0700 | [diff] [blame] | 79 | tool_paths = ",\n ".join(['"%s": "%s"' % (k, v) for k, v in tool_path.items()]) |
rosica | 71bc38f | 2019-02-04 02:39:30 -0800 | [diff] [blame] | 80 | include_directories = (' "%s/",\n ' % tool_path_prefix) if msys_root else "" |
rosica | beaba92 | 2019-05-20 02:36:26 -0700 | [diff] [blame] | 81 | return tool_paths, tool_bin_path, include_directories |
Yun Peng | 65cda4f | 2017-06-22 11:06:11 +0200 | [diff] [blame] | 82 | |
Yun Peng | 65cda4f | 2017-06-22 11:06:11 +0200 | [diff] [blame] | 83 | def _get_system_root(repository_ctx): |
Marwan Tammam | 20c8413 | 2019-06-04 07:27:31 -0700 | [diff] [blame] | 84 | """Get System root path on Windows, default is C:\\Windows. Doesn't %-escape the result.""" |
Laszlo Csomor | 63d4f11 | 2019-05-14 06:40:26 -0700 | [diff] [blame] | 85 | systemroot = _get_path_env_var(repository_ctx, "SYSTEMROOT") |
| 86 | if not systemroot: |
| 87 | systemroot = "C:\\Windows" |
Marcel Hlopko | ff6fa78 | 2019-06-04 05:52:05 -0700 | [diff] [blame] | 88 | auto_configure_warning_maybe( |
Laszlo Csomor | 63d4f11 | 2019-05-14 06:40:26 -0700 | [diff] [blame] | 89 | repository_ctx, |
| 90 | "SYSTEMROOT is not set, using default SYSTEMROOT=C:\\Windows", |
| 91 | ) |
| 92 | return escape_string(systemroot) |
Yun Peng | 65cda4f | 2017-06-22 11:06:11 +0200 | [diff] [blame] | 93 | |
Yun Peng | 65cda4f | 2017-06-22 11:06:11 +0200 | [diff] [blame] | 94 | def _add_system_root(repository_ctx, env): |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 95 | """Running VCVARSALL.BAT and VCVARSQUERYREGISTRY.BAT need %SYSTEMROOT%\\\\system32 in PATH.""" |
| 96 | if "PATH" not in env: |
| 97 | env["PATH"] = "" |
| 98 | env["PATH"] = env["PATH"] + ";" + _get_system_root(repository_ctx) + "\\system32" |
| 99 | return env |
Yun Peng | 65cda4f | 2017-06-22 11:06:11 +0200 | [diff] [blame] | 100 | |
Yun Peng | ff12a22 | 2017-12-01 07:27:24 -0800 | [diff] [blame] | 101 | def find_vc_path(repository_ctx): |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 102 | """Find Visual C++ build tools install path. Doesn't %-escape the result.""" |
Yun Peng | 65cda4f | 2017-06-22 11:06:11 +0200 | [diff] [blame] | 103 | |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 104 | # 1. Check if BAZEL_VC or BAZEL_VS is already set by user. |
Laszlo Csomor | 63d4f11 | 2019-05-14 06:40:26 -0700 | [diff] [blame] | 105 | bazel_vc = _get_path_env_var(repository_ctx, "BAZEL_VC") |
| 106 | if bazel_vc: |
| 107 | if repository_ctx.path(bazel_vc).exists: |
| 108 | return bazel_vc |
| 109 | else: |
Marcel Hlopko | ff6fa78 | 2019-06-04 05:52:05 -0700 | [diff] [blame] | 110 | auto_configure_warning_maybe( |
Laszlo Csomor | 63d4f11 | 2019-05-14 06:40:26 -0700 | [diff] [blame] | 111 | repository_ctx, |
| 112 | "%BAZEL_VC% is set to non-existent path, ignoring.", |
| 113 | ) |
Yun Peng | 65cda4f | 2017-06-22 11:06:11 +0200 | [diff] [blame] | 114 | |
Laszlo Csomor | 63d4f11 | 2019-05-14 06:40:26 -0700 | [diff] [blame] | 115 | bazel_vs = _get_path_env_var(repository_ctx, "BAZEL_VS") |
| 116 | if bazel_vs: |
| 117 | if repository_ctx.path(bazel_vs).exists: |
| 118 | bazel_vc = bazel_vs + "\\VC" |
| 119 | if repository_ctx.path(bazel_vc).exists: |
| 120 | return bazel_vc |
| 121 | else: |
Marcel Hlopko | ff6fa78 | 2019-06-04 05:52:05 -0700 | [diff] [blame] | 122 | auto_configure_warning_maybe( |
Laszlo Csomor | 63d4f11 | 2019-05-14 06:40:26 -0700 | [diff] [blame] | 123 | repository_ctx, |
| 124 | "No 'VC' directory found under %BAZEL_VS%, ignoring.", |
| 125 | ) |
| 126 | else: |
Marcel Hlopko | ff6fa78 | 2019-06-04 05:52:05 -0700 | [diff] [blame] | 127 | auto_configure_warning_maybe( |
Laszlo Csomor | 63d4f11 | 2019-05-14 06:40:26 -0700 | [diff] [blame] | 128 | repository_ctx, |
| 129 | "%BAZEL_VS% is set to non-existent path, ignoring.", |
| 130 | ) |
| 131 | |
Marcel Hlopko | ff6fa78 | 2019-06-04 05:52:05 -0700 | [diff] [blame] | 132 | auto_configure_warning_maybe( |
Laszlo Csomor | 63d4f11 | 2019-05-14 06:40:26 -0700 | [diff] [blame] | 133 | repository_ctx, |
| 134 | "Neither %BAZEL_VC% nor %BAZEL_VS% are set, start looking for the latest Visual C++" + |
| 135 | " installed.", |
| 136 | ) |
Yun Peng | 65cda4f | 2017-06-22 11:06:11 +0200 | [diff] [blame] | 137 | |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 138 | # 2. Check if VS%VS_VERSION%COMNTOOLS is set, if true then try to find and use |
Laszlo Csomor | 18d7024 | 2019-04-03 00:38:02 -0700 | [diff] [blame] | 139 | # vcvarsqueryregistry.bat / VsDevCmd.bat to detect VC++. |
Marcel Hlopko | ff6fa78 | 2019-06-04 05:52:05 -0700 | [diff] [blame] | 140 | auto_configure_warning_maybe(repository_ctx, "Looking for VS%VERSION%COMNTOOLS environment variables, " + |
| 141 | "eg. VS140COMNTOOLS") |
Laszlo Csomor | 18d7024 | 2019-04-03 00:38:02 -0700 | [diff] [blame] | 142 | for vscommontools_env, script in [ |
| 143 | ("VS160COMNTOOLS", "VsDevCmd.bat"), |
| 144 | ("VS150COMNTOOLS", "VsDevCmd.bat"), |
| 145 | ("VS140COMNTOOLS", "vcvarsqueryregistry.bat"), |
| 146 | ("VS120COMNTOOLS", "vcvarsqueryregistry.bat"), |
| 147 | ("VS110COMNTOOLS", "vcvarsqueryregistry.bat"), |
| 148 | ("VS100COMNTOOLS", "vcvarsqueryregistry.bat"), |
| 149 | ("VS90COMNTOOLS", "vcvarsqueryregistry.bat"), |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 150 | ]: |
| 151 | if vscommontools_env not in repository_ctx.os.environ: |
| 152 | continue |
Laszlo Csomor | 63d4f11 | 2019-05-14 06:40:26 -0700 | [diff] [blame] | 153 | script = _get_path_env_var(repository_ctx, vscommontools_env) + "\\" + script |
Laszlo Csomor | 18d7024 | 2019-04-03 00:38:02 -0700 | [diff] [blame] | 154 | if not repository_ctx.path(script).exists: |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 155 | continue |
| 156 | repository_ctx.file( |
| 157 | "get_vc_dir.bat", |
| 158 | "@echo off\n" + |
Laszlo Csomor | 18d7024 | 2019-04-03 00:38:02 -0700 | [diff] [blame] | 159 | "call \"" + script + "\"\n" + |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 160 | "echo %VCINSTALLDIR%", |
| 161 | True, |
| 162 | ) |
| 163 | env = _add_system_root(repository_ctx, repository_ctx.os.environ) |
| 164 | vc_dir = execute(repository_ctx, ["./get_vc_dir.bat"], environment = env) |
| 165 | |
Marcel Hlopko | ff6fa78 | 2019-06-04 05:52:05 -0700 | [diff] [blame] | 166 | auto_configure_warning_maybe(repository_ctx, "Visual C++ build tools found at %s" % vc_dir) |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 167 | return vc_dir |
| 168 | |
Laszlo Csomor | 18d7024 | 2019-04-03 00:38:02 -0700 | [diff] [blame] | 169 | # 3. User might have purged all environment variables. If so, look for Visual C++ in registry. |
| 170 | # Works for Visual Studio 2017 and older. (Does not work for Visual Studio 2019 Preview.) |
| 171 | # TODO(laszlocsomor): check if "16.0" also has this registry key, after VS 2019 is released. |
Marcel Hlopko | ff6fa78 | 2019-06-04 05:52:05 -0700 | [diff] [blame] | 172 | auto_configure_warning_maybe(repository_ctx, "Looking for Visual C++ through registry") |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 173 | reg_binary = _get_system_root(repository_ctx) + "\\system32\\reg.exe" |
| 174 | vc_dir = None |
| 175 | for key, suffix in (("VC7", ""), ("VS7", "\\VC")): |
| 176 | for version in ["15.0", "14.0", "12.0", "11.0", "10.0", "9.0", "8.0"]: |
| 177 | if vc_dir: |
| 178 | break |
| 179 | result = repository_ctx.execute([reg_binary, "query", "HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\VisualStudio\\SxS\\" + key, "/v", version]) |
Marcel Hlopko | ff6fa78 | 2019-06-04 05:52:05 -0700 | [diff] [blame] | 180 | auto_configure_warning_maybe(repository_ctx, "registry query result for VC %s:\n\nSTDOUT(start)\n%s\nSTDOUT(end)\nSTDERR(start):\n%s\nSTDERR(end)\n" % |
| 181 | (version, result.stdout, result.stderr)) |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 182 | if not result.stderr: |
| 183 | for line in result.stdout.split("\n"): |
| 184 | line = line.strip() |
| 185 | if line.startswith(version) and line.find("REG_SZ") != -1: |
| 186 | vc_dir = line[line.find("REG_SZ") + len("REG_SZ"):].strip() + suffix |
Yun Peng | f445af5 | 2018-11-02 07:55:01 -0700 | [diff] [blame] | 187 | if vc_dir: |
Marcel Hlopko | ff6fa78 | 2019-06-04 05:52:05 -0700 | [diff] [blame] | 188 | auto_configure_warning_maybe(repository_ctx, "Visual C++ build tools found at %s" % vc_dir) |
Yun Peng | f445af5 | 2018-11-02 07:55:01 -0700 | [diff] [blame] | 189 | return vc_dir |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 190 | |
pcloudy | df42789 | 2018-07-04 06:32:33 -0700 | [diff] [blame] | 191 | # 4. Check default directories for VC installation |
Marcel Hlopko | ff6fa78 | 2019-06-04 05:52:05 -0700 | [diff] [blame] | 192 | auto_configure_warning_maybe(repository_ctx, "Looking for default Visual C++ installation directory") |
Laszlo Csomor | 63d4f11 | 2019-05-14 06:40:26 -0700 | [diff] [blame] | 193 | program_files_dir = _get_path_env_var(repository_ctx, "PROGRAMFILES(X86)") |
| 194 | if not program_files_dir: |
| 195 | program_files_dir = "C:\\Program Files (x86)" |
Marcel Hlopko | ff6fa78 | 2019-06-04 05:52:05 -0700 | [diff] [blame] | 196 | auto_configure_warning_maybe( |
Laszlo Csomor | 63d4f11 | 2019-05-14 06:40:26 -0700 | [diff] [blame] | 197 | repository_ctx, |
| 198 | "'PROGRAMFILES(X86)' environment variable is not set, using '%s' as default" % program_files_dir, |
| 199 | ) |
pcloudy | df42789 | 2018-07-04 06:32:33 -0700 | [diff] [blame] | 200 | for path in [ |
Laszlo Csomor | 18d7024 | 2019-04-03 00:38:02 -0700 | [diff] [blame] | 201 | "Microsoft Visual Studio\\2019\\Preview\\VC", |
| 202 | "Microsoft Visual Studio\\2019\\BuildTools\\VC", |
| 203 | "Microsoft Visual Studio\\2019\\Community\\VC", |
| 204 | "Microsoft Visual Studio\\2019\\Professional\\VC", |
| 205 | "Microsoft Visual Studio\\2019\\Enterprise\\VC", |
pcloudy | df42789 | 2018-07-04 06:32:33 -0700 | [diff] [blame] | 206 | "Microsoft Visual Studio\\2017\\BuildTools\\VC", |
| 207 | "Microsoft Visual Studio\\2017\\Community\\VC", |
Gregor Jasny | 7f9de5d | 2018-08-20 09:00:36 -0700 | [diff] [blame] | 208 | "Microsoft Visual Studio\\2017\\Professional\\VC", |
pcloudy | df42789 | 2018-07-04 06:32:33 -0700 | [diff] [blame] | 209 | "Microsoft Visual Studio\\2017\\Enterprise\\VC", |
| 210 | "Microsoft Visual Studio 14.0\\VC", |
| 211 | ]: |
| 212 | path = program_files_dir + "\\" + path |
| 213 | if repository_ctx.path(path).exists: |
| 214 | vc_dir = path |
| 215 | break |
| 216 | |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 217 | if not vc_dir: |
Marcel Hlopko | ff6fa78 | 2019-06-04 05:52:05 -0700 | [diff] [blame] | 218 | auto_configure_warning_maybe(repository_ctx, "Visual C++ build tools not found.") |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 219 | return None |
Marcel Hlopko | ff6fa78 | 2019-06-04 05:52:05 -0700 | [diff] [blame] | 220 | auto_configure_warning_maybe(repository_ctx, "Visual C++ build tools found at %s" % vc_dir) |
Yun Peng | 65cda4f | 2017-06-22 11:06:11 +0200 | [diff] [blame] | 221 | return vc_dir |
| 222 | |
Laszlo Csomor | 18d7024 | 2019-04-03 00:38:02 -0700 | [diff] [blame] | 223 | def _is_vs_2017_or_2019(vc_path): |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 224 | """Check if the installed VS version is Visual Studio 2017.""" |
| 225 | |
Laszlo Csomor | 18d7024 | 2019-04-03 00:38:02 -0700 | [diff] [blame] | 226 | # In VS 2017 and 2019, the location of VC is like: |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 227 | # C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\ |
| 228 | # In VS 2015 or older version, it is like: |
| 229 | # C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ |
Laszlo Csomor | 18d7024 | 2019-04-03 00:38:02 -0700 | [diff] [blame] | 230 | return vc_path.find("2017") != -1 or vc_path.find("2019") != -1 |
Yun Peng | 65cda4f | 2017-06-22 11:06:11 +0200 | [diff] [blame] | 231 | |
Yun Peng | 65cda4f | 2017-06-22 11:06:11 +0200 | [diff] [blame] | 232 | def _find_vcvarsall_bat_script(repository_ctx, vc_path): |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 233 | """Find vcvarsall.bat script. Doesn't %-escape the result.""" |
Laszlo Csomor | 18d7024 | 2019-04-03 00:38:02 -0700 | [diff] [blame] | 234 | if _is_vs_2017_or_2019(vc_path): |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 235 | vcvarsall = vc_path + "\\Auxiliary\\Build\\VCVARSALL.BAT" |
| 236 | else: |
| 237 | vcvarsall = vc_path + "\\VCVARSALL.BAT" |
Yun Peng | 65cda4f | 2017-06-22 11:06:11 +0200 | [diff] [blame] | 238 | |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 239 | if not repository_ctx.path(vcvarsall).exists: |
| 240 | return None |
Yun Peng | 7284d6e | 2018-03-14 04:13:54 -0700 | [diff] [blame] | 241 | |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 242 | return vcvarsall |
Yun Peng | 65cda4f | 2017-06-22 11:06:11 +0200 | [diff] [blame] | 243 | |
Yun Peng | a3dd777 | 2018-03-22 03:09:32 -0700 | [diff] [blame] | 244 | def setup_vc_env_vars(repository_ctx, vc_path): |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 245 | """Get environment variables set by VCVARSALL.BAT. Doesn't %-escape the result!""" |
| 246 | vcvarsall = _find_vcvarsall_bat_script(repository_ctx, vc_path) |
| 247 | if not vcvarsall: |
| 248 | return None |
Yun Peng | e5b7bd6 | 2019-05-21 01:26:45 -0700 | [diff] [blame] | 249 | vcvars_ver = "" |
| 250 | if _is_vs_2017_or_2019(vc_path): |
| 251 | full_version = _get_vc_full_version(repository_ctx, vc_path) |
| 252 | if full_version: |
| 253 | vcvars_ver = "-vcvars_ver=" + full_version |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 254 | repository_ctx.file( |
| 255 | "get_env.bat", |
| 256 | "@echo off\n" + |
Yun Peng | e5b7bd6 | 2019-05-21 01:26:45 -0700 | [diff] [blame] | 257 | ("call \"%s\" amd64 %s > NUL \n" % (vcvarsall, vcvars_ver)) + |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 258 | "echo PATH=%PATH%,INCLUDE=%INCLUDE%,LIB=%LIB%,WINDOWSSDKDIR=%WINDOWSSDKDIR% \n", |
| 259 | True, |
| 260 | ) |
| 261 | env = _add_system_root( |
| 262 | repository_ctx, |
| 263 | {"PATH": "", "INCLUDE": "", "LIB": "", "WINDOWSSDKDIR": ""}, |
| 264 | ) |
| 265 | envs = execute(repository_ctx, ["./get_env.bat"], environment = env).split(",") |
| 266 | env_map = {} |
| 267 | for env in envs: |
| 268 | key, value = env.split("=", 1) |
| 269 | env_map[key] = escape_string(value.replace("\\", "\\\\")) |
| 270 | return env_map |
Yun Peng | 65cda4f | 2017-06-22 11:06:11 +0200 | [diff] [blame] | 271 | |
Yun Peng | e5b7bd6 | 2019-05-21 01:26:45 -0700 | [diff] [blame] | 272 | def _get_latest_subversion(repository_ctx, vc_path): |
| 273 | """Get the latest subversion of a VS 2017/2019 installation. |
| 274 | |
| 275 | For VS 2017 & 2019, there could be multiple versions of VC build tools. |
| 276 | The directories are like: |
| 277 | <vc_path>\\Tools\\MSVC\\14.10.24930\\bin\\HostX64\\x64 |
| 278 | <vc_path>\\Tools\\MSVC\\14.16.27023\\bin\\HostX64\\x64 |
| 279 | This function should return 14.16.27023 in this case.""" |
| 280 | versions = [path.basename for path in repository_ctx.path(vc_path + "\\Tools\\MSVC").readdir()] |
| 281 | if len(versions) < 1: |
Marcel Hlopko | ff6fa78 | 2019-06-04 05:52:05 -0700 | [diff] [blame] | 282 | auto_configure_warning_maybe(repository_ctx, "Cannot find any VC installation under BAZEL_VC(%s)" % vc_path) |
Yun Peng | e5b7bd6 | 2019-05-21 01:26:45 -0700 | [diff] [blame] | 283 | return None |
| 284 | |
| 285 | # Parse the version string into integers, then sort the integers to prevent textual sorting. |
| 286 | version_list = [] |
| 287 | for version in versions: |
| 288 | parts = [int(i) for i in version.split(".")] |
| 289 | version_list.append((parts, version)) |
| 290 | |
| 291 | version_list = sorted(version_list) |
| 292 | latest_version = version_list[-1][1] |
| 293 | |
Marcel Hlopko | ff6fa78 | 2019-06-04 05:52:05 -0700 | [diff] [blame] | 294 | auto_configure_warning_maybe(repository_ctx, "Found the following VC verisons:\n%s\n\nChoosing the latest version = %s" % ("\n".join(versions), latest_version)) |
Yun Peng | e5b7bd6 | 2019-05-21 01:26:45 -0700 | [diff] [blame] | 295 | return latest_version |
| 296 | |
| 297 | def _get_vc_full_version(repository_ctx, vc_path): |
| 298 | """Return the value of BAZEL_VC_FULL_VERSION if defined, otherwise the latest version.""" |
| 299 | if "BAZEL_VC_FULL_VERSION" in repository_ctx.os.environ: |
| 300 | return repository_ctx.os.environ["BAZEL_VC_FULL_VERSION"] |
| 301 | return _get_latest_subversion(repository_ctx, vc_path) |
| 302 | |
Yun Peng | ff12a22 | 2017-12-01 07:27:24 -0800 | [diff] [blame] | 303 | def find_msvc_tool(repository_ctx, vc_path, tool): |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 304 | """Find the exact path of a specific build tool in MSVC. Doesn't %-escape the result.""" |
Yun Peng | e5b7bd6 | 2019-05-21 01:26:45 -0700 | [diff] [blame] | 305 | tool_path = None |
Laszlo Csomor | 18d7024 | 2019-04-03 00:38:02 -0700 | [diff] [blame] | 306 | if _is_vs_2017_or_2019(vc_path): |
Yun Peng | e5b7bd6 | 2019-05-21 01:26:45 -0700 | [diff] [blame] | 307 | full_version = _get_vc_full_version(repository_ctx, vc_path) |
| 308 | if full_version: |
| 309 | tool_path = "%s\\Tools\\MSVC\\%s\\bin\\HostX64\\x64\\%s" % (vc_path, full_version, tool) |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 310 | else: |
| 311 | # For VS 2015 and older version, the tools are under: |
| 312 | # C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64 |
| 313 | tool_path = vc_path + "\\bin\\amd64\\" + tool |
Yun Peng | 7284d6e | 2018-03-14 04:13:54 -0700 | [diff] [blame] | 314 | |
Yun Peng | e5b7bd6 | 2019-05-21 01:26:45 -0700 | [diff] [blame] | 315 | if not tool_path or not repository_ctx.path(tool_path).exists: |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 316 | return None |
| 317 | |
Yun Peng | f445af5 | 2018-11-02 07:55:01 -0700 | [diff] [blame] | 318 | return tool_path.replace("\\", "/") |
Yun Peng | 65cda4f | 2017-06-22 11:06:11 +0200 | [diff] [blame] | 319 | |
Yun Peng | 7284d6e | 2018-03-14 04:13:54 -0700 | [diff] [blame] | 320 | def _find_missing_vc_tools(repository_ctx, vc_path): |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 321 | """Check if any required tool is missing under given VC path.""" |
| 322 | missing_tools = [] |
| 323 | if not _find_vcvarsall_bat_script(repository_ctx, vc_path): |
| 324 | missing_tools.append("VCVARSALL.BAT") |
Yun Peng | 7284d6e | 2018-03-14 04:13:54 -0700 | [diff] [blame] | 325 | |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 326 | for tool in ["cl.exe", "link.exe", "lib.exe", "ml64.exe"]: |
| 327 | if not find_msvc_tool(repository_ctx, vc_path, tool): |
| 328 | missing_tools.append(tool) |
Yun Peng | 7284d6e | 2018-03-14 04:13:54 -0700 | [diff] [blame] | 329 | |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 330 | return missing_tools |
Yun Peng | 7284d6e | 2018-03-14 04:13:54 -0700 | [diff] [blame] | 331 | |
Yun Peng | f445af5 | 2018-11-02 07:55:01 -0700 | [diff] [blame] | 332 | def _is_support_debug_fastlink(repository_ctx, linker): |
| 333 | """Run linker alone to see if it supports /DEBUG:FASTLINK.""" |
| 334 | if _use_clang_cl(repository_ctx): |
| 335 | # LLVM's lld-link.exe doesn't support /DEBUG:FASTLINK. |
| 336 | return False |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 337 | result = execute(repository_ctx, [linker], expect_failure = True) |
| 338 | return result.find("/DEBUG[:{FASTLINK|FULL|NONE}]") != -1 |
Yun Peng | 09a6a9f | 2017-12-11 07:24:45 -0800 | [diff] [blame] | 339 | |
Yun Peng | f445af5 | 2018-11-02 07:55:01 -0700 | [diff] [blame] | 340 | def find_llvm_path(repository_ctx): |
| 341 | """Find LLVM install path.""" |
| 342 | |
| 343 | # 1. Check if BAZEL_LLVM is already set by user. |
Laszlo Csomor | 63d4f11 | 2019-05-14 06:40:26 -0700 | [diff] [blame] | 344 | bazel_llvm = _get_path_env_var(repository_ctx, "BAZEL_LLVM") |
| 345 | if bazel_llvm: |
| 346 | return bazel_llvm |
Yun Peng | f445af5 | 2018-11-02 07:55:01 -0700 | [diff] [blame] | 347 | |
Marcel Hlopko | ff6fa78 | 2019-06-04 05:52:05 -0700 | [diff] [blame] | 348 | auto_configure_warning_maybe(repository_ctx, "'BAZEL_LLVM' is not set, " + |
| 349 | "start looking for LLVM installation on machine.") |
Yun Peng | f445af5 | 2018-11-02 07:55:01 -0700 | [diff] [blame] | 350 | |
| 351 | # 2. Look for LLVM installation through registry. |
Marcel Hlopko | ff6fa78 | 2019-06-04 05:52:05 -0700 | [diff] [blame] | 352 | auto_configure_warning_maybe(repository_ctx, "Looking for LLVM installation through registry") |
Yun Peng | f445af5 | 2018-11-02 07:55:01 -0700 | [diff] [blame] | 353 | reg_binary = _get_system_root(repository_ctx) + "\\system32\\reg.exe" |
| 354 | llvm_dir = None |
| 355 | result = repository_ctx.execute([reg_binary, "query", "HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\LLVM\\LLVM"]) |
Marcel Hlopko | ff6fa78 | 2019-06-04 05:52:05 -0700 | [diff] [blame] | 356 | auto_configure_warning_maybe(repository_ctx, "registry query result for LLVM:\n\nSTDOUT(start)\n%s\nSTDOUT(end)\nSTDERR(start):\n%s\nSTDERR(end)\n" % |
| 357 | (result.stdout, result.stderr)) |
Yun Peng | f445af5 | 2018-11-02 07:55:01 -0700 | [diff] [blame] | 358 | if not result.stderr: |
| 359 | for line in result.stdout.split("\n"): |
| 360 | line = line.strip() |
| 361 | if line.startswith("(Default)") and line.find("REG_SZ") != -1: |
| 362 | llvm_dir = line[line.find("REG_SZ") + len("REG_SZ"):].strip() |
| 363 | if llvm_dir: |
Marcel Hlopko | ff6fa78 | 2019-06-04 05:52:05 -0700 | [diff] [blame] | 364 | auto_configure_warning_maybe(repository_ctx, "LLVM installation found at %s" % llvm_dir) |
Yun Peng | f445af5 | 2018-11-02 07:55:01 -0700 | [diff] [blame] | 365 | return llvm_dir |
| 366 | |
| 367 | # 3. Check default directories for LLVM installation |
Marcel Hlopko | ff6fa78 | 2019-06-04 05:52:05 -0700 | [diff] [blame] | 368 | auto_configure_warning_maybe(repository_ctx, "Looking for default LLVM installation directory") |
Laszlo Csomor | 63d4f11 | 2019-05-14 06:40:26 -0700 | [diff] [blame] | 369 | program_files_dir = _get_path_env_var(repository_ctx, "PROGRAMFILES") |
| 370 | if not program_files_dir: |
| 371 | program_files_dir = "C:\\Program Files" |
Marcel Hlopko | ff6fa78 | 2019-06-04 05:52:05 -0700 | [diff] [blame] | 372 | auto_configure_warning_maybe( |
Laszlo Csomor | 63d4f11 | 2019-05-14 06:40:26 -0700 | [diff] [blame] | 373 | repository_ctx, |
| 374 | "'PROGRAMFILES' environment variable is not set, using '%s' as default" % program_files_dir, |
| 375 | ) |
Yun Peng | f445af5 | 2018-11-02 07:55:01 -0700 | [diff] [blame] | 376 | path = program_files_dir + "\\LLVM" |
| 377 | if repository_ctx.path(path).exists: |
| 378 | llvm_dir = path |
| 379 | |
| 380 | if not llvm_dir: |
Marcel Hlopko | ff6fa78 | 2019-06-04 05:52:05 -0700 | [diff] [blame] | 381 | auto_configure_warning_maybe(repository_ctx, "LLVM installation not found.") |
Yun Peng | f445af5 | 2018-11-02 07:55:01 -0700 | [diff] [blame] | 382 | return None |
Marcel Hlopko | ff6fa78 | 2019-06-04 05:52:05 -0700 | [diff] [blame] | 383 | auto_configure_warning_maybe(repository_ctx, "LLVM installation found at %s" % llvm_dir) |
Yun Peng | f445af5 | 2018-11-02 07:55:01 -0700 | [diff] [blame] | 384 | return llvm_dir |
| 385 | |
| 386 | def find_llvm_tool(repository_ctx, llvm_path, tool): |
| 387 | """Find the exact path of a specific build tool in LLVM. Doesn't %-escape the result.""" |
| 388 | tool_path = llvm_path + "\\bin\\" + tool |
| 389 | |
| 390 | if not repository_ctx.path(tool_path).exists: |
| 391 | return None |
| 392 | |
| 393 | return tool_path.replace("\\", "/") |
| 394 | |
| 395 | def _use_clang_cl(repository_ctx): |
| 396 | """Returns True if USE_CLANG_CL is set to 1.""" |
| 397 | return repository_ctx.os.environ.get("USE_CLANG_CL", default = "0") == "1" |
| 398 | |
Yun Peng | 009e6c0 | 2018-12-03 05:31:26 -0800 | [diff] [blame] | 399 | def _get_clang_version(repository_ctx, clang_cl): |
| 400 | result = repository_ctx.execute([clang_cl, "-v"]) |
| 401 | if result.return_code != 0: |
| 402 | auto_configure_fail("Failed to get clang version by running \"%s -v\"" % clang_cl) |
| 403 | |
| 404 | # Stderr should look like "clang version X.X.X ..." |
| 405 | return result.stderr.strip().split(" ")[2] |
| 406 | |
Yun Peng | 65cda4f | 2017-06-22 11:06:11 +0200 | [diff] [blame] | 407 | def configure_windows_toolchain(repository_ctx): |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 408 | """Configure C++ toolchain on Windows.""" |
| 409 | paths = resolve_labels(repository_ctx, [ |
rosica | beaba92 | 2019-05-20 02:36:26 -0700 | [diff] [blame] | 410 | "@bazel_tools//tools/cpp:BUILD.windows.tpl", |
| 411 | "@bazel_tools//tools/cpp:windows_cc_toolchain_config.bzl", |
| 412 | "@bazel_tools//tools/cpp:armeabi_cc_toolchain_config.bzl", |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 413 | "@bazel_tools//tools/cpp:vc_installation_error.bat.tpl", |
Yun Peng | f66086d | 2018-10-24 08:33:09 -0700 | [diff] [blame] | 414 | "@bazel_tools//tools/cpp:msys_gcc_installation_error.bat", |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 415 | ]) |
jmmv | 5b02559 | 2018-05-29 12:03:21 -0700 | [diff] [blame] | 416 | |
rosica | beaba92 | 2019-05-20 02:36:26 -0700 | [diff] [blame] | 417 | repository_ctx.symlink( |
| 418 | paths["@bazel_tools//tools/cpp:windows_cc_toolchain_config.bzl"], |
| 419 | "windows_cc_toolchain_config.bzl", |
| 420 | ) |
| 421 | repository_ctx.symlink( |
| 422 | paths["@bazel_tools//tools/cpp:armeabi_cc_toolchain_config.bzl"], |
| 423 | "armeabi_cc_toolchain_config.bzl", |
| 424 | ) |
Yun Peng | f66086d | 2018-10-24 08:33:09 -0700 | [diff] [blame] | 425 | repository_ctx.symlink( |
| 426 | paths["@bazel_tools//tools/cpp:msys_gcc_installation_error.bat"], |
| 427 | "msys_gcc_installation_error.bat", |
| 428 | ) |
Yun Peng | 65cda4f | 2017-06-22 11:06:11 +0200 | [diff] [blame] | 429 | |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 430 | vc_path = find_vc_path(repository_ctx) |
| 431 | missing_tools = None |
| 432 | if not vc_path: |
| 433 | repository_ctx.template( |
| 434 | "vc_installation_error.bat", |
| 435 | paths["@bazel_tools//tools/cpp:vc_installation_error.bat.tpl"], |
| 436 | {"%{vc_error_message}": ""}, |
| 437 | ) |
| 438 | else: |
| 439 | missing_tools = _find_missing_vc_tools(repository_ctx, vc_path) |
| 440 | if missing_tools: |
| 441 | message = "\r\n".join([ |
| 442 | "echo. 1>&2", |
| 443 | "echo Visual C++ build tools seems to be installed at %s 1>&2" % vc_path, |
| 444 | "echo But Bazel can't find the following tools: 1>&2", |
| 445 | "echo %s 1>&2" % ", ".join(missing_tools), |
| 446 | "echo. 1>&2", |
| 447 | ]) |
| 448 | repository_ctx.template( |
| 449 | "vc_installation_error.bat", |
| 450 | paths["@bazel_tools//tools/cpp:vc_installation_error.bat.tpl"], |
| 451 | {"%{vc_error_message}": message}, |
| 452 | ) |
Yun Peng | 7284d6e | 2018-03-14 04:13:54 -0700 | [diff] [blame] | 453 | |
rosica | beaba92 | 2019-05-20 02:36:26 -0700 | [diff] [blame] | 454 | tool_paths_mingw, tool_bin_path_mingw, inc_dir_mingw = _get_escaped_windows_msys_starlark_content(repository_ctx, use_mingw = True) |
| 455 | tool_paths, tool_bin_path, inc_dir_msys = _get_escaped_windows_msys_starlark_content(repository_ctx) |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 456 | if not vc_path or missing_tools: |
| 457 | repository_ctx.template( |
rosica | beaba92 | 2019-05-20 02:36:26 -0700 | [diff] [blame] | 458 | "BUILD", |
| 459 | paths["@bazel_tools//tools/cpp:BUILD.windows.tpl"], |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 460 | { |
pcloudy | 56366ee | 2019-03-07 07:48:17 -0800 | [diff] [blame] | 461 | "%{msvc_env_tmp}": "msvc_not_found", |
| 462 | "%{msvc_env_path}": "msvc_not_found", |
| 463 | "%{msvc_env_include}": "msvc_not_found", |
| 464 | "%{msvc_env_lib}": "msvc_not_found", |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 465 | "%{msvc_cl_path}": "vc_installation_error.bat", |
| 466 | "%{msvc_ml_path}": "vc_installation_error.bat", |
| 467 | "%{msvc_link_path}": "vc_installation_error.bat", |
| 468 | "%{msvc_lib_path}": "vc_installation_error.bat", |
rosica | beaba92 | 2019-05-20 02:36:26 -0700 | [diff] [blame] | 469 | "%{dbg_mode_debug_flag}": "/DEBUG", |
| 470 | "%{fastbuild_mode_debug_flag}": "/DEBUG", |
pcloudy | b137071 | 2019-04-05 03:05:53 -0700 | [diff] [blame] | 471 | "%{cxx_builtin_include_directories}": inc_dir_msys, |
rosica | 71bc38f | 2019-02-04 02:39:30 -0800 | [diff] [blame] | 472 | "%{mingw_cxx_builtin_include_directories}": inc_dir_mingw, |
rosica | beaba92 | 2019-05-20 02:36:26 -0700 | [diff] [blame] | 473 | "%{msvc_cxx_builtin_include_directories}": "", |
rosica | 71bc38f | 2019-02-04 02:39:30 -0800 | [diff] [blame] | 474 | "%{tool_paths}": tool_paths, |
| 475 | "%{mingw_tool_paths}": tool_paths_mingw, |
rosica | 71bc38f | 2019-02-04 02:39:30 -0800 | [diff] [blame] | 476 | "%{tool_bin_path}": tool_bin_path, |
| 477 | "%{mingw_tool_bin_path}": tool_bin_path_mingw, |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 478 | }, |
| 479 | ) |
| 480 | return |
| 481 | |
| 482 | env = setup_vc_env_vars(repository_ctx, vc_path) |
| 483 | escaped_paths = escape_string(env["PATH"]) |
| 484 | escaped_include_paths = escape_string(env["INCLUDE"]) |
| 485 | escaped_lib_paths = escape_string(env["LIB"]) |
Laszlo Csomor | 63d4f11 | 2019-05-14 06:40:26 -0700 | [diff] [blame] | 486 | escaped_tmp_dir = escape_string(_get_temp_env(repository_ctx).replace("\\", "\\\\")) |
Yun Peng | f445af5 | 2018-11-02 07:55:01 -0700 | [diff] [blame] | 487 | |
| 488 | llvm_path = "" |
| 489 | if _use_clang_cl(repository_ctx): |
| 490 | llvm_path = find_llvm_path(repository_ctx) |
| 491 | if not llvm_path: |
| 492 | auto_configure_fail("\nUSE_CLANG_CL is set to 1, but Bazel cannot find Clang installation on your system.\n" + |
| 493 | "Please install Clang via http://releases.llvm.org/download.html\n") |
| 494 | cl_path = find_llvm_tool(repository_ctx, llvm_path, "clang-cl.exe") |
| 495 | link_path = find_llvm_tool(repository_ctx, llvm_path, "lld-link.exe") |
Yun Peng | 009e6c0 | 2018-12-03 05:31:26 -0800 | [diff] [blame] | 496 | if not link_path: |
| 497 | link_path = find_msvc_tool(repository_ctx, vc_path, "link.exe") |
Yun Peng | f445af5 | 2018-11-02 07:55:01 -0700 | [diff] [blame] | 498 | lib_path = find_llvm_tool(repository_ctx, llvm_path, "llvm-lib.exe") |
Yun Peng | 009e6c0 | 2018-12-03 05:31:26 -0800 | [diff] [blame] | 499 | if not lib_path: |
| 500 | lib_path = find_msvc_tool(repository_ctx, vc_path, "lib.exe") |
Yun Peng | f445af5 | 2018-11-02 07:55:01 -0700 | [diff] [blame] | 501 | else: |
| 502 | cl_path = find_msvc_tool(repository_ctx, vc_path, "cl.exe") |
| 503 | link_path = find_msvc_tool(repository_ctx, vc_path, "link.exe") |
| 504 | lib_path = find_msvc_tool(repository_ctx, vc_path, "lib.exe") |
| 505 | |
| 506 | msvc_ml_path = find_msvc_tool(repository_ctx, vc_path, "ml64.exe") |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 507 | escaped_cxx_include_directories = [] |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 508 | |
| 509 | for path in escaped_include_paths.split(";"): |
| 510 | if path: |
rosica | 71bc38f | 2019-02-04 02:39:30 -0800 | [diff] [blame] | 511 | escaped_cxx_include_directories.append("\"%s\"" % path) |
Yun Peng | f445af5 | 2018-11-02 07:55:01 -0700 | [diff] [blame] | 512 | if llvm_path: |
Yun Peng | 009e6c0 | 2018-12-03 05:31:26 -0800 | [diff] [blame] | 513 | clang_version = _get_clang_version(repository_ctx, cl_path) |
| 514 | clang_dir = llvm_path + "\\lib\\clang\\" + clang_version |
| 515 | clang_include_path = (clang_dir + "\\include").replace("\\", "\\\\") |
rosica | 71bc38f | 2019-02-04 02:39:30 -0800 | [diff] [blame] | 516 | escaped_cxx_include_directories.append("\"%s\"" % clang_include_path) |
Yun Peng | 009e6c0 | 2018-12-03 05:31:26 -0800 | [diff] [blame] | 517 | clang_lib_path = (clang_dir + "\\lib\\windows").replace("\\", "\\\\") |
| 518 | escaped_lib_paths = escaped_lib_paths + ";" + clang_lib_path |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 519 | |
Yun Peng | f445af5 | 2018-11-02 07:55:01 -0700 | [diff] [blame] | 520 | support_debug_fastlink = _is_support_debug_fastlink(repository_ctx, link_path) |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 521 | |
jmmv | 5b02559 | 2018-05-29 12:03:21 -0700 | [diff] [blame] | 522 | repository_ctx.template( |
rosica | beaba92 | 2019-05-20 02:36:26 -0700 | [diff] [blame] | 523 | "BUILD", |
| 524 | paths["@bazel_tools//tools/cpp:BUILD.windows.tpl"], |
jmmv | 5b02559 | 2018-05-29 12:03:21 -0700 | [diff] [blame] | 525 | { |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 526 | "%{msvc_env_tmp}": escaped_tmp_dir, |
| 527 | "%{msvc_env_path}": escaped_paths, |
| 528 | "%{msvc_env_include}": escaped_include_paths, |
| 529 | "%{msvc_env_lib}": escaped_lib_paths, |
Yun Peng | f445af5 | 2018-11-02 07:55:01 -0700 | [diff] [blame] | 530 | "%{msvc_cl_path}": cl_path, |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 531 | "%{msvc_ml_path}": msvc_ml_path, |
Yun Peng | f445af5 | 2018-11-02 07:55:01 -0700 | [diff] [blame] | 532 | "%{msvc_link_path}": link_path, |
| 533 | "%{msvc_lib_path}": lib_path, |
rosica | beaba92 | 2019-05-20 02:36:26 -0700 | [diff] [blame] | 534 | "%{dbg_mode_debug_flag}": "/DEBUG:FULL" if support_debug_fastlink else "/DEBUG", |
| 535 | "%{fastbuild_mode_debug_flag}": "/DEBUG:FASTLINK" if support_debug_fastlink else "/DEBUG", |
pcloudy | b137071 | 2019-04-05 03:05:53 -0700 | [diff] [blame] | 536 | "%{cxx_builtin_include_directories}": inc_dir_msys + ",\n ".join(escaped_cxx_include_directories), |
| 537 | "%{msvc_cxx_builtin_include_directories}": " " + ",\n ".join(escaped_cxx_include_directories), |
rosica | 71bc38f | 2019-02-04 02:39:30 -0800 | [diff] [blame] | 538 | "%{mingw_cxx_builtin_include_directories}": inc_dir_mingw + ",\n ".join(escaped_cxx_include_directories), |
rosica | 71bc38f | 2019-02-04 02:39:30 -0800 | [diff] [blame] | 539 | "%{tool_paths}": tool_paths, |
| 540 | "%{mingw_tool_paths}": tool_paths_mingw, |
rosica | 71bc38f | 2019-02-04 02:39:30 -0800 | [diff] [blame] | 541 | "%{tool_bin_path}": tool_bin_path, |
| 542 | "%{mingw_tool_bin_path}": tool_bin_path_mingw, |
vladmos | 20a042f | 2018-06-01 04:51:21 -0700 | [diff] [blame] | 543 | }, |
| 544 | ) |