[PATCH] D95534: clang-cl: Invent a /winsysroot concept

Nico Weber via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 27 08:15:18 PST 2021


thakis created this revision.
thakis added a reviewer: hans.
Herald added subscribers: dang, pengfei.
Herald added a reviewer: jansvoboda11.
thakis requested review of this revision.

On non-Windows platforms, --sysroot can be used to make the compiler use
a single, hermetic directory for all header and library files.

This is useful, but difficult to do on Windows. After D95472 <https://reviews.llvm.org/D95472> it's
possible to achieve this with two flags:

  out/gn/bin/clang-cl win.c -fuse-ld=lld \
      /vctoolsdir path/to/VC/Tools/MSVC/14.26.28801 \
      /winsdkdir path/to/win_sdk

But that's still cumbersome: It requires two flags instead of one, and
it requires writing down the (changing) VC/Tools/MSVC version.

Require a new /winsysroot <dir> flag that's effectively an alias to these two
flags. `/winsysroot <dir>` is effetively an alias for these two flags.

It adds `/vctoolsdir <dir>/VC/Tools/MSVC/<vctoolsversion>`, where
<vctoolsversion> is the subdirectory of VC/Tools/MSVC with the highest
number. (This also adds a flag /vctoolsversion to explicitly set that
version for full determinism, similar to /winsdkversion>).
Given that %VCToolsInstallDir% is something like
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.25.28610\"
looking at VC/Tools/... below /winsysroot seems like an obvious choice.

%WindowsSDKDir% and %UniversalCRTDir% both expand to
"C:\Program Files (x86)\Windows Kits\10\", so it's less obvious
an what subdirectory /winsdkdir should be below the sysroot.
"Windows Kits/10" has the drawback that it contains a space and
yet another number. Ideally the contents of that directory
would be available under some short name, so I went with
`/winsdkdir <dir>/win_sdk`. I'm not married to this though.
Maybe `<dir>/WinSdk` looks move like `VC/Tools/MSVC`?

---

This is missing the actual code change for now. I figured I'd send out the CL description early so we can get a head start on discussing the path names.


https://reviews.llvm.org/D95534

Files:
  clang/include/clang/Driver/Options.td


Index: clang/include/clang/Driver/Options.td
===================================================================
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -5762,10 +5762,15 @@
 def _SLASH_TP : CLCompileFlag<"TP">, HelpText<"Treat all source files as C++">;
 def _SLASH_vctoolsdir : CLJoinedOrSeparate<"vctoolsdir">,
   HelpText<"Path to the VCToolChain">, MetaVarName<"<dir>">;
+def _SLASH_vctoolsversion : CLJoinedOrSeparate<"vctoolsversion">,
+  HelpText<"For use with /winsysroot, defaults to newest found">;
 def _SLASH_winsdkdir : CLJoinedOrSeparate<"winsdkdir">,
   HelpText<"Path to the Windows SDK">, MetaVarName<"<dir>">;
 def _SLASH_winsdkversion : CLJoinedOrSeparate<"winsdkversion">,
-  HelpText<"Full version of the Windows SDK">;
+  HelpText<"Full version of the Windows SDK, defaults to newest found">;
+def _SLASH_winsysroot : CLJoinedOrSeparate<"winsysroot">,
+  HelpText<"Same as /vctoolsdir<dir>/VC/Tools/MSVC/<vctoolsversion> /winsdkdir<dir>/win_sdk">,
+  MetaVarName<"<dir>">;
 def _SLASH_volatile_iso : Option<["/", "-"], "volatile:iso", KIND_FLAG>,
   Group<_SLASH_volatile_Group>, Flags<[CLOption, NoXarchOption]>,
   HelpText<"Volatile loads and stores have standard semantics">;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95534.319586.patch
Type: text/x-patch
Size: 1250 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210127/fa6b5312/attachment-0001.bin>


More information about the cfe-commits mailing list