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

error fetching local_config_cc on version 0.28 on Windows #8943

Closed
weggert2 opened this issue Jul 22, 2019 · 20 comments
Closed

error fetching local_config_cc on version 0.28 on Windows #8943

weggert2 opened this issue Jul 22, 2019 · 20 comments
Assignees
Labels
area-Windows Windows-specific issues and feature requests P1 I'll work on this now. (Assignee required) team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website

Comments

@weggert2
Copy link

weggert2 commented Jul 22, 2019

ATTENTION! Please read and follow:

When upgrading from Version 0.27.2 to 0.28 on Windows, and trying to build a previously-successfully-built C++ project, I get a new error:

λ bazel build //...
INFO: Call stack for the definition of repository 'local_config_cc' which is a cc_autoconf (rule definition at C:/users/cperatrovich/_bazel_cperatrovich/udrnertk/external/bazel_tools/tools/cpp/cc_configure.bzl:121:15):
 - C:/users/cperatrovich/_bazel_cperatrovich/udrnertk/external/bazel_tools/tools/cpp/cc_configure.bzl:164:5
 - /DEFAULT.WORKSPACE.SUFFIX:315:1
ERROR: An error occurred during the fetch of repository 'local_config_cc':
   Traceback (most recent call last):
        File "C:/users/cperatrovich/_bazel_cperatrovich/udrnertk/external/bazel_tools/tools/cpp/cc_configure.bzl", line 114
                configure_windows_toolchain(repository_ctx)
        File "C:/users/cperatrovich/_bazel_cperatrovich/udrnertk/external/bazel_tools/tools/cpp/windows_cc_configure.bzl", line 521, in configure_windows_toolchain
                setup_vc_env_vars(repository_ctx, vc_path)
        File "C:/users/cperatrovich/_bazel_cperatrovich/udrnertk/external/bazel_tools/tools/cpp/windows_cc_configure.bzl", line 296, in setup_vc_env_vars
                _check_env_vars(env_map, cmd)
        File "C:/users/cperatrovich/_bazel_cperatrovich/udrnertk/external/bazel_tools/tools/cpp/windows_cc_configure.bzl", line 303, in _check_env_vars
                auto_configure_fail(("Setting up VC environment vari...)))
        File "C:/users/cperatrovich/_bazel_cperatrovich/udrnertk/external/bazel_tools/tools/cpp/lib_cc_configure.bzl", line 112, in auto_configure_fail
                fail(("\n%sAuto-Configuration Error:%...)))

Auto-Configuration Error: Setting up VC environment variables failed, WINDOWSSDKDIR is not set by the following command:
    "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\VCVARSALL.BAT" amd64  -vcvars_ver=14.21.27702
Internal error thrown during build. Printing stack trace: java.util.UnknownFormatConversionException: Conversion = '.'
        at java.base/java.util.Formatter.checkText(Unknown Source)
        at java.base/java.util.Formatter.parse(Unknown Source)

Uninstalling 0.28 and re-installing 0.27.2 fixed allowed a successful build so I'm not blocked, but it would be great to have a working build with 0.28

What operating system are you running Bazel on?

Windows

What's the output of bazel info release?

0.28

Have you found anything relevant by searching the web?

#8781 seemed relevant, but we do not use any external git repos, so it was not the same issue.

@weggert2 weggert2 changed the title local_config_cc on version 0.28 on Windows error fetchin local_config_cc on version 0.28 on Windows prevents building Jul 22, 2019
@weggert2 weggert2 changed the title error fetchin local_config_cc on version 0.28 on Windows prevents building error fetching local_config_cc on version 0.28 on Windows Jul 22, 2019
@dslomov dslomov added the area-Windows Windows-specific issues and feature requests label Jul 22, 2019
@dslomov dslomov added release blocker P0 This is an emergency and more important than other current work. (Assignee required) labels Jul 22, 2019
@dslomov
Copy link
Contributor

dslomov commented Jul 22, 2019

@meteorcloudy this looks bad - could you take a look and asses?

@meteorcloudy
Copy link
Member

meteorcloudy commented Jul 22, 2019

@weggert2 Can you try to run the following command from cmd.exe?

"C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\VCVARSALL.BAT" amd64  -vcvars_ver=14.21.27702

If your VC installation is correct, the value of "PATH", "INCLUDE", "LIB", "WINDOWSSDKDIR" environment variables should be set.

@meteorcloudy meteorcloudy added P1 I'll work on this now. (Assignee required) and removed P0 This is an emergency and more important than other current work. (Assignee required) labels Jul 22, 2019
@meteorcloudy
Copy link
Member

Need more information from user. Probably due to a problem in user's VS installation, so downgrade to P1.

@dslomov
Copy link
Contributor

dslomov commented Jul 22, 2019

Apparently it does work with 0.27.2 though... Do you know what have changed?

@meteorcloudy
Copy link
Member

meteorcloudy commented Jul 22, 2019

Yes, In 0.28.0 we explicitly check if all required environment variables are set by VCVARSALL.BAT script.
If not, we report an error.
8167f46#diff-457360df3a98d4f91f49ccc5c8f3b35aR299

Normally, WINDOWSSDKDIR should also be set, but we can remove the check for WINDOWSSDKDIR because it's actually not used in toolchain configuration.

@dslomov
Copy link
Contributor

dslomov commented Jul 22, 2019

Looks like VS2019 does not set WINDOWSSDKDIR? If that's the case (and it is not an indication of a broken VS2019 installation) I think we should remove the check for WINDOWSSDKDIR and issue a patch release.

@weggert2
Copy link
Author

weggert2 commented Jul 22, 2019

@weggert2 Can you try to run the following command from cmd.exe?

"C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\VCVARSALL.BAT" amd64  -vcvars_ver=14.21.27702

If your VC installation is correct, the value of "PATH", "INCLUDE", "LIB", "WINDOWSSDKDIR" environment variables should be set.

Running the suggested command produces:

C:\code\test_project>"C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\VCVARSALL.BAT" amd64  -vcvars_ver=14.21.27702
**********************************************************************
** Visual Studio 2019 Developer Command Prompt v16.0
** Copyright (c) 2019 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'

The Bazel error remains the same. Here's the full error it prints:

C:\code\test_project>bazel build //...
Starting local Bazel server and connecting to it...
INFO: Call stack for the definition of repository 'local_config_cc' which is a cc_autoconf (rule definition at C:/users/bill/_bazel_bill/xhcx54wq/external/bazel_tools/tools/cpp/cc_configure.bzl:121:15):
 - C:/users/bill/_bazel_bill/xhcx54wq/external/bazel_tools/tools/cpp/cc_configure.bzl:164:5
 - /DEFAULT.WORKSPACE.SUFFIX:315:1
ERROR: An error occurred during the fetch of repository 'local_config_cc':
   Traceback (most recent call last):
        File "C:/users/bill/_bazel_bill/xhcx54wq/external/bazel_tools/tools/cpp/cc_configure.bzl", line 114
                configure_windows_toolchain(repository_ctx)
        File "C:/users/bill/_bazel_bill/xhcx54wq/external/bazel_tools/tools/cpp/windows_cc_configure.bzl", line 521, in configure_windows_toolchain
                setup_vc_env_vars(repository_ctx, vc_path)
        File "C:/users/bill/_bazel_bill/xhcx54wq/external/bazel_tools/tools/cpp/windows_cc_configure.bzl", line 296, in setup_vc_env_vars
                _check_env_vars(env_map, cmd)
        File "C:/users/bill/_bazel_bill/xhcx54wq/external/bazel_tools/tools/cpp/windows_cc_configure.bzl", line 303, in _check_env_vars
                auto_configure_fail(("Setting up VC environment vari...)))
        File "C:/users/bill/_bazel_bill/xhcx54wq/external/bazel_tools/tools/cpp/lib_cc_configure.bzl", line 112, in auto_configure_fail
                fail(("\n%sAuto-Configuration Error:%...)))

Auto-Configuration Error: Setting up VC environment variables failed, WINDOWSSDKDIR is not set by the following command:
    "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\VCVARSALL.BAT" amd64  -vcvars_ver=14.21.27702
Internal error thrown during build. Printing stack trace: java.util.UnknownFormatConversionException: Conversion = '.'
        at java.base/java.util.Formatter.checkText(Unknown Source)
        at java.base/java.util.Formatter.parse(Unknown Source)
        at java.base/java.util.Formatter.format(Unknown Source)
        at java.base/java.util.Formatter.format(Unknown Source)
        at java.base/java.lang.String.format(Unknown Source)
        at com.google.devtools.build.lib.skyframe.SkyframeDependencyResolver.getTargets(SkyframeDependencyResolver.java:145)
        at com.google.devtools.build.lib.analysis.DependencyResolver.dependentNodeMap(DependencyResolver.java:274)
        at com.google.devtools.build.lib.skyframe.ConfiguredTargetFunction.computeDependencies(ConfiguredTargetFunction.java:562)
        at com.google.devtools.build.lib.skyframe.ConfiguredTargetFunction.compute(ConfiguredTargetFunction.java:317)
        at com.google.devtools.build.skyframe.AbstractExceptionalParallelEvaluator.bubbleErrorUp(AbstractExceptionalParallelEvaluator.java:495)
        at com.google.devtools.build.skyframe.ParallelEvaluator.bubbleErrorUpExceptionally(ParallelEvaluator.java:77)
        at com.google.devtools.build.skyframe.AbstractExceptionalParallelEvaluator.waitForCompletionAndConstructResult(AbstractExceptionalParallelEvaluator.java:282)
        at com.google.devtools.build.skyframe.AbstractExceptionalParallelEvaluator.doMutatingEvaluation(AbstractExceptionalParallelEvaluator.java:265)
        at com.google.devtools.build.skyframe.AbstractExceptionalParallelEvaluator.evalExceptionally(AbstractExceptionalParallelEvaluator.java:201)
        at com.google.devtools.build.skyframe.ParallelEvaluator.eval(ParallelEvaluator.java:70)
        at com.google.devtools.build.skyframe.InMemoryMemoizingEvaluator.evaluate(InMemoryMemoizingEvaluator.java:205)
        at com.google.devtools.build.skyframe.SequentialBuildDriver.evaluate(SequentialBuildDriver.java:38)
        at com.google.devtools.build.lib.skyframe.SkyframeExecutor.configureTargets(SkyframeExecutor.java:2381)
        at com.google.devtools.build.lib.skyframe.SkyframeBuildView.configureTargets(SkyframeBuildView.java:373)
        at com.google.devtools.build.lib.analysis.BuildView.update(BuildView.java:399)
        at com.google.devtools.build.lib.buildtool.AnalysisPhaseRunner.runAnalysisPhase(AnalysisPhaseRunner.java:198)
        at com.google.devtools.build.lib.buildtool.AnalysisPhaseRunner.execute(AnalysisPhaseRunner.java:110)
        at com.google.devtools.build.lib.buildtool.BuildTool.buildTargets(BuildTool.java:141)
        at com.google.devtools.build.lib.buildtool.BuildTool.processRequest(BuildTool.java:268)
        at com.google.devtools.build.lib.runtime.commands.BuildCommand.exec(BuildCommand.java:98)
        at com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.execExclusively(BlazeCommandDispatcher.java:524)
        at com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.exec(BlazeCommandDispatcher.java:192)
        at com.google.devtools.build.lib.server.GrpcServerImpl.executeCommand(GrpcServerImpl.java:573)
        at com.google.devtools.build.lib.server.GrpcServerImpl.lambda$run$2(GrpcServerImpl.java:624)
        at java.base/java.lang.Thread.run(Unknown Source)

INFO: Elapsed time: 7.486s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (14 packages loaded, 29 targets configured)
Internal error thrown during build. Printing stack trace: java.util.UnknownFormatConversionException: Conversion = '.'
        at java.base/java.util.Formatter.checkText(Unknown Source)
        at java.base/java.util.Formatter.parse(Unknown Source)
        at java.base/java.util.Formatter.format(Unknown Source)
        at java.base/java.util.Formatter.format(Unknown Source)
        at java.base/java.lang.String.format(Unknown Source)
        at com.google.devtools.build.lib.skyframe.SkyframeDependencyResolver.getTargets(SkyframeDependencyResolver.java:145)
        at com.google.devtools.build.lib.analysis.DependencyResolver.dependentNodeMap(DependencyResolver.java:274)
        at com.google.devtools.build.lib.skyframe.ConfiguredTargetFunction.computeDependencies(ConfiguredTargetFunction.java:562)
        at com.google.devtools.build.lib.skyframe.ConfiguredTargetFunction.compute(ConfiguredTargetFunction.java:317)
        at com.google.devtools.build.skyframe.AbstractExceptionalParallelEvaluator.bubbleErrorUp(AbstractExceptionalParallelEvaluator.java:495)
        at com.google.devtools.build.skyframe.ParallelEvaluator.bubbleErrorUpExceptionally(ParallelEvaluator.java:77)
        at com.google.devtools.build.skyframe.AbstractExceptionalParallelEvaluator.waitForCompletionAndConstructResult(AbstractExceptionalParallelEvaluator.java:282)
        at com.google.devtools.build.skyframe.AbstractExceptionalParallelEvaluator.doMutatingEvaluation(AbstractExceptionalParallelEvaluator.java:265)
        at com.google.devtools.build.skyframe.AbstractExceptionalParallelEvaluator.evalExceptionally(AbstractExceptionalParallelEvaluator.java:201)
        at com.google.devtools.build.skyframe.ParallelEvaluator.eval(ParallelEvaluator.java:70)
        at com.google.devtools.build.skyframe.InMemoryMemoizingEvaluator.evaluate(InMemoryMemoizingEvaluator.java:205)
        at com.google.devtools.build.skyframe.SequentialBuildDriver.evaluate(SequentialBuildDriver.java:38)
        at com.google.devtools.build.lib.skyframe.SkyframeExecutor.configureTargets(SkyframeExecutor.java:2381)
        at com.google.devtools.build.lib.skyframe.SkyframeBuildView.configureTargets(SkyframeBuildView.java:373)
        at com.google.devtools.build.lib.analysis.BuildView.update(BuildView.java:399)
        at com.google.devtools.build.lib.buildtool.AnalysisPhaseRunner.runAnalysisPhase(AnalysisPhaseRunner.java:198)
        at com.google.devtools.build.lib.buildtool.AnalysisPhaseRunner.execute(AnalysisPhaseRunner.java:110)
        at com.google.devtools.build.lib.buildtool.BuildTool.buildTargets(BuildTool.java:141)
        at com.google.devtools.build.lib.buildtool.BuildTool.processRequest(BuildTool.java:268)
        at com.google.devtools.build.lib.runtime.commands.BuildCommand.exec(BuildCommand.java:98)
        at com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.execExclusively(BlazeCommandDispatcher.java:524)
        at com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.exec(BlazeCommandDispatcher.java:192)
        at com.google.devtools.build.lib.server.GrpcServerImpl.executeCommand(GrpcServerImpl.java:573)
        at com.google.devtools.build.lib.server.GrpcServerImpl.lambda$run$2(GrpcServerImpl.java:624)
        at java.base/java.lang.Thread.run(Unknown Source)
java.util.UnknownFormatConversionException: Conversion = '.'
        at java.base/java.util.Formatter.checkText(Unknown Source)
        at java.base/java.util.Formatter.parse(Unknown Source)
        at java.base/java.util.Formatter.format(Unknown Source)
        at java.base/java.util.Formatter.format(Unknown Source)
        at java.base/java.lang.String.format(Unknown Source)
        at com.google.devtools.build.lib.skyframe.SkyframeDependencyResolver.getTargets(SkyframeDependencyResolver.java:145)
        at com.google.devtools.build.lib.analysis.DependencyResolver.dependentNodeMap(DependencyResolver.java:274)
        at com.google.devtools.build.lib.skyframe.ConfiguredTargetFunction.computeDependencies(ConfiguredTargetFunction.java:562)
        at com.google.devtools.build.lib.skyframe.ConfiguredTargetFunction.compute(ConfiguredTargetFunction.java:317)
        at com.google.devtools.build.skyframe.AbstractExceptionalParallelEvaluator.bubbleErrorUp(AbstractExceptionalParallelEvaluator.java:495)
        at com.google.devtools.build.skyframe.ParallelEvaluator.bubbleErrorUpExceptionally(ParallelEvaluator.java:77)
        at com.google.devtools.build.skyframe.AbstractExceptionalParallelEvaluator.waitForCompletionAndConstructResult(AbstractExceptionalParallelEvaluator.java:282)
        at com.google.devtools.build.skyframe.AbstractExceptionalParallelEvaluator.doMutatingEvaluation(AbstractExceptionalParallelEvaluator.java:265)
        at com.google.devtools.build.skyframe.AbstractExceptionalParallelEvaluator.evalExceptionally(AbstractExceptionalParallelEvaluator.java:201)
        at com.google.devtools.build.skyframe.ParallelEvaluator.eval(ParallelEvaluator.java:70)
        at com.google.devtools.build.skyframe.InMemoryMemoizingEvaluator.evaluate(InMemoryMemoizingEvaluator.java:205)
        at com.google.devtools.build.skyframe.SequentialBuildDriver.evaluate(SequentialBuildDriver.java:38)
        at com.google.devtools.build.lib.skyframe.SkyframeExecutor.configureTargets(SkyframeExecutor.java:2381)
        at com.google.devtools.build.lib.skyframe.SkyframeBuildView.configureTargets(SkyframeBuildView.java:373)
        at com.google.devtools.build.lib.analysis.BuildView.update(BuildView.java:399)
        at com.google.devtools.build.lib.buildtool.AnalysisPhaseRunner.runAnalysisPhase(AnalysisPhaseRunner.java:198)
        at com.google.devtools.build.lib.buildtool.AnalysisPhaseRunner.execute(AnalysisPhaseRunner.java:110)
        at com.google.devtools.build.lib.buildtool.BuildTool.buildTargets(BuildTool.java:141)
        at com.google.devtools.build.lib.buildtool.BuildTool.processRequest(BuildTool.java:268)
        at com.google.devtools.build.lib.runtime.commands.BuildCommand.exec(BuildCommand.java:98)
        at com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.execExclusively(BlazeCommandDispatcher.java:524)
        at com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.exec(BlazeCommandDispatcher.java:192)
        at com.google.devtools.build.lib.server.GrpcServerImpl.executeCommand(GrpcServerImpl.java:573)
        at com.google.devtools.build.lib.server.GrpcServerImpl.lambda$run$2(GrpcServerImpl.java:624)
FAILED: Build did NOT complete successfully (14 packages loaded, 29 targets configured)
WARNING: Waiting for server process to terminate (waited 5 seconds, waiting at most 60)

I've got to run to work now, but when I get there I'll see if I can put together a minimal example.

@weggert2
Copy link
Author

Looks like VS2019 does not set WINDOWSSDKDIR? If that's the case (and it is not an indication of a broken VS2019 installation) I think we should remove the check for WINDOWSSDKDIR and issue a patch release.

I think you might be on to something. This is how I've been installing Bazel for my users:

@echo off

:: Install Chocolatey package manager
@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

:: Install Bazel and Clang
choco install bazel llvm -y

:: Install Visual Studio Build Tools
choco install visualstudio2019buildtools --package-parameters "--add Microsoft.VisualStudio.Workload.VCTools --includeRecommended --passive" -y

:: Set environment variables
setx -m BAZEL_SH "c:\tools\msys64\usr\bin\bash.exe"
setx -m BAZEL_VC "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC"
setx -m BAZEL_LLVM "C:\Program Files\LLVM"
setx -m USE_CLANG_CL "1"

echo Success! You may close the window.
PAUSE

@meteorcloudy
Copy link
Member

meteorcloudy commented Jul 22, 2019

@weggert2 Thanks for the information! Do you also have windows sdk installed?
You can do that by choco install windows-sdk-10

And after that, can you retry

echo %WINDOWSSDKDIR%
"C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\VCVARSALL.BAT" amd64  -vcvars_ver=14.21.27702
echo %WINDOWSSDKDIR%

@meteorcloudy
Copy link
Member

@dslomov VS 2019 does set WINDOWSSDKDIR on my local machine, but I guess there are indeed some situation it will skip this, probably due to Windows SDK not installed?

So I agree, we should skip the check for WINDOWSSDKDIR to allow Bazel work in such situations.

@meteorcloudy
Copy link
Member

meteorcloudy commented Jul 22, 2019

So I agree, we should skip the check for WINDOWSSDKDIR to allow Bazel work in such situations.

But I do want to confirm the reason why WINDOWSSDKDIR is not set first.

@meteorcloudy
Copy link
Member

meteorcloudy commented Jul 22, 2019

I tried to reproduce issue on a completely clean Windows VM.
I installed VS 2019 via

choco install visualstudio2019buildtools --package-parameters "--add Microsoft.VisualStudio.Workload.VCTools --includeRecommended --passive" -y

It did installed Windows 10 SDK for me. And I'm able to build a cc_binary with Bazel 0.28.1 without doing anything else.

@weggert2 Can you check your VS 2019 installation, could it be corrupted for some reason?

@weggert2
Copy link
Author

weggert2 commented Jul 22, 2019

@weggert2 Thanks for the information! Do you also have windows sdk installed?
You can do that by choco install windows-sdk-10

And after that, can you retry

echo %WINDOWSSDKDIR%
"C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\VCVARSALL.BAT" amd64  -vcvars_ver=14.21.27702
echo %WINDOWSSDKDIR%

From the Microsoft documentation, the Windows SDK is a required component of the build tools, so it should be installed: https://docs.microsoft.com/en-us/visualstudio/install/workload-component-id-vs-build-tools?view=vs-2019

I'm at work now, so I can dig a little deeper. I spun up a fresh VM, fresh bazel 0.28 install using my original build script, and made a trivial hello-world project. It built successfully. Without changing the Bazel configuration, our actual codebase throws the same error as above. I'll spend a few minutes trying to isolate what's making it complain

@meteorcloudy
Copy link
Member

@weggert2 Thanks!

@weggert2
Copy link
Author

weggert2 commented Jul 22, 2019

Sorry for the slow reply, I got pulled off to other things. I didn't spend too much time looking, but I didn't manage to find what the difference between our codebase and a trivial "hello world" project that caused the fetch error. For now, I'll downgrade to 0.27.2. Visual Studio has been a bit of a thorn, so I've been hunting for a way to exorcise it from the requirements altogether (I'd also like to enable usage of tools like gdb and valgrind, so we want to get away from the MSVC compiler). For others who come upon this thread, this is undocumented, but you can set up Bazel to work with MinGW only:

@echo off

:: Install Chocolatey package manager
@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

:: Install Bazel
choco install bazel -y

:: Install VC++ runtime 2015
choco install vcredist2015

:: Update MSYS2.  The --ask=20 removes a msys catgets issue: https://github.com/msys2/MSYS2-packages/issues/1147
C:\tools\msys64\usr\bin\bash.exe -c -l "pacman -Syu --ask=20"

:: Install MinGW, not visual studio!
C:\tools\msys64\usr\bin\bash.exe -c -l "pacman -Sy --noconfirm mingw-w64-x86_64-gcc"

:: Set environment variables
setx -m BAZEL_SH "c:\tools\msys64\usr\bin\bash.exe"

echo Success! You may close the window.
PAUSE

Targets can now be built with bazel build //... --compiler=mingw-gcc (Make sure to add linkopts = ["-static"] to your binary targets).

I tend to recommend that Windows users add the --compiler flag to their .bazelrc, and enable developer mode with:

REG ADD "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock" /t REG_DWORD /f /v "AllowDevelopmentWithoutDevLicense" /d "1" so that our run targets can use data files.

Hope this helps!

@meteorcloudy
Copy link
Member

meteorcloudy commented Jul 23, 2019

@weggert2 Be aware, --compiler is expected to be removed in Bazel 1.0, when incompatible_enable_cc_toolchain_resolution is enabled.
You'll have to select other cc toolchain (clang, mingw) differently https://docs.bazel.build/versions/master/windows.html#build-c-with-clang

@meteorcloudy
Copy link
Member

I doubt the code base would affect the cc toolchain configuration. Did you check they were running in the same terminal with the same environment variables?

@weggert2
Copy link
Author

Thanks for the heads up about the platform selection in the BUILD file, I’ll transition us over to that.

I think we cleared up the issue: a combination of enabling developer mode, restarting, and downgrading/re-upgrading Bazel seemed to do it. I’m a little perplexed as to why that worked, the solution and the problem seem unconnected. But in any case, my specific issue is resolved so I’m ok with closing this ticket.

@meteorcloudy
Copy link
Member

@weggert2 Sounds good, feel free to reopen this issue if you encounter it again or figure out a repo. Thanks!

@philwo philwo added the team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website label Jun 15, 2020
@MohdNofal
Copy link

MohdNofal commented Dec 10, 2020

Hi everybody,

I also faced this issue on Windows. After 4 days I was finally able to fix it by re-installing all of Microsoft Visual C++. The way I did it is by doing the following:

  • Search for "Add or Remove Programs" on Windows
  • Uninstall all of Microsoft Visual C++ (I had Microsoft Visual C++ from 2005 up until 2019)
  • Then I also uninstalled Microsoft Visual Studio Code
  • Restart PC
  • Then I installed Microsoft Visual Studio Code again (It will automatically ask you if you want to download Microsoft Visual C++ which you should obviously accept)
  • Restart PC again

This should hopefully fix your problem =)

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 P1 I'll work on this now. (Assignee required) team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website
Projects
None yet
Development

No branches or pull requests

5 participants