[compiler-rt] 8cfab5d - [Windows build] Use "DIA SDK" in sysroot
Nico Weber via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 14 06:00:54 PDT 2021
Author: Nico Weber
Date: 2021-09-14T08:59:28-04:00
New Revision: 8cfab5de13a8ec3a2ffccb1b94b0165512a33552
URL: https://github.com/llvm/llvm-project/commit/8cfab5de13a8ec3a2ffccb1b94b0165512a33552
DIFF: https://github.com/llvm/llvm-project/commit/8cfab5de13a8ec3a2ffccb1b94b0165512a33552.diff
LOG: [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
Added:
Modified:
compiler-rt/cmake/config-ix.cmake
llvm/cmake/config-ix.cmake
llvm/cmake/modules/HandleLLVMOptions.cmake
llvm/utils/gn/secondary/llvm/lib/DebugInfo/PDB/BUILD.gn
llvm/utils/gn/secondary/llvm/lib/DebugInfo/PDB/enable_dia.gni
llvm/utils/sysroot.py
Removed:
################################################################################
diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake
index 4d3a5ab3d9d1e..482297a251b4b 100644
--- a/compiler-rt/cmake/config-ix.cmake
+++ b/compiler-rt/cmake/config-ix.cmake
@@ -564,8 +564,19 @@ else()
endif()
if (MSVC)
+ # Allow setting clang-cl's /winsysroot flag.
+ set(LLVM_WINSYSROOT "" CACHE STRING
+ "If set, argument to clang-cl's /winsysroot")
+
+ if (LLVM_WINSYSROOT)
+ set(MSVC_DIA_SDK_DIR "${LLVM_WINSYSROOT}/DIA SDK" CACHE PATH
+ "Path to the DIA SDK")
+ else()
+ set(MSVC_DIA_SDK_DIR "$ENV{VSINSTALLDIR}DIA SDK" CACHE PATH
+ "Path to the DIA SDK")
+ endif()
+
# See if the DIA SDK is available and usable.
- set(MSVC_DIA_SDK_DIR "$ENV{VSINSTALLDIR}DIA SDK")
if (IS_DIRECTORY ${MSVC_DIA_SDK_DIR})
set(CAN_SYMBOLIZE 1)
else()
diff --git a/llvm/cmake/config-ix.cmake b/llvm/cmake/config-ix.cmake
index b590110d344e3..3569c2d1389af 100644
--- a/llvm/cmake/config-ix.cmake
+++ b/llvm/cmake/config-ix.cmake
@@ -503,10 +503,19 @@ if( MSVC )
set(stricmp "_stricmp")
set(strdup "_strdup")
- # See if the DIA SDK is available and usable.
- set(MSVC_DIA_SDK_DIR "$ENV{VSINSTALLDIR}DIA SDK" CACHE PATH
- "Path to the DIA SDK")
+ # Allow setting clang-cl's /winsysroot flag.
+ set(LLVM_WINSYSROOT "" CACHE STRING
+ "If set, argument to clang-cl's /winsysroot")
+ if (LLVM_WINSYSROOT)
+ set(MSVC_DIA_SDK_DIR "${LLVM_WINSYSROOT}/DIA SDK" CACHE PATH
+ "Path to the DIA SDK")
+ else()
+ set(MSVC_DIA_SDK_DIR "$ENV{VSINSTALLDIR}DIA SDK" CACHE PATH
+ "Path to the DIA SDK")
+ endif()
+
+ # See if the DIA SDK is available and usable.
# Due to a bug in MSVC 2013's installation software, it is possible
# for MSVC 2013 to write the DIA SDK into the Visual Studio 2012
# install directory. If this happens, the installation is corrupt
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 6df81f4c6f740..278a38a3b81c7 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -458,9 +458,6 @@ if( MSVC )
-D_UNICODE
)
- # Allow setting clang-cl's /winsysroot flag.
- set(LLVM_WINSYSROOT "" CACHE STRING
- "If set, argument to clang-cl's /winsysroot")
if (LLVM_WINSYSROOT)
if (NOT CLANG_CL)
message(ERROR "LLVM_WINSYSROOT requires clang-cl")
diff --git a/llvm/utils/gn/secondary/llvm/lib/DebugInfo/PDB/BUILD.gn b/llvm/utils/gn/secondary/llvm/lib/DebugInfo/PDB/BUILD.gn
index 35f392b6d6463..07b34d41b9213 100644
--- a/llvm/utils/gn/secondary/llvm/lib/DebugInfo/PDB/BUILD.gn
+++ b/llvm/utils/gn/secondary/llvm/lib/DebugInfo/PDB/BUILD.gn
@@ -1,4 +1,5 @@
import("//llvm/lib/DebugInfo/PDB/enable_dia.gni")
+import("//llvm/utils/gn/build/sysroot.gni")
static_library("PDB") {
output_name = "LLVMDebugInfoPDB"
@@ -122,6 +123,22 @@ static_library("PDB") {
"DIA/DIASourceFile.cpp",
"DIA/DIATable.cpp",
]
- libs = [ "diaguids.lib" ]
+
+ dia_lib_path = ""
+ if (sysroot != "") {
+ assert(gn_version >= 1937,
+ "Building with sysroot and DIA requires a newer GN. " +
+ "Run `python3 llvm\utils\gn\get.py` to update.")
+ include_dirs = [ "$sysroot/DIA SDK/include" ]
+ dia_lib_path = "$sysroot/DIA SDK/lib/" # x86 .lib file is here.
+ if (current_cpu == "arm") {
+ dia_lib_path += "arm/"
+ } else if (current_cpu == "arm64") {
+ dia_lib_path += "arm64/"
+ } else if (current_cpu == "x64") {
+ dia_lib_path += "amd64/"
+ }
+ }
+ libs = [ "${dia_lib_path}diaguids.lib" ]
}
}
diff --git a/llvm/utils/gn/secondary/llvm/lib/DebugInfo/PDB/enable_dia.gni b/llvm/utils/gn/secondary/llvm/lib/DebugInfo/PDB/enable_dia.gni
index 3b655747a4fde..7c1cd3fbc8f30 100644
--- a/llvm/utils/gn/secondary/llvm/lib/DebugInfo/PDB/enable_dia.gni
+++ b/llvm/utils/gn/secondary/llvm/lib/DebugInfo/PDB/enable_dia.gni
@@ -1,6 +1,7 @@
declare_args() {
# Whether to build code that requires the Microsoft DIA SDK.
# If this is set, %INCLUDE% must contain ".../DIA SDK/include"
- # and %LIB% must contain ".../DIA SDK/lib/amd64".
+ # and %LIB% must contain ".../DIA SDK/lib/amd64". Or use
+ # llvm/utils/sysroot.py and set sysroot in args.gn.
llvm_enable_dia_sdk = false
}
diff --git a/llvm/utils/sysroot.py b/llvm/utils/sysroot.py
index 48b52ec712c96..599197dbd0a9e 100755
--- a/llvm/utils/sysroot.py
+++ b/llvm/utils/sysroot.py
@@ -13,6 +13,10 @@ def cmdout(cmd):
return subprocess.check_output(cmd).decode(sys.stdout.encoding).strip()
if sys.platform == 'win32':
+ def mkjunction(dst, src):
+ subprocess.check_call(['mklink', '/j', dst, src], shell=True)
+
+ os.mkdir(out_dir)
p = os.getenv('ProgramFiles(x86)', 'C:\\Program Files (x86)')
winsdk = os.getenv('WindowsSdkDir')
@@ -20,6 +24,8 @@ def cmdout(cmd):
winsdk = os.path.join(p, 'Windows Kits', '10')
print('%WindowsSdkDir% not set. You might want to run this from')
print('a Visual Studio cmd prompt. Defaulting to', winsdk)
+ os.mkdir(os.path.join(out_dir, 'Windows Kits'))
+ mkjunction(os.path.join(out_dir, 'Windows Kits', '10'), winsdk)
vswhere = os.path.join(
p, 'Microsoft Visual Studio', 'Installer', 'vswhere')
@@ -28,13 +34,12 @@ def cmdout(cmd):
[vswhere, '-latest', '-products', '*', '-requires', vcid,
'-property', 'installationPath'])
- def mkjunction(dst, src):
- subprocess.check_call(['mklink', '/j', dst, src], shell=True)
- os.mkdir(out_dir)
mkjunction(os.path.join(out_dir, 'VC'),
os.path.join(vsinstalldir, 'VC'))
- os.mkdir(os.path.join(out_dir, 'Windows Kits'))
- mkjunction(os.path.join(out_dir, 'Windows Kits', '10'), winsdk)
+ # Not all MSVC versions ship the DIA SDK, so the junction destination
+ # might not exist. That's fine.
+ mkjunction(os.path.join(out_dir, 'DIA SDK'),
+ os.path.join(vsinstalldir, 'DIA SDK'))
elif sys.platform == 'darwin':
# The SDKs used by default in compiler-rt/cmake/base-config-ix.cmake.
# COMPILER_RT_ENABLE_IOS defaults to on.
More information about the llvm-commits
mailing list