bazelbuild / bazel

a fast, scalable, multi-language and extensible build system
https://bazel.build
Apache License 2.0
23.24k stars 4.08k forks source link

Problem with bazel on windows targeting visual studio 2022 professional #18816

Open fpgauserdude opened 1 year ago

fpgauserdude commented 1 year ago

I am required to use bazel to compile a tool that I need. But I am having problems using VS 2022 professional. Am I doing something wrong here? There appear to be some other similar issues that users have reported, but those issues have been closed. Is it possible to debug this by having bazel report where it is looking for the Visual Studio executables? I imagine what is going wrong is that Microsoft changed the directory structure in version 2022. Do I need to just use VS 2019?

Thanks.

D:\path\verible>echo %BAZEL_VC%
C:\Program Files\Microsoft Visual Studio\2022\Professional\VC

D:\path\verible>echo %BAZEL_VC_FULL_VERSION%
14.36.32532

D:\path\verible>where cl
C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.36.32532\bin\Hostx64\x64\cl.exe

D:\path\verible>where lib
C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.36.32532\bin\Hostx64\x64\lib.exe

D:\path\verible>where link
C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.36.32532\bin\Hostx64\x64\link.exe

D:\path\verible>where ml64
C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.36.32532\bin\Hostx64\x64\ml64.exe

D:\path\verible>bazel build -c opt //...
INFO: Build option --compilation_mode has changed, discarding analysis cache.
INFO: Analyzed 1898 targets (1 packages loaded, 5705 targets configured).
INFO: Found 1898 targets...
ERROR: C:/users/<redacted>/_bazel_<redacted>/gigcqpgm/external/com_google_absl/absl/base/BUILD.bazel:220:11: Compiling absl/base/internal/unscaledcycleclock.cc failed: (Exit 1): vc_installation_error_x64.bat failed: error executing command (from target @com_google_absl//absl/base:base) external\local_config_cc\vc_installation_error_x64.bat /nologo /DCOMPILER_MSVC /DNOMINMAX /D_WIN32_WINNT=0x0601 /D_CRT_SECURE_NO_DEPRECATE /D_CRT_SECURE_NO_WARNINGS /bigobj /Zm500 /EHsc /wd4351 /wd4291 ... (remaining 27 arguments skipped)

The target you are compiling requires Visual C++ build tools.
Bazel couldn't find a valid Visual C++ build tools installation on your machine.

Visual C++ build tools seems to be installed at C:\Program Files\Microsoft Visual Studio\2022\Professional\VC
But Bazel can't find the following tools:
    VCVARSALL.BAT, cl.exe, link.exe, lib.exe, ml64.exe
for x64 target architecture

Please check your installation following https://bazel.build/docs/windows#using

ERROR: D:/work/sandbox/verible/common/util/BUILD:212:11: Compiling common/util/spacer.cc failed: (Exit 1): vc_installation_error_x64.bat failed: error executing command (from target //common/util:spacer) external\local_config_cc\vc_installation_error_x64.bat /nologo /DCOMPILER_MSVC /DNOMINMAX /D_WIN32_WINNT=0x0601 /D_CRT_SECURE_NO_DEPRECATE /D_CRT_SECURE_NO_WARNINGS /bigobj /Zm500 /EHsc /wd4351 /wd4291 ... (remaining 21 arguments skipped)

The target you are compiling requires Visual C++ build tools.
Bazel couldn't find a valid Visual C++ build tools installation on your machine.
Pavank1992 commented 1 year ago

Hi @fpgauserdude, Seems you issue is related to https://github.com/bazelbuild/bazel/issues/18592, if yes, please follow the respective issue for further details.

If no, Could you please help us with details issue and minimal steps to reproduce the issue? Also, please specify which bazel, VS and OS version you are using?

cctv130 commented 1 year ago

@Pavank1992 @fpgauserdude I think you should be using windows powershell

Setting temporary variables in the cmd terminal and in powershell is different In the cmd terminal set BAZEL_VC="C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC" In the windows powershell $env:BAZEL_VC="C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC"

After that, you'll see a success message,in cpp-tutorial\stage1.

PS D:\code\test\demo01\examples\cpp-tutorial\stage1> bazel build ... INFO: Analyzed target //main:hello-world (1 packages loaded, 31 targets configured). INFO: Found 1 target... Target //main:hello-world up-to-date: bazel-bin/main/hello-world.exe INFO: Elapsed time: 2.412s, Critical Path: 0.89s INFO: 4 processes: 2 internal, 2 local. INFO: Build completed successfully, 4 total actions

Now you can close your issue.

fpgauserdude commented 1 year ago

Thanks for the responses. @Pavank1992, yes, I think that is my issue. @cctv130, running in PowerShell resulted in the same problem.

PS D:\path\verible> echo $env:BAZEL_VC C:\Program Files\Microsoft Visual Studio\2022\Professional\VC PS D:\path\verible> echo $env:BAZEL_VC_FULL_VERSION 14.36.32532 PS D:\path\verible> bazel build -c opt //... INFO: Analyzed 1898 targets (0 packages loaded, 0 targets configured). INFO: Found 1898 targets... ERROR: C:/users/path/gigcqpgm/external/com_google_googletest/BUILD.bazel:80:11: Compiling googlemock/src/gmock.cc failed: (Exit 1): vc_installation_error_x64.bat failed: error executing command (from target @com_google_googletest//:gtest) external\local_config_cc\vc_installation_error_x64.bat /nologo /DCOMPILER_MSVC /DNOMINMAX /D_WIN32_WINNT=0x0601 /D_CRT_SECURE_NO_DEPRECATE /D_CRT_SECURE_NO_WARNINGS /bigobj /Zm500 /EHsc /wd4351 /wd4291 ... (remaining 34 arguments skipped)

The target you are compiling requires Visual C++ build tools. Bazel couldn't find a valid Visual C++ build tools installation on your machine.

Visual C++ build tools seems to be installed at C:\Program Files\Microsoft Visual Studio\2022\Professional\VC But Bazel can't find the following tools: VCVARSALL.BAT, cl.exe, link.exe, lib.exe, ml64.exe for x64 target architecture

Please check your installation following https://bazel.build/docs/windows#using

INFO: Elapsed time: 0.450s, Critical Path: 0.16s INFO: 16 processes: 16 internal. FAILED: Build did NOT complete successfully

cctv130 commented 1 year ago

Thanks for the responses. @Pavank1992, yes, I think that is my issue. @cctv130, running in PowerShell resulted in the same problem.

PS D:\path\verible> echo $env:BAZEL_VC C:\Program Files\Microsoft Visual Studio\2022\Professional\VC PS D:\path\verible> echo $env:BAZEL_VC_FULL_VERSION 14.36.32532 PS D:\path\verible> bazel build -c opt //... INFO: Analyzed 1898 targets (0 packages loaded, 0 targets configured). INFO: Found 1898 targets... ERROR: C:/users/path/gigcqpgm/external/com_google_googletest/BUILD.bazel:80:11: Compiling googlemock/src/gmock.cc failed: (Exit 1): vc_installation_error_x64.bat failed: error executing command (from target @com_google_googletest//:gtest) external\local_config_cc\vc_installation_error_x64.bat /nologo /DCOMPILER_MSVC /DNOMINMAX /D_WIN32_WINNT=0x0601 /D_CRT_SECURE_NO_DEPRECATE /D_CRT_SECURE_NO_WARNINGS /bigobj /Zm500 /EHsc /wd4351 /wd4291 ... (remaining 34 arguments skipped)

The target you are compiling requires Visual C++ build tools. Bazel couldn't find a valid Visual C++ build tools installation on your machine.

Visual C++ build tools seems to be installed at C:\Program Files\Microsoft Visual Studio\2022\Professional\VC But Bazel can't find the following tools: VCVARSALL.BAT, cl.exe, link.exe, lib.exe, ml64.exe for x64 target architecture

Please check your installation following https://bazel.build/docs/windows#using

INFO: Elapsed time: 0.450s, Critical Path: 0.16s INFO: 16 processes: 16 internal. FAILED: Build did NOT complete successfully

Sorry, I don't know you are the Professional version, if your cl.exe, link.exe, lib.exe, ml64.exe can not be found, you can use the simplest method, start menu search Developer PowerShell for VS 2022, Then cd to the project directory and add environment variables, build your project, these are small problems, usually with serious thought can solve the problem. Simple. [make great efforts]

fpgauserdude commented 1 year ago

@cctv130 Sorry, but despite every "great effort", this astoundingly stupid tool still cannot find my installed visual studio. And the debug information provided is utterly worthless. I had considered adopting bazel for some other kinds of builds, but that ship has definitely sailed. I suspect this would work on linux, but lots of things work on linux. What I need is something that works on windows too. With VS 2022 Professional.

PS D:\path\verible> get-command cl

CommandType Name Version Source


Application cl.exe 14.36.3... C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.3...

PS D:\path\verible> get-command link

CommandType Name Version Source


Application link.exe 14.36.3... C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.3...

PS D:\work\sandbox\verible> get-command lib

CommandType Name Version Source


Application lib.exe 14.36.3... C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.3...

PS D:\path\verible> get-command ml64

CommandType Name Version Source


Application ml64.exe 14.36.3... C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.3...

PS D:\path\verible> $env:BAZEL_VC="C:\Program Files\Microsoft Visual Studio\2022\Professional\VC" PS D:\path\verible> bazel build -c opt //... INFO: Analyzed 1898 targets (1 packages loaded, 2596 targets configured). INFO: Found 1898 targets... ERROR: C:/users//bazel/gigcqpgm/external/com_google_absl/absl/flags/BUILD.bazel:44:11: Compiling absl/flags/internal/program_name.cc failed: (Exit 1): vc_installation_error_x64.bat failed: error executing command (from target @com_google_absl//absl/flags:program_name) external\local_config_cc\vc_installation_error_x64.bat /nologo /DCOMPILER_MSVC /DNOMINMAX /D_WIN32_WINNT=0x0601 /D_CRT_SECURE_NO_DEPRECATE /D_CRT_SECURE_NO_WARNINGS /bigobj /Zm500 /EHsc /wd4351 /wd4291 ... (remaining 27 arguments skipped)

The target you are compiling requires Visual C++ build tools. Bazel couldn't find a valid Visual C++ build tools installation on your machine.

Visual C++ build tools seems to be installed at C:\Program Files\Microsoft Visual Studio\2022\Professional\VC But Bazel can't find the following tools: VCVARSALL.BAT, cl.exe, link.exe, lib.exe, ml64.exe for x64 target architecture

Please check your installation following https://bazel.build/docs/windows#using

INFO: Elapsed time: 1.088s, Critical Path: 0.15s INFO: 16 processes: 16 internal. FAILED: Build did NOT complete successfully

cctv130 commented 1 year ago

请参考我的路径,这个下边有你想要的cl,link,lib C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.36.32532\bin\Hostx64\x64

Developer PowerShell for VS 2022 1691480673420 Developer PowerShell for VS 2022 This tool automatically searches for cl, link, lib, etc. If not found the Developer PowerShell for VS 2022, uninstall Community edition and install vs2022 Enterprise Edition

ValYouW commented 9 months ago

Looks like this issue is solved in Bazel 6.3.0