HomePhabricator

clang-cl: Invent a /winsysroot concept

Authored by thakis on Jan 27 2021, 8:01 AM.

Description

clang-cl: Invent a /winsysroot concept

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 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.

This adds a new /winsysroot <dir> flag that's effectively an alias to
these two flags. With this, building against a hermetic Windows
toolchain only needs:

out/gn/bin/clang-cl win.c -fuse-ld=lld /winsysroot path

/winsysroot <dir> is the same as adding

/vctoolsdir <dir>/VC/Tools/MSVC/<vctoolsver>
/winsdkdir <dir>/Windows Kits/<winsdkmajorversion>

<vctoolsver> is taken from /vctoolsversion if passed, or else it's
the name of the directory in <dir>/VC/Tools/MSVC that's the highest
numeric tuple.

<winsdkmajorversion> is the major version in /winsdkversion if passed,
else it's the name of the directory in <dir>/Windows Kits that's the
highest number.

So /winsysroot <path> requires this subfolder structure:

path/
  VC/
    Tools/
      MSVC/
        14.26.28801  (or another number)
          include/
          ...
  Windows Kits/
    10/
      Include/
        10.0.19041.0/ (or another number)
          um/
          ...
      Lib/
        10.0.19041.0/ (or another number)
          um/
            x64/
            ...
          ...

Differential Revision: https://reviews.llvm.org/D95534

Details