no need to use juliet obj everywhere, compile the dll directly
This commit is contained in:
+80
-78
@@ -6,18 +6,18 @@
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <cassert>
|
||||
#include <windows.h>
|
||||
|
||||
// ============================================================================
|
||||
// Minimal string / path helpers (no STL, no std::filesystem — pure speed)
|
||||
// ============================================================================
|
||||
|
||||
static constexpr int MaxPath = 1024;
|
||||
static constexpr int MaxFiles = 4096;
|
||||
static constexpr int MaxPath = 1024;
|
||||
static constexpr int MaxFiles = 4096;
|
||||
static constexpr int MaxHashEntries = 512;
|
||||
|
||||
struct FixedString
|
||||
@@ -25,7 +25,11 @@ struct FixedString
|
||||
char Data[MaxPath];
|
||||
int Length;
|
||||
|
||||
FixedString() : Data{}, Length(0) {}
|
||||
FixedString()
|
||||
: Data{}
|
||||
, Length(0)
|
||||
{
|
||||
}
|
||||
|
||||
void Set(const char* str)
|
||||
{
|
||||
@@ -48,7 +52,7 @@ struct FixedString
|
||||
Data[i] = str[i];
|
||||
}
|
||||
Data[len] = '\0';
|
||||
Length = len;
|
||||
Length = len;
|
||||
}
|
||||
|
||||
void Append(const char* str)
|
||||
@@ -67,7 +71,7 @@ struct FixedString
|
||||
if (Length < MaxPath - 1)
|
||||
{
|
||||
Data[Length++] = c;
|
||||
Data[Length] = '\0';
|
||||
Data[Length] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,8 +121,9 @@ struct FileContent
|
||||
[[nodiscard]] static FileContent ReadEntireFile(const char* path)
|
||||
{
|
||||
assert(path != nullptr);
|
||||
FileContent result = {nullptr, 0};
|
||||
HANDLE file = CreateFileA(path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
|
||||
FileContent result = { nullptr, 0 };
|
||||
HANDLE file = CreateFileA(path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_EXISTING,
|
||||
FILE_ATTRIBUTE_NORMAL, nullptr);
|
||||
if (file == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
return result;
|
||||
@@ -139,8 +144,8 @@ struct FileContent
|
||||
ReadFile(file, buffer, size, &bytesRead, nullptr);
|
||||
CloseHandle(file);
|
||||
buffer[bytesRead] = '\0';
|
||||
result.Data = buffer;
|
||||
result.Size = bytesRead;
|
||||
result.Data = buffer;
|
||||
result.Size = bytesRead;
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -158,7 +163,8 @@ static bool WriteEntireFile(const char* path, const char* data, DWORD size)
|
||||
{
|
||||
assert(path != nullptr);
|
||||
assert(data != nullptr);
|
||||
HANDLE file = CreateFileA(path, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
|
||||
HANDLE file = CreateFileA(path, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, CREATE_ALWAYS,
|
||||
FILE_ATTRIBUTE_NORMAL, nullptr);
|
||||
if (file == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
return false;
|
||||
@@ -196,7 +202,7 @@ static void EnsureDirectoryExists(const char* path)
|
||||
if (GetFileAttributesExA(path, GetFileExInfoStandard, &data))
|
||||
{
|
||||
ULARGE_INTEGER li;
|
||||
li.LowPart = data.ftLastWriteTime.dwLowDateTime;
|
||||
li.LowPart = data.ftLastWriteTime.dwLowDateTime;
|
||||
li.HighPart = data.ftLastWriteTime.dwHighDateTime;
|
||||
return static_cast<int64_t>(li.QuadPart);
|
||||
}
|
||||
@@ -250,7 +256,7 @@ struct HashCache
|
||||
}
|
||||
}
|
||||
|
||||
HashCache(const HashCache&) = delete;
|
||||
HashCache(const HashCache&) = delete;
|
||||
HashCache& operator=(const HashCache&) = delete;
|
||||
|
||||
[[nodiscard]] const char* Find(const char* path) const
|
||||
@@ -314,7 +320,7 @@ static void LoadHashCache(const char* cachePath, HashCache& cache)
|
||||
FixedString key;
|
||||
key.Set(lineStart, static_cast<int>(sep - lineStart));
|
||||
|
||||
int valLen = static_cast<int>((lineStart + lineLen) - (sep + 1));
|
||||
int valLen = static_cast<int>((lineStart + lineLen) - (sep + 1));
|
||||
char val[32] = {};
|
||||
if (valLen > 0 && valLen < 32)
|
||||
{
|
||||
@@ -338,7 +344,7 @@ static void SaveHashCache(const char* cachePath, const HashCache& cache)
|
||||
{
|
||||
assert(cachePath != nullptr);
|
||||
size_t bufSize = static_cast<size_t>(MaxHashEntries) * (MaxPath + 32 + 2);
|
||||
char* buffer = static_cast<char*>(HeapAlloc(GetProcessHeap(), 0, bufSize));
|
||||
char* buffer = static_cast<char*>(HeapAlloc(GetProcessHeap(), 0, bufSize));
|
||||
if (buffer == nullptr)
|
||||
{
|
||||
return;
|
||||
@@ -347,8 +353,8 @@ static void SaveHashCache(const char* cachePath, const HashCache& cache)
|
||||
|
||||
for (int i = 0; i < cache.Count; i++)
|
||||
{
|
||||
int written = sprintf_s(buffer + offset, bufSize - static_cast<size_t>(offset),
|
||||
"%s=%s\n", cache.Entries[i].Path.Data, cache.Entries[i].HashStr);
|
||||
int written = sprintf_s(buffer + offset, bufSize - static_cast<size_t>(offset), "%s=%s\n",
|
||||
cache.Entries[i].Path.Data, cache.Entries[i].HashStr);
|
||||
if (written > 0)
|
||||
{
|
||||
offset += written;
|
||||
@@ -372,7 +378,7 @@ struct CleanResult
|
||||
[[nodiscard]] static CleanResult CleanAndHashUnityFile(const char* filePath)
|
||||
{
|
||||
assert(filePath != nullptr);
|
||||
CleanResult result = {{}, false};
|
||||
CleanResult result = { {}, false };
|
||||
|
||||
FileContent content = ReadEntireFile(filePath);
|
||||
if (content.Data == nullptr)
|
||||
@@ -461,7 +467,7 @@ struct CleanResult
|
||||
searchPath.Append("\\*");
|
||||
|
||||
WIN32_FIND_DATAA findData;
|
||||
HANDLE hFind = FindFirstFileA(searchPath.Data, &findData);
|
||||
HANDLE hFind = FindFirstFileA(searchPath.Data, &findData);
|
||||
if (hFind == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
return newest;
|
||||
@@ -490,23 +496,22 @@ struct CleanResult
|
||||
}
|
||||
else
|
||||
{
|
||||
if (EndsWithNoCase(findData.cFileName, ".cpp") ||
|
||||
EndsWithNoCase(findData.cFileName, ".h") ||
|
||||
EndsWithNoCase(findData.cFileName, ".hpp") ||
|
||||
EndsWithNoCase(findData.cFileName, ".inl") ||
|
||||
if (EndsWithNoCase(findData.cFileName, ".cpp") || EndsWithNoCase(findData.cFileName, ".h") ||
|
||||
EndsWithNoCase(findData.cFileName, ".hpp") || EndsWithNoCase(findData.cFileName, ".inl") ||
|
||||
EndsWithNoCase(findData.cFileName, ".c"))
|
||||
{
|
||||
ULARGE_INTEGER li;
|
||||
li.LowPart = findData.ftLastWriteTime.dwLowDateTime;
|
||||
li.LowPart = findData.ftLastWriteTime.dwLowDateTime;
|
||||
li.HighPart = findData.ftLastWriteTime.dwHighDateTime;
|
||||
int64_t ft = static_cast<int64_t>(li.QuadPart);
|
||||
int64_t ft = static_cast<int64_t>(li.QuadPart);
|
||||
if (ft > newest)
|
||||
{
|
||||
newest = ft;
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (FindNextFileA(hFind, &findData));
|
||||
}
|
||||
while (FindNextFileA(hFind, &findData));
|
||||
|
||||
FindClose(hFind);
|
||||
return newest;
|
||||
@@ -537,7 +542,7 @@ struct FilePathList
|
||||
}
|
||||
}
|
||||
|
||||
FilePathList(const FilePathList&) = delete;
|
||||
FilePathList(const FilePathList&) = delete;
|
||||
FilePathList& operator=(const FilePathList&) = delete;
|
||||
|
||||
void Add(const char* path)
|
||||
@@ -559,7 +564,7 @@ static void CollectUnityFiles(const char* dirPath, FilePathList& list)
|
||||
searchPath.Append("\\*");
|
||||
|
||||
WIN32_FIND_DATAA findData;
|
||||
HANDLE hFind = FindFirstFileA(searchPath.Data, &findData);
|
||||
HANDLE hFind = FindFirstFileA(searchPath.Data, &findData);
|
||||
if (hFind == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
return;
|
||||
@@ -589,7 +594,8 @@ static void CollectUnityFiles(const char* dirPath, FilePathList& list)
|
||||
list.Add(fullPath.Data);
|
||||
}
|
||||
}
|
||||
} while (FindNextFileA(hFind, &findData));
|
||||
}
|
||||
while (FindNextFileA(hFind, &findData));
|
||||
|
||||
FindClose(hFind);
|
||||
}
|
||||
@@ -608,7 +614,7 @@ static int CommandStartBuild()
|
||||
FILETIME ft;
|
||||
GetSystemTimeAsFileTime(&ft);
|
||||
ULARGE_INTEGER li;
|
||||
li.LowPart = ft.dwLowDateTime;
|
||||
li.LowPart = ft.dwLowDateTime;
|
||||
li.HighPart = ft.dwHighDateTime;
|
||||
|
||||
char buf[32];
|
||||
@@ -627,11 +633,11 @@ static int CommandStartStep(int argc, char* argv[])
|
||||
FILETIME ft;
|
||||
GetSystemTimeAsFileTime(&ft);
|
||||
ULARGE_INTEGER li;
|
||||
li.LowPart = ft.dwLowDateTime;
|
||||
li.LowPart = ft.dwLowDateTime;
|
||||
li.HighPart = ft.dwHighDateTime;
|
||||
|
||||
char buf[MaxPath + 64];
|
||||
int len = sprintf_s(buf, "%s\n%llu\n", stepName, li.QuadPart);
|
||||
int len = sprintf_s(buf, "%s\n%llu\n", stepName, li.QuadPart);
|
||||
if (len > 0)
|
||||
{
|
||||
WriteEntireFile("Intermediate\\step_start.tmp", buf, static_cast<DWORD>(len));
|
||||
@@ -653,8 +659,8 @@ static int CommandEndStep(int argc, char* argv[])
|
||||
return 0;
|
||||
}
|
||||
|
||||
char stepName[MaxPath] = "Unnamed Step";
|
||||
uint64_t startTicks = 0;
|
||||
char stepName[MaxPath] = "Unnamed Step";
|
||||
uint64_t startTicks = 0;
|
||||
|
||||
const char* line1End = strchr(content.Data, '\n');
|
||||
if (line1End != nullptr)
|
||||
@@ -678,18 +684,18 @@ static int CommandEndStep(int argc, char* argv[])
|
||||
FILETIME ftNow;
|
||||
GetSystemTimeAsFileTime(&ftNow);
|
||||
ULARGE_INTEGER nowLi;
|
||||
nowLi.LowPart = ftNow.dwLowDateTime;
|
||||
nowLi.LowPart = ftNow.dwLowDateTime;
|
||||
nowLi.HighPart = ftNow.dwHighDateTime;
|
||||
|
||||
double elapsedSeconds = static_cast<double>(nowLi.QuadPart - startTicks) / 10000000.0;
|
||||
|
||||
char appendBuf[MaxPath + 64];
|
||||
int appendLen = sprintf_s(appendBuf, "%s|%.3fs\n", stepName, elapsedSeconds);
|
||||
int appendLen = sprintf_s(appendBuf, "%s|%.3fs\n", stepName, elapsedSeconds);
|
||||
if (appendLen > 0)
|
||||
{
|
||||
FileContent existing = ReadEntireFile("Intermediate\\step_timings.tmp");
|
||||
DWORD newSize = static_cast<DWORD>(appendLen) + existing.Size;
|
||||
char* combined = static_cast<char*>(HeapAlloc(GetProcessHeap(), 0, newSize + 1));
|
||||
DWORD newSize = static_cast<DWORD>(appendLen) + existing.Size;
|
||||
char* combined = static_cast<char*>(HeapAlloc(GetProcessHeap(), 0, newSize + 1));
|
||||
if (combined != nullptr)
|
||||
{
|
||||
DWORD offset = 0;
|
||||
@@ -712,8 +718,8 @@ static int CommandEndStep(int argc, char* argv[])
|
||||
static int CommandFinishBuild()
|
||||
{
|
||||
// Compute elapsed time
|
||||
const char* elapsedStr = "0.000s";
|
||||
char elapsedBuf[64] = {};
|
||||
const char* elapsedStr = "0.000s";
|
||||
char elapsedBuf[64] = {};
|
||||
|
||||
if (FileExists("Intermediate\\build_start.tmp"))
|
||||
{
|
||||
@@ -727,7 +733,7 @@ static int CommandFinishBuild()
|
||||
FILETIME ftNow;
|
||||
GetSystemTimeAsFileTime(&ftNow);
|
||||
ULARGE_INTEGER nowLi;
|
||||
nowLi.LowPart = ftNow.dwLowDateTime;
|
||||
nowLi.LowPart = ftNow.dwLowDateTime;
|
||||
nowLi.HighPart = ftNow.dwHighDateTime;
|
||||
|
||||
double elapsedSeconds = static_cast<double>(nowLi.QuadPart - startTicks) / 10000000.0;
|
||||
@@ -739,10 +745,10 @@ static int CommandFinishBuild()
|
||||
else
|
||||
{
|
||||
int totalMs = static_cast<int>(elapsedSeconds * 1000.0);
|
||||
int hours = totalMs / 3600000;
|
||||
int hours = totalMs / 3600000;
|
||||
int minutes = (totalMs % 3600000) / 60000;
|
||||
int seconds = (totalMs % 60000) / 1000;
|
||||
int ms = totalMs % 1000;
|
||||
int ms = totalMs % 1000;
|
||||
sprintf_s(elapsedBuf, "%02d:%02d:%02d.%03d", hours, minutes, seconds, ms);
|
||||
}
|
||||
elapsedStr = elapsedBuf;
|
||||
@@ -785,7 +791,7 @@ static int CommandFinishBuild()
|
||||
if (pipePos != nullptr)
|
||||
{
|
||||
char stepName[MaxPath] = {};
|
||||
int nameLen = static_cast<int>(pipePos - lineStart);
|
||||
int nameLen = static_cast<int>(pipePos - lineStart);
|
||||
if (nameLen < MaxPath)
|
||||
{
|
||||
memcpy(stepName, lineStart, static_cast<size_t>(nameLen));
|
||||
@@ -793,7 +799,7 @@ static int CommandFinishBuild()
|
||||
}
|
||||
|
||||
char durationStr[64] = {};
|
||||
int durLen = static_cast<int>((lineStart + lineLen) - (pipePos + 1));
|
||||
int durLen = static_cast<int>((lineStart + lineLen) - (pipePos + 1));
|
||||
if (durLen < 64)
|
||||
{
|
||||
memcpy(durationStr, pipePos + 1, static_cast<size_t>(durLen));
|
||||
@@ -816,7 +822,7 @@ static int CommandFinishBuild()
|
||||
if (FileExists("Intermediate\\built_outputs.tmp"))
|
||||
{
|
||||
FileContent outputsContent = ReadEntireFile("Intermediate\\built_outputs.tmp");
|
||||
bool anyPrinted = false;
|
||||
bool anyPrinted = false;
|
||||
|
||||
if (outputsContent.Data != nullptr)
|
||||
{
|
||||
@@ -848,9 +854,9 @@ static int CommandFinishBuild()
|
||||
if (GetFileAttributesExA(filePath, GetFileExInfoStandard, &fileData))
|
||||
{
|
||||
ULARGE_INTEGER fileSize;
|
||||
fileSize.LowPart = fileData.nFileSizeLow;
|
||||
fileSize.LowPart = fileData.nFileSizeLow;
|
||||
fileSize.HighPart = fileData.nFileSizeHigh;
|
||||
double sizeMB = static_cast<double>(fileSize.QuadPart) / (1024.0 * 1024.0);
|
||||
double sizeMB = static_cast<double>(fileSize.QuadPart) / (1024.0 * 1024.0);
|
||||
printf(" - %s (%.2f MB)\n", filePath, sizeMB);
|
||||
anyPrinted = true;
|
||||
}
|
||||
@@ -882,11 +888,11 @@ static int CommandEvaluate(int argc, char* argv[])
|
||||
QueryPerformanceCounter(&perfStart);
|
||||
QueryPerformanceFrequency(&perfFreq);
|
||||
|
||||
const char* cfg = (argc > 2) ? argv[2] : "Debug";
|
||||
bool targetJuliet = (argc > 3) && argv[3][0] == '1';
|
||||
bool targetGame = (argc > 4) && argv[4][0] == '1';
|
||||
bool targetRomeo = (argc > 5) && argv[5][0] == '1';
|
||||
bool targetShader = (argc > 6) && argv[6][0] == '1';
|
||||
const char* cfg = (argc > 2) ? argv[2] : "Debug";
|
||||
bool targetJuliet = (argc > 3) && argv[3][0] == '1';
|
||||
bool targetGame = (argc > 4) && argv[4][0] == '1';
|
||||
bool targetRomeo = (argc > 5) && argv[5][0] == '1';
|
||||
bool targetShader = (argc > 6) && argv[6][0] == '1';
|
||||
|
||||
EnsureDirectoryExists("Intermediate");
|
||||
|
||||
@@ -895,7 +901,7 @@ static int CommandEvaluate(int argc, char* argv[])
|
||||
LoadHashCache("Intermediate\\.unity_hashes_cache", oldCache);
|
||||
|
||||
HashCache newCache;
|
||||
bool unityChanged = false;
|
||||
bool unityChanged = false;
|
||||
|
||||
FilePathList unityFiles;
|
||||
CollectUnityFiles("Intermediate", unityFiles);
|
||||
@@ -955,12 +961,12 @@ static int CommandEvaluate(int argc, char* argv[])
|
||||
|
||||
char path[MaxPath];
|
||||
|
||||
sprintf_s(path, "%s\\Juliet_Unity1.obj", intDir);
|
||||
bool julietNeed = unityChanged || !IsUpToDate(path, julietCombined);
|
||||
|
||||
sprintf_s(path, "%s\\ImGui_Unity1.obj", intDir);
|
||||
bool imguiNeed = unityChanged || !IsUpToDate(path, imguiTime);
|
||||
|
||||
sprintf_s(path, "%s\\Juliet.dll", binDir);
|
||||
bool julietNeed = unityChanged || !IsUpToDate(path, julietCombined);
|
||||
|
||||
bool gameNeed = false;
|
||||
if (targetJuliet || targetGame)
|
||||
{
|
||||
@@ -990,26 +996,22 @@ static int CommandEvaluate(int argc, char* argv[])
|
||||
}
|
||||
|
||||
QueryPerformanceCounter(&perfEnd);
|
||||
double durationMs = static_cast<double>(perfEnd.QuadPart - perfStart.QuadPart) * 1000.0 / static_cast<double>(perfFreq.QuadPart);
|
||||
double durationMs =
|
||||
static_cast<double>(perfEnd.QuadPart - perfStart.QuadPart) * 1000.0 / static_cast<double>(perfFreq.QuadPart);
|
||||
printf("[PERF] Fast Native C++ EvaluateConfig: %.1f ms\n", durationMs);
|
||||
|
||||
// Write results
|
||||
char statusBuf[512];
|
||||
int statusLen = sprintf_s(statusBuf,
|
||||
"FASTBUILD_UNITY_CHANGED=%d\n"
|
||||
"JULIET_NEED_COMPILE=%d\n"
|
||||
"IMGUI_NEED_COMPILE=%d\n"
|
||||
"GAME_NEED_COMPILE=%d\n"
|
||||
"JULIETAPP_NEED_COMPILE=%d\n"
|
||||
"ROMEO_NEED_COMPILE=%d\n"
|
||||
"SHADER_NEED_COMPILE=%d\n",
|
||||
unityChanged ? 1 : 0,
|
||||
julietNeed ? 1 : 0,
|
||||
imguiNeed ? 1 : 0,
|
||||
gameNeed ? 1 : 0,
|
||||
julietAppNeed ? 1 : 0,
|
||||
romeoNeed ? 1 : 0,
|
||||
shaderNeed ? 1 : 0);
|
||||
int statusLen = sprintf_s(statusBuf,
|
||||
"FASTBUILD_UNITY_CHANGED=%d\n"
|
||||
"JULIET_NEED_COMPILE=%d\n"
|
||||
"IMGUI_NEED_COMPILE=%d\n"
|
||||
"GAME_NEED_COMPILE=%d\n"
|
||||
"JULIETAPP_NEED_COMPILE=%d\n"
|
||||
"ROMEO_NEED_COMPILE=%d\n"
|
||||
"SHADER_NEED_COMPILE=%d\n",
|
||||
unityChanged ? 1 : 0, julietNeed ? 1 : 0, imguiNeed ? 1 : 0, gameNeed ? 1 : 0,
|
||||
julietAppNeed ? 1 : 0, romeoNeed ? 1 : 0, shaderNeed ? 1 : 0);
|
||||
|
||||
WriteEntireFile("Intermediate\\config_status.tmp", statusBuf, static_cast<DWORD>(statusLen));
|
||||
fflush(stdout);
|
||||
@@ -1038,10 +1040,10 @@ int main(int argc, char* argv[])
|
||||
const char* cmd = argv[1];
|
||||
if (strcmp(cmd, "check_alive") == 0) return 0;
|
||||
if (strcmp(cmd, "start_build") == 0) return CommandStartBuild();
|
||||
if (strcmp(cmd, "start_step") == 0) return CommandStartStep(argc, argv);
|
||||
if (strcmp(cmd, "end_step") == 0) return CommandEndStep(argc, argv);
|
||||
if (strcmp(cmd, "finish_build")== 0) return CommandFinishBuild();
|
||||
if (strcmp(cmd, "evaluate") == 0) return CommandEvaluate(argc, argv);
|
||||
if (strcmp(cmd, "start_step") == 0) return CommandStartStep(argc, argv);
|
||||
if (strcmp(cmd, "end_step") == 0) return CommandEndStep(argc, argv);
|
||||
if (strcmp(cmd, "finish_build") == 0) return CommandFinishBuild();
|
||||
if (strcmp(cmd, "evaluate") == 0) return CommandEvaluate(argc, argv);
|
||||
|
||||
printf("[ERROR] Unknown command: %s\n", cmd);
|
||||
return 1;
|
||||
|
||||
Reference in New Issue
Block a user