bazel: Bazel failing with VC++ compilers in "C:\Program Files"

Description of the problem / feature request:

The default install of Visual Studio puts the C++ compiler in a subdirectory under “Program Files”. When trying to build a project, it fails saying “c:\Program” does not exist:

ERROR: C:/users/patrick/appdata/local/temp/_bazel_patrick/dmhbzmu0/external/go_stdlib_windows_amd64_cgo/BUILD.bazel:4:1: error executing shell command: 'export GOROOT="$(pwd)/bazel-out/x64_windows-fastbuild/bin/external/go_stdlib_windows_amd64_cgo" GOROOT_FINAL="GOROOT" GOOS="windows" GOARCH="amd64" CGO_ENABLED="1" CC="C:/Program Files (x86)/Micros...' failed (Exit 2)
# runtime/cgo
exec: "C:/Program": file does not exist

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

Prerequisites

  1. Visual Studio 2017 community edition - easiest way to get MS C++ compiler and SDK
  • Tick the boxes for at least desktop development with C++
  1. Chocolatey
  2. Bazel

Surprisingly, Go doesn’t need to be preinstalled

Code used

https://github.com/PatrickLang/iso9660wrap/tree/bazel-manual

be sure to use branch bazel-manual

Build attempt

bazel build //...

Fails

Extracting Bazel installation...
............
DEBUG: C:/users/patrick/appdata/local/temp/_bazel_patrick/dmhbzmu0/external/bazel_tools/tools/cpp/lib_cc_configure.bzl:37:3:
Auto-Configuration Warning: 'BAZEL_VC' is not set, start looking for the latest Visual C++ installed.
DEBUG: C:/users/patrick/appdata/local/temp/_bazel_patrick/dmhbzmu0/external/bazel_tools/tools/cpp/lib_cc_configure.bzl:37:3:
Auto-Configuration Warning: Looking for VS%VERSION%COMNTOOLS environment variables,eg. VS140COMNTOOLS
DEBUG: C:/users/patrick/appdata/local/temp/_bazel_patrick/dmhbzmu0/external/bazel_tools/tools/cpp/lib_cc_configure.bzl:37:3:
Auto-Configuration Warning: Looking for Visual C++ through registry
DEBUG: C:/users/patrick/appdata/local/temp/_bazel_patrick/dmhbzmu0/external/bazel_tools/tools/cpp/lib_cc_configure.bzl:37:3:
Auto-Configuration Warning: Visual C++ build tools found at C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\\VC
INFO: Analysed 2 targets (167 packages loaded).
INFO: Found 2 targets...
ERROR: C:/users/patrick/appdata/local/temp/_bazel_patrick/dmhbzmu0/external/go_stdlib_windows_amd64_cgo/BUILD.bazel:4:1: error executing shell command: 'export GOROOT="$(pwd)/bazel-out/x64_windows-fastbuild/bin/external/go_stdlib_windows_amd64_cgo" GOROOT_FINAL="GOROOT" GOOS="windows" GOARCH="amd64" CGO_ENABLED="1" CC="C:/Program Files (x86)/Micros...' failed (Exit 2)
# runtime/cgo
exec: "C:/Program": file does not exist
INFO: Elapsed time: 129.897s, Critical Path: 31.18s
FAILED: Build did NOT complete successfully

What operating system are you running Bazel on?

Windows 10 1709 (build 16299)

What’s the output of bazel info release?

release 0.9.0

What’s the output of git remote get-url origin ; git rev-parse master ; git rev-parse HEAD ?

https://github.com/PatrickLang/iso9660wrap.git 6129215f4acaa171e394fa3a90c09f71c308c0ac e580362bc6eec0400f03a15557c42b19c150dc77

Have you found anything relevant by searching the web?

No

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

Entire build log from stdout/err is above

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 17 (9 by maintainers)

Most upvoted comments

+1

@laszlocsomor - I got around this by using a symlink at C:\bazel_vc to point to the Program Files VC path. because it seems we can’t specify the VC build tools install location from the Microsoft supported installer. The issue from there is an invalid argument is passed to the C++ compiler so the Go bits cannot be compiled. From what I gather compiling Go code on Windows is simply not working at all with bazel. Seemingly no issue compiling C++ code.

So two issues:

  1. Somewhere in the process via commands executed with spaces in path for the VC tools blows up. Workaround is to symlink to a non-space path.

  2. Compiling Go code on Windows doesn’t work because of some bad arguments to the VC compiler. Happy to help further.

$ bazel build :hello --verbose_failures
INFO: Analysed target //hello:hello (0 packages loaded).
INFO: Found 1 target...
ERROR: C:/users/dominic/appdata/local/temp/_bazel_dominic/miiivhdk/external/io_bazel_rules_go/BUILD.bazel:9:1: GoStdlib external/io_bazel_rules_go/windows_amd64_stripped/stdlib~/pkg failed (Exit 1): stdlib.exe failed: error executing command
  cd C:/users/dominic/appdata/local/temp/_bazel_dominic/miiivhdk/execroot/__main__
bazel-out/host/bin/external/io_bazel_rules_go/go/tools/builders/windows_amd64_stripped/stdlib.exe -go external/go_sdk/bin/go.exe -root_file external/go_sdk/packages.txt -goos windows -goarch amd64 -cgo=1 -compiler_path C:/bazel_vc/bin/amd64 -cc C:/bazel_vc/bin/amd64/cl.exe -cpp_flag /DCOMPILER_MSVC -cpp_flag /DNOMINMAX -cpp_flag /D_WIN32_WINNT=0x0600 -cpp_flag /D_CRT_SECURE_NO_DEPRECATE -cpp_flag /D_CRT_SECURE_NO_WARNINGS -cpp_flag /D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS -cpp_flag /bigobj -cpp_flag /Zm500 -cpp_flag /J -cpp_flag /Gy -cpp_flag /GF -cpp_flag /EHsc -cpp_flag /wd4351 -cpp_flag /wd4291 -cpp_flag /wd4250 -cpp_flag /wd4996 -ld_flag /MACHINE:X64 -out bazel-out/x64_windows-fastbuild/bin/external/io_bazel_rules_go/windows_amd64_stripped/stdlib~
# runtime/cgo
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24231 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

cl : Command line error D8021 : invalid numeric argument '/Werror'
2018/04/10 22:45:39 error running go install std: exit status 2
Target //hello:hello failed to build
INFO: Elapsed time: 31.923s, Critical Path: 31.20s
FAILED: Build did NOT complete successfully

BUILD.bazel

load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test")

go_binary(
    name = "hello",
    srcs = ["hello.go"],
)

hello.go

package main

import (
	"fmt"
)

func main() {
	fmt.Println("Hello!")
}