Skip to content

Commit

Permalink
support Zig cross-compilation
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Gutekanst <[email protected]>
  • Loading branch information
emidoots committed Nov 1, 2023
1 parent 245fd12 commit 95a93fe
Show file tree
Hide file tree
Showing 28 changed files with 420 additions and 136 deletions.
49 changes: 31 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,27 @@ endif()
option(DXC_DISABLE_ALLOCATOR_OVERRIDES "Disable usage of allocator overrides" OFF)
mark_as_advanced(DXC_DISABLE_ALLOCATOR_OVERRIDES)

# adjust link option to enable debugging from kernel mode; not compatible with incremental linking
if(NOT CMAKE_VERSION VERSION_LESS "3.13" AND WIN32 AND NOT CMAKE_C_COMPILER_ARCHITECTURE_ID STREQUAL "ARM64EC")
add_link_options(/DEBUGTYPE:CV,FIXUP,PDATA /INCREMENTAL:NO)
endif()

# enable control flow guard
if(WIN32)
add_compile_options(/guard:cf)
add_link_options(/guard:cf)
endif(WIN32)

# Enable CET Shadow Stack
if(WIN32 AND NOT (CMAKE_C_COMPILER_ARCHITECTURE_ID MATCHES "ARM.*"))
add_link_options(/CETCOMPAT)
endif()
#------------------
# Mach change start
#------------------
# # adjust link option to enable debugging from kernel mode; not compatible with incremental linking
# if(NOT CMAKE_VERSION VERSION_LESS "3.13" AND WIN32 AND NOT CMAKE_C_COMPILER_ARCHITECTURE_ID STREQUAL "ARM64EC")
# add_link_options(/DEBUGTYPE:CV,FIXUP,PDATA /INCREMENTAL:NO)
# endif()

# # enable control flow guard
# if(WIN32)
# add_compile_options(/guard:cf)
# add_link_options(/guard:cf)
# endif(WIN32)

# # Enable CET Shadow Stack
# if(WIN32 AND NOT (CMAKE_C_COMPILER_ARCHITECTURE_ID MATCHES "ARM.*"))
# add_link_options(/CETCOMPAT)
# endif()
#------------------
# Mach change end
#------------------

# HLSL Change Ends

Expand Down Expand Up @@ -804,9 +810,16 @@ endif()

include(CoverageReport)

# HLSL Change begin - Set default distribution value.
set(LLVM_DISTRIBUTION_COMPONENTS "dxc;dxcompiler;dxc-headers" CACHE STRING "")
# HLSL Change end - Set default distribution value.
#------------------
# Mach change start
#------------------
# # HLSL Change begin - Set default distribution value.
# set(LLVM_DISTRIBUTION_COMPONENTS "dxc;dxcompiler;dxc-headers" CACHE STRING "")
# # HLSL Change end - Set default distribution value.
set(LLVM_DISTRIBUTION_COMPONENTS "dxcompiler;dxc-headers" CACHE STRING "")
#------------------
# Mach change end
#------------------

# This must be at the end of the LLVM root CMakeLists file because it must run
# after all targets are created.
Expand Down
8 changes: 7 additions & 1 deletion cmake/modules/AddLLVM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ function(llvm_update_compile_flags name)
endif()
else()
if(LLVM_COMPILER_IS_GCC_COMPATIBLE)
list(APPEND LLVM_COMPILE_FLAGS "-fno-exceptions")
#------------------
# Mach change start
#------------------
# list(APPEND LLVM_COMPILE_FLAGS "-fno-exceptions")
#------------------
# Mach change end
#------------------
elseif(MSVC)
list(APPEND LLVM_COMPILE_DEFINITIONS _HAS_EXCEPTIONS=0)
list(APPEND LLVM_COMPILE_FLAGS "/EHs-c-")
Expand Down
8 changes: 7 additions & 1 deletion external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,13 @@ if (${ENABLE_SPIRV_CODEGEN})
# Avoid exception handling warning from MSVC.
# This add_compile_options() will only affect the current directory and its subdirectories.
if (WIN32)
add_compile_options(/EHs)
#------------------
# Mach change start
#------------------
# add_compile_options(/EHs)
#------------------
# Mach change end
#------------------
else(WIN32)
# Disable all warnings in subproject RE2
add_compile_options(-w)
Expand Down
50 changes: 37 additions & 13 deletions include/dxc/Tracing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,53 @@

# Create the header in a temporary file and only update when necessary,
# to avoid invalidating targets that depend on it.
#------------------
# Mach change start
#------------------
# add_custom_command(
# OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/tmpdxcetw.h
# COMMAND mc -r ${CMAKE_CURRENT_BINARY_DIR} -h ${CMAKE_CURRENT_BINARY_DIR} -p DxcEtw_ -um -z tmpdxcetw ${CMAKE_CURRENT_SOURCE_DIR}/dxcetw.man
# DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/dxcetw.man
# COMMENT "Building instrumentation manifest ..."
# )
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/tmpdxcetw.h
COMMAND mc -r ${CMAKE_CURRENT_BINARY_DIR} -h ${CMAKE_CURRENT_BINARY_DIR} -p DxcEtw_ -um -z tmpdxcetw ${CMAKE_CURRENT_SOURCE_DIR}/dxcetw.man
COMMAND touch ${CMAKE_CURRENT_BINARY_DIR}/tmpdxcetw.h
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/dxcetw.man
COMMENT "Building instrumentation manifest ..."
)
#------------------
# Mach change end
#------------------
#------------------
# Mach change start
#------------------
# add_custom_command(
# OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/dxcetw.h
# COMMAND ${CMAKE_COMMAND} -E copy_if_different
# ${CMAKE_CURRENT_BINARY_DIR}/tmpdxcetw.h
# ${CMAKE_CURRENT_BINARY_DIR}/dxcetw.h
# COMMAND ${CMAKE_COMMAND} -E copy_if_different
# ${CMAKE_CURRENT_BINARY_DIR}/tmpdxcetw.rc
# ${CMAKE_CURRENT_BINARY_DIR}/dxcetw.rc
# COMMAND ${CMAKE_COMMAND} -E copy_if_different
# ${CMAKE_CURRENT_BINARY_DIR}/tmpdxcetwTEMP.bin
# ${CMAKE_CURRENT_BINARY_DIR}/dxcetwTEMP.bin
# COMMAND ${CMAKE_COMMAND} -E copy_if_different
# ${CMAKE_CURRENT_BINARY_DIR}/tmpdxcetw_MSG00001.bin
# ${CMAKE_CURRENT_BINARY_DIR}/MSG00001.bin
# DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/tmpdxcetw.h
# COMMENT "Updating instrumentation manifest ..."
# )
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/dxcetw.h
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_CURRENT_BINARY_DIR}/tmpdxcetw.h
${CMAKE_CURRENT_BINARY_DIR}/dxcetw.h
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_CURRENT_BINARY_DIR}/tmpdxcetw.rc
${CMAKE_CURRENT_BINARY_DIR}/dxcetw.rc
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_CURRENT_BINARY_DIR}/tmpdxcetwTEMP.bin
${CMAKE_CURRENT_BINARY_DIR}/dxcetwTEMP.bin
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_CURRENT_BINARY_DIR}/tmpdxcetw_MSG00001.bin
${CMAKE_CURRENT_BINARY_DIR}/MSG00001.bin
COMMAND touch ${CMAKE_CURRENT_BINARY_DIR}/dxcetw.h
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/tmpdxcetw.h
COMMENT "Updating instrumentation manifest ..."
)
#------------------
# Mach change end
#------------------

set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/dxcetw.h PROPERTIES GENERATED 1)
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/dxcetw.rc PROPERTIES GENERATED 1)
Expand Down
8 changes: 7 additions & 1 deletion include/llvm/Support/Host.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@
#include <endian.h>
#else
#if !defined(BYTE_ORDER) && !defined(LLVM_ON_WIN32)
#include <machine/endian.h>
//#------------------
//# Mach change start
//#------------------
// #include <machine/endian.h>
//#------------------
//# Mach change end
//#------------------
#endif
#endif

Expand Down
8 changes: 7 additions & 1 deletion lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ add_subdirectory(DXIL) # HLSL Change
add_subdirectory(DxilContainer) # HLSL Change
add_subdirectory(DxilPdbInfo) # HLSL Change
add_subdirectory(DxilPIXPasses) # HLSL Change
add_subdirectory(DxilDia) # HLSL Change
#------------------
# Mach change start
#------------------
# add_subdirectory(DxilDia) # HLSL Change
#------------------
# Mach change end
#------------------
add_subdirectory(DxilRootSignature) # HLSL Change
add_subdirectory(DxcBindingTable) # HLSL Change
add_subdirectory(DxrFallback) # HLSL Change
Expand Down
9 changes: 8 additions & 1 deletion lib/DxilDia/DxilDiaDataSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,14 @@ getMemBufferFromStream(IStream *pStream, std::vector<char> &DataContainer,

STATSTG statstg;
IFT(pStream->Stat(&statstg, STATFLAG_NONAME));
size_t size = statstg.cbSize.LowPart;
//#------------------
//# Mach change start
//#------------------
// size_t size = statstg.cbSize.LowPart;
size_t size = statstg.cbSize.u.LowPart;
//#------------------
//# Mach change end
//#------------------

DataContainer.resize(size);
ULONG read;
Expand Down
8 changes: 7 additions & 1 deletion lib/HLSL/DxilContainerReflection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1478,7 +1478,13 @@ void CShaderReflectionConstantBuffer::Initialize(
}

static unsigned CalcResTypeSize(DxilModule &M, DxilResource &R) {
UNREFERENCED_PARAMETER(M);
//#------------------
//# Mach change start
//#------------------
// UNREFERENCED_PARAMETER(M);
//#------------------
//# Mach change end
//#------------------
Type *Ty = R.GetHLSLType()->getPointerElementType();
if (R.IsStructuredBuffer()) {
Ty = dxilutil::StripArrayTypes(Ty);
Expand Down
12 changes: 9 additions & 3 deletions lib/Support/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,14 @@ add_llvm_library(LLVMSupport
)

set_property(TARGET LLVMSupport PROPERTY LLVM_SYSTEM_LIBS "${system_libs}")
if(WIN32)
set_property(TARGET LLVMSupport PROPERTY COMPILE_FLAGS /EHsc )
endif(WIN32)
#------------------
# Mach change start
#------------------
# if(WIN32)
# set_property(TARGET LLVMSupport PROPERTY COMPILE_FLAGS /EHsc )
# endif(WIN32)
#------------------
# Mach change end
#------------------

target_link_libraries(LLVMSupport PUBLIC LLVMMSSupport) # HLSL Change
42 changes: 36 additions & 6 deletions lib/Support/MSFileSystemBasic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,16 @@ static HRESULT CopyStatStg(const STATSTG *statStg,
lpFindFileData->ftCreationTime = statStg->ctime;
lpFindFileData->ftLastAccessTime = statStg->atime;
lpFindFileData->ftLastWriteTime = statStg->mtime;
lpFindFileData->nFileSizeLow = statStg->cbSize.LowPart;
lpFindFileData->nFileSizeHigh = statStg->cbSize.HighPart;
//#------------------
//# Mach change start
//#------------------
// lpFindFileData->nFileSizeLow = statStg->cbSize.LowPart;
// lpFindFileData->nFileSizeHigh = statStg->cbSize.HighPart;
lpFindFileData->nFileSizeLow = statStg->cbSize.u.LowPart;
lpFindFileData->nFileSizeHigh = statStg->cbSize.u.HighPart;
//#------------------
//# Mach change end
//#------------------
if (statStg->pwcsName != nullptr) {
IFC(StringCchCopyW(lpFindFileData->cFileName,
_countof(lpFindFileData->cFileName), statStg->pwcsName));
Expand Down Expand Up @@ -842,8 +850,16 @@ long MSFileSystemForIface::lseek(int fd, long offset, int origin) throw() {
}

GetHandleStream(GetHandleForFD(fd), &stream);
li.HighPart = 0;
li.LowPart = offset;
//#------------------
//# Mach change start
//#------------------
// li.HighPart = 0;
// li.LowPart = offset;
li.u.HighPart = 0;
li.u.LowPart = offset;
//#------------------
//# Mach change end
//#------------------
IFC(stream->Seek(li, origin, &uli));

Cleanup:
Expand All @@ -852,12 +868,26 @@ long MSFileSystemForIface::lseek(int fd, long offset, int origin) throw() {
return -1;
}

if (uli.HighPart > 0) {
//#------------------
//# Mach change start
//#------------------
// if (uli.HighPart > 0) {
if (uli.u.HighPart > 0) {
//#------------------
//# Mach change end
//#------------------
errno = EOVERFLOW;
return -1;
}

return uli.LowPart;
//#------------------
//# Mach change start
//#------------------
// return uli.LowPart;
return uli.u.LowPart;
//#------------------
//# Mach change end
//#------------------
}

int MSFileSystemForIface::setmode(int fd, int mode) throw() { return 0; }
Expand Down
24 changes: 20 additions & 4 deletions lib/Support/Windows/MSFileSystem.inc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,16 @@ UniqueID file_status::getUniqueID() const {

TimeValue file_status::getLastModificationTime() const {
ULARGE_INTEGER UI;
UI.LowPart = LastWriteTimeLow;
UI.HighPart = LastWriteTimeHigh;
//#------------------
//# Mach change start
//#------------------
// UI.LowPart = LastWriteTimeLow;
// UI.HighPart = LastWriteTimeHigh;
UI.u.LowPart = LastWriteTimeLow;
UI.u.HighPart = LastWriteTimeHigh;
//#------------------
//# Mach change end
//#------------------

TimeValue Ret;
Ret.fromWin32Time(UI.QuadPart);
Expand Down Expand Up @@ -703,8 +711,16 @@ error_code setLastModificationAndAccessTime(int FD, TimeValue Time) {
ULARGE_INTEGER UI;
UI.QuadPart = Time.toWin32Time();
FILETIME FT;
FT.dwLowDateTime = UI.LowPart;
FT.dwHighDateTime = UI.HighPart;
//#------------------
//# Mach change start
//#------------------
// FT.dwLowDateTime = UI.LowPart;
// FT.dwHighDateTime = UI.HighPart;
FT.dwLowDateTime = UI.u.LowPart;
FT.dwHighDateTime = UI.u.HighPart;
//#------------------
//# Mach change end
//#------------------
HANDLE FileHandle = reinterpret_cast<HANDLE>(fsr->get_osfhandle(FD));
if (!fsr->SetFileTime(FileHandle, NULL, &FT, &FT))
return mapWindowsError(::GetLastError());
Expand Down
24 changes: 20 additions & 4 deletions lib/Support/Windows/Path.inc
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,16 @@ UniqueID file_status::getUniqueID() const {

TimeValue file_status::getLastModificationTime() const {
ULARGE_INTEGER UI;
UI.LowPart = LastWriteTimeLow;
UI.HighPart = LastWriteTimeHigh;
//#------------------
//# Mach change start
//#------------------
// UI.LowPart = LastWriteTimeLow;
// UI.HighPart = LastWriteTimeHigh;
UI.u.LowPart = LastWriteTimeLow;
UI.u.HighPart = LastWriteTimeHigh;
//#------------------
//# Mach change end
//#------------------

TimeValue Ret;
Ret.fromWin32Time(UI.QuadPart);
Expand Down Expand Up @@ -449,8 +457,16 @@ std::error_code setLastModificationAndAccessTime(int FD, TimeValue Time) {
ULARGE_INTEGER UI;
UI.QuadPart = Time.toWin32Time();
FILETIME FT;
FT.dwLowDateTime = UI.LowPart;
FT.dwHighDateTime = UI.HighPart;
//#------------------
//# Mach change start
//#------------------
// FT.dwLowDateTime = UI.LowPart;
// FT.dwHighDateTime = UI.HighPart;
FT.dwLowDateTime = UI.u.LowPart;
FT.dwHighDateTime = UI.u.HighPart;
//#------------------
//# Mach change end
//#------------------
HANDLE FileHandle = reinterpret_cast<HANDLE>(_get_osfhandle(FD));
if (!SetFileTime(FileHandle, NULL, &FT, &FT))
return mapWindowsError(::GetLastError());
Expand Down
Loading

0 comments on commit 95a93fe

Please sign in to comment.