This is an archive of the discontinued LLVM Phabricator instance.

Updated getting started guide for visual studio + cmake
ClosedPublic

Authored by aaron.ballman on May 25 2017, 5:38 AM.

Details

Summary

It took me a while to track this down and I figured I'd save someone else the time. By default, CMake uses the 32-bit toolchain on Windows, even if generating a 64-bit solution. Given the size of LLVM's code base, this can lead to quite a few link errors with the linker running out of memory. If you pass -Thost=x64 when generating the Visual Studio solution, then the resulting project files will use the 64-bit toolchain and the toolchain no longer runs out of memory.

I will add some similar wording to Clang's getting started guide as well.

Diff Detail

Event Timeline

zturner edited edge metadata.May 25 2017, 8:39 AM

Can we just error out if this is not specified and have CMake print the error message? CMAKE_GENERATOR_TOOLSET contains the value at generation time, and we can just check the value and print an error. Given that you can't successfully build LLVM / clang / etc without it, we might as well fail fast.

Can we just error out if this is not specified and have CMake print the error message? CMAKE_GENERATOR_TOOLSET contains the value at generation time, and we can just check the value and print an error. Given that you can't successfully build LLVM / clang / etc without it, we might as well fail fast.

We can successfully build LLVM/clang/etc without it (I've done so for *far* too long), but you may get some sporadic "linker out of memory" errors (recompiles will eventually link, however). Also, not everyone may want to use the native toolset. I'm thinking about people who may have something like 8GB of RAM, where the x86 linker is less likely to throttle the machine than the x64 linker.

Since it does work out of the box, why force users to use an extra command line argument?

Can we just error out if this is not specified and have CMake print the error message? CMAKE_GENERATOR_TOOLSET contains the value at generation time, and we can just check the value and print an error. Given that you can't successfully build LLVM / clang / etc without it, we might as well fail fast.

We can successfully build LLVM/clang/etc without it (I've done so for *far* too long), but you may get some sporadic "linker out of memory" errors (recompiles will eventually link, however). Also, not everyone may want to use the native toolset. I'm thinking about people who may have something like 8GB of RAM, where the x86 linker is less likely to throttle the machine than the x64 linker.

Since it does work out of the box, why force users to use an extra command line argument?

I've never successfully built clang without using the x64 host toolchain. At the very least, I think we should print a warning.

Can we just error out if this is not specified and have CMake print the error message? CMAKE_GENERATOR_TOOLSET contains the value at generation time, and we can just check the value and print an error. Given that you can't successfully build LLVM / clang / etc without it, we might as well fail fast.

We can successfully build LLVM/clang/etc without it (I've done so for *far* too long), but you may get some sporadic "linker out of memory" errors (recompiles will eventually link, however). Also, not everyone may want to use the native toolset. I'm thinking about people who may have something like 8GB of RAM, where the x86 linker is less likely to throttle the machine than the x64 linker.

Since it does work out of the box, why force users to use an extra command line argument?

I've never successfully built clang without using the x64 host toolchain. At the very least, I think we should print a warning.

I've managed it for five years, entirely by accident (and not without frustration, hence the patch), but a warning seems like a reasonable idea.

Now, with CMake warning. This is only needed for the llvm cmake files (since Clang relies on them anyway).

I couldn't find a way to tell if the host system architecture is not 64-bit in CMake (we could skip the diagnostic on 32-bit hosts), so if someone knows a good incantation for that, it could be useful. I was able to find ways if the target architecture is 64-bit, but that's not helpful since a 32-bit host can still target a 64-bit architecture.

zturner accepted this revision.May 25 2017, 1:50 PM

It might be overkill, but CMAKE_HOST_SYSTEM_PROCESSOR probably contains what you need. In any case, lgtm even without doing that.

Presumably you tested this and confirmed that the warning shows up if and only if you don't specify -Thost=x64?

This revision is now accepted and ready to land.May 25 2017, 1:50 PM

It might be overkill, but CMAKE_HOST_SYSTEM_PROCESSOR probably contains what you need. In any case, lgtm even without doing that.

I found that, but it spits out the friendly name of the processor, which I'd have to parse for the pertinent information. That seemed too fragile for my tastes.

Presumably you tested this and confirmed that the warning shows up if and only if you don't specify -Thost=x64?

Yes. In my tests, if you start from a clean build directory and elide the -T entirely, you get a warning. If you specify -T<anything>, you do not get the warning. Once you specify -Thost=x64, if you reconfigure and leave the -T option off, CMAKE_GENERATOR_TOOLSET still retains the host=x64 and the project files are sane.

One thing to note: -Tv140 will use the MSVC 2015 32-bit toolset and not generate a warning here. However, I suspect that if you are specifying the -T flag, you already know what you want to have happen.

aaron.ballman closed this revision.May 25 2017, 2:01 PM

Commit in r303912