Bug 100201 - Windows scons build with MSVC toolchain and LLVM 4.0 fails
Summary: Windows scons build with MSVC toolchain and LLVM 4.0 fails
Status: RESOLVED FIXED
Alias: None
Product: Mesa
Classification: Unclassified
Component: Mesa core (show other bugs)
Version: 17.0
Hardware: All Windows (All)
: medium major
Assignee: mesa-dev
QA Contact: mesa-dev
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-03-14 16:39 UTC by Anonymous Helper
Modified: 2017-08-30 07:35 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments
Build output. (49.29 KB, text/plain)
2017-03-14 16:39 UTC, Anonymous Helper
Details
Complete MSVC 2015 build log with LLVM 4.0 of Mesa 17.0.2 (72.41 KB, text/plain)
2017-03-25 10:41 UTC, Alex Granni
Details
17.0.2 build with LLVM 4.0 after xtime patch, OpenSWR excluded, link error with unresolved symbols (75.88 KB, text/plain)
2017-03-28 09:00 UTC, Anonymous Helper
Details
llvmpipe 17.0.2 with xtime patch 32-bit build log with LLVM 4.0 using MSVC 2015 toolset for both (75.78 KB, text/plain)
2017-03-30 10:14 UTC, Anonymous Helper
Details
OpenSWR 17.0.2 with xtime patch 32-bit build log with LLVM 4.0 using MSVC 2015 toolset for both (87.02 KB, text/plain)
2017-03-30 10:17 UTC, Anonymous Helper
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Anonymous Helper 2017-03-14 16:39:49 UTC
Created attachment 130219 [details]
Build output.

llvmpipe build is broken again with newest LLVM release - 4.0.
Comment 1 Jose Fonseca 2017-03-15 22:44:28 UTC
Log shows that the problem is not LLVM 4.0 per se, but rather MSVC 2017 headers:

 C:\Software\Development\projects\mesa\mesa\include\c11/threads.h(44): error C2011: 'xtime': 'struct' type redefinition
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.10.25017\include\thr/xtimec.h(20): note: see declaration of 'xtime'

It seems that MSVC 2017 already defines.

But I don't understand how your building with MSVC 2017 given bug 100202.  I wonder if you're running MSVC 2017 vcvars, but then building with 2015?
Comment 2 Anonymous Helper 2017-03-16 10:04:50 UTC
After discovering 100202 I worked around by installing the optional Visual Studio 2015.3 toolchain. When releasing a new version of Visual Studio, Microsoft provides the previous version toolchain as an optional component for compatibility reasons.

You are right about the issue being slightly different with Visual Studio 2015.
Here is a log from before VS 2017

https://www.phoronix.com/forums/forum/linux-graphics-x-org-drivers/opengl-vulkan-mesa-gallium3d/936368-mesa3d-17-and-llvm-4-0-windows-build-with-scons-and-visual-studio-fails
Comment 3 Alex Granni 2017-03-25 10:41:41 UTC
Created attachment 130447 [details]
Complete MSVC 2015 build log with LLVM 4.0 of Mesa 17.0.2
Comment 4 Anonymous Helper 2017-03-27 20:04:22 UTC
These changes in mesa code in include/c11/threads.h solve both undefined and redefinition errors with xtime with MSVC 2015 and 2017, but compilation still fails in the end during linking due to unresolved symbols.

 #include <time.h>
+#if _MSC_VER >= 1900
+#include <thr/xtimec.h>
+#endif


+#if _MSC_VER < 1900
 struct xtime {
     time_t sec;
     long nsec;
 };
 typedef struct xtime xtime;
+#endif


Jose Fonseca, warned me in a previous comment that I was using MSVC 2017 toolset, but it turns out that if I install the optional MSVC 2015 Update 3 toolset for MSVC 2017, Scons can use either toolset just fine.
Comment 5 Anonymous Helper 2017-03-28 08:57:47 UTC
After applying the patch from above over 17.0.2 release (it works over master too, I only noticed minor indent changes in master, no actual functional changes on that header), I got unresolved symbols during link phase.
Comment 6 Anonymous Helper 2017-03-28 09:00:59 UTC
Created attachment 130496 [details]
17.0.2 build with LLVM 4.0 after xtime patch, OpenSWR excluded, link error with unresolved symbols
Comment 7 Jose Fonseca 2017-03-28 21:39:07 UTC
The links errors are possibly due to Mesa and LLVM not being built exactly with the same compiler as Mesa, no?

Or perhaps we need to update mesa/scons/llvm.py with a special case for LLVM 4.0 with additional libraries?


I installed all the MSVC components, but still haven't figured out how to repro the build logs you attached.


At any rate, your xtime fix is on the right track.  So I tweaked a bit and pushed it.
Comment 8 Anonymous Helper 2017-03-29 09:02:04 UTC
(In reply to Jose Fonseca from comment #7)
> The links errors are possibly due to Mesa and LLVM not being built exactly
> with the same compiler as Mesa, no?
LLVM 4.0 was built with MSVC 2017 toolset. I get linker errors regardless of what toolset I use to build Mesa (MSVC 2015 or 2017). Building LLVM with MSVC 2015 toolset requires the whole Viual Studio 2015 because CMake uses Msbuild tool which backward compatibility toolsets like MSVC 2015 toolset on MSVC 2017 don't have access to. With Mesa on the other hand using Scons which is an alternative to Msbuild I can get away, by just using the toolset. I'd rather wait for this to be fixed, then reinstalling Visual Studio 2015 to see if it works, it was horribly bloated, forcing me to install .NET and Azure SDKs just to tell everything is up-to-date although I never used them.    
> Or perhaps we need to update mesa/scons/llvm.py with a special case for LLVM
> 4.0 with additional libraries?
> 
> 
> I installed all the MSVC components, but still haven't figured out how to
> repro the build logs you attached.
> 
> 
> At any rate, your xtime fix is on the right track.  So I tweaked a bit and
> pushed it.

The log I posted in all attachments is from this script:
https://github.com/pal1000/mesa-dist-win/tree/master/buildscript
Comment 9 Jose Fonseca 2017-03-29 10:20:22 UTC
(In reply to Anonymous Helper from comment #8)
> (In reply to Jose Fonseca from comment #7)
> > The links errors are possibly due to Mesa and LLVM not being built exactly
> > with the same compiler as Mesa, no?
> LLVM 4.0 was built with MSVC 2017 toolset. I get linker errors regardless of
> what toolset I use to build Mesa (MSVC 2015 or 2017). Building LLVM with
> MSVC 2015 toolset requires the whole Viual Studio 2015 because CMake uses
> Msbuild tool which backward compatibility toolsets like MSVC 2015 toolset on
> MSVC 2017 don't have access to. 

FWIW, you can use also use CMake with Ninja which enables you to use any vcvarsall.bat file you want.  The process there

  call path\to\vcvarsall.bat
  cmake -G Ninja -Hpath\to\llvm-src -Bpath\to\llvm-bld ...
  ninja -C path\to\llvm-bld

> The log I posted in all attachments is from this script:
> https://github.com/pal1000/mesa-dist-win/tree/master/buildscript

Thanks.
Comment 10 Anonymous Helper 2017-03-30 10:10:53 UTC
Thanks, for the suggestion on how to build LLVM 4.0 with MSVC 2015 toolset when having Visual Studio 2017 installed, unfortunately it didn't help. Building both LLVM 4.0 and Mesa 17.0.2 with C11 threads patch with MSVC 2015 toolset leads to similar link error with same LLVM library. I always tried 32-bit builds when using LLVM 4.0, haven't tried 64-bit yet. Below are the logs from 2 attempts (with OpenSWR and without). I updated my build script to support Ninja build system:
https://raw.githubusercontent.com/pal1000/mesa-dist-win/d55a0657b8e6f537c21e322a76c13f657d0cdcc2/buildscript/build.cmd
Unfortunately, I could not include in the log the LLVM build. it was too late, had to stop after LLVM build completed, now re-ran the script skipping straight to Mesa build.
Comment 11 Anonymous Helper 2017-03-30 10:14:03 UTC
Created attachment 130561 [details]
llvmpipe 17.0.2 with xtime patch 32-bit build log with LLVM 4.0 using MSVC 2015 toolset for both
Comment 12 Anonymous Helper 2017-03-30 10:17:25 UTC
Created attachment 130562 [details]
OpenSWR 17.0.2 with xtime patch 32-bit build log with LLVM 4.0 using MSVC 2015 toolset for both
Comment 13 Anonymous Helper 2017-05-10 19:20:46 UTC
Fixed with this patch:
https://patchwork.freedesktop.org/patch/153385 part of Mesa 17.1. Closing.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct.