bazel-contrib / bazel-contrib/rules_go
go_binary does not build on windows: cgo.exe: exit status 2
- Dominant language
- Go
- Stars
- 1.5k
- Forks
- 762
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 12
Description
### What version of rules_go are you using?
I have tried v0.30.0, v0.33.0 and v0.35.0
### What version of gazelle are you using?
v0.25.0
### What version of Bazel are you using?
bazel 5.2.0
### Does this issue reproduce with the latest releases of all the above?
Not sure, but I will need to use v0.33.0 for rules_go at the latest. v0.34.0 breaks some dependencies. Dont think changing gazelle and bazel version would fix it.
### What operating system and processor architecture are you using?
Windows Server 2022, x86-64
### Any other potentially useful information about your toolchain?
c compiler: msyc/mingw
I installed visual studio in a directory without spaces.
I installed VS community 2022 with `MSVC v143 x86-64`, `Git for Windows`, and `Windows 10 SDK`
### What did you do?
In a minimal example, call c code from go code and build a `go_binary` using `bazel build //callC/... --verbose_failures`
I have baked up an example at https://github.com/PaperbagLife/windows-bazel-cgo
### What did you expect to see?
Compiles successfully
### What did you see instead?
```
ERROR: C:/users/ricky/windows-bazel-cgo/callC/BUILD.bazel:3:10: GoCompilePkg callC/ctest.a failed: (Exit 1): builder.exe failed: error executing command
cd /d C:/users/ricky/_bazel_ricky/q327xwjq/execroot/__main__
SET CC=C:/VS/VC/Tools/MSVC/14.33.31629/bin/HostX64/x64/cl.exe
SET CGO_ENABLED=1
SET GOARCH=amd64
SET GOOS=windows
SET GOPATH=
SET GOROOT=external/go_sdk
SET GOROOT_FINAL=GOROOT
SET INCLUDE=C:\VS\VC\Tools\MSVC\14.33.31629\include;C:\VS\VC\Auxiliary\VS\include;C:\Program Files (x86)\Windows Kits\10\include\10.0.20348.0\ucrt;C:\Program Files (x86)\Windows Kits\10\\include\10.0.20348.0\\um;C:\Program Files (x86)\Windows Kits\10\\include\10.0.20348.0\\shared;C:\Program Files (x86)\Windows Kits\10\\include\10.0.20348.0\\winrt;C:\Program Files (x86)\Windows Kits\10\\include\10.0.20348.0\\cppwinrt
SET LIB=C:\VS\VC\Tools\MSVC\14.33.31629\lib\x64;C:\Program Files (x86)\Windows Kits\10\lib\10.0.20348.0\ucrt\x64;C:\Program Files (x86)\Windows Kits\10\\lib\10.0.20348.0\\um\x64
SET PATH=;C:/VS/VC/Tools/MSVC/14.33.31629/bin/HostX64/x64;C:\Program Files (x86)\Windows Kits\10\bin\10.0.20348.0\\x64;C:\Program Files (x86)\Windows Kits\10\bin\\x64;C:\VS\Common7\IDE\;C:\VS\Common7\Tools\;C:\VS\VC\Tools\MSVC\14.33.31629\bin\HostX64\x64;C:\VS\\MSBuild\Current\Bin\amd64;C:\Windows\Microsoft.NET\Framework64\v4.0.30319;C:\Windows\system32
SET TEMP=C:\Users\ricky\AppData\Local\Temp
SET TMP=C:\Users\ricky\AppData\Local\Temp
bazel-out\x64_windows-opt-exec-2B5CBBC6\bin\external\go_sdk\builder.exe compilepkg -sdk external/go_sdk -installsuffix windows_amd64 -src callC/main.go -src callC/helper.c -p main -package_list bazel-out/x64_windows-opt-exec-2B5CBBC6/bin/external/go_sdk/packages.txt -o bazel-out/x64_windows-fastbuild/bin/callC/ctest.a -x bazel-out/x64_windows-fastbuild/bin/callC/ctest.x -gcflags -asmflags -cppflags -iquote . -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 /MD /Od /Z7 /wd4117 -D__DATE__="redacted" -D__TIMESTAMP__="redacted" -D__TIME__="redacted" -fPIC -cxxflags /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 /MD /Od /Z7 /wd4117 -D__DATE__="redacted" -D__TIMESTAMP__="redacted" -D__TIME__="redacted" -fPIC -objcflags /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 /MD /Od /Z7 /wd4117 -D__DATE__="redacted" -D__TIMESTAMP__="redacted" -D__TIME__="redacted" -fPIC -objcxxflags /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 /MD /Od /Z7 /wd4117 -D__DATE__="redacted" -D__TIMESTAMP__="redacted" -D__TIME__="redacted" -fPIC -ldflags /nologo /SUBSYSTEM:CONSOLE /MACHINE:X64 /DEFAULTLIB:msvcrt.lib /DEBUG:FASTLINK /INCREMENTAL:NO
# Configuration: 72cc8654fb071a612a1834f98fbbc11d935b98b9b146db1936c8636da61b3a58
# Execution platform: @local_config_platform//:host
cl : Command line warning D9002 : ignoring unknown option '-dM'
cl : Command line warning D9002 : ignoring unknown option '-m64'
cl : Command line warning D9002 : ignoring unknown option '-iquote'
cl : Command line warning D9002 : ignoring unknown option '-iquote'
cl : Command line warning D9002 : ignoring unknown option '-fPIC'
.
c1: fatal error C1083: Cannot open source file: '.': No such file or directory
main
c1: fatal error C1083: Cannot open source file: 'C:\Users\ricky\AppData\Local\Temp\rules_go_work-1744271222\cgo\main': No such file or directory
cgo-gcc-input-600785766.c
Note: including file: C:\Program Files (x86)\Windows Kits\10\include\10.0.20348.0\ucrt\stddef.h
Note: including file: C:\Program Files (x86)\Windows Kits\10\include\10.0.20348.0\ucrt\corecrt.h
Note: including file: C:\VS\VC\Tools\MSVC\14.33.31629\include\vcruntime.h
Note: including file: C:\VS\VC\Tools\MSVC\14.33.31629\include\sal.h
Note: including file: C:\VS\VC\Tools\MSVC\14.33.31629\include\concurrencysal.h
Note: including file: C:\VS\VC\Tools\MSVC\14.33.31629\include\vadefs.h
Note: including file: C:\Program Files (x86)\Windows Kits\10\include\10.0.20348.0\ucrt\stdio.h
Note: including file: C:\Program Files (x86)\Windows Kits\10\include\10.0.20348.0\ucrt\corecrt_wstdio.h
Note: including file: C:\Program Files (x86)\Windows Kits\10\include\10.0.20348.0\ucrt\corecrt_stdio_config.h
compilepkg: error running subcommand external\go_sdk\pkg\tool\windows_amd64\cgo.exe: exit status 2
```
I was wondering if I could get some help on this.
Thanks
Contributor guide
Research direction
Reproduce the failure with `bazel build //callC/... --verbose_failures` in the linked minimal example, then inspect `callC/BUILD.bazel`, `callC/main.go`, and `callC/helper.c` alongside the cgo.exe output. Done means the cgo example builds successfully as a Windows `go_binary` with the reported MSVC toolchain.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- build-system, operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100