Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bazel is not working with visual studio 2019 #8589

Closed
monamimani opened this issue Jun 9, 2019 · 12 comments
Closed

Bazel is not working with visual studio 2019 #8589

monamimani opened this issue Jun 9, 2019 · 12 comments
Labels
area-Windows Windows-specific issues and feature requests P2 We'll consider working on this in future. (Assignee optional) team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website type: bug

Comments

@monamimani
Copy link

Description of the problem / feature request:

I want to compile a simple helloworld project but Bazel fails early he seems to be confused about where to find what he need.

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

execute this commands in powershell
bazel build Project1/HelloWorld --compilation_mode=dbg --verbose_failures -s

What operating system are you running Bazel on?

windows

What's the output of bazel info release?

release 0.26.1

Have you found anything relevant by searching the web?

no, it seems it should work

Any other information, logs, or outputs that you want to share?

here is the console output

PS F:_Dev\Playground\BazelVs> bazel build Project1/HelloWorld --compilation_mode=dbg --verbose_failures -s
Extracting Bazel installation...
Starting local Bazel server and connecting to it...
INFO: Analyzed target //Project1:HelloWorld (10 packages loaded, 76 targets configured).
INFO: Found 1 target...
SUBCOMMAND: # //Project1:HelloWorld [action 'Compiling Project1/main.cpp']
cd C:/users/mani/bazel_mani/iiicvl3t/execroot/main
SET INCLUDE=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\ATLMFC\include;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared;C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\cppwinrt
SET PATH=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\bin\HostX64\x64;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\VC\VCPackages;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\TestWindow;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\bin\Roslyn;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Team Tools\Performance Tools\x64;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Team Tools\Performance Tools;C:\Program Files (x86)\Microsoft Visual Studio\Shared\Common\VSPerfCollectionTools\vs2019\x64;C:\Program Files (x86)\Microsoft Visual Studio\Shared\Common\VSPerfCollectionTools\vs2019;C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\x64;C:\Program Files (x86)\Windows Kits\10\bin\10.0.17763.0\x64;C:\Program Files (x86)\Windows Kits\10\bin\x64;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin;C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools;;C:\WINDOWS\system32;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja
SET PWD=/proc/self/cwd
SET RUNFILES_MANIFEST_ONLY=1
SET TEMP=C:\Users\Mani\AppData\Local\Temp
SET TMP=C:\Users\Mani\AppData\Local\Temp
C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64/cl.exe /nologo /DCOMPILER_MSVC /DNOMINMAX /D_WIN32_WINNT=0x0601 /D_CRT_SECURE_NO_DEPRECATE /D_CRT_SECURE_NO_WARNINGS /bigobj /Zm500 /EHsc /wd4351 /wd4291 /wd4250 /wd4996 /I. /Ibazel-out/x64_windows-dbg/bin /Iexternal/bazel_tools /Ibazel-out/x64_windows-dbg/bin/external/bazel_tools /showIncludes /MDd /Od /Z7 /wd4117 -D__DATE
_="redacted" -D__TIMESTAMP__="redacted" -D__TIME__="redacted" /Fobazel-out/x64_windows-dbg/bin/Project1/objs/HelloWorld/main.obj /c Project1/main.cpp
ERROR: F:/dev/playground/bazelvs/Project1/BUILD:2:1: C++ compilation of rule '//Project1:HelloWorld' failed (Exit 2): cl.exe failed: error executing command
cd C:/users/mani/bazel_mani/iiicvl3t/execroot/main
SET INCLUDE=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\ATLMFC\include;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared;C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\cppwinrt
SET PATH=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\bin\HostX64\x64;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\VC\VCPackages;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\TestWindow;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\bin\Roslyn;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Team Tools\Performance Tools\x64;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Team Tools\Performance Tools;C:\Program Files (x86)\Microsoft Visual Studio\Shared\Common\VSPerfCollectionTools\vs2019\x64;C:\Program Files (x86)\Microsoft Visual Studio\Shared\Common\VSPerfCollectionTools\vs2019;C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\x64;C:\Program Files (x86)\Windows Kits\10\bin\10.0.17763.0\x64;C:\Program Files (x86)\Windows Kits\10\bin\x64;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin;C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools;;C:\WINDOWS\system32;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin;C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja
SET PWD=/proc/self/cwd
SET RUNFILES_MANIFEST_ONLY=1
SET TEMP=C:\Users\Mani\AppData\Local\Temp
SET TMP=C:\Users\Mani\AppData\Local\Temp
C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.16.27023/bin/HostX64/x64/cl.exe /nologo /DCOMPILER_MSVC /DNOMINMAX /D_WIN32_WINNT=0x0601 /D_CRT_SECURE_NO_DEPRECATE /D_CRT_SECURE_NO_WARNINGS /bigobj /Zm500 /EHsc /wd4351 /wd4291 /wd4250 /wd4996 /I. /Ibazel-out/x64_windows-dbg/bin /Iexternal/bazel_tools /Ibazel-out/x64_windows-dbg/bin/external/bazel_tools /showIncludes /MDd /Od /Z7 /wd4117 -D__DATE
="redacted" -D__TIMESTAMP
_="redacted" -D__TIME__="redacted" /Fobazel-out/x64_windows-dbg/bin/Project1/_objs/HelloWorld/main.obj /c Project1/main.cpp
Execution platform: @bazel_tools//platforms:host_platform
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\include\yvals_core.h(352): fatal error C1189: #error: STL1001: Unexpected compiler version, expected MSVC 19.20 or newer.
Target //Project1:HelloWorld failed to build
INFO: Elapsed time: 10.725s, Critical Path: 0.40s
INFO: 0 processes.
FAILED: Build did NOT complete successfully

BAZEL_VC = C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC
BAZEL_VS = C:\Program Files (x86)\Microsoft Visual Studio\2019\Community

@monamimani
Copy link
Author

Reading closely the log output.
It seems the paths are setup for MSVC 14.21 but is calling cl.exe from MSVC 14.16

@monamimani
Copy link
Author

I found a workaround. here https://github.com/bazelbuild/bazel/blob/master/site/docs/windows.md
by using BAZEL_VC_FULL_VERSION and setting it to 14.21.27702 it now compiles.

I had to find this env var in the github, maybe if it is the official solution for this it should be in install-windows troubleshooting of the install-windows page.

I still feel there is a bug here. it should at least by default be consistent. And not taking the includes from
14.21 and the compiler fromt 14.16.

@monamimani
Copy link
Author

Ok I spoke too fast it doesn't fix the issue all the time.
the behavior is actually really random. Sometimes after a clean and killing the server process it might actually compile something but then after if you change the cmd line like remove --verbose_failures --subcommands or even edit code and re compile it will fail.

@monamimani
Copy link
Author

the only thing that works is having only 1 folder under the MSVC folder.

@jin jin added area-Windows Windows-specific issues and feature requests untriaged labels Jun 10, 2019
@laszlocsomor
Copy link
Contributor

Thanks for reporting.

What other versions do you have installed, i.e. what other subdirectories are there under C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC? Do you have any other versions than 2019 Community installed, e.g. 2019\BuildTools or C:\Program Files (x86)\Microsoft Visual Studio\2017?

@monamimani
Copy link
Author

I only have one version of community 2019 but it has 2 versions of the compiler. 14.61 and 14.21.
After all this I instralled the build tools with only the compiler 14.21 and that is what I am using.
I also have insltalled community 2017 with the compiler 14.16. Plus C:\Program Files (x86)\Microsoft Visual Studio 11.0, 12.0 and 14.0

The issue is that the include path is not consistent with the compiler. This include path was set
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.16.27023\include
but used the compiler
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.21.27702\bin\Hostx64\x64
and the build failes because the headers are checking for the compile version.

@laszlocsomor laszlocsomor added P1 I'll work on this now. (Assignee required) type: bug and removed untriaged labels Jun 25, 2019
@laszlocsomor
Copy link
Contributor

Thanks. I couldn't repro this bug yet, but let's assume it's a Bazel bug until proven otherwise.
/cc @meteorcloudy

@laszlocsomor laszlocsomor added P2 We'll consider working on this in future. (Assignee optional) and removed P1 I'll work on this now. (Assignee required) labels Jun 25, 2019
@meteorcloudy
Copy link
Member

Hi @monamimani , I fixed exactly this issue at e5b7bd6, BAZEL_VC_FULL_VERSION is only available since 0.27.0, that's why it didn't work for you.

And with 0.27.0, the include directories should be consistent with the compiler even if you don't specify BAZEL_VC_FULL_VERSION

@monamimani
Copy link
Author

Thanks it is fixed

@roman-kruglov
Copy link

I'm on Bazel 2.0 and it still couldn't pick the right MSVC version. I had both 2017 and 2019 installed. And even removing the older one didn't help. Even after a full reboot it tried to use the deleted version.

In my case specifying the exact directory helped set BAZEL_VC=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC, according to this.

@meteorcloudy
Copy link
Member

@roman-kruglov Is there any stale directories from the deleted version? That could confuse Bazel's MSVC auto configure.
But yes, setting the BAZEL_VC env var is the correct way to tell Bazel which MSVC you want to use.

@roman-kruglov
Copy link

Yep, there was a leftover directory, something like C:\Program Files (x86)\Microsoft Visual Studio\2017 and it was empty. I removed it and tried again with no luck. Maybe MSVC installer left some garbage in the registry or somewhere else. But specifying the env var was the only way I was able to force the single installed newest version to be used.

@philwo philwo added the team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website label Jun 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Windows Windows-specific issues and feature requests P2 We'll consider working on this in future. (Assignee optional) team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website type: bug
Projects
None yet
Development

No branches or pull requests

6 participants