浏览代码

Enable building with ninja through Visual Studio (#4889)

Chris B 2 年之前
父节点
当前提交
ac3a6ae9f4

+ 48 - 0
CMakeSettings.json

@@ -0,0 +1,48 @@
+{
+  "configurations": [
+    {
+      "name": "x64-Release",
+      "generator": "Ninja",
+      "configurationType": "RelWithDebInfo",
+      "buildRoot": "${projectDir}\\out\\build\\${name}",
+      "installRoot": "${projectDir}\\out\\install\\${name}",
+      "cmakeCommandArgs": "-DDXC_USE_LIT=On -C ${projectDir}\\cmake\\caches\\PredefinedParams.cmake -DLLVM_ENABLE_ASSERTIONS=On -DLLVM_LIT_ARGS=\"-v\"",
+      "buildCommandArgs": "-v",
+      "ctestCommandArgs": "",
+      "inheritEnvironments": [ "msvc_x64_x64" ]
+    },
+    {
+      "name": "x64-Debug",
+      "generator": "Ninja",
+      "configurationType": "Debug",
+      "buildRoot": "${projectDir}\\out\\build\\${name}",
+      "installRoot": "${projectDir}\\out\\install\\${name}",
+      "cmakeCommandArgs": "-DDXC_USE_LIT=On -C ${projectDir}\\cmake\\caches\\PredefinedParams.cmake -DLLVM_ENABLE_ASSERTIONS=On -DLLVM_LIT_ARGS=\"-v\"",
+      "buildCommandArgs": "-v",
+      "ctestCommandArgs": "",
+      "inheritEnvironments": [ "msvc_x64_x64" ]
+    },
+    {
+      "name": "x86-Release",
+      "generator": "Ninja",
+      "configurationType": "RelWithDebInfo",
+      "buildRoot": "${projectDir}\\out\\build\\${name}",
+      "installRoot": "${projectDir}\\out\\install\\${name}",
+      "cmakeCommandArgs": "-DDXC_USE_LIT=On -C ${projectDir}\\cmake\\caches\\PredefinedParams.cmake -DLLVM_ENABLE_ASSERTIONS=On -DLLVM_LIT_ARGS=\"-v\"",
+      "buildCommandArgs": "-v",
+      "ctestCommandArgs": "",
+      "inheritEnvironments": [ "msvc_x86_x64" ]
+    },
+    {
+      "name": "x86-Debug",
+      "generator": "Ninja",
+      "configurationType": "Debug",
+      "buildRoot": "${projectDir}\\out\\build\\${name}",
+      "installRoot": "${projectDir}\\out\\install\\${name}",
+      "cmakeCommandArgs": "-DDXC_USE_LIT=On -C ${projectDir}\\cmake\\caches\\PredefinedParams.cmake -DLLVM_ENABLE_ASSERTIONS=On -DLLVM_LIT_ARGS=\"-v\"",
+      "buildCommandArgs": "-v",
+      "ctestCommandArgs": "",
+      "inheritEnvironments": [ "msvc_x86_x64" ]
+    }
+  ]
+}

+ 20 - 0
README.md

@@ -42,6 +42,26 @@ Binary packages containing the output of this project are available from appveyo
 As an example of community contribution, this project can also target the [SPIR-V](https://www.khronos.org/registry/spir-v/) intermediate representation. Please see the [doc](docs/SPIR-V.rst) for how HLSL features are mapped to SPIR-V, and the [wiki](https://github.com/microsoft/DirectXShaderCompiler/wiki/SPIR%E2%80%90V-CodeGen) page for how to build, use, and contribute to the SPIR-V CodeGen.
 
 ## Building Sources
+
+Building DXC requires:
+
+* [Git](http://git-scm.com/downloads).
+* [Python](https://www.python.org/downloads/) - version 3.x is required
+* [CMake](https://cmake.org/download/) - version >= 3.10
+    * The bundled version with Visual Studio works for Windows.
+* The C++ 14 compiler and runtime of your choosing.
+    * DXC is known to compile with recent versions of GCC, Clang and MSVC.
+
+Building on windows additionally requires:
+
+* [Visual Studio 2019 or later](https://www.visualstudio.com/downloads) - select the following workloads: 
+    * Universal Windows Platform Development
+    * Desktop Development with C++
+* [Windows SDK](https://developer.microsoft.com/en-US/windows/downloads/windows-10-sdk) - version 10.0.18362.0 or newer
+* [Windows Driver Kit](https://docs.microsoft.com/en-us/windows-hardware/drivers/download-the-wdk) - same version as the SDK
+
+> A new experimental simplified build and test workflow is documented [here](docs/BuildingAndTestingDXC.rst).
+
 Note: If you intend to build from sources on Linux/macOS, follow [these instructions](docs/DxcOnUnix.rst).
 
 Before you build, you will need to have some additional software installed. This is the most straightforward path - see [Building Sources](https://github.com/microsoft/DirectXShaderCompiler/wiki/Building-Sources) on the Wiki for more options, including Visual Studio 2015 and Ninja support.

+ 11 - 13
cmake/modules/FindTAEF.cmake

@@ -41,20 +41,18 @@ set(TAEF_INCLUDE_DIRS ${TAEF_INCLUDE_DIR})
 set(TAEF_NUGET_BIN ${TAEF_INCLUDE_DIR}/../Binaries/Release)
 set(TAEF_SDK_BIN ${TAEF_INCLUDE_DIR}/../../Runtimes/TAEF)
 
-if(EXISTS "$ENV{HLSL_TAEF_DIR}/x64/te.exe" OR EXISTS "$ENV{HLSL_TAEF_DIR}/x86/te.exe")
-  # Use HLSL_TAEF_DIR for debug executable setting if set.
-  # we don't actually support multiple architectures in the same project.
-  set(TAEF_BIN_DIR "$ENV{HLSL_TAEF_DIR}")
-elseif(EXISTS "${TAEF_NUGET_BIN}/x64/te.exe" AND EXISTS "${TAEF_NUGET_BIN}/x86/te.exe")
-  set(TAEF_BIN_DIR "${TAEF_NUGET_BIN}")
-elseif(EXISTS "${TAEF_SDK_BIN}/x64/te.exe" AND EXISTS "${TAEF_SDK_BIN}/x86/te.exe")
-  set(TAEF_BIN_DIR "${TAEF_SDK_BIN}")
-elseif(EXISTS "${WINDOWS_KIT_10_PATH}")
-  message(ERROR "Unable to find TAEF binaries under Windows 10 SDK.")
-elseif(EXISTS "${WINDOWS_KIT_81_PATH}")
-  message(ERROR "Unable to find TAEF binaries under Windows 8.1 or 10 SDK.")
+find_program(TAEF_EXECUTABLE te.exe PATHS
+  $ENV{HLSL_TAEF_DIR}/${CMAKE_C_COMPILER_ARCHITECTURE_ID}
+  ${TAEF_NUGET_BIN}/${CMAKE_C_COMPILER_ARCHITECTURE_ID}
+  ${TAEF_SDK_BIN}/${CMAKE_C_COMPILER_ARCHITECTURE_ID}
+  ${WINDOWS_KIT_10_PATH}
+  ${WINDOWS_KIT_81_PATH}
+  )
+
+if (TAEF_EXECUTABLE)
+  get_filename_component(TAEF_BIN_DIR ${TAEF_EXECUTABLE} DIRECTORY)
 else()
-  message(ERROR "Unable to find TAEF binaries or Windows 8.1 or 10 SDK.")
+  message(ERROR "Unable to find TAEF binaries.")
 endif()
 
 include(FindPackageHandleStandardArgs)

+ 6 - 0
projects/dxilconv/test/CMakeLists.txt

@@ -1,6 +1,12 @@
 # Test runner infrastructure for dxilconv. This configures the dxilconv test trees
 # for use by Lit, and delegates to LLVM's lit test handlers.
 
+if (CMAKE_CFG_INTDIR STREQUAL ".")
+  set(LLVM_BUILD_MODE ".")
+else ()
+  set(LLVM_BUILD_MODE "%(build_mode)s")
+endif ()
+
 configure_lit_site_cfg(
   ${CMAKE_CURRENT_SOURCE_DIR}/taef/lit.site.cfg.in
   ${CMAKE_CURRENT_BINARY_DIR}/taef/lit.site.cfg

+ 5 - 8
projects/dxilconv/test/taef/lit.cfg

@@ -11,8 +11,8 @@ import lit.util
 config.name = 'dxilconv'
 
 # Check that the object root is known.
-llvm_obj_root = getattr(config, 'llvm_obj_root', None)
-if llvm_obj_root is None:
+te = getattr(config, 'te', None)
+if te is None:
     # Otherwise, we haven't loaded the site specific configuration (the user is
     # probably trying to run on a test file directly, and either the site
     # configuration hasn't been created by the build system, or we are in an
@@ -24,14 +24,11 @@ if llvm_obj_root is None:
         lit_config.load_config(config, site_cfg)
         raise SystemExit
 
-
-te = os.path.join(config.llvm_obj_root, "TAEF", config.arch, 'te.exe')
-
-test_dll = os.path.join(config.llvm_obj_root, config.build_mode, 'bin', 'dxilconv-tests.dll')
+test_dll = os.path.join(config.llvm_obj_root, config.llvm_build_mode, 'bin', 'dxilconv-tests.dll')
 
 hlsl_data_dir = os.path.join(config.llvm_src_root, 'projects', 'dxilconv', 'test')
 
-test_dir = os.path.join(config.llvm_obj_root, config.build_mode, 'test')
+test_dir = os.path.join(config.llvm_obj_root, config.llvm_build_mode, 'test')
 
-config.test_format = lit.formats.TaefTest(te, test_dll, hlsl_data_dir, test_dir)
+config.test_format = lit.formats.TaefTest(config.te, test_dll, hlsl_data_dir, test_dir)
 

+ 12 - 2
projects/dxilconv/test/taef/lit.site.cfg.in

@@ -4,8 +4,18 @@ import sys
 # Do not edit!
 config.llvm_src_root = "@LLVM_SOURCE_DIR@"
 config.llvm_obj_root = "@LLVM_BINARY_DIR@"
-config.build_mode = lit_config.params["build_mode"]
-config.arch = "@CMAKE_C_COMPILER_ARCHITECTURE_ID@"
+config.llvm_build_mode = "@LLVM_BUILD_MODE@"
+config.te = "@TAEF_EXECUTABLE@"
+
+# Support substitution of the tools_dir, libs_dirs, and build_mode with user
+# parameters. This is used when we can't determine the tool dir at
+# configuration time.
+try:
+    config.llvm_build_mode = config.llvm_build_mode % lit_config.params
+except KeyError:
+    e = sys.exc_info()[1]
+    key, = e.args
+    lit_config.fatal("unable to find %r parameter, use '--param=%s=VALUE'" % (key,key))
 
 # Let the main config do the real work.
 lit_config.load_config(config, "@LLVM_SOURCE_DIR@/projects/dxilconv/test/taef/lit.cfg")

+ 4 - 1
projects/dxilconv/unittests/CMakeLists.txt

@@ -23,7 +23,10 @@ target_include_directories(dxilconv-tests PRIVATE
   ${TAEF_INCLUDE_DIRS}
 )
 
-add_dependencies(dxilconv-tests dxilconv HLSLTestLib)
+# dxilconv-tests calls out to several external tools. Those need to be listed
+# here to ensure they build with dxilconv for our test target depencencies to be
+# correct.
+add_dependencies(dxilconv-tests dxilconv HLSLTestLib dxbc2dxil dxa opt)
 
 install(TARGETS dxilconv-tests
   RUNTIME DESTINATION bin)

+ 3 - 5
tools/clang/test/taef/lit.cfg

@@ -12,8 +12,8 @@ import lit.util
 config.name = 'clang-taef'
 
 # Check that the object root is known.
-llvm_obj_root = getattr(config, 'llvm_obj_root', None)
-if llvm_obj_root is None:
+te = getattr(config, 'te', None)
+if te is None:
     # Otherwise, we haven't loaded the site specific configuration (the user is
     # probably trying to run on a test file directly, and either the site
     # configuration hasn't been created by the build system, or we are in an
@@ -29,11 +29,9 @@ if llvm_obj_root is None:
 if platform.system() != 'Windows':
   config.unsupported = True
 else:
-  te = os.path.join(config.llvm_obj_root, "TAEF", config.arch, 'te.exe')
-
   test_dll = os.path.join(config.llvm_obj_root, config.llvm_build_mode, 'bin', 'ClangHLSLTests.dll')
 
   hlsl_data_dir = os.path.join(config.llvm_src_root, 'tools', 'clang', 'test', 'HLSL')
 
   test_dir = os.path.join(config.llvm_obj_root, config.llvm_build_mode, 'test')
-  config.test_format = lit.formats.TaefTest(te, test_dll, hlsl_data_dir, test_dir)
+  config.test_format = lit.formats.TaefTest(config.te, test_dll, hlsl_data_dir, test_dir)

+ 1 - 1
tools/clang/test/taef/lit.site.cfg.in

@@ -5,7 +5,7 @@ import sys
 config.llvm_src_root = "@LLVM_SOURCE_DIR@"
 config.llvm_obj_root = "@LLVM_BINARY_DIR@"
 config.llvm_build_mode = "@LLVM_BUILD_MODE@"
-config.arch = "@CMAKE_C_COMPILER_ARCHITECTURE_ID@"
+config.te = "@TAEF_EXECUTABLE@"
 
 # Support substitution of the tools_dir, libs_dirs, and build_mode with user
 # parameters. This is used when we can't determine the tool dir at

+ 1 - 1
utils/lit/lit/formats/taef.py

@@ -42,7 +42,7 @@ class TaefTest(TestFormat):
             lines = lines.replace('\r', '')
             lines = lines.split('\n')
         except:
-            litConfig.error("unable to discover taef in %r" % dll_path)
+            litConfig.error("unable to discover taef tests in %r, using %s" % (dll_path, self.te))
             raise StopIteration
 
         for ln in lines: