Skip to content

Commit

Permalink
Windows: genenrate a fake CROSSTOOL when VC not found
Browse files Browse the repository at this point in the history
When Visual C++ build tools are not found on Windows, we generating a
fake CROSSTOOL so that users can still build for other languages.
In the fake CROSSTOOL, we point all tools to a batch script which prints
error messages to notify users when they try to build any cc targets.

Also, added an extra default_toolchain specification for x64_windows cpu
value, so that users can use this cpu in select on non-Windows
platforms.

Fixed bazelbuild#3853

Change-Id: Ib4d7a38fd4d98075f6b73ce310c28822e58af4e2
PiperOrigin-RevId: 172341985
  • Loading branch information
meteorcloudy authored and buchgr committed Oct 18, 2017
1 parent 93c080a commit 1f61472
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
5 changes: 5 additions & 0 deletions tools/cpp/CROSSTOOL.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ default_toolchain {
toolchain_identifier: "stub_armeabi-v7a"
}

default_toolchain {
cpu: "x64_windows"
toolchain_identifier: "msvc_x64"
}

default_toolchain {
cpu: "x64_windows_msvc"
toolchain_identifier: "msvc_x64"
Expand Down
24 changes: 24 additions & 0 deletions tools/cpp/vc_path_not_found.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
:: 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.

:: Invoke the python script under pydir with the same basename
@echo OFF

echo. 1>&2
echo The target you are compiling requires Visual C++ build tools. 1>&2
echo Bazel couldn't find Visual C++ build tools on your machine. 1>&2
echo Please check your installation following https://docs.bazel.build/versions/master/windows.html#using 1>&2
echo. 1>&2

exit -1
25 changes: 24 additions & 1 deletion tools/cpp/windows_cc_configure.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def _find_vc_path(repository_ctx):
vc_dir = line[line.find("REG_SZ") + len("REG_SZ"):].strip() + suffix

if not vc_dir:
auto_configure_fail("Visual C++ build tools not found on your machine.")
return "visual-studio-not-found"
auto_configure_warning("Visual C++ build tools found at %s" % vc_dir)
return vc_dir

Expand Down Expand Up @@ -288,6 +288,29 @@ def configure_windows_toolchain(repository_ctx):
repository_ctx.symlink(Label("@bazel_tools//tools/cpp:BUILD.static"), "BUILD")

vc_path = _find_vc_path(repository_ctx)
if vc_path == "visual-studio-not-found":
vc_path_error_script = "vc_path_not_found.bat"
repository_ctx.symlink(Label("@bazel_tools//tools/cpp:vc_path_not_found.bat"), vc_path_error_script)
tpl(repository_ctx, "CROSSTOOL", {
"%{cpu}": "x64_windows",
"%{default_toolchain_name}": "msvc_x64",
"%{toolchain_name}": "msys_x64",
"%{msvc_env_tmp}": "",
"%{msvc_env_path}": "",
"%{msvc_env_include}": "",
"%{msvc_env_lib}": "",
"%{msvc_cl_path}": vc_path_error_script,
"%{msvc_link_path}": vc_path_error_script,
"%{msvc_lib_path}": vc_path_error_script,
"%{compilation_mode_content}": "",
"%{content}": _get_escaped_windows_msys_crosstool_content(repository_ctx),
"%{opt_content}": "",
"%{dbg_content}": "",
"%{cxx_builtin_include_directory}": "",
"%{coverage}": "",
})
return

env = _find_env_vars(repository_ctx, vc_path)
escaped_paths = escape_string(env["PATH"])
escaped_include_paths = escape_string(env["INCLUDE"])
Expand Down

0 comments on commit 1f61472

Please sign in to comment.