This is an archive of the discontinued LLVM Phabricator instance.

Modifies Windows toolchain to prefer link.exe from the MSVC folder rather than PATH and extends capability to implicitly find MSVC 11.0 includes and tools.
Needs ReviewPublic

Authored by kumquats.a.pair on Jun 8 2014, 8:11 AM.
This revision needs review, but there are no reviewers specified.

Details

Reviewers
None
Summary

This patch prevents Clang from calling link.exe that happens to be in the PATH environment variable in favor of the one where MSVC is installed. Clang would commonly call upon "C:\gnuwin32\bin\link.exe"; which is a tool for creating "links" between files on a filesystem, which is probably not the expected behavior.

This patch also adds support for calling on 64-bit MSVC tools when the host process is 64-bit.

This patch also extends the support for implicitly finding MSVC 11.0 includes in the same way it does for MSVC 9.0 and 10.0. It also corrects the path for 64-bit machines.

Diff Detail

Event Timeline

kumquats.a.pair retitled this revision from to Modifies Windows toolchain to prefer link.exe from the MSVC folder rather than PATH and extends capability to implicitly find MSVC 11.0 includes and tools..
kumquats.a.pair updated this object.
kumquats.a.pair edited the test plan for this revision. (Show Details)
kumquats.a.pair added a subscriber: Unknown Object (MLST).Jun 8 2014, 8:15 AM

Hello, I have created a patch located here: http://reviews.llvm.org/D4061

Please review at your convenience.

Summary:
This patch prevents Clang from calling link.exe that happens to be in the PATH environment variable in favor of the one where MSVC is installed. Clang would commonly call upon "C:\gnuwin32\bin\link.exe"; which is a tool for creating "links" between files on a filesystem, which is probably not the expected behavior.

This patch also adds support for calling on 64-bit MSVC tools when the host process is 64-bit.

This patch also extends the support for implicitly finding MSVC 11.0 includes in the same way it does for MSVC 9.0 and 10.0. It also corrects the path for 64-bit machines.

rnk added a subscriber: rnk.Jun 9 2014, 11:06 AM

IMO we have to trust PATH before we start looking in hardcoded places. The expectation is that the user will be running clang from a vcvars.bat shell, which is one that has INCLUDE, LIB, and PATH all set to point to the version of VS they wanted, which could be one of the many CTPs that we don't have listed here.

This is a real use case, it's how I test Clang with different versions of VS. :)

rnk added a comment.Jun 9 2014, 11:07 AM

We can definitely apply the rest of the changes, though.

rnk added a comment.Jun 9 2014, 11:08 AM

Other idea: do a PATH search to find the next cl.exe, and use the link.exe in that directory. Usually they are co-located.

In D4061#4, @rnk wrote:

IMO we have to trust PATH before we start looking in hardcoded places. The expectation is that the user will be running clang from a vcvars.bat shell, which is one that has INCLUDE, LIB, and PATH all set to point to the version of VS they wanted, which could be one of the many CTPs that we don't have listed here.

This is a real use case, it's how I test Clang with different versions of VS. :)

I agree with you. Something like vcvars.bat is also essential to running cl.exe correctly. Does Clang like to behave more like cl.exe when the host is Windows and using the Windows toolchain? Or would it prefer to emulate GCC or other similar compiler and make some assumptions regarding paths? Is there a need for consistency?

rnk added a comment.Jun 9 2014, 12:02 PM

Yes, Clang will try to behave like MSVC, unless you are using the MinGW triple, in which case we try to behave like GCC.