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

Windows build issue #1007

Closed
cgbystrom opened this issue Nov 9, 2017 · 3 comments
Closed

Windows build issue #1007

cgbystrom opened this issue Nov 9, 2017 · 3 comments
Assignees
Labels

Comments

@cgbystrom
Copy link

I set up a small single file Go app in Bazel and trying to make it build under Windows.
Have run into three issues with two fixed (mentioning them here for sake completeness).

First issue I was getting:

DEBUG: C:/users/cgbys_000/appdata/local/temp/_bazel_cgbys_000/3q0k7szh/external/io_bazel_rules_go/go/private/toolchain.bzl:104:5: java.io.IOException: CreateProcess(): The system cannot find the file
specified.

Which is a bit cryptic, but turns out it's the env command that is missing. Which was caused by a misconfigured BAZEL_SH variable. Easy fix.

Second issue was same as #736 (comment) (temp directory ending up being C:\Windows). Solved by running msys2 shell as admin. Not ideal, but works for now.

Last issue I'm stuck with is this:

$ ./bazel build ///...
____Loading package:
____Found 2 targets...
____Building...
____[3 / 11] SkylarkAction external/go_stdlib_windows_amd64_cgo/bin/go [for host]
ERROR: C:/dev/msys64/tmp/_bazel_cgbys_000/3q0k7szh/external/go_stdlib_windows_amd64_cgo/BUILD.bazel:4:1: error executing shell command: 'export GOROOT=$(pwd)/bazel-out/host/bin/external/go_stdlib_windows_amd64_cgo GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=$(pwd)/C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/amd64/cl.ex...' failed (Exit 1).
/usr/bin/bash: -c: line 0: syntax error near unexpected token `('
/usr/bin/bash: -c: line 0: `export GOROOT=$(pwd)/bazel-out/host/bin/external/go_stdlib_windows_amd64_cgo GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=$(pwd)/C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/amd64/cl.exe CXX=$(pwd)/C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/amd64/cl.exe COMPILER_PATH=C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/amd64 && mkdir -p bazel-out/host/bin/external/go_stdlib_windows_amd64_cgo/src && mkdir -p bazel-out/host/bin/external/go_stdlib_windows_amd64_cgo/pkg && cp external/go_sdk//bin/go bazel-out/host/bin/external/go_stdlib_windows_amd64_cgo/bin/go && cp -rf external/go_sdk//src/* bazel-out/host/bin/external/go_stdlib_windows_amd64_cgo/src/ && cp -rf external/go_sdk//pkg/tool bazel-out/host/bin/external/go_stdlib_windows_amd64_cgo/pkg/ && cp -rf external/go_sdk//pkg/include bazel-out/host/bin/external/go_stdlib_windows_amd64_cgo/pkg/ && bazel-out/host/bin/external/go_stdlib_windows_amd64_cgo/bin/go install  std && bazel-out/host/bin/external/go_stdlib_windows_amd64_cgo/bin/go install  runtime/cgo'
____Elapsed time: 2,842s, Critical Path: 0,40s

Test app I used https://gist.github.com/cgbystrom/6973b478e23286604c80c506b216a9b3 with Bazel 0.7.0 on Windows 8.1

@cgbystrom
Copy link
Author

cgbystrom commented Nov 10, 2017

Got it to build after doing this:

  1. Symlinking MSVS directory to something without spaces using mklink /D worked. Spaces in CC and CXX was no good.
  2. Removed the $(pwd)/ prefix that's added at
    cc_path = "$(pwd)/" + cc_path
  3. Setting CGO_ENABLED to 0 at
    "CGO_ENABLED": "1" if ctx.attr.cgo else "0",
  4. Adding a .exe as described by the TODO at
    go = ctx.actions.declare_file("bin/go") # TODO: .exe
  5. Created the C:\tmp directory. Some assumptions going on with temp directories as well?

Produces a binary without .exe extension, but that is perhaps a known issue.

pjh added a commit to pjh/rules_go that referenced this issue Nov 16, 2017
@Xjs
Copy link
Contributor

Xjs commented Dec 14, 2017

I tried the symlinking trick, but still fail to build (a simple almost-empty go file with straightforward rules, cf. #1122 (comment)). My error message is:

$ bazel build bazel_test_cmd
Loading:
Loading: 0 packages loaded
ERROR: in target '//external:cc_toolchain': no such package '@local_config_cc//': Traceback (most recent call last):
        File "C:/tools/msys64/tmp/_bazel_jannis.schnitzer/xsd1mqcu/external/bazel_tools/tools/cpp/cc_configure.bzl", line 34
                configure_windows_toolchain(repository_ctx)
        File "C:/tools/msys64/tmp/_bazel_jannis.schnitzer/xsd1mqcu/external/bazel_tools/tools/cpp/windows_cc_configure.bzl", line 314, in configure_windows_toolchain
                _find_env_vars(repository_ctx, vc_path)
        File "C:/tools/msys64/tmp/_bazel_jannis.schnitzer/xsd1mqcu/external/bazel_tools/tools/cpp/windows_cc_configure.bzl", line 193, in _find_env_vars
                _find_vcvarsall_bat_script(repository_ctx, vc_path)
        File "C:/tools/msys64/tmp/_bazel_jannis.schnitzer/xsd1mqcu/external/bazel_tools/tools/cpp/windows_cc_configure.bzl", line 187, in _find_vcvarsall_bat_script
                auto_configure_fail((vcvarsall + " doesn't exist, pl..."))
        File "C:/tools/msys64/tmp/_bazel_jannis.schnitzer/xsd1mqcu/external/bazel_tools/tools/cpp/lib_cc_configure.bzl", line 30, in auto_configure_fail
                fail(("\n%sAuto-Configuration Error:%...)))

Auto-Configuration Error: C:\MSVC\VCVARSALL.BAT doesn't exist, please check your VC++ installation
INFO: Elapsed time: 8,144s
FAILED: Build did NOT complete successfully (0 packages loaded)

There exists a vcvarsall.bat file in C:\MSVC\Auxiliary\Build\.

Setting BAZEL_VC=C:\MSVC\Auxiliary\Build\ doesn't help either, it fails with the following error message:

Auto-Configuration Error: C:\MSVC\Auxiliary\Build\bin\amd64\cl.exe not found, please check your VC++ installation.

(cl.exe resides in C:\MSVC\Tools\MSVC\14.12.25827\bin\Hostx64\x64\cl.exe).

What might be the way to go?

@ianthehat
Copy link
Contributor

As I mentioned in #736, go itself does not work with cl.exe, only gcc, so making msvc work is not going to help you much.
I am going to close this bug so we have just one bug to track rules_go working on windows, so the conversation does not get fractured.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants