<div dir="ltr"><div>I'm kind of imagining this world where we have one VS Integration that works no matter what version of LLVM you have.  The nice thing about this is that it allows it to work with hermetic toolchains, older versions of LLVM that may already be installed on a user's machine, local dev builds of LLVM, etc.</div><div><br></div>The only maintenance burden I can think of is one where we remove or add flags in clang-cl, which doesn't happen very often, if ever.  Any flag that is added to MSVC doesn't require any action from us.<div><br></div><div>I plan to expose a UI for optimizations and warning, so I could see a maintenace burden when we add new -W or -f flags that are not exposed to the UI.  But those can still be specified via additional compiler flags.  And the maintenance burden is actually less than coupling it to the installed toolchain because we can do it at our leisure, rather than being pressed to get it done by a release.</div><div><br></div><div>One thing I could maybe do to lower the maintenance burden a little is to try to have some better logic for detecting the clang version.  We were already using the registry before anyway to find the installed LLVM, maybe there's a way for me to just figure out the version without the additional registry value.  I'll have to look into that though.<br><div><br></div><div><div><br><div class="gmail_quote"><div dir="ltr">On Thu, Feb 1, 2018 at 11:09 AM Zachary Turner <<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="gmail_quote"><div dir="auto">On Thu, Feb 1, 2018 at 10:48 AM Hans Wennborg via Phabricator <<a href="mailto:reviews@reviews.llvm.org" target="_blank">reviews@reviews.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">hans added inline comments.<br>
<br>
<br>
================<br>
Comment at: llvm/tools/msbuild/Clang.Cpp.Common.props:41<br>
+<br>
+    <!-- The registry key may not be set if it's an old installer, try the newest version that exists --><br>
+    <LLVMVersion Condition="'$(LLVMVersion)' == '' and Exists('$(LLVMInstallDir)\lib\clang\7.0.0')">7.0.0</LLVMVersion><br>
----------------<br>
zturner wrote:<br>
> hans wrote:<br>
> > As I mentioned before, separating the toolset config from the actual toolchain installation makes me a little nervous.<br>
> ><br>
> > But if we're doing it, the version checks below should probably include the .1 versions too, i.e. at least 5.0.1 and 6.0.1.<br>
> Unless we're going to release the full thing including the compiler, linker, etc through the marketplace I don't see an alternative.  In any case, I actually think this it's preferable this way.  There's nothing really about the two that benefits from having them coupled together, as far as I can see.   I'm willing to be convinced though, if we can figure out how to to do it so that we can still ship it on the marketplace.<br>
"There's nothing really about the two that benefits from having them coupled together,"<br>
<br>
The toolset needs to know at least where to find the toolchain and how to invoke it. If we decouple them, there needs to be an interface between them that can't change: in this case the LLVM path and version number in the registry.</blockquote></div></div><div><div class="gmail_quote"><div dir="auto">Has that ever changed?  Doesn’t seem too onerous, using the registry is the windows way anyway, if anything this feels like the proper way.</div></div></div><div><div class="gmail_quote"><div dir="auto"><br></div><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
But at the same time you're baking in all this logic in the toolset about how to invoke the toolchain, what flags are supported, etc. Those things are strongly dependent on the toolchain, which in this de-coupled world seems problematic. It seems like you're actually making the coupling tighter in that way, except you still want to ship the two parts separately.<br>
<br>
Are there restrictions in the marketplace about how big a vsix can be? Because if not, I think we could just package up clang+headers+runtime into a vsix and ship the whole thing, and maybe that would be the best thing.</blockquote></div></div><div><div class="gmail_quote"><div dir="auto">An installer is very large though, and even if it’s allowed it’s kind of obnoxious to have to download a large amount of stuff if only one thing changes.  Being able to push changes to the Integration independently of an llvm release seems like a feature to me.</div><div dir="auto"><br></div><div dir="auto"> coupling it would also make it more difficult to use a custom built llvm toolchain, i can just change a registry setting right now and it’s good to go.  Even the builtin VS toolchains use the registry to locate paths, and we were already reading the registry before this anyway </div></div></div><div><div class="gmail_quote"><div dir="auto"><br></div><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
Or we could just stick to the current installer version and make it a little smarter about finding VS2017. Maybe instead of the batch files we write an actual program that finds the installation and copies the files.</blockquote></div></div><div><div class="gmail_quote"><div dir="auto">I definitely think vsix is the way to go.  I’d hate to stick with batch files and not use the proper method of having an extension.  It’s also more discoverable as an extension on the marketplace.</div></div></div><div><div class="gmail_quote"><div dir="auto"><br></div><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
<br>
================<br>
Comment at: llvm/tools/msbuild/LLVM.props:8<br>
+    <!-- Friendly names added to the PlatformToolset in the property pages. --><br>
+    <_PlatformToolsetFriendlyNameFor_llvm Condition="'$(_PlatformToolsetFriendlyNameFor_llvm)' == ''">Clang for Windows</_PlatformToolsetFriendlyNameFor_llvm><br>
+  </PropertyGroup><br>
----------------<br>
zturner wrote:<br>
> hans wrote:<br>
> > Hmm, we previously intentionally called the toolset "LLVM" with the thinking that it would eventually include lld and designated the complete llvm toolchain, not just Clang. And is the "for Windows" part necessary?<br>
> Do you think there's any value in having a toolset that does Clang+Link and a second one that does Clang+LLD?  Or do you think we should stick with only a single one?  I can change the name to LLVM though.<br>
The best would be to only have one, but where the user could select between the two linkers, I think.</blockquote></div></div><div><div class="gmail_quote"><div dir="auto">Yea.  Can try that in a followup, may be tricky though </div></div></div><div><div class="gmail_quote"><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
<br>
================<br>
Comment at: llvm/tools/msbuild/Toolset.targets:38<br>
+<br>
+    <!-- Warn if Fiber Safe Optimizations are enabled, and then ignore them. --><br>
+    <Warning Condition="'%(ClCompile.EnableFiberSafeOptimizations)' == 'true'"<br>
----------------<br>
zturner wrote:<br>
> hans wrote:<br>
> > This seems to duplicate a lot of logic from clang-cl. It's nice to provide a good UI for the user, but maintaining this seems a lot of work. Are you not concerned that this will rot?<br>
> I don't think it will.  Maybe I'm being overly optimistic here, but the only case we would ever need to maintain this again is if we started supporting these options.  Fiber Safe Optimizations, for example, I'm pretty sure we will never support.  If MSVC ever removes the option, for example, we can do nothing and continue to work.<br>
><br>
> We could also just silently ignore them and just pass the option through to clang-cl, but these are pretty unusual options with pretty specialized use cases, so I feel like if I had gone out of my way to enable such a strange option I would want to know if the compiler was not going to respect it.<br>
I feel pretty strongly that we should handle this clang-cl side. If a flag is not supported, either we should ignore it, or if it's something the user would want to know about us not supporting, we should warn. That's what clang-cl tries to do currently, and if there are flags we don't get right, we should fix it.<br>
<br>
And we do move flags from the unsupported to supported category now and then, so the "only case we would ever need to maintain this again is if we started supporting these options" scenario is real.</blockquote></div></div><div><div class="gmail_quote"><div dir="auto">It’s not a matter of clang-cl doing it right or wrong, it’s that there are other moving parts before it even gets to clang-cl.  Specifically, MSBuild.  We’ve already seen one example of how  just letting clang-cl do its thing is insufficient, and nothing we can ever do in clang-cl can fix that.  Given that it’s required sometimes, and that doing it for all options doesn’t increase our maintenance burden, i think it makes sense to do it everywhere and never have to deal with msbuild issues again.</div></div></div><div><div class="gmail_quote"><div dir="auto"><br></div><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
<br>
================<br>
Comment at: llvm/tools/msbuild/Toolset.targets:46<br>
+             File="@(ClCompile)(0,0)"<br>
+             Text="clang-cl does not support MSVC Link Time Optimization.  Disable this option in compatibility settings to silence this warning."/><br>
+<br>
----------------<br>
zturner wrote:<br>
> hans wrote:<br>
> > But maybe we want clang-cl to map this to -flto one day. Now we need to update two places. And with the toolset/toolchain install split, the two places may be installed separately :-/<br>
> That's even better then.  All we have to do is change this xml, push a new build to the market place, and the VS UI will update their extension for them.<br>
><br>
> Note that we could do the mapping at the MSBuild level, in this file down below where we have an `ItemGroup`.  Just add a line that says `<AdditionalOptions Condition="%(ClCompile.WholeProgramOptimization)' == 'true'>-flto=thin %(AdditionalOptions)</AdditionalOptions>`<br>
><br>
> and we can do this without touching clang.<br>
But the toolset is decoupled from the toolchain in your proposal.<br>
<br>
Not only would we need to update both clang-cl and this file, but this file would need to handle clang-cl versions both before and after.</blockquote></div></div><div><div class="gmail_quote"><div dir="auto">We wouldn’t have to update clang-cl.  We could map ltcg to -flto=thin in the extension and it would automatically work with the installed toolchain.</div></div></div><div><div class="gmail_quote"><div dir="auto"><br></div><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
<br>
================<br>
Comment at: llvm/tools/msbuild/Toolset.targets:83<br>
+<br>
+    <!-- Warn if XML Documentation is generated, and then ignore it. --><br>
+    <Warning Condition="'%(ClCompile.GenerateXMLDocumentationFiles)' == 'true'"<br>
----------------<br>
zturner wrote:<br>
> hans wrote:<br>
> > Keeping up with all these flags seems like a huge amount of work. Why not just let clang-cl ignore it?<br>
> See the large comment at the top of the file.  For some options, we could probably get by with this.  Maybe even this one, I debated on this particular one.<br>
><br>
> My bar was "If the option fundamentally changes assumptions about the way code could be compiled, we should generate an error.  If it changes the behavior of the language in a way we don't support,  changes the way we generate code in a meaningful way, or causes specialized output files to be written, warn, and if it's an option we ignore then drop it"<br>
><br>
> The last category there we could probably just pass through in some cases, but in that comment I also mentioned a case where setting an option that clang-cl ignores impacts MSBuild's ability to figure out dependencies and ends up causing a full rebuild every time even when nothing changed.<br>
><br>
> We can scour the entire cl build tasks and try to discover if any other ones have unintended consequences, but I think it's easier to just turn them off at the MSBuild level.  And as a side benefit, the user gets shorter command lines, which is always nice.<br>
><br>
> As for maintenance, this all looks like zero-maintenance code to me.  Did you have an example in mind of where we'd need to update this?  Whether it be a new VS version, or VS dropping support for one of these options or deprecating them, I don't think we'd have to do anything.<br>
The maintenance would come from when clang-cl changes how it handles some option, or when VS adds new options.</blockquote></div></div><div><div class="gmail_quote"><div dir="auto">But these are all really obscure options that we will probably never touch.  When vc adds new options we’re not obligated to update this file either.</div></div></div><div><div class="gmail_quote"><div dir="auto"><br></div><div dir="auto"><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
<br>
================<br>
Comment at: llvm/tools/msbuild/install.bat:10<br>
+REM Older versions of VS would look for these files in the Program Files\MSBuild directory<br>
+REM but with VS2017 it seems to look for these directly in the Visual Studio instance.<br>
+REM This means we'll need to do a little extra work to properly detect all the various<br>
----------------<br>
zturner wrote:<br>
> hans wrote:<br>
> > Don't we want to support at least 2015 too?<br>
> Mentioned in the other review, but the install.bat file shouldn't really be used anymore except for during development.  The VSIX supports both 2015 and 2017 (I tested it in both and confirmed it works)<br>
Hmm, but then we should delete it, or at least take it out of the installer, and we need a replacement. As it is now, if we land this, it breaks the installer for versions before 2017.</blockquote><div dir="auto"><br></div></div></div><div><div class="gmail_quote"><div dir="auto">I thought i took it out of the installer, but maybe I missed something.  We still need it for dev purposes because it allows us to overwrite the existing installed version with new files</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"></blockquote></div></div></blockquote></div></div></div></div></div>