Adding more core layer stuff. Can now boot.

This commit is contained in:
Patedam committed 2026-10-18 23:06:41 -04:00
1 parent 16664c68b5
commit 5d6ca639fd
30 files changed
+1308 -36

No files matched your search

+281 -16
View File
@@ -248,6 +248,241 @@ static void get_normalized_cwd(char* out_cwd, size_t out_cwd_size, char* out_rea
}
}
static int32 get_layer_order_from_main(char layers[32][64])
{
int32 count = 0;
FILE* file = fopen("Juliet/appbin/appbin_main.c", "rb");
if (file != NULL)
{
char line[512];
while (fgets(line, sizeof(line), file) != NULL)
{
char* inc_pos = strstr(line, "#include");
if (inc_pos != NULL)
{
char* quote_start = strchr(inc_pos, '"');
if (quote_start != NULL)
{
quote_start++;
char* slash = strchr(quote_start, '/');
if (slash == NULL)
{
slash = strchr(quote_start, '\\');
}
if (slash != NULL)
{
size_t layer_len = (size_t)(slash - quote_start);
if (layer_len > 0 && layer_len < 64)
{
char layer_name[64];
memcpy(layer_name, quote_start, layer_len);
layer_name[layer_len] = '\0';
char* quote_end = strchr(slash, '"');
if (quote_end != NULL && strstr(slash, "_inc.h") != NULL)
{
bool already_added = false;
for (int32 i = 0; i < count; ++i)
{
if (_stricmp(layers[i], layer_name) == 0)
{
already_added = true;
break;
}
}
if (!already_added && count < 32)
{
strncpy_s(layers[count], sizeof(layers[count]), layer_name, _TRUNCATE);
count++;
}
}
}
}
}
}
}
fclose(file);
}
// Always ensure "core" is present
bool has_core = false;
for (int32 i = 0; i < count; ++i)
{
if (_stricmp(layers[i], "core") == 0)
{
has_core = true;
break;
}
}
if (!has_core && count < 32)
{
for (int32 i = count; i > 0; --i)
{
strncpy_s(layers[i], sizeof(layers[i]), layers[i - 1], _TRUNCATE);
}
strncpy_s(layers[0], sizeof(layers[0]), "core", _TRUNCATE);
count++;
}
// Discover any other directories in Juliet/ that have <dir>_inc.h but weren't in appbin_main.c yet
WIN32_FIND_DATAA find_data;
HANDLE find_handle = FindFirstFileA("Juliet\\*", &find_data);
if (find_handle != INVALID_HANDLE_VALUE)
{
do
{
if (strcmp(find_data.cFileName, ".") == 0 || strcmp(find_data.cFileName, "..") == 0)
{
continue;
}
if (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if (_stricmp(find_data.cFileName, "src") == 0 ||
_stricmp(find_data.cFileName, "include") == 0 ||
_stricmp(find_data.cFileName, "appbin") == 0)
{
continue;
}
bool already = false;
for (int32 i = 0; i < count; ++i)
{
if (_stricmp(layers[i], find_data.cFileName) == 0)
{
already = true;
break;
}
}
if (!already && count < 32)
{
strncpy_s(layers[count], sizeof(layers[count]), find_data.cFileName, _TRUNCATE);
count++;
}
}
} while (FindNextFileA(find_handle, &find_data));
FindClose(find_handle);
}
return count;
}
static int32 find_layer_index_for_file(const char* file_path, char layers[32][64], int32 layer_count)
{
Assert(file_path != NULL);
if (strstr(file_path, "win32/core") != NULL || strstr(file_path, "win32\\core") != NULL)
{
for (int32 i = 0; i < layer_count; ++i)
{
if (_stricmp(layers[i], "core") == 0)
{
return i;
}
}
}
for (int32 i = 0; i < layer_count; ++i)
{
char prefix1[128];
char prefix2[128];
snprintf(prefix1, sizeof(prefix1), "Juliet/%s/", layers[i]);
snprintf(prefix2, sizeof(prefix2), "Juliet\\%s\\", layers[i]);
if (_strnicmp(file_path, prefix1, strlen(prefix1)) == 0 ||
_strnicmp(file_path, prefix2, strlen(prefix2)) == 0)
{
return i;
}
}
return -1;
}
static void get_preceding_includes_from_inc_h(const char* layer_name, const char* target_file_path, char* out_flags, size_t out_flags_size)
{
Assert(layer_name != NULL);
Assert(target_file_path != NULL);
Assert(out_flags != NULL);
char inc_h_path[512];
snprintf(inc_h_path, sizeof(inc_h_path), "Juliet/%s/%s_inc.h", layer_name, layer_name);
FILE* file = fopen(inc_h_path, "rb");
if (file == NULL)
{
return;
}
char line[512];
while (fgets(line, sizeof(line), file) != NULL)
{
char* hash = strchr(line, '#');
if (hash == NULL)
{
continue;
}
char* inc_pos = strstr(hash, "include");
if (inc_pos == NULL)
{
continue;
}
char* quote_start = strchr(inc_pos, '"');
if (quote_start == NULL)
{
continue;
}
quote_start++;
char* quote_end = strchr(quote_start, '"');
if (quote_end == NULL)
{
continue;
}
size_t inc_file_len = (size_t)(quote_end - quote_start);
if (inc_file_len == 0 || inc_file_len >= 256)
{
continue;
}
char inc_file[256];
memcpy(inc_file, quote_start, inc_file_len);
inc_file[inc_file_len] = '\0';
normalize_path_slashes_forward(inc_file);
char full_inc_path[512];
if (strstr(inc_file, "/") != NULL)
{
snprintf(full_inc_path, sizeof(full_inc_path), "Juliet/%s", inc_file);
}
else
{
snprintf(full_inc_path, sizeof(full_inc_path), "Juliet/%s/%s", layer_name, inc_file);
}
normalize_path_slashes_forward(full_inc_path);
char expected_suffix[256];
snprintf(expected_suffix, sizeof(expected_suffix), "/%s", inc_file);
if (_stricmp(full_inc_path, target_file_path) == 0 ||
str_ends_with_no_case(target_file_path, expected_suffix))
{
break;
}
char flag[512];
if (strstr(inc_file, "/") != NULL)
{
snprintf(flag, sizeof(flag), " \"/FI%s\",\n", inc_file);
}
else
{
snprintf(flag, sizeof(flag), " \"/FI%s/%s\",\n", layer_name, inc_file);
}
strncat_s(out_flags, out_flags_size, flag, _TRUNCATE);
}
fclose(file);
}
static void generate_compile_commands(void)
{
char cwd[512];
@@ -263,8 +498,10 @@ static void generate_compile_commands(void)
bool is_first = true;
// 1. Scan new Juliet modules (core, appbin, etc.)
// We scan folders directly inside Juliet/, ignoring legacy 'src' and 'include'
char layers[32][64];
int32 layer_count = get_layer_order_from_main(layers);
// 1. Scan new Juliet modules (core, render, ui, appbin, etc.)
WIN32_FIND_DATAA find_data;
HANDLE find_handle = FindFirstFileA("Juliet\\*", &find_data);
if (find_handle != INVALID_HANDLE_VALUE)
@@ -287,21 +524,49 @@ static void generate_compile_commands(void)
snprintf(module_dir, sizeof(module_dir), "Juliet\\%s", find_data.cFileName);
FileList module_files = {0};
find_files_recursive(module_dir, &module_files, false);
char module_name[64];
strncpy_s(module_name, sizeof(module_name), find_data.cFileName, _TRUNCATE);
char module_inc_flag[128] = "";
char module_inc_disk_path[512];
snprintf(module_inc_disk_path, sizeof(module_inc_disk_path), "Juliet\\%s\\%s_inc.h", module_name, module_name);
if (_stricmp(module_name, "core") != 0 && GetFileAttributesA(module_inc_disk_path) != INVALID_FILE_ATTRIBUTES)
{
snprintf(module_inc_flag, sizeof(module_inc_flag), " \"/FI%s/%s_inc.h\",\n", module_name, module_name);
}
find_files_recursive(module_dir, &module_files, true);
for (FileNode* node = module_files.first; node != NULL; node = node->next)
{
char forced_inc_flags[1024] = "";
int32 file_layer_idx = find_layer_index_for_file(node->path, layers, layer_count);
if (file_layer_idx >= 0 && _stricmp(layers[file_layer_idx], "appbin") != 0)
{
for (int32 i = 0; i <= file_layer_idx; ++i)
{
if (i < file_layer_idx)
{
char inc_disk_path[512];
snprintf(inc_disk_path, sizeof(inc_disk_path), "Juliet\\%s\\%s_inc.h", layers[i], layers[i]);
if (GetFileAttributesA(inc_disk_path) != INVALID_FILE_ATTRIBUTES)
{
char flag[128];
snprintf(flag, sizeof(flag), " \"/FI%s/%s_inc.h\",\n", layers[i], layers[i]);
strncat_s(forced_inc_flags, sizeof(forced_inc_flags), flag, _TRUNCATE);
}
}
else
{
if (is_c_source_file(node->path))
{
char inc_disk_path[512];
snprintf(inc_disk_path, sizeof(inc_disk_path), "Juliet\\%s\\%s_inc.h", layers[i], layers[i]);
if (GetFileAttributesA(inc_disk_path) != INVALID_FILE_ATTRIBUTES)
{
char flag[128];
snprintf(flag, sizeof(flag), " \"/FI%s/%s_inc.h\",\n", layers[i], layers[i]);
strncat_s(forced_inc_flags, sizeof(forced_inc_flags), flag, _TRUNCATE);
}
}
else if (!str_ends_with_no_case(node->path, "_inc.h"))
{
get_preceding_includes_from_inc_h(layers[i], node->path, forced_inc_flags, sizeof(forced_inc_flags));
}
}
}
}
const char* dirs_to_emit[2] = { cwd, (real_cwd[0] && _stricmp(cwd, real_cwd) != 0) ? real_cwd : NULL };
for (int32 d = 0; d < 2; d++)
@@ -331,16 +596,16 @@ static void generate_compile_commands(void)
" \"/clang:-std=c11\",\n"
" \"/W4\",\n"
" \"/Wno-unused-function\",\n"
" \"/clang:-Wno-initializer-overrides\",\n"
" \"/utf-8\",\n"
" \"/DBUILD_DEBUG=1\",\n"
" \"/IJuliet\",\n"
" \"/FIcore/core_inc.h\",\n"
"%s"
" \"-c\",\n"
" \"%s\"\n"
" ]\n"
" }",
dirs_to_emit[d], full_file_path, module_inc_flag, full_file_path);
dirs_to_emit[d], full_file_path, forced_inc_flags, full_file_path);
}
}