[llvm] 44ea794 - build: Add LLVM_WINSYSROOT to make setting /winsysroot easy on Win
Nico Weber via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 17 07:29:22 PST 2021
Author: Nico Weber
Date: 2021-02-17T10:27:25-05:00
New Revision: 44ea794cf9ab8590a6abdf6d61622ba85e5ab1bc
URL: https://github.com/llvm/llvm-project/commit/44ea794cf9ab8590a6abdf6d61622ba85e5ab1bc
DIFF: https://github.com/llvm/llvm-project/commit/44ea794cf9ab8590a6abdf6d61622ba85e5ab1bc.diff
LOG: build: Add LLVM_WINSYSROOT to make setting /winsysroot easy on Win
Also add a script for sysroot management. For now, it can only create
fake sysroots that just symlink to local folders. This is useful for
testing.
Differential Revision: https://reviews.llvm.org/D96868
Added:
llvm/utils/sysroot.py
Modified:
llvm/cmake/modules/HandleLLVMOptions.cmake
llvm/utils/gn/build/BUILD.gn
Removed:
################################################################################
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake
index 63fe83af0f02..45b84528d21d 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -431,6 +431,16 @@ 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")
+ endif()
+ append("/winsysroot${LLVM_WINSYSROOT}" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
+ endif()
+
if (LLVM_ENABLE_WERROR)
append("/WX" CMAKE_C_FLAGS CMAKE_CXX_FLAGS)
endif (LLVM_ENABLE_WERROR)
diff --git a/llvm/utils/gn/build/BUILD.gn b/llvm/utils/gn/build/BUILD.gn
index 195f526da6b8..362924a91c35 100644
--- a/llvm/utils/gn/build/BUILD.gn
+++ b/llvm/utils/gn/build/BUILD.gn
@@ -22,6 +22,9 @@ declare_args() {
# The version of host gcc. Ignored if is_clang is true.
gcc_version = 9
+
+ # Path of sysroot to use.
+ sysroot = ""
}
assert(!llvm_build_instrumented_coverage || is_clang,
@@ -281,6 +284,11 @@ config("compiler_defaults") {
]
}
}
+ if (sysroot != "") {
+ assert(current_os == "win", "FIXME: Make sysroot work on non-win")
+ assert(is_clang, "sysroot only works with clang-cl as host compiler")
+ cflags += [ "/winsysroot" + rebase_path(sysroot, root_build_dir) ]
+ }
if (use_ubsan) {
assert(is_clang && current_os == "linux",
diff --git a/llvm/utils/sysroot.py b/llvm/utils/sysroot.py
new file mode 100755
index 000000000000..3acf6bc7a73c
--- /dev/null
+++ b/llvm/utils/sysroot.py
@@ -0,0 +1,66 @@
+#!/usr/bin/env python3
+
+"""Helps manage sysroots."""
+
+import argparse
+import os
+import subprocess
+import sys
+
+
+def make_fake_sysroot(out_dir):
+ def cmdout(cmd):
+ return subprocess.check_output(cmd).decode(sys.stdout.encoding).strip()
+
+ if sys.platform == 'win32':
+ p = os.getenv('ProgramFiles(x86)', 'C:\\Program Files (x86)')
+
+ winsdk = os.getenv('WindowsSdkDir')
+ if not winsdk:
+ 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)
+
+ vswhere = os.path.join(
+ p, 'Microsoft Visual Studio', 'Installer', 'vswhere')
+ vcid = 'Microsoft.VisualStudio.Component.VC.Tools.x86.x64'
+ vsinstalldir = cmdout(
+ [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)
+ else:
+ assert False, "FIXME: Implement on non-win"
+
+ print('Done.')
+ if sys.platform == 'win32':
+ # CMake doesn't like backslashes in commandline args.
+ abs_out_dir = os.path.abspath(out_dir).replace(os.path.sep, '/')
+ print('Pass -DLLVM_WINSYSROOT=' + abs_out_dir + ' to cmake.')
+ else:
+ print('Pass -DCMAKE_SYSROOT=' + abs_out_dir + ' to cmake.')
+
+
+def main():
+ parser = argparse.ArgumentParser(description=__doc__)
+
+ subparsers = parser.add_subparsers(dest='command', required=True)
+
+ makefake = subparsers.add_parser('make-fake',
+ help='Create a sysroot that symlinks to local directories.')
+ makefake.add_argument('--out-dir', required=True)
+
+ args = parser.parse_args()
+
+ assert args.command == 'make-fake'
+ make_fake_sysroot(args.out_dir)
+
+
+if __name__ == '__main__':
+ main()
More information about the llvm-commits
mailing list