Fix build in release mode.

This commit is contained in:
Musa Mahmood 2025-12-18 21:04:19 -05:00
parent 14eb817631
commit 3335ac4cfd
11 changed files with 83 additions and 51 deletions

View File

@ -46,9 +46,6 @@ elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
) )
endif() endif()
SET (SYSTEM_LIBRARIES
)
add_executable(${EXE_NAME} ${SRC_FILES}) add_executable(${EXE_NAME} ${SRC_FILES})
target_include_directories(${EXE_NAME} PRIVATE ${INCLUDE_DIRS}) target_include_directories(${EXE_NAME} PRIVATE ${INCLUDE_DIRS})
target_link_libraries(${EXE_NAME} PRIVATE ${LINK_LIBS_DIRS} ${SYSTEM_LIBRARIES}) target_link_libraries(${EXE_NAME} PRIVATE ${LINK_LIBS_DIRS})

View File

@ -1,3 +1,9 @@
# Build Overview
- #TODO: Explain build configuration: library, exe
- Why do we use CMake (even though I hate it)? (because it's industry standard?)
- Plans to use a metaprogram to modify code for certain reasons (e.g. getting stack traces)
## Configuration ## Configuration
This project uses CMake to configure and build. Currently only Win32 is supported. This project uses CMake to configure and build. Currently only Win32 is supported.
``` ```
@ -7,8 +13,32 @@ cmake -S . -B build
``` ```
cmake --build build --config Debug cmake --build build --config Debug
``` ```
<!---build either with `build.cmd Debug` or `build.cmd Release`
Run `build_imgui_lib.cmd` to build imgui dependency
Both scripts must be run in x64 Native Tools Command Prompt for VS 20xx.
You can also build with `jai build.jai - build_exe` or `jai build.jai - build_exe release`---> ## Roadmap for Supporting Other platforms
- Linux
- MacOS
- Android
- iOS
# APIs
## Base Layer
### Thread-local Context
## OS Platform Layer
## Debug Tooling
# Explorer Application Notes
## File Enumeration
## Sorting
## Searching Algorithms
## Multithreading

View File

@ -1,7 +1,7 @@
// Treat library files as a single-file (single translation unit) header // Treat library files as a single-file header (single translation unit)
#include "lib_main.cpp" #include "lib_main.cpp"
#define BASE_RUN_TESTS BUILD_DEBUG #define BASE_RUN_TESTS 0
#define BUILD_EXPLORER_APP_WIN32 1 #define BUILD_EXPLORER_APP_WIN32 1
#define BUILD_CUSTOM_GUI 0 #define BUILD_CUSTOM_GUI 0
@ -17,6 +17,7 @@
#pragma comment(lib, "d3d11.lib") #pragma comment(lib, "d3d11.lib")
#pragma comment(lib, "dxgi.lib") #pragma comment(lib, "dxgi.lib")
#pragma comment(lib, "msvcrt.lib")
#include "lib/third_party/dear-imgui/imgui.h" #include "lib/third_party/dear-imgui/imgui.h"
#include "lib/third_party/dear-imgui/imgui_impl_win32.h" #include "lib/third_party/dear-imgui/imgui_impl_win32.h"

View File

@ -325,20 +325,26 @@ void* fixed_arena_allocator_proc (Allocator_Mode mode, s64 requested_size, s64 o
} }
force_inline void initialize_arenas_in_use_list () { force_inline void initialize_arenas_in_use_list () {
#if BUILD_DEBUG
if (arenas_in_use.allocated > 0) return; if (arenas_in_use.allocated > 0) return;
mutex_init(&arenas_in_use_mutex); mutex_init(&arenas_in_use_mutex);
arenas_in_use.allocator = default_allocator(); arenas_in_use.allocator = default_allocator();
array_reserve(arenas_in_use, 256); array_reserve(arenas_in_use, 256);
#endif
} }
force_inline void add_arena_to_in_use_list (Arena* arena) { force_inline void add_arena_to_in_use_list (Arena* arena) {
#if BUILD_DEBUG
Assert(arenas_in_use.allocated > 0); // check we initialized! Assert(arenas_in_use.allocated > 0); // check we initialized!
lock_guard(&arenas_in_use_mutex); lock_guard(&arenas_in_use_mutex);
array_add(arenas_in_use, arena); array_add(arenas_in_use, arena);
#endif
} }
force_inline void remove_arena_from_in_use_list (Arena* arena) { force_inline void remove_arena_from_in_use_list (Arena* arena) {
#if BUILD_DEBUG
Assert(arenas_in_use.allocated > 0); // check we initialized! Assert(arenas_in_use.allocated > 0); // check we initialized!
lock_guard(&arenas_in_use_mutex); lock_guard(&arenas_in_use_mutex);
array_unordered_remove_by_value(arenas_in_use, arena, 1); array_unordered_remove_by_value(arenas_in_use, arena, 1);
#endif
} }

View File

@ -139,10 +139,14 @@ static const int __arch_endian_check_num = 1;
#if defined(_MSC_VER) #if defined(_MSC_VER)
#ifdef _DEBUG #ifdef _DEBUG
#define BUILD_DEBUG 1 #define BUILD_DEBUG 1
#else
#define BUILD_DEBUG 0
#endif #endif
#elif defined(__GNUC__) || defined(__clang__) #elif defined(__GNUC__) || defined(__clang__)
#ifndef NDEBUG #ifndef NDEBUG
#define BUILD_DEBUG 1 #define BUILD_DEBUG 1
#else
#define BUILD_DEBUG 0
#endif #endif
#endif #endif

View File

@ -1,6 +1,7 @@
#if GP_ALLOCATOR_TRACK_ALLOCATIONS #if GP_ALLOCATOR_TRACK_ALLOCATIONS
global General_Allocator gAllocator; // @Shared global General_Allocator gAllocator; // @Shared
global Mutex allocator_mutex; global Mutex allocator_mutex;
global bool default_allocator_show_small_allocations = true;
#endif #endif
#if !COMPILER_MSVC #if !COMPILER_MSVC

View File

@ -79,6 +79,10 @@ string format_bytes (s64 bytes, s32 trailing_width = 3) {
unit_index += 1; unit_index += 1;
} }
// This makes the trailing width param kinda pointless... idk.
if (unit_index == 0) trailing_width = 0;
// if (unit_index == 1) trailing_width = 2;
switch (trailing_width) { switch (trailing_width) {
case 0: return format_string("%.0f %s", count_f64, units[unit_index].data); case 0: return format_string("%.0f %s", count_f64, units[unit_index].data);
case 1: return format_string("%.1f %s", count_f64, units[unit_index].data); case 1: return format_string("%.1f %s", count_f64, units[unit_index].data);

View File

@ -1088,8 +1088,13 @@ bool Win32_Discover_Drives () {
Win32_Max_Path_Length, &serial_number, &max_comp_len, &file_system_flags, Win32_Max_Path_Length, &serial_number, &max_comp_len, &file_system_flags,
(LPWSTR)file_system_name, Win32_Max_Path_Length)) { (LPWSTR)file_system_name, Win32_Max_Path_Length)) {
drive->label = drive_label; drive->label = drive_label;
if (volume_name[0] == 0) {
drive->volume_name = copy_string("Local Disk");
} else {
drive->volume_name = wide_to_utf8(volume_name); drive->volume_name = wide_to_utf8(volume_name);
if (drive->volume_name == "") { drive->volume_name = copy_string("Local Disk"); } }
if (drive->volume_name == "") { drive->volume_name = copy_string("Local Disk"); } // Probably redundant??
drive->type = (Win32_Drive_Type)drive_type; drive->type = (Win32_Drive_Type)drive_type;
{ push_allocator(temp()); { push_allocator(temp());
drive->file_system = Win32_filesystem_from_string(wide_to_utf8(file_system_name)); drive->file_system = Win32_filesystem_from_string(wide_to_utf8(file_system_name));

View File

@ -7,6 +7,7 @@ internal void Main_Entry_Point (int argc, WCHAR **argv);
return 0; return 0;
} }
#else #else
#pragma comment(linker, "/SUBSYSTEM:WINDOWS")
#include <cstdlib> // globals __argc, __wargv #include <cstdlib> // globals __argc, __wargv
int wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd) { int wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nShowCmd) {

View File

@ -50,6 +50,9 @@ bool Ex1_Register_Global_Hotkeys () {
global Key_Combination program_exit_hotkey { ImGuiKey_W, USE_CTRL, USE_SHIFT, KEY_UNUSED, TRIGGER_ONCE }; global Key_Combination program_exit_hotkey { ImGuiKey_W, USE_CTRL, USE_SHIFT, KEY_UNUSED, TRIGGER_ONCE };
global Key_Combination program_minimize_hotkey { ImGuiKey_W, USE_CTRL, KEY_UNUSED, KEY_UNUSED, TRIGGER_ONCE }; global Key_Combination program_minimize_hotkey { ImGuiKey_W, USE_CTRL, KEY_UNUSED, KEY_UNUSED, TRIGGER_ONCE };
global Key_Combination decrease_font_size_hotkey { ImGuiKey_Minus, USE_CTRL, KEY_UNUSED, KEY_UNUSED, TRIGGER_ONCE };
global Key_Combination increase_font_size_hotkey { ImGuiKey_Equal, USE_CTRL, KEY_UNUSED, KEY_UNUSED, TRIGGER_ONCE };
bool Ex1_check_key_combinations() { bool Ex1_check_key_combinations() {
update_global_keyboard_state(); update_global_keyboard_state();
// #program_hotkeys // #program_hotkeys
@ -59,6 +62,12 @@ bool Ex1_check_key_combinations() {
if (check_key_combination(&program_minimize_hotkey)) { if (check_key_combination(&program_minimize_hotkey)) {
Win32_Minimize_Window_To_Tray(get_main_window_pointer()); Win32_Minimize_Window_To_Tray(get_main_window_pointer());
} }
if (check_key_combination(&decrease_font_size_hotkey)) { // see ImGui_Show_Font_Info.
imgui_default_font.current_size = clamp<s64>(imgui_default_font.current_size - 1, 0, 5);
}
if (check_key_combination(&increase_font_size_hotkey)) {
imgui_default_font.current_size = clamp<s64>(imgui_default_font.current_size + 1, 0, 5);
}
// #Ex1_hotkeys // #Ex1_hotkeys
return false; return false;
} }
@ -224,12 +233,12 @@ void Ex1_Control_Panel () { using namespace ImGui;
// bool all_drives_enumerated = !ex1_ntfs.threads_in_flight.count // bool all_drives_enumerated = !ex1_ntfs.threads_in_flight.count
// && (drives_enumerated == drives.count); // && (drives_enumerated == drives.count);
// string file_path = format_string_temp("%s_DriveData.bin", os_get_machine_name().data); string file_path = format_string_temp("D:/TempSync/Filesystem_Data/%s_DriveData.bin", os_get_machine_name().data);
string file_path = "D:/TempSync/Filesystem_Data/MUSA-PC3_DriveData.bin"; // string file_path = "D:/TempSync/Filesystem_Data/MUSA-PC3_DriveData.bin";
Text("fixed file_path: %s", file_path.data); Text("fixed file_path: %s", file_path.data);
// if (!all_drives_enumerated && file_exists(file_path)) { // #autoload if (!all_drives_enumerated && file_exists(file_path)) { // #autoload
// Deserialize_ST_File_Enumeration(file_path); Deserialize_ST_File_Enumeration(file_path);
// } }
if (drives.count > 0 && !all_drives_enumerated && file_exists(file_path) && Button("Load from file (this machine)")) { if (drives.count > 0 && !all_drives_enumerated && file_exists(file_path) && Button("Load from file (this machine)")) {
Deserialize_ST_File_Enumeration(file_path); Deserialize_ST_File_Enumeration(file_path);
// Deserialize_Win32_Drives(file_path); // Deserialize_Win32_Drives(file_path);
@ -303,47 +312,21 @@ void ImGui_Debug_Panel () { using namespace ImGui;
Begin("Debug Panel"); Begin("Debug Panel");
// #cpuid // #cpuid
Text("[cpus] physical: %d, logical: %d, primary: %d, secondary: %d", os_cpu_physical_core_count(), os_cpu_logical_core_count(), os_cpu_primary_core_count(), os_cpu_secondary_core_count()); Text("[cpus] physical: %d, logical: %d, primary: %d, secondary: %d", os_cpu_physical_core_count(), os_cpu_logical_core_count(), os_cpu_primary_core_count(), os_cpu_secondary_core_count());
/*{ SeparatorText("Arena In-Use List");
lock_guard(&arena_free_list->mutex);
for (u8 i = 0; i < Arena_Reserve_Count; i += 1) {
#if ARENA_DEBUG
auto t = format_cstring(
" [%s] in_use: %d, committed_bytes: %s",
format_bytes(Arena_Sizes[i], 0).data,
arena_free_list->in_flight_count[i],
format_bytes(committed_bytes(arena_free_list->in_flight[i])).data
);
#else
auto t = format_cstring(
" [%s] in_use: %d, committed_bytes: %s",
format_bytes(Arena_Sizes[i], 0).data,
arena_free_list->in_flight_count[i],
"disabled in release mode"
);
#endif
Text(t);
}
SeparatorText("Arena Free List");
for (u8 i = 0; i < Arena_Reserve_Count; i += 1) {
auto t = format_cstring(
" [%s] free: %d, committed_bytes: %s",
format_bytes(Arena_Sizes[i], 0).data,
(s32)arena_free_list->free_table[i].count,
format_bytes(committed_bytes(arena_free_list->free_table[i])).data
);
Text(t);
}
}*/
#if BUILD_DEBUG #if BUILD_DEBUG
SeparatorText("Default Allocator Allocations"); SeparatorText("Default Allocator Allocations");
{ lock_guard(&allocator_mutex); { lock_guard(&allocator_mutex);
// Replace this with two sliders min and max to filter allocations?
Checkbox("Show small allocations (<1kB)", &default_allocator_show_small_allocations);
auto allocations = to_view(get_general_allocator_data()->allocations); auto allocations = to_view(get_general_allocator_data()->allocations);
Text("%s in %lld allocations", Text("%s in %lld allocations",
format_bytes(get_general_allocator_data()->total_bytes_allocated).data, format_bytes(get_general_allocator_data()->total_bytes_allocated).data,
allocations.count); allocations.count);
for_each(a, allocations) { for_each(a, allocations) {
Text(" [%lld] ptr: %p (size: %lld, alignment: %d)", if (!default_allocator_show_small_allocations && allocations[a].size < 1024) {
a, allocations[a].memory, allocations[a].size, allocations[a].alignment); continue;
}
Text(" [%lld] ptr: %p (size: %s, alignment: %d)",
a, allocations[a].memory, format_bytes(allocations[a].size).data, allocations[a].alignment);
} }
} }
SeparatorText("Arenas in Use"); SeparatorText("Arenas in Use");

View File

@ -151,7 +151,7 @@ void Explorer_ImGui_Application_Win32 () {
ImGui_Debug_Panel(); ImGui_Debug_Panel();
Ex1_Control_Panel(); Ex1_Control_Panel();
ImGui_Show_Font_Info(); // ImGui_Show_Font_Info();
ImGui_Pop_Default_Font(); ImGui_Pop_Default_Font();