envoyproxy / envoy

Cloud-native high-performance edge/middle/service proxy
https://www.envoyproxy.io
Apache License 2.0
24.81k stars 4.77k forks source link

Unable to build `go` code on Windows with current bazel setup #25144

Open phlax opened 1 year ago

phlax commented 1 year ago

After adding some bazel targets to build go plugins for config tests - the build fails on windows

ERROR: C:/build/tmp/external/io_bazel_rules_go/BUILD.bazel:42:7: GoStdlib external/io_bazel_rules_go/stdlib_/pkg failed: (Exit 1): builder.exe failed: error executing command (from target @io_bazel_rules_go//:stdlib) 
  cd /d C:/build/tmp/execroot/envoy
  SET CC=C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.29.30133/bin/HostX64/x64/cl.exe
    SET CGO_CFLAGS=/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 /showIncludes /O2 /Oy- /DNDEBUG /Gy /Gw -DABSL_MIN_LOG_LEVEL=4 -DCARES_STATICLIB -DNGHTTP2_STATICLIB -DCURL_STATICLIB
    SET CGO_ENABLED=1
    SET CGO_LDFLAGS=/nologo /DLL /SUBSYSTEM:CONSOLE /MACHINE:X64 /OPT:ICF /OPT:REF
    SET GOARCH=amd64
    SET GOOS=windows
    SET GOPATH=
    SET GOROOT=external/go_sdk
    SET GOROOT_FINAL=GOROOT
    SET INCLUDE=C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\include;C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\ucrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\shared;C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\winrt;C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\cppwinrt
    SET LIB=C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\lib\x64;C:\Program Files (x86)\Windows Kits\10\lib\10.0.22000.0\ucrt\x64;C:\Program Files (x86)\Windows Kits\10\lib\10.0.22000.0\um\x64
    SET PATH=;C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.29.30133/bin/HostX64/x64;C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\Common7\IDE\;C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer;C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\Common7\IDE\CommonExtensions\Microsoft\TestWindow;C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\Common7\IDE\VC\VCPackages;C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\Common7\Tools\;C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\Common7\Tools\devinit;C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\bin\Roslyn;C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64;C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\\MSBuild\Current\Bin;C:\Program Files (x86)\Windows Kits\10\bin\10.0.22000.0\x64;C:\Program Files (x86)\Windows Kits\10\bin\x64;C:\Windows\Microsoft.NET\Framework64\v4.0.30319;C:\Windows\system32
    SET TEMP=C:\Windows\Temp
    SET TMP=C:\Windows\Temp
  bazel-out\x64_windows-opt-exec-FFA80BB1-ST-e9a6c15ec566\bin\external\go_sdk\builder.exe stdlib -sdk external/go_sdk -installsuffix windows_amd64 -out bazel-out/x64_windows-opt-ST-e9a6c15ec566/bin/external/io_bazel_rules_go/stdlib_
# Configuration: 81c042e2c21586c1c991cb5180956f2071665809bc5b0d932dc2f6fdeec54758
# Execution platform: @envoy_build_tools//toolchains:rbe_windows_msvc_cl_platform
# runtime/cgo
cgo: C compiler "C:\\Program" not found: exec: "C:\\Program": file does not exist
filterbuildid: exit status 2
stdlib: error running subcommand external\go_sdk\bin\go.exe: exit status 2

from my reading of https://github.com/bazelbuild/rules_go/blob/master/windows.rst i think its becase cgo requires gcc (or clang) and cannot use msvc

not sure if this is correct, but i think the win container has gcc somewhere so im guessing its a matter of hooking up some bazel flags or env vars

i can disable the relevant test/s on windows for now so not so high priority, but would be good to have this working i guess

phlax commented 1 year ago

cc @wrowe @wangfakang

wangfakang commented 1 year ago

It seems to be the same issue https://github.com/golang/go/issues/41400#issuecomment-841606623, need to switch the compiler to mingw-gcc on the Win platform.

github-actions[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in the next 7 days unless it is tagged "help wanted" or "no stalebot" or other activity occurs. Thank you for your contributions.