Fix build in release mode.

This commit is contained in:
Musa Mahmood 2025-12-18 21:04:19 -05:00
parent 14eb817631
commit c9941629d8
13 changed files with 129 additions and 65 deletions

View File

@ -46,9 +46,15 @@ elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
)
endif()
SET (SYSTEM_LIBRARIES
)
add_executable(${EXE_NAME} ${SRC_FILES})
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})
message(STATUS "Build type: $<CONFIG>")
add_custom_command(TARGET ${EXE_NAME} POST_BUILD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND ${CMAKE_COMMAND} -E echo "Running post-build script..."
COMMAND cmd.exe /c "${CMAKE_SOURCE_DIR}/copy_files.cmd" $<CONFIG>
COMMENT "Running custom post-build script."
)

View File

@ -1,14 +1,49 @@
# 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
This project uses CMake to configure and build. Currently only Win32 is supported.
```
cmake -S . -B build
```
## Build
To build in debug mode:
```
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.
To build in release mode:
```
cmake --build build --config Release
```
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

17
copy_files.cmd Normal file
View File

@ -0,0 +1,17 @@
@echo off
set CONFIG=%1
echo Build configuration is: %CONFIG%
if /i "%CONFIG%"=="Debug" (
echo Copying files to debug directory
copy /Y "extras\fonts\RobotoMono-Regular.ttf" "build\Debug\RobotoMono-Regular.ttf"
copy /Y "extras\icons\tmp.ico" "build\Debug\tmp.ico"
copy /Y "extras\icons\tmp_min.ico" "build\Debug\tmp_min.ico"
:: #TODO: Copy DLLs: Varjo
rem copy /Y "third_party\bin\some_dll.dll" "build/Debug\some_dll.dll"
) else if /i "%CONFIG%"=="Release" (
echo Copying files to release directory
copy /Y "extras\fonts\RobotoMono-Regular.ttf" "build\Release\RobotoMono-Regular.ttf"
copy /Y "extras\icons\tmp.ico" "build\Release\tmp.ico"
copy /Y "extras\icons\tmp_min.ico" "build\Release\tmp_min.ico"
)

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"
#define BASE_RUN_TESTS BUILD_DEBUG
#define BASE_RUN_TESTS 0
#define BUILD_EXPLORER_APP_WIN32 1
#define BUILD_CUSTOM_GUI 0
@ -17,6 +17,7 @@
#pragma comment(lib, "d3d11.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_impl_win32.h"

View File

@ -26,12 +26,12 @@ Collapsed=0
[Window][WindowOverViewport_11111111]
Pos=0,0
Size=4533,1681
Size=3391,1672
Collapsed=0
[Window][Font Settings]
Pos=0,1565
Size=3372,116
Pos=0,1556
Size=1371,116
Collapsed=0
DockId=0x00000001,0
@ -41,30 +41,30 @@ Size=691,540
Collapsed=0
[Window][Debug Panel]
Pos=3374,0
Size=1159,816
Pos=1374,0
Size=2017,1269
Collapsed=0
DockId=0x00000005,0
[Window][Control Panel]
Pos=3374,818
Size=1159,863
Pos=1374,1272
Size=2017,400
Collapsed=0
DockId=0x00000006,0
[Window][Enumerated Data Workspace]
Pos=0,0
Size=3372,1563
Size=1371,1672
Collapsed=0
DockId=0x00000002,0
[Docking][Data]
DockSpace ID=0x08BD597D Window=0x1BBC0F80 Pos=294,254 Size=4533,1681 Split=X Selected=0x1FC7AC8C
DockNode ID=0x00000003 Parent=0x08BD597D SizeRef=3372,1672 Split=Y
DockSpace ID=0x08BD597D Window=0x1BBC0F80 Pos=225,261 Size=3391,1672 Split=X Selected=0x1FC7AC8C
DockNode ID=0x00000003 Parent=0x08BD597D SizeRef=1371,1672 Split=Y
DockNode ID=0x00000002 Parent=0x00000003 SizeRef=1582,1553 CentralNode=1 Selected=0x671FC263
DockNode ID=0x00000001 Parent=0x00000003 SizeRef=1582,116 Selected=0x355F9D19
DockNode ID=0x00000004 Parent=0x08BD597D SizeRef=1159,1672 Split=Y Selected=0xD2C573A7
DockNode ID=0x00000005 Parent=0x00000004 SizeRef=1351,536 Selected=0xD2C573A7
DockNode ID=0x00000006 Parent=0x00000004 SizeRef=1351,567 Selected=0xF930105C
DockNode ID=0x00000004 Parent=0x08BD597D SizeRef=2017,1672 Split=Y Selected=0xD2C573A7
DockNode ID=0x00000005 Parent=0x00000004 SizeRef=1351,1269 Selected=0xD2C573A7
DockNode ID=0x00000006 Parent=0x00000004 SizeRef=1351,400 Selected=0xF930105C
DockSpace ID=0xC0DFADC4 Pos=0,51 Size=2560,1511 CentralNode=1 Selected=0x5E5F7166

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 () {
#if BUILD_DEBUG
if (arenas_in_use.allocated > 0) return;
mutex_init(&arenas_in_use_mutex);
arenas_in_use.allocator = default_allocator();
array_reserve(arenas_in_use, 256);
#endif
}
force_inline void add_arena_to_in_use_list (Arena* arena) {
#if BUILD_DEBUG
Assert(arenas_in_use.allocated > 0); // check we initialized!
lock_guard(&arenas_in_use_mutex);
array_add(arenas_in_use, arena);
#endif
}
force_inline void remove_arena_from_in_use_list (Arena* arena) {
#if BUILD_DEBUG
Assert(arenas_in_use.allocated > 0); // check we initialized!
lock_guard(&arenas_in_use_mutex);
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)
#ifdef _DEBUG
#define BUILD_DEBUG 1
#else
#define BUILD_DEBUG 0
#endif
#elif defined(__GNUC__) || defined(__clang__)
#ifndef NDEBUG
#define BUILD_DEBUG 1
#else
#define BUILD_DEBUG 0
#endif
#endif

View File

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

View File

@ -79,6 +79,10 @@ string format_bytes (s64 bytes, s32 trailing_width = 3) {
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) {
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);

View File

@ -1088,8 +1088,13 @@ bool Win32_Discover_Drives () {
Win32_Max_Path_Length, &serial_number, &max_comp_len, &file_system_flags,
(LPWSTR)file_system_name, Win32_Max_Path_Length)) {
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);
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;
{ push_allocator(temp());
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;
}
#else
#pragma comment(linker, "/SUBSYSTEM:WINDOWS")
#include <cstdlib> // globals __argc, __wargv
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_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() {
update_global_keyboard_state();
// #program_hotkeys
@ -59,6 +62,12 @@ bool Ex1_check_key_combinations() {
if (check_key_combination(&program_minimize_hotkey)) {
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
return false;
}
@ -73,7 +82,8 @@ struct Ex1_Workspace {
RadixSort dir_modtime_radix;
bool sort_completed;
// Reordered strings:
// Reordered strings: #note: these are NOT required to save in memory, better to search and
// sort the filtered strings using the solved radices
ArrayView<string> files_sorted_by_size;
ArrayView<string> files_sorted_by_modtime;
};
@ -224,12 +234,12 @@ void Ex1_Control_Panel () { using namespace ImGui;
// bool all_drives_enumerated = !ex1_ntfs.threads_in_flight.count
// && (drives_enumerated == drives.count);
// string file_path = format_string_temp("%s_DriveData.bin", os_get_machine_name().data);
string file_path = "D:/TempSync/Filesystem_Data/MUSA-PC3_DriveData.bin";
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";
Text("fixed file_path: %s", file_path.data);
// if (!all_drives_enumerated && file_exists(file_path)) { // #autoload
// Deserialize_ST_File_Enumeration(file_path);
// }
if (!all_drives_enumerated && file_exists(file_path)) { // #autoload
Deserialize_ST_File_Enumeration(file_path);
}
if (drives.count > 0 && !all_drives_enumerated && file_exists(file_path) && Button("Load from file (this machine)")) {
Deserialize_ST_File_Enumeration(file_path);
// Deserialize_Win32_Drives(file_path);
@ -303,47 +313,21 @@ void ImGui_Debug_Panel () { using namespace ImGui;
Begin("Debug Panel");
// #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());
/*{ 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
SeparatorText("Default Allocator Allocations");
{ 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);
Text("%s in %lld allocations",
format_bytes(get_general_allocator_data()->total_bytes_allocated).data,
allocations.count);
for_each(a, allocations) {
Text(" [%lld] ptr: %p (size: %lld, alignment: %d)",
a, allocations[a].memory, allocations[a].size, allocations[a].alignment);
if (!default_allocator_show_small_allocations && allocations[a].size < 1024) {
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");

View File

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