This is an archive of the discontinued LLVM Phabricator instance.

[clang-cl] Add a /diasdkdir flag and make /winsysroot imply it
ClosedPublic

Authored by thakis on Sep 15 2021, 7:30 AM.

Details

Summary

D109708 added "DIA SDK" to our win sysroot for hermetic builds
that use LLVM_ENABLE_DIA_SDK. But the build system still has to
manually pass flags pointing to it.

Since we have a /winsysroot flag, make it look at DIA SDK in
the sysroot.

With this, the following is enough to compile the DIA2Dump example:

out\gn\bin\clang-cl ^

"sysroot\DIA SDK\Samples\DIA2Dump\DIA2Dump.cpp" ^
"sysroot\DIA SDK\Samples\DIA2Dump\PrintSymbol.cpp" ^
"sysroot\DIA SDK\Samples\DIA2Dump\regs.cpp" ^
/diasdkdir "sysroot\DIA SDK" ^
ole32.lib oleaut32.lib diaguids.lib

Given that the DIA SDK is part of the MSVC installation (at C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\DIA SDK on my machine), I think there's a case for letting clang-cl know about it. Arguably, adding /I sysroot\DIA SDK\include to your cflags isn't super difficult, but one day we'll teach lld-link about /winsysroot too, and then it means you don't need to know about the lib\ folder layout inside DIA SDK. Also, if you link through clang-cl instead of calling the linker directly, you get that simplification with this change already. That's nice for local one-off commands, but in practice most projects admittedly call link.exe directly.

So all-in-all, I think this is a good idea, but I could be convinced otherwise if others disagree.

Diff Detail

Event Timeline

thakis created this revision.Sep 15 2021, 7:30 AM
thakis requested review of this revision.Sep 15 2021, 7:30 AM
hans added a comment.Sep 15 2021, 11:04 AM

The /winsysroot part makes sense to me, but what's the case for the new /diasdkdir flag?

clang/lib/Driver/ToolChains/MSVC.cpp
66

Maybe move the arch functions up to before visualstudio::Linker::ConstructJob instead?

The file is already kind of organized in that way, with lots of static helper functions on top, and then the implementations of the member functions.

thakis updated this revision to Diff 372782.Sep 15 2021, 1:04 PM
thakis marked an inline comment as done.

move arch functions

The /winsysroot part makes sense to me, but what's the case for the new /diasdkdir flag?

  • If you do have a vcvars shell, you don't need the full sysroot path and it's kind of useful (see example in commit message)
  • it seems nice to be able to explain /winsysroot as combination of other flags in the help text
  • it makes writing the test a bit easier
  • it makes diasdkdir more like the other flags controlled by /winsysroot
clang/lib/Driver/ToolChains/MSVC.cpp
66

Sure, done. The file has a bunch of other static functions all over the place too though :)

hans accepted this revision.Sep 16 2021, 3:25 AM

The /winsysroot part makes sense to me, but what's the case for the new /diasdkdir flag?

  • If you do have a vcvars shell, you don't need the full sysroot path and it's kind of useful (see example in commit message)
  • it seems nice to be able to explain /winsysroot as combination of other flags in the help text
  • it makes writing the test a bit easier
  • it makes diasdkdir more like the other flags controlled by /winsysroot

Okay, sounds good to me.

This revision is now accepted and ready to land.Sep 16 2021, 3:25 AM
This revision was landed with ongoing or failed builds.Sep 16 2021, 4:43 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptSep 16 2021, 4:43 AM