@@ -63,6 +63,61 @@ using namespace clang::driver::tools;
63
63
using namespace clang ;
64
64
using namespace llvm ::opt;
65
65
66
+ // Windows SDKs and VC Toolchains group their contents into subdirectories based
67
+ // on the target architecture. This function converts an llvm::Triple::ArchType
68
+ // to the corresponding subdirectory name.
69
+ static const char *llvmArchToWindowsSDKArch (llvm::Triple::ArchType Arch) {
70
+ using ArchType = llvm::Triple::ArchType;
71
+ switch (Arch) {
72
+ case ArchType::x86:
73
+ return " x86" ;
74
+ case ArchType::x86_64:
75
+ return " x64" ;
76
+ case ArchType::arm:
77
+ return " arm" ;
78
+ case ArchType::aarch64:
79
+ return " arm64" ;
80
+ default :
81
+ return " " ;
82
+ }
83
+ }
84
+
85
+ // Similar to the above function, but for Visual Studios before VS2017.
86
+ static const char *llvmArchToLegacyVCArch (llvm::Triple::ArchType Arch) {
87
+ using ArchType = llvm::Triple::ArchType;
88
+ switch (Arch) {
89
+ case ArchType::x86:
90
+ // x86 is default in legacy VC toolchains.
91
+ // e.g. x86 libs are directly in /lib as opposed to /lib/x86.
92
+ return " " ;
93
+ case ArchType::x86_64:
94
+ return " amd64" ;
95
+ case ArchType::arm:
96
+ return " arm" ;
97
+ case ArchType::aarch64:
98
+ return " arm64" ;
99
+ default :
100
+ return " " ;
101
+ }
102
+ }
103
+
104
+ // Similar to the above function, but for DevDiv internal builds.
105
+ static const char *llvmArchToDevDivInternalArch (llvm::Triple::ArchType Arch) {
106
+ using ArchType = llvm::Triple::ArchType;
107
+ switch (Arch) {
108
+ case ArchType::x86:
109
+ return " i386" ;
110
+ case ArchType::x86_64:
111
+ return " amd64" ;
112
+ case ArchType::arm:
113
+ return " arm" ;
114
+ case ArchType::aarch64:
115
+ return " arm64" ;
116
+ default :
117
+ return " " ;
118
+ }
119
+ }
120
+
66
121
static bool canExecute (llvm::vfs::FileSystem &VFS, StringRef Path) {
67
122
auto Status = VFS.status (Path);
68
123
if (!Status)
@@ -396,6 +451,20 @@ void visualstudio::Linker::ConstructJob(Compilation &C, const JobAction &JA,
396
451
// the environment variable is set however, assume the user knows what
397
452
// they're doing. If the user passes /vctoolsdir or /winsdkdir, trust that
398
453
// over env vars.
454
+ if (const Arg *A = Args.getLastArg (options::OPT__SLASH_diasdkdir,
455
+ options::OPT__SLASH_winsysroot)) {
456
+ // cl.exe doesn't find the DIA SDK automatically, so this too requires
457
+ // explicit flags and doesn't automatically look in "DIA SDK" relative
458
+ // to the path we found for VCToolChainPath.
459
+ llvm::SmallString<128 > DIAPath (A->getValue ());
460
+ if (A->getOption ().getID () == options::OPT__SLASH_winsysroot)
461
+ llvm::sys::path::append (DIAPath, " DIA SDK" );
462
+
463
+ // The DIA SDK always uses the legacy vc arch, even in new MSVC versions.
464
+ llvm::sys::path::append (DIAPath, " lib" ,
465
+ llvmArchToLegacyVCArch (TC.getArch ()));
466
+ CmdArgs.push_back (Args.MakeArgString (Twine (" -libpath:" ) + DIAPath));
467
+ }
399
468
if (!llvm::sys::Process::GetEnv (" LIB" ) ||
400
469
Args.getLastArg (options::OPT__SLASH_vctoolsdir,
401
470
options::OPT__SLASH_winsysroot)) {
@@ -752,61 +821,6 @@ void MSVCToolChain::printVerboseInfo(raw_ostream &OS) const {
752
821
RocmInstallation.print (OS);
753
822
}
754
823
755
- // Windows SDKs and VC Toolchains group their contents into subdirectories based
756
- // on the target architecture. This function converts an llvm::Triple::ArchType
757
- // to the corresponding subdirectory name.
758
- static const char *llvmArchToWindowsSDKArch (llvm::Triple::ArchType Arch) {
759
- using ArchType = llvm::Triple::ArchType;
760
- switch (Arch) {
761
- case ArchType::x86:
762
- return " x86" ;
763
- case ArchType::x86_64:
764
- return " x64" ;
765
- case ArchType::arm:
766
- return " arm" ;
767
- case ArchType::aarch64:
768
- return " arm64" ;
769
- default :
770
- return " " ;
771
- }
772
- }
773
-
774
- // Similar to the above function, but for Visual Studios before VS2017.
775
- static const char *llvmArchToLegacyVCArch (llvm::Triple::ArchType Arch) {
776
- using ArchType = llvm::Triple::ArchType;
777
- switch (Arch) {
778
- case ArchType::x86:
779
- // x86 is default in legacy VC toolchains.
780
- // e.g. x86 libs are directly in /lib as opposed to /lib/x86.
781
- return " " ;
782
- case ArchType::x86_64:
783
- return " amd64" ;
784
- case ArchType::arm:
785
- return " arm" ;
786
- case ArchType::aarch64:
787
- return " arm64" ;
788
- default :
789
- return " " ;
790
- }
791
- }
792
-
793
- // Similar to the above function, but for DevDiv internal builds.
794
- static const char *llvmArchToDevDivInternalArch (llvm::Triple::ArchType Arch) {
795
- using ArchType = llvm::Triple::ArchType;
796
- switch (Arch) {
797
- case ArchType::x86:
798
- return " i386" ;
799
- case ArchType::x86_64:
800
- return " amd64" ;
801
- case ArchType::arm:
802
- return " arm" ;
803
- case ArchType::aarch64:
804
- return " arm64" ;
805
- default :
806
- return " " ;
807
- }
808
- }
809
-
810
824
// Get the path to a specific subdirectory in the current toolchain for
811
825
// a given target architecture.
812
826
// VS2017 changed the VC toolchain layout, so this should be used instead
@@ -1263,6 +1277,19 @@ void MSVCToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
1263
1277
AddSystemIncludesFromEnv (Var);
1264
1278
}
1265
1279
1280
+ // Add DIA SDK include if requested.
1281
+ if (const Arg *A = DriverArgs.getLastArg (options::OPT__SLASH_diasdkdir,
1282
+ options::OPT__SLASH_winsysroot)) {
1283
+ // cl.exe doesn't find the DIA SDK automatically, so this too requires
1284
+ // explicit flags and doesn't automatically look in "DIA SDK" relative
1285
+ // to the path we found for VCToolChainPath.
1286
+ llvm::SmallString<128 > DIASDKPath (A->getValue ());
1287
+ if (A->getOption ().getID () == options::OPT__SLASH_winsysroot)
1288
+ llvm::sys::path::append (DIASDKPath, " DIA SDK" );
1289
+ AddSystemIncludeWithSubfolder (DriverArgs, CC1Args, std::string (DIASDKPath),
1290
+ " include" );
1291
+ }
1292
+
1266
1293
if (DriverArgs.hasArg (options::OPT_nostdlibinc))
1267
1294
return ;
1268
1295
0 commit comments