Skip to content

Commit 42a21aa

Browse files
author
Stephen Gutekanst
committed
build libdxcompiler (static) and dxc.exe with build.zig
Signed-off-by: Stephen Gutekanst <[email protected]>
1 parent 8b871f6 commit 42a21aa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+463
-244
lines changed

include/dxc/Support/dxcapi.use.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616

1717
namespace dxc {
1818

19-
extern const char *kDxCompilerLib;
20-
extern const char *kDxilLib;
19+
// Mach change start: static
20+
// extern const char *kDxCompilerLib;
21+
// extern const char *kDxilLib;
22+
// Mach change end
2123

2224
// Helper class to dynamically load the dxcompiler or a compatible libraries.
2325
class DxcDllSupport {
@@ -87,9 +89,11 @@ class DxcDllSupport {
8789

8890
~DxcDllSupport() { Cleanup(); }
8991

90-
HRESULT Initialize() {
91-
return InitializeInternal(kDxCompilerLib, "DxcCreateInstance");
92-
}
92+
// Mach change start: static
93+
// HRESULT Initialize() {
94+
// return InitializeInternal(kDxCompilerLib, "DxcCreateInstance");
95+
// }
96+
// Mach change end
9397

9498
HRESULT InitializeForDll(LPCSTR dll, LPCSTR entryPoint) {
9599
return InitializeInternal(dll, entryPoint);

include/dxc/WinAdapter.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,9 @@
1515
#ifndef LLVM_SUPPORT_WIN_ADAPTER_H
1616
#define LLVM_SUPPORT_WIN_ADAPTER_H
1717

18-
//#------------------
19-
//# Mach change start
20-
//#------------------
18+
// Mach change start
2119
#include "ZigGNUWinAdapter.h"
22-
//#------------------
23-
//# Mach change end
24-
//#------------------
20+
// Mach change end
2521

2622
#ifndef _WIN32
2723

include/dxc/ZigGNUWinAdapter.h

Lines changed: 93 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,72 @@
1111

1212
#if defined(__clang__) && !defined(_MSC_VER) && defined(_WIN32) // Zig windows-gnu target
1313

14+
// MinGW UUIDOF specializations
15+
//-------------------------------------------------------------
16+
// This is needed because clang GNU target / MinGW headers will emit references to e.g.
17+
//
18+
// error: undefined symbol: _GUID const& __mingw_uuidof<IDxcSystemAccess>()
19+
//
20+
// which do not match MSVC.
21+
#include <guiddef.h>
22+
#include <stdint.h>
23+
24+
#ifdef __cplusplus
25+
#define MINGW_UUIDOF(type, spec) \
26+
extern "C++" { \
27+
struct __declspec(uuid(spec)) type; \
28+
template<> const GUID &__mingw_uuidof<type>() { \
29+
static constexpr IID __uuid_inst = guid_from_string(spec); \
30+
return __uuid_inst; \
31+
} \
32+
template<> const GUID &__mingw_uuidof<type*>() { \
33+
return __mingw_uuidof<type>(); \
34+
} \
35+
}
36+
37+
constexpr uint8_t nybble_from_hex(char c) {
38+
return ((c >= '0' && c <= '9')
39+
? (c - '0')
40+
: ((c >= 'a' && c <= 'f')
41+
? (c - 'a' + 10)
42+
: ((c >= 'A' && c <= 'F') ? (c - 'A' + 10)
43+
: /* Should be an error */ -1)));
44+
}
45+
46+
constexpr uint8_t byte_from_hex(char c1, char c2) {
47+
return nybble_from_hex(c1) << 4 | nybble_from_hex(c2);
48+
}
49+
50+
constexpr uint8_t byte_from_hexstr(const char str[2]) {
51+
return nybble_from_hex(str[0]) << 4 | nybble_from_hex(str[1]);
52+
}
53+
54+
constexpr GUID guid_from_string(const char str[37]) {
55+
return GUID{static_cast<uint32_t>(byte_from_hexstr(str)) << 24 |
56+
static_cast<uint32_t>(byte_from_hexstr(str + 2)) << 16 |
57+
static_cast<uint32_t>(byte_from_hexstr(str + 4)) << 8 |
58+
byte_from_hexstr(str + 6),
59+
static_cast<uint16_t>(
60+
static_cast<uint16_t>(byte_from_hexstr(str + 9)) << 8 |
61+
byte_from_hexstr(str + 11)),
62+
static_cast<uint16_t>(
63+
static_cast<uint16_t>(byte_from_hexstr(str + 14)) << 8 |
64+
byte_from_hexstr(str + 16)),
65+
{byte_from_hexstr(str + 19), byte_from_hexstr(str + 21),
66+
byte_from_hexstr(str + 24), byte_from_hexstr(str + 26),
67+
byte_from_hexstr(str + 28), byte_from_hexstr(str + 30),
68+
byte_from_hexstr(str + 32), byte_from_hexstr(str + 34)}};
69+
}
70+
71+
#ifdef ZIG_MINGW_DECLARE_SPECIALIZATIONS
72+
#define CROSS_PLATFORM_UUIDOF(type, spec) MINGW_UUIDOF(type, spec)
73+
#else // ZIG_MINGW_DECLARE_SPECIALIZATIONS
74+
#define CROSS_PLATFORM_UUIDOF(type, spec)
75+
#endif // ZIG_MINGW_DECLARE_SPECIALIZATIONS
76+
#endif // __cplusplus
77+
78+
79+
1480
// General
1581
//-------------------------------------------------------------
1682
// mingw-w64 tends to define it as 0x0502 in its headers.
@@ -563,8 +629,9 @@ HRESULT UInt32Mult(UINT a, UINT b, UINT *out);
563629
#define D3D12_SHVER_GET_MINOR(_Version) \
564630
(((_Version) >> 0) & 0xf)
565631

566-
#define D3D_NAME_STENCIL_REF ((D3D_NAME)69)
567-
#define D3D_NAME_INNER_COVERAGE ((D3D_NAME)70)
632+
// TODO: #ifndef?
633+
// #define D3D_NAME_STENCIL_REF ((D3D_NAME)69)
634+
// #define D3D_NAME_INNER_COVERAGE ((D3D_NAME)70)
568635

569636
#define D3D_SHADER_REQUIRES_DOUBLES 0x00000001
570637
#define D3D_SHADER_REQUIRES_EARLY_DEPTH_STENCIL 0x00000002
@@ -1020,6 +1087,30 @@ class CComBSTR {
10201087
return s;
10211088
}
10221089
};
1090+
1091+
//===--------- Convert argv to wchar ----------------===//
1092+
class WArgV {
1093+
std::vector<std::wstring> WStringVector;
1094+
std::vector<const wchar_t *> WCharPtrVector;
1095+
1096+
public:
1097+
WArgV(int argc, const char **argv);
1098+
const wchar_t **argv() { return WCharPtrVector.data(); }
1099+
};
1100+
1101+
1102+
1103+
#ifdef ZIG_MINGW_DECLARE_SPECIALIZATIONS
1104+
#include "dxc/dxcapi.h"
1105+
#include "dxc/dxcapi.internal.h"
1106+
#include "dxc/dxcisense.h"
1107+
#include "dxc/dxctools.h"
1108+
CROSS_PLATFORM_UUIDOF(IDiaDataSource, "79F1BB5F-B66E-48e5-B6A9-1545C323CA3D")
1109+
CROSS_PLATFORM_UUIDOF(ID3D12LibraryReflection, "8E349D19-54DB-4A56-9DC9-119D87BDB804")
1110+
CROSS_PLATFORM_UUIDOF(ID3D12ShaderReflection, "5A58797D-A72C-478D-8BA2-EFC6B0EFE88E")
1111+
CROSS_PLATFORM_UUIDOF(IDxcPixDxilDebugInfoFactory, "9c2a040d-8068-44ec-8c68-8bfef1b43789")
1112+
#endif // ZIG_MINGW_DECLARE_SPECIALIZATIONS
1113+
10231114
#endif // __cplusplus
10241115

10251116
#endif // defined(__clang__) && !defined(_MSC_VER) && defined(_WIN32) // Zig windows-gnu target

include/dxc/dxcapi.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
#ifndef __DXC_API__
1414
#define __DXC_API__
1515

16+
// Mach change start: static
17+
#define DXC_API_IMPORT
18+
// Mach change end
1619
#ifdef _WIN32
1720
#ifndef DXC_API_IMPORT
1821
#define DXC_API_IMPORT __declspec(dllimport)
@@ -23,7 +26,10 @@
2326
#endif
2427
#endif
2528

26-
#ifdef _WIN32
29+
// Mach change start
30+
// #ifdef _WIN32
31+
#ifdef _MSC_VER
32+
// Mach change end
2733

2834
#ifndef CROSS_PLATFORM_UUIDOF
2935
// Warning: This macro exists in WinAdapter.h as well
@@ -34,8 +40,13 @@
3440
#else
3541

3642
#include "WinAdapter.h"
43+
// Mach change start
44+
// #include <dlfcn.h>
45+
#if HAVE_DLFCN_H
3746
#include <dlfcn.h>
3847
#endif
48+
// Mach change end
49+
#endif
3950

4051
struct IMalloc;
4152

include/llvm/Support/Host.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,9 @@
2020
#include <endian.h>
2121
#else
2222
#if !defined(BYTE_ORDER) && !defined(LLVM_ON_WIN32)
23-
//#------------------
24-
//# Mach change start
25-
//#------------------
23+
// Mach change start
2624
// #include <machine/endian.h>
27-
//#------------------
28-
//# Mach change end
29-
//#------------------
25+
// Mach change end
3026
#endif
3127
#endif
3228

lib/DxcSupport/WinAdapter.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,22 @@
77
//
88
//===----------------------------------------------------------------------===//
99

10+
// Mach change start
11+
#include "dxc/Support/WinIncludes.h"
12+
#include "dxc/dxcapi.h"
13+
#include "dxc/dxcapi.internal.h"
14+
#include "dxc/dxcisense.h"
15+
#include "dxc/dxctools.h"
16+
#include "dxc/WinAdapter.h"
17+
// Mach change end
18+
1019
#include "assert.h"
1120
#include "dxc/Support/WinFunctions.h"
12-
#include "dxc/Support/WinIncludes.h"
13-
#ifndef _WIN32
21+
// Mach change start
22+
// #include "dxc/Support/WinIncludes.h"
23+
// #ifndef _WIN32
24+
#if defined(_WIN32) || defined(__clang__)
25+
// Mach change end
1426

1527
#include "dxc/Support/Unicode.h"
1628

@@ -22,6 +34,9 @@ void *CAllocator::Reallocate(void *p, size_t nBytes) throw() {
2234
void *CAllocator::Allocate(size_t nBytes) throw() { return malloc(nBytes); }
2335
void CAllocator::Free(void *p) throw() { free(p); }
2436

37+
// Mach change start
38+
#ifndef __clang__
39+
// Mach change end
2540
//===--------------------------- BSTR Allocation --------------------------===//
2641

2742
void SysFreeString(BSTR bstrString) {
@@ -51,6 +66,9 @@ BSTR SysAllocStringLen(const OLECHAR *strIn, UINT ui) {
5166

5267
return strOut;
5368
}
69+
// Mach change start
70+
#endif
71+
// Mach change end
5472

5573
//===---------------------- Char converstion ------------------------------===//
5674

@@ -97,6 +115,9 @@ bool CComBSTR::operator==(const CComBSTR &bstrSrc) const throw() {
97115
return wcscmp(m_str, bstrSrc.m_str) == 0;
98116
}
99117

118+
// Mach change start
119+
#ifndef __clang__
120+
// Mach change end
100121
//===--------------------------- WArgV -------------------------------===//
101122
WArgV::WArgV(int argc, const char **argv)
102123
: WStringVector(argc), WCharPtrVector(argc) {
@@ -112,5 +133,8 @@ WArgV::WArgV(int argc, const char **argv)
112133
WCharPtrVector[i] = WStringVector[i].data();
113134
}
114135
}
136+
// Mach change start
137+
#endif
138+
// Mach change end
115139

116140
#endif

lib/DxcSupport/WinFunctions.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,28 @@
1313
//
1414
//===----------------------------------------------------------------------===//
1515

16+
// Mach change start
17+
#ifdef __clang__
18+
#include <fcntl.h>
19+
#include <map>
20+
#include <string.h>
21+
#include <sys/stat.h>
22+
#include <unistd.h>
23+
24+
#include "dxc/Support/WinFunctions.h"
25+
#include "dxc/Support/microcom.h"
26+
27+
HRESULT UInt32Mult(UINT a, UINT b, UINT *out) {
28+
uint64_t result = (uint64_t)a * (uint64_t)b;
29+
if (result > uint64_t(UINT_MAX))
30+
return ERROR_ARITHMETIC_OVERFLOW;
31+
32+
*out = (uint32_t)result;
33+
return S_OK;
34+
}
35+
#endif
36+
// Mach change end
37+
1638
#ifndef _WIN32
1739
#include <fcntl.h>
1840
#include <map>

lib/DxcSupport/dxcapi.use.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,21 @@
1515

1616
#include "dxc/Support/FileIOHelper.h"
1717
#include "dxc/Support/Global.h"
18-
#include "dxc/Support/SharedLibAffix.h" // header generated during DXC build
18+
// Mach change start: static
19+
// #include "dxc/Support/SharedLibAffix.h" // header generated during DXC build
20+
// Mach change end
1921
#include "dxc/Support/Unicode.h"
2022
#include "dxc/Support/WinFunctions.h"
2123

2224
namespace dxc {
2325

24-
const char *kDxCompilerLib =
25-
CMAKE_SHARED_LIBRARY_PREFIX "dxcompiler" CMAKE_SHARED_LIBRARY_SUFFIX;
26-
const char *kDxilLib =
27-
CMAKE_SHARED_LIBRARY_PREFIX "dxil" CMAKE_SHARED_LIBRARY_SUFFIX;
26+
// Mach change start: static
27+
// const char *kDxCompilerLib =
28+
// CMAKE_SHARED_LIBRARY_PREFIX "dxcompiler" CMAKE_SHARED_LIBRARY_SUFFIX;
29+
// const char *kDxilLib =
30+
// CMAKE_SHARED_LIBRARY_PREFIX "dxil" CMAKE_SHARED_LIBRARY_SUFFIX;
31+
//
32+
// Mach change end
2833

2934
#ifdef _WIN32
3035
static void TrimEOL(char *pMsg) {
@@ -74,9 +79,11 @@ void IFT_Data(HRESULT hr, LPCWSTR data) {
7479
}
7580

7681
void EnsureEnabled(DxcDllSupport &dxcSupport) {
77-
if (!dxcSupport.IsEnabled()) {
78-
IFT(dxcSupport.Initialize());
79-
}
82+
// Mach change start: static
83+
// if (!dxcSupport.IsEnabled()) {
84+
// IFT(dxcSupport.Initialize());
85+
// }
86+
// Mach change end
8087
}
8188

8289
void ReadFileIntoBlob(DxcDllSupport &dxcSupport, LPCWSTR pFileName,

lib/DxilContainer/DxcContainerBuilder.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@
2424

2525
// This declaration is used for the locally-linked validator.
2626
HRESULT CreateDxcValidator(REFIID riid, LPVOID *ppv);
27-
template <class TInterface>
28-
HRESULT DxilLibCreateInstance(REFCLSID rclsid, TInterface **ppInterface);
27+
// Mach change start: static
28+
// template <class TInterface>
29+
// HRESULT DxilLibCreateInstance(REFCLSID rclsid, TInterface **ppInterface);
30+
// Mach change end
2931

3032
using namespace hlsl;
3133

lib/DxilDia/DxcPixCompilationInfo.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ namespace dxil_debug_info {
4949

5050
struct CompilationInfo : public IDxcPixCompilationInfo {
5151
private:
52-
DXC_MICROCOM_TM_REF_FIELDS();
52+
// Mach change start
53+
// DXC_MICROCOM_TM_REF_FIELDS();
54+
DXC_MICROCOM_TM_REF_FIELDS()
55+
// Mach change end
5356

5457
dxil_dia::Session *m_pSession;
5558
llvm::NamedMDNode *m_contents;

0 commit comments

Comments
 (0)