Browse Source

Split dxc.exe into a static lib and a driver executable (#1952)

* Split dxc.exe into a static lib and a driver executable

We have a need to produce a version of dxc.exe that has a few default
command line arguments but otherwise is just the standard dxc executable.
This commit splits dxc.exe into a static lib with all the dxc logic and
a thin wrapper main function that calls into the lib.

The split allows us to link to the dxc lib and pass our own default arguments.

* Include SPIRV-Tools if SPIR-V code generation is enabled.

* Update the GCC version used by Linux buildbots.

* Revert "Update the GCC version used by Linux buildbots."

This reverts commit f6ce38ce2e7fa3e78ebb2ed32dedad27b7c97242.

* Fix link order for linux-gcc build

* Remove accidental addition
David Peixotto 6 years ago
parent
commit
9270063f99

+ 5 - 2
tools/clang/tools/dxc/CMakeLists.txt

@@ -17,11 +17,12 @@ set( LLVM_LINK_COMPONENTS
   )
 
 add_clang_executable(dxc
-  dxc.cpp
+  dxcmain.cpp
 #  dxr.rc
   )
 
 target_link_libraries(dxc
+  dxclib
   dxcompiler
   )
 
@@ -36,7 +37,7 @@ if (WIN32)
   include_directories(AFTER ${DIASDK_INCLUDE_DIRS})
 endif (WIN32)
 
-add_dependencies(dxc dxcompiler)
+add_dependencies(dxc dxclib dxcompiler)
 
 if(UNIX)
   set(CLANGXX_LINK_OR_COPY create_symlink)
@@ -50,3 +51,5 @@ endif()
 install(TARGETS dxc
   RUNTIME DESTINATION bin)
 
+add_subdirectory(dxclib)
+

+ 20 - 0
tools/clang/tools/dxc/dxclib/CMakeLists.txt

@@ -0,0 +1,20 @@
+# Copyright (C) Microsoft Corporation. All rights reserved.
+# This file is distributed under the University of Illinois Open Source License. See LICENSE.TXT for details.
+# Builds dxclib
+
+if (WIN32)
+  find_package(DiaSDK REQUIRED) # Used for constants and declarations.
+endif (WIN32)
+
+add_clang_library(dxclib
+  dxc.cpp
+  )
+
+if(ENABLE_SPIRV_CODEGEN)
+  target_link_libraries(dxclib SPIRV-Tools)
+endif()
+
+if (WIN32)
+  include_directories(AFTER ${DIASDK_INCLUDE_DIRS})
+endif (WIN32)
+

+ 3 - 2
tools/clang/tools/dxc/dxc.cpp → tools/clang/tools/dxc/dxclib/dxc.cpp

@@ -41,6 +41,7 @@
 #include "dxc/Support/Unicode.h"
 #include "dxc/Support/WinIncludes.h"
 #include "dxc/Support/WinFunctions.h"
+#include "dxc.h"
 #include <vector>
 #include <string>
 
@@ -1058,9 +1059,9 @@ void DxcContext::GetCompilerVersionInfo(llvm::raw_string_ostream &OS) {
 }
 
 #ifdef _WIN32
-int __cdecl wmain(int argc, const wchar_t **argv_) {
+int dxc::main(int argc, const wchar_t **argv_) {
 #else
-int main(int argc, const char **argv_) {
+int dxc::main(int argc, const char **argv_) {
 #endif // _WIN32
   const char *pStage = "Operation";
   int retVal = 0;

+ 25 - 0
tools/clang/tools/dxc/dxclib/dxc.h

@@ -0,0 +1,25 @@
+///////////////////////////////////////////////////////////////////////////////
+//                                                                           //
+// dxc.h                                                                     //
+// Copyright (C) Microsoft Corporation. All rights reserved.                 //
+// This file is distributed under the University of Illinois Open Source     //
+// License. See LICENSE.TXT for details.                                     //
+//                                                                           //
+// Provides wrappers to dxc main function.                                   //
+//                                                                           //
+///////////////////////////////////////////////////////////////////////////////
+
+#pragma once
+#ifndef __DXC_DXCLIB__
+#define __DXC_DXCLIB__
+
+namespace dxc
+{
+#ifdef _WIN32
+int main(int argc, const wchar_t **argv_);
+#else
+int main(int argc, const char **argv_);
+#endif // _WIN32
+}
+
+#endif // __DXC_DXCLIB__

+ 22 - 0
tools/clang/tools/dxc/dxcmain.cpp

@@ -0,0 +1,22 @@
+///////////////////////////////////////////////////////////////////////////////
+//                                                                           //
+// dxc.cpp                                                                   //
+// Copyright (C) Microsoft Corporation. All rights reserved.                 //
+// This file is distributed under the University of Illinois Open Source     //
+// License. See LICENSE.TXT for details.                                     //
+//                                                                           //
+// Provides the entry point for the dxc console program.                     //
+//                                                                           //
+///////////////////////////////////////////////////////////////////////////////
+
+#include "dxclib/dxc.h"
+
+#ifdef _WIN32
+int __cdecl wmain(int argc, const wchar_t **argv_) 
+{
+    return dxc::main(argc, argv_);
+#else
+int main(int argc, const char **argv_) {
+    return dxc::main(argc, argv_);
+#endif // _WIN32
+}