Skip to content

Commit 8cfab5d

Browse files
committed
[Windows build] Use "DIA SDK" in sysroot
This updates llvm/utils/sysroot.py to include the "DIA SDK" folder in the sysroot. It also updates the build to look for the DIA SDK there if a sysroot is set. This requires moving LLVM_WINSYSROOT to config-ix.cmake. For the GN build, I chose to pass a qualified path to diaguids in libs instead of pushing a config with a `/libpath:` flag. The former requires a GN with https://gn-review.googlesource.com/c/gn/+/12200, the latter requires D109624. The former is more like the cmake build, arguably a bit simpler, and it's easier to check for the wrong GN revision and easier to update GN. Differential Revision: https://reviews.llvm.org/D109708
1 parent f78f613 commit 8cfab5d

File tree

6 files changed

+54
-14
lines changed

6 files changed

+54
-14
lines changed

compiler-rt/cmake/config-ix.cmake

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,8 +564,19 @@ else()
564564
endif()
565565

566566
if (MSVC)
567+
# Allow setting clang-cl's /winsysroot flag.
568+
set(LLVM_WINSYSROOT "" CACHE STRING
569+
"If set, argument to clang-cl's /winsysroot")
570+
571+
if (LLVM_WINSYSROOT)
572+
set(MSVC_DIA_SDK_DIR "${LLVM_WINSYSROOT}/DIA SDK" CACHE PATH
573+
"Path to the DIA SDK")
574+
else()
575+
set(MSVC_DIA_SDK_DIR "$ENV{VSINSTALLDIR}DIA SDK" CACHE PATH
576+
"Path to the DIA SDK")
577+
endif()
578+
567579
# See if the DIA SDK is available and usable.
568-
set(MSVC_DIA_SDK_DIR "$ENV{VSINSTALLDIR}DIA SDK")
569580
if (IS_DIRECTORY ${MSVC_DIA_SDK_DIR})
570581
set(CAN_SYMBOLIZE 1)
571582
else()

llvm/cmake/config-ix.cmake

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -503,10 +503,19 @@ if( MSVC )
503503
set(stricmp "_stricmp")
504504
set(strdup "_strdup")
505505

506-
# See if the DIA SDK is available and usable.
507-
set(MSVC_DIA_SDK_DIR "$ENV{VSINSTALLDIR}DIA SDK" CACHE PATH
508-
"Path to the DIA SDK")
506+
# Allow setting clang-cl's /winsysroot flag.
507+
set(LLVM_WINSYSROOT "" CACHE STRING
508+
"If set, argument to clang-cl's /winsysroot")
509509

510+
if (LLVM_WINSYSROOT)
511+
set(MSVC_DIA_SDK_DIR "${LLVM_WINSYSROOT}/DIA SDK" CACHE PATH
512+
"Path to the DIA SDK")
513+
else()
514+
set(MSVC_DIA_SDK_DIR "$ENV{VSINSTALLDIR}DIA SDK" CACHE PATH
515+
"Path to the DIA SDK")
516+
endif()
517+
518+
# See if the DIA SDK is available and usable.
510519
# Due to a bug in MSVC 2013's installation software, it is possible
511520
# for MSVC 2013 to write the DIA SDK into the Visual Studio 2012
512521
# install directory. If this happens, the installation is corrupt

llvm/cmake/modules/HandleLLVMOptions.cmake

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,9 +458,6 @@ if( MSVC )
458458
-D_UNICODE
459459
)
460460

461-
# Allow setting clang-cl's /winsysroot flag.
462-
set(LLVM_WINSYSROOT "" CACHE STRING
463-
"If set, argument to clang-cl's /winsysroot")
464461
if (LLVM_WINSYSROOT)
465462
if (NOT CLANG_CL)
466463
message(ERROR "LLVM_WINSYSROOT requires clang-cl")

llvm/utils/gn/secondary/llvm/lib/DebugInfo/PDB/BUILD.gn

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import("//llvm/lib/DebugInfo/PDB/enable_dia.gni")
2+
import("//llvm/utils/gn/build/sysroot.gni")
23

34
static_library("PDB") {
45
output_name = "LLVMDebugInfoPDB"
@@ -122,6 +123,22 @@ static_library("PDB") {
122123
"DIA/DIASourceFile.cpp",
123124
"DIA/DIATable.cpp",
124125
]
125-
libs = [ "diaguids.lib" ]
126+
127+
dia_lib_path = ""
128+
if (sysroot != "") {
129+
assert(gn_version >= 1937,
130+
"Building with sysroot and DIA requires a newer GN. " +
131+
"Run `python3 llvm\utils\gn\get.py` to update.")
132+
include_dirs = [ "$sysroot/DIA SDK/include" ]
133+
dia_lib_path = "$sysroot/DIA SDK/lib/" # x86 .lib file is here.
134+
if (current_cpu == "arm") {
135+
dia_lib_path += "arm/"
136+
} else if (current_cpu == "arm64") {
137+
dia_lib_path += "arm64/"
138+
} else if (current_cpu == "x64") {
139+
dia_lib_path += "amd64/"
140+
}
141+
}
142+
libs = [ "${dia_lib_path}diaguids.lib" ]
126143
}
127144
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
declare_args() {
22
# Whether to build code that requires the Microsoft DIA SDK.
33
# If this is set, %INCLUDE% must contain ".../DIA SDK/include"
4-
# and %LIB% must contain ".../DIA SDK/lib/amd64".
4+
# and %LIB% must contain ".../DIA SDK/lib/amd64". Or use
5+
# llvm/utils/sysroot.py and set sysroot in args.gn.
56
llvm_enable_dia_sdk = false
67
}

llvm/utils/sysroot.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,19 @@ def cmdout(cmd):
1313
return subprocess.check_output(cmd).decode(sys.stdout.encoding).strip()
1414

1515
if sys.platform == 'win32':
16+
def mkjunction(dst, src):
17+
subprocess.check_call(['mklink', '/j', dst, src], shell=True)
18+
19+
os.mkdir(out_dir)
1620
p = os.getenv('ProgramFiles(x86)', 'C:\\Program Files (x86)')
1721

1822
winsdk = os.getenv('WindowsSdkDir')
1923
if not winsdk:
2024
winsdk = os.path.join(p, 'Windows Kits', '10')
2125
print('%WindowsSdkDir% not set. You might want to run this from')
2226
print('a Visual Studio cmd prompt. Defaulting to', winsdk)
27+
os.mkdir(os.path.join(out_dir, 'Windows Kits'))
28+
mkjunction(os.path.join(out_dir, 'Windows Kits', '10'), winsdk)
2329

2430
vswhere = os.path.join(
2531
p, 'Microsoft Visual Studio', 'Installer', 'vswhere')
@@ -28,13 +34,12 @@ def cmdout(cmd):
2834
[vswhere, '-latest', '-products', '*', '-requires', vcid,
2935
'-property', 'installationPath'])
3036

31-
def mkjunction(dst, src):
32-
subprocess.check_call(['mklink', '/j', dst, src], shell=True)
33-
os.mkdir(out_dir)
3437
mkjunction(os.path.join(out_dir, 'VC'),
3538
os.path.join(vsinstalldir, 'VC'))
36-
os.mkdir(os.path.join(out_dir, 'Windows Kits'))
37-
mkjunction(os.path.join(out_dir, 'Windows Kits', '10'), winsdk)
39+
# Not all MSVC versions ship the DIA SDK, so the junction destination
40+
# might not exist. That's fine.
41+
mkjunction(os.path.join(out_dir, 'DIA SDK'),
42+
os.path.join(vsinstalldir, 'DIA SDK'))
3843
elif sys.platform == 'darwin':
3944
# The SDKs used by default in compiler-rt/cmake/base-config-ix.cmake.
4045
# COMPILER_RT_ENABLE_IOS defaults to on.

0 commit comments

Comments
 (0)