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: Bazel 0.19.0 cannot select mingw gcc correctly using --compiler=mingw-gcc #6610

Closed
meteorcloudy opened this issue Nov 6, 2018 · 6 comments

Comments

@meteorcloudy
Copy link
Member

@meteorcloudy meteorcloudy commented Nov 6, 2018

Description of the problem / feature request:

On Windows, users should be able to use the mingw gcc to build C++ targets by specifying --compiler=mingw-gcc. But with Bazel 0.19.0, it wrongly selects MSVC toolchain.

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

pcloudy@pcloudy0-w MSYS ~/workspace/my_tests/bazel
$ bazel-0.19.0 build examples/cpp:hello-world --compiler=mingw-gcc -s
WARNING: The following rc files are no longer being read, please transfer their contents or import their path into one of the standard rc files:
C:\Users\pcloudy/.bazelrc
INFO: Build options have changed, discarding analysis cache.
INFO: Analysed target //examples/cpp:hello-world (0 packages loaded, 66 targets configured).
INFO: Found 1 target...
SUBCOMMAND: # //examples/cpp:hello-lib [action 'Compiling examples/cpp/hello-lib.cc']
cd C:/src/tmp/wa6d46al/execroot/io_bazel
  SET INCLUDE=C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE;C:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\ucrt;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\shared;C:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\winrt;
    SET PATH=C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64;C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319;C:\WINDOWS\Microsoft.NET\Framework64\;C:\Program Files (x86)\Windows Kits\10\bin\x64;C:\Program Files (x86)\Windows Kits\10\bin\x86;C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\x64\;;C:\WINDOWS\system32
    SET PWD=/proc/self/cwd
    SET TEMP=C:\Users\pcloudy\AppData\Local\Temp
    SET TMP=C:\Users\pcloudy\AppData\Local\Temp
  C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/amd64/cl.exe /nologo /DCOMPILER_MSVC /DNOMINMAX /D_WIN32_WINNT=0x0600 /D_CRT_SECURE_NO_DEPRECATE /D_CRT_SECURE_NO_WARNINGS /bigobj /Zm500 /EHsc /wd4351 /wd4291 /wd4250 /wd4996 /I. /Ibazel-out/x64_windows-fastbuild/genfiles /Ibazel-out/x64_windows-fastbuild/bin /Iexternal/bazel_tools /Ibazel-out/x64_windows-fastbuild/genfiles/external/bazel_tools /Ibazel-out/x64_windows-fastbuild/bin/external/bazel_tools /showIncludes /MD /Od /Z7 /wd4117 -D__DATE__="redacted" -D__TIMESTAMP__="redacted" -D__TIME__="redacted" -w /Fobazel-out/x64_windows-fastbuild/bin/examples/cpp/_objs/hello-lib/hello-lib.obj /c examples/cpp/hello-lib.cc
SUBCOMMAND: # //examples/cpp:hello-world [action 'Compiling examples/cpp/hello-world.cc']
cd C:/src/tmp/wa6d46al/execroot/io_bazel
  SET INCLUDE=C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE;C:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\ucrt;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\shared;C:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\um;C:\Program Files (x86)\Windows Kits\10\include\10.0.17134.0\winrt;
    SET PATH=C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64;C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319;C:\WINDOWS\Microsoft.NET\Framework64\;C:\Program Files (x86)\Windows Kits\10\bin\x64;C:\Program Files (x86)\Windows Kits\10\bin\x86;C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\x64\;;C:\WINDOWS\system32
    SET PWD=/proc/self/cwd
    SET TEMP=C:\Users\pcloudy\AppData\Local\Temp
    SET TMP=C:\Users\pcloudy\AppData\Local\Temp
  C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/amd64/cl.exe /nologo /DCOMPILER_MSVC /DNOMINMAX /D_WIN32_WINNT=0x0600 /D_CRT_SECURE_NO_DEPRECATE /D_CRT_SECURE_NO_WARNINGS /bigobj /Zm500 /EHsc /wd4351 /wd4291 /wd4250 /wd4996 /I. /Ibazel-out/x64_windows-fastbuild/genfiles /Ibazel-out/x64_windows-fastbuild/bin /Iexternal/bazel_tools /Ibazel-out/x64_windows-fastbuild/genfiles/external/bazel_tools /Ibazel-out/x64_windows-fastbuild/bin/external/bazel_tools /showIncludes /MD /Od /Z7 /wd4117 -D__DATE__="redacted" -D__TIMESTAMP__="redacted" -D__TIME__="redacted" -w /Fobazel-out/x64_windows-fastbuild/bin/examples/cpp/_objs/hello-world/hello-world.obj /c examples/cpp/hello-world.cc
SUBCOMMAND: # //examples/cpp:hello-lib [action 'Linking examples/cpp/hello-lib.lib']
cd C:/src/tmp/wa6d46al/execroot/io_bazel
  SET LIB=C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\LIB\amd64;C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\ucrt\x64;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\lib\um\x64;C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x64;
    SET PATH=C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64;C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319;C:\WINDOWS\Microsoft.NET\Framework64\;C:\Program Files (x86)\Windows Kits\10\bin\x64;C:\Program Files (x86)\Windows Kits\10\bin\x86;C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\x64\;;C:\WINDOWS\system32
    SET PWD=/proc/self/cwd
    SET TEMP=C:\Users\pcloudy\AppData\Local\Temp
    SET TMP=C:\Users\pcloudy\AppData\Local\Temp
  C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/amd64/lib.exe /nologo /OUT:bazel-out/x64_windows-fastbuild/bin/examples/cpp/hello-lib.lib bazel-out/x64_windows-fastbuild/bin/examples/cpp/_objs/hello-lib/hello-lib.obj /ignore:4221
SUBCOMMAND: # //examples/cpp:hello-world [action 'Linking examples/cpp/hello-world.exe']
cd C:/src/tmp/wa6d46al/execroot/io_bazel
  SET LIB=C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\LIB\amd64;C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\ucrt\x64;C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\lib\um\x64;C:\Program Files (x86)\Windows Kits\10\lib\10.0.17134.0\um\x64;
    SET PATH=C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64;C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319;C:\WINDOWS\Microsoft.NET\Framework64\;C:\Program Files (x86)\Windows Kits\10\bin\x64;C:\Program Files (x86)\Windows Kits\10\bin\x86;C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\x64\;;C:\WINDOWS\system32
    SET PWD=/proc/self/cwd
    SET TEMP=C:\Users\pcloudy\AppData\Local\Temp
    SET TMP=C:\Users\pcloudy\AppData\Local\Temp
  C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/amd64/link.exe /nologo /OUT:bazel-out/x64_windows-fastbuild/bin/examples/cpp/hello-world.exe bazel-out/x64_windows-fastbuild/bin/examples/cpp/_objs/hello-world/hello-world.obj bazel-out/x64_windows-fastbuild/bin/examples/cpp/hello-lib.lib /SUBSYSTEM:CONSOLE /MACHINE:X64 /DEFAULTLIB:msvcrt.lib /DEBUG:FASTLINK /INCREMENTAL:NO
Target //examples/cpp:hello-world up-to-date:
  C:/src/tmp/wa6d46al/execroot/io_bazel/bazel-out/x64_windows-fastbuild/bin/examples/cpp/hello-world.exe
INFO: Elapsed time: 0.815s, Critical Path: 0.58s, Remote (0.00% of the time): [queue: 0.00%, setup: 0.00%, process: 0.00%]
INFO: 4 processes: 4 local.
INFO: Build completed successfully, 5 total actions

What operating system are you running Bazel on?

Windows 10

What's the output of bazel info release?

release 0.19.0

I can confirm 0.18.1 works correctly, so this is a regression in 0.19.0, unfortunately, we might need a patch release. @katre

But using Bazel built from HEAD, everything works correctly, so it's not a release blocker for 0.20.0.

This will block bazelbuild/rules_go#1791

@scentini Do you have any idea what's going on?

@meteorcloudy

This comment has been minimized.

Copy link
Member Author

@meteorcloudy meteorcloudy commented Nov 6, 2018

A part of the reason this happens is because we don't have tests for mingw toolchain on Windows, I'll working on adding tests for it.

@scentini

This comment has been minimized.

Copy link
Contributor

@scentini scentini commented Nov 6, 2018

Probably related to recent changes by @mhlopko on toolchain selection. Looking into it.

@katre

This comment has been minimized.

Copy link
Member

@katre katre commented Nov 6, 2018

This sounds like a regression, so let me know when we have identified a cause and if there's an easy fix for a point release.

bazel-io pushed a commit that referenced this issue Nov 7, 2018
This will prevent #6610 from happening again.

RELNOTES: None
PiperOrigin-RevId: 220423789
@scentini

This comment has been minimized.

Copy link
Contributor

@scentini scentini commented Nov 7, 2018

I believe this was introduced in 46e65d1. It was fixed in c3fb1db.

In the first commit, we modify the toolchain selection process to depend on (in order):

  1. 'toolchain_identifier' attribute of cc_toolchain, if present.
  2. 'cpu' (and 'compiler' if specified) attributes of cc_toolchain, if present.
  3. --cpu and --compiler command line options.

As the mingw-gcc cc_toolchain has a 'cpu' attribute (and doesn't have a 'compiler' one to know the right compiler), Bazel selects the CToolchain by step 2, therefore ignoring the --compiler option.

c3fb1db adds 'toolchain_identifier' attributes to each of the cc_toolchains therefore forcing Bazel to select the right toolchain.

@katre, could you cherrypick c3fb1db ?

@katre

This comment has been minimized.

Copy link
Member

@katre katre commented Nov 7, 2018

This will need to be a new patch release, 0.19.1. I'll start the process.

@meteorcloudy

This comment has been minimized.

Copy link
Member Author

@meteorcloudy meteorcloudy commented Nov 7, 2018

@scentini @katre Thank you so much!

katre added a commit that referenced this issue Nov 7, 2018
This will prevent #6610 from happening again.

RELNOTES: None
PiperOrigin-RevId: 220423789
katre added a commit that referenced this issue Nov 7, 2018
This will prevent #6610 from happening again.

RELNOTES: None
PiperOrigin-RevId: 220423789
katre added a commit that referenced this issue Nov 7, 2018
This will prevent #6610 from happening again.

RELNOTES: None
PiperOrigin-RevId: 220423789
bazel-io pushed a commit that referenced this issue Nov 12, 2018
Baseline: ac88041

Cherry picks:

   + 9bc3b20:
     Fix the "nojava" platform and enable full presubmit checks for
     the various JDK platforms now that we have enough GCE resources.
   + 54c2572:
     Add openjdk_linux_archive java_toolchain for nojava platform.
   + 20bfdc6:
     Automated rollback of commit
     19a401c.
   + 914b4ce:
     Windows: Fix Precondition check for addDynamicInputLinkOptions
   + 83d406b:
     Windows, test-setup.sh: Setting RUNFILES_MANIFEST_FILE only when
     it exists.
   + e025726:
     Update turbine
   + 5f312dd:
     Fix event id for action_completed BEP events
   + f0c844c:
     Release 0.19.0 (2018-10-29)
   + c3fb1db:
     Do not use CROSSTOOL to select cc_toolchain
   + 8e28083:
     Windows Add tests for msys gcc toolchain and mingw gcc toolchain
   + fd52341:
     update bazel-toolchains pin to latest release Part of changes to
     allow bazelci to use 0.19.0 configs. RBE toolchain configs at or
     before 0.17.0 are not compatible with bazel 0.19.0 or above.

Important changes:
- Fix regression #6610, which prevents using the MINGW compiler on Windows.
katre added a commit that referenced this issue Nov 13, 2018
Baseline: ac88041

Cherry picks:

   + 9bc3b20:
     Fix the "nojava" platform and enable full presubmit checks for
     the various JDK platforms now that we have enough GCE resources.
   + 54c2572:
     Add openjdk_linux_archive java_toolchain for nojava platform.
   + 20bfdc6:
     Automated rollback of commit
     19a401c.
   + 914b4ce:
     Windows: Fix Precondition check for addDynamicInputLinkOptions
   + 83d406b:
     Windows, test-setup.sh: Setting RUNFILES_MANIFEST_FILE only when
     it exists.
   + e025726:
     Update turbine
   + 5f312dd:
     Fix event id for action_completed BEP events
   + f0c844c:
     Release 0.19.0 (2018-10-29)
   + c3fb1db:
     Do not use CROSSTOOL to select cc_toolchain
   + 8e28083:
     Windows Add tests for msys gcc toolchain and mingw gcc toolchain
   + fd52341:
     update bazel-toolchains pin to latest release Part of changes to
     allow bazelci to use 0.19.0 configs. RBE toolchain configs at or
     before 0.17.0 are not compatible with bazel 0.19.0 or above.

Important changes:
- Fix regression #6610, which prevents using the MINGW compiler on Windows.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.