bazelbuild / rules_go

Go rules for Bazel
Apache License 2.0
1.36k stars 637 forks source link

Cgo errors building standard library on Windows with mingw #1677

Open jayconrod opened 5 years ago

jayconrod commented 5 years ago

Originally reported by @Xjs in #1676.


Somewhat related (?): building the same repository with --compiler=mingw-gcc like @jayconrod documented in https://github.com/bazelbuild/rules_go/issues/1613 fails with some C compiler errors:

(15:41:48) ERROR: C:/tmp/_bazel_jannis.schnitzer/47bkkx3e/external/io_bazel_rules_go/BUILD.bazel:8:1: Couldn't build file external/io_bazel_rules_go/linux_amd64_stripped/stdlib%/pkg: GoStdlib external/io_bazel_rules_go/linux_amd64_stripped/stdlib%/pkg failed (Exit 1): stdlib.exe failed: error executing command
  cd C:/tmp/_bazel_jannis.schnitzer/47bkkx3e/execroot/com_github_Xjs_proto_test
  SET CC=c:/tools/msys64/mingw64/bin/gcc
    SET CGO_CFLAGS=
    SET CGO_CPPFLAGS=
    SET CGO_ENABLED=1
    SET CGO_LDFLAGS=-lstdc++
    SET GOARCH=amd64
    SET GOOS=linux
    SET GOROOT=external/go_sdk
    SET GOROOT_FINAL=GOROOT
    SET PATH=c:/tools/msys64/mingw64/bin
  bazel-out/host/bin/external/io_bazel_rules_go/go/tools/builders/windows_amd64_stripped/stdlib.exe -sdk external/go_sdk -installsuffix linux_amd64 -out bazel-out/x64_windows-fastbuild/bin/external/io_bazel_rules_go/linux_amd64_stripped/stdlib% -filter_buildid bazel-out/host/bin/external/io_bazel_rules_go/go/tools/builders/windows_amd64_stripped/filter_buildid.exe
# runtime/cgo
gcc_linux_amd64.c: In function '_cgo_sys_thread_start':
gcc_linux_amd64.c:62:2: error: unknown type name 'sigset_t'; did you mean '_sigset_t'?
  sigset_t ign, oset;
  ^~~~~~~~
  _sigset_t
gcc_linux_amd64.c:67:2: error: implicit declaration of function 'sigfillset' [-Werror=implicit-function-declaration]
  sigfillset(&ign);
  ^~~~~~~~~~
gcc_linux_amd64.c:62:16: error: unused variable 'oset' [-Werror=unused-variable]
  sigset_t ign, oset;
                ^~~~
cc1.exe: all warnings being treated as errors
GoStdlib: error running subcommand: exit status 2
kevinburke1 commented 5 years ago

FWIW I'm getting this same set of errors attempting to cross compile go-sqlite3 on Darwin, for Linux.

CC=x86_64-w64-mingw32-gcc CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build --tags "linux" -a -o /dev/null .