fp: Add non hot-reload build

This commit is contained in:
doyle 2023-10-10 23:00:35 +11:00
parent 64cf8787d7
commit 1ea15d00e0
6 changed files with 239 additions and 15 deletions

2
External/tely vendored

@ -1 +1 @@
Subproject commit e5c7d83121adb093e23655d7ae01820374872340
Subproject commit a131934ffcc917dda53e0084ff7c3a136b6250ec

View File

@ -82,29 +82,28 @@ set clang_dll_cmd=clang-cl %dll_compile_flags% /Fotely_dll_clang /Fetely_dll_c
REM MSVC build =====================================================================================
set msvc_sprite_packer_cmd=cl %common_compile_flags% %code_dir%\feely_pona_sprite_packer.cpp /Fofeely_pona_sprite_packer /Fefeely_pona_sprite_packer %common_link_flags%
powershell -Command "$duration = Measure-Command {%msvc_sprite_packer_cmd% | Out-Default}; Write-Host 'msvc (sprite packer):' $duration.TotalSeconds 'seconds'"
set msvc_build_platform=$platform_time = Measure-Command {%msvc_cmd% ^| Out-Default};
set msvc_build_dll=$dll_time = Measure-Command {%msvc_dll_cmd% ^| Out-Default};
set msvc_print_dll_time=Write-Host 'msvc dll:'$dll_time.TotalSeconds's'
set msvc_print_platform_and_dll_time=Write-Host 'msvc (platform+dll):'($platform_time.TotalSeconds + $dll_time.TotalSeconds)'s ('$platform_time.TotalSeconds + $dll_time.TotalSeconds')'
set msvc_check_if_exe_locked=$File = [System.IO.File]::Open('%build_dir%\%msvc_exe_name%.exe', 'Open', 'Write'); $File.Close(); $File.Dispose()
set msvc_exe_is_locked=0
if exist %build_dir%\%msvc_exe_name%.exe (
powershell -Command "%msvc_check_if_exe_locked%" 2>nul && set msvc_exe_is_locked=0 || set msvc_exe_is_locked=1
)
powershell -Command "$file = [System.IO.File]::Open('%build_dir%\%msvc_exe_name%.exe', 'Open', 'Write'); $file.Close(); $file.Dispose()" 2>nul && set msvc_exe_is_locked=0 || set msvc_exe_is_locked=1
powershell -Command "$duration = Measure-Command {%msvc_dll_cmd% | Out-Default}; Write-Host 'msvc (dll):' $duration.TotalSeconds 'seconds'"
echo foo> %msvc_exe_name%.lock
if %msvc_exe_is_locked% == 1 (
powershell -Command "%msvc_build_dll% %msvc_print_dll_time%"
) else (
powershell -Command "%msvc_build_platform% %msvc_build_dll% %msvc_print_platform_and_dll_time%"
if %msvc_exe_is_locked% == 0 (
powershell -Command "$time_a = Measure-Command {%msvc_cmd% | Out-Default }; Write-Host 'msvc (raylib):' $time_a.TotalSeconds 'seconds'"
)
del %msvc_exe_name%.lock
REM CLANG build ====================================================================================
REM MSVC no-dll ====================================================================================
set msvc_no_dll_cmd=cl %common_compile_flags% /Tp %code_dir%\feely_pona_unity_nodll.h /Fofeely_pona_msvc_nodll /Fefeely_pona_msvc_nodll %raylib_link_flags%
set msvc_sprite_packer_cmd=cl %common_compile_flags% %code_dir%\feely_pona_sprite_packer.cpp /Fofeely_pona_sprite_packer /Fefeely_pona_sprite_packer %common_link_flags%
powershell -Command "$duration = Measure-Command {%msvc_sprite_packer_cmd% | Out-Default}; Write-Host 'msvc (sprite packer):' $duration.TotalSeconds 'seconds'"
powershell -Command "$duration = Measure-Command {%msvc_no_dll_cmd% | Out-Default}; Write-Host 'msvc (no-dll):' $duration.TotalSeconds 'seconds'"
REM cl /nologo /Z7 %code_dir%\feely_pona_build.cpp
popd
exit /B 1

129
feely_pona_build.cpp Normal file
View File

@ -0,0 +1,129 @@
// #include <Windows.h>
#define DQN_IMPLEMENTATION
#include "External/tely/External/dqn/dqn.h"
struct Dqn_OSRunCommandAsyncResult
{
void *process;
};
struct Dqn_OSRunCommandResult
{
uint32_t os_error_code;
uint32_t exit_code;
};
Dqn_OSRunCommandResult Dqn_OS_RunCommandWait(Dqn_OSRunCommandAsyncResult run_cmd)
{
Dqn_OSRunCommandResult result = {};
DWORD exec_result = WaitForSingleObject(run_cmd.process, INFINITE);
if (exec_result == WAIT_FAILED) {
result.os_error_code = GetLastError();
return result;
}
DWORD exit_status;
if (!GetExitCodeProcess(run_cmd.process, &exit_status)) {
result.os_error_code = GetLastError();
return result;
}
result.exit_code = exit_status;
CloseHandle(run_cmd.process);
return result;
}
Dqn_OSRunCommandAsyncResult Dqn_OS_RunCommandAsync(Dqn_String8 cmd)
{
Dqn_OSRunCommandAsyncResult result = {};
#if defined(DQN_OS_WIN32)
Dqn_ThreadScratch scratch = Dqn_Thread_GetScratch(nullptr);
Dqn_String16 cmd16 = Dqn_Win_String8ToString16(scratch.arena, cmd);
PROCESS_INFORMATION proc_info = {};
STARTUPINFOW startup_info = {};
startup_info.cb = sizeof(STARTUPINFOW);
startup_info.hStdError = GetStdHandle(STD_ERROR_HANDLE);
startup_info.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
startup_info.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
startup_info.dwFlags |= STARTF_USESTDHANDLES;
BOOL create_result = CreateProcessW(nullptr, cmd16.data, nullptr, nullptr, true, 0, nullptr, nullptr, &startup_info, &proc_info);
if (!create_result)
return result;
CloseHandle(proc_info.hThread);
result.process = proc_info.hProcess;
#else
pid_t cpid = fork();
if (cpid < 0) {
nob_log(NOB_ERROR, "Could not fork child process: %s", strerror(errno));
return NOB_INVALID_PROC;
}
if (cpid == 0) {
// NOTE: This leaks a bit of memory in the child process.
// But do we actually care? It's a one off leak anyway...
Nob_Cmd cmd_null = {0};
nob_da_append_many(&cmd_null, cmd.items, cmd.count);
nob_cmd_append(&cmd_null, NULL);
if (execvp(cmd.items[0], (char * const*) cmd_null.items) < 0) {
nob_log(NOB_ERROR, "Could not exec child process: %s", strerror(errno));
exit(1);
}
NOB_ASSERT(0 && "unreachable");
}
return cpid;
#endif
return result;
}
int main()
{
Dqn_Library_Init();
Dqn_String8 build_dir = DQN_STRING8("./Build");
if (!Dqn_Fs_MakeDir(build_dir)) {
Dqn_Log_ErrorF("Failed to make build dir '%.*s'", DQN_STRING_FMT(build_dir));
return -1;
}
Dqn_ThreadScratch scratch = Dqn_Thread_GetScratch(nullptr);
Dqn_String8 exe_dir = Dqn_OS_EXEDir(scratch.arena);
Dqn_String8Builder raylib_cmd_builder = {};
raylib_cmd_builder.allocator = scratch.allocator;
Dqn_String8 raylib_files[] = {
DQN_STRING8("rcore.c"),
DQN_STRING8("utils.c"),
DQN_STRING8("raudio.c"),
DQN_STRING8("rmodels.c"),
DQN_STRING8("rtext.c"),
DQN_STRING8("rtextures.c"),
DQN_STRING8("rshapes.c"),
DQN_STRING8("rglfw.c"),
};
Dqn_String8 raylib_dir = Dqn_FsPath_ConvertF(scratch.arena, "%.*s/External/tely/external/raylib", DQN_STRING_FMT(exe_dir));
Dqn_String8 raylib_include_dirs[] = {
Dqn_FsPath_ConvertF(scratch.arena, "%.*s", DQN_STRING_FMT(raylib_dir)),
Dqn_FsPath_ConvertF(scratch.arena, "%.*s/external/glfw/include", DQN_STRING_FMT(raylib_dir)),
Dqn_FsPath_ConvertF(scratch.arena, "%.*s/glfw/deps/mingw", DQN_STRING_FMT(raylib_dir)),
};
Dqn_String8 compile_flags = DQN_STRING8("/W4 /Z7 /MT /EHsc /nologo");
Dqn_String8 link_flags = DQN_STRING8("/link /incremental:no");
Dqn_String8Builder_AppendF(&raylib_cmd_builder, "cl %.*s /w /c /D _DEFAULT_SOURCE /D PLATFORM_DESKTOP", DQN_STRING_FMT(compile_flags));
for (Dqn_String8 include_dir : raylib_include_dirs)
Dqn_String8Builder_AppendF(&raylib_cmd_builder, " /I %.*s", DQN_STRING_FMT(include_dir));
for (Dqn_String8 file_name : raylib_files)
Dqn_String8Builder_AppendRef(&raylib_cmd_builder, Dqn_FsPath_ConvertF(scratch.arena, " %.*s/%.*s", DQN_STRING_FMT(raylib_dir), DQN_STRING_FMT(file_name)));
Dqn_String8 cmd = Dqn_String8Builder_Build(&raylib_cmd_builder, scratch.allocator);
Dqn_OSRunCommandAsyncResult run_result = Dqn_OS_RunCommandAsync(cmd);
Dqn_OS_RunCommandWait(run_result);
return 0;
}

View File

@ -40,6 +40,7 @@
// NOTE: TELY ======================================================================================
DQN_MSVC_WARNING_PUSH
DQN_MSVC_WARNING_DISABLE(4505) // warning C4505: unreferenced function with internal linkage has been removed
#include "External/tely/tely_profile.h"
#include "External/tely/tely_platform_input.h"
@ -70,3 +71,4 @@ DQN_MSVC_WARNING_DISABLE(4505) // warning C4505: unreferenced function with inte
#include "feely_pona_entity_create.cpp"
#include "feely_pona_misc.cpp"
#include "feely_pona.cpp"
DQN_MSVC_WARNING_POP

94
feely_pona_unity_nodll.h Normal file
View File

@ -0,0 +1,94 @@
// =================================================================================================
// NOTE(doyle): Work-around for clangd to correctly resolve symbols in unity
// builds by providing symbol definition and prototypes by including this
// mega-header in all files and using the "#pragma once" directive to
// avoid multiple defined symbols when compiling the unity build itself.
//
// See: https://www.frogtoss.com/labs/clangd-with-unity-builds.html
#pragma once
// NOTE: DQN =======================================================================================
// NOTE: C-strings declared in a ternary cause global-buffer-overflow in
// MSVC2022.
// stb_sprintf assumes c-string literals are 4 byte aligned which is always
// true, however, reading past the end of a string whose size is not a multiple
// of 4 is UB causing ASAN to complain.
#if defined(_MSC_VER) && !defined(__clang__)
#define STBSP__ASAN __declspec(no_sanitize_address)
#endif
#define DQN_ASAN_POISON 0
#define DQN_ASAN_VET_POISON 1
#define DQN_ONLY_RECT
#define DQN_ONLY_V2
#define DQN_ONLY_V3
#define DQN_ONLY_V4
#define DQN_ONLY_WIN
#define DQN_ONLY_FARRAY
#define DQN_ONLY_PROFILER
#define DQN_ONLY_SLICE
#define DQN_ONLY_LIST
#define DQN_ONLY_VARRAY
#define DQN_ONLY_DSMAP
#define DQN_ONLY_FS
#define _CRT_SECURE_NO_WARNINGS
#define DQN_IMPLEMENTATION
#include "External/tely/External/dqn/dqn.h"
// NOTE: STB Headers ===============================================================================
DQN_GCC_WARNING_PUSH
DQN_GCC_WARNING_DISABLE(-Wunused-function)
#include "External/tely/external/stb/stb_image.h"
DQN_GCC_WARNING_POP
// =================================================================================================
#include "External/tely/external/raylib/raylib.h"
#include "External/tely/external/raylib/rlgl.h"
#include "External/tely/external/raylib/external/glfw/include/GLFW/glfw3.h"
// NOTE: TELY ======================================================================================
DQN_MSVC_WARNING_PUSH
DQN_MSVC_WARNING_DISABLE(4505) // warning C4505: unreferenced function with internal linkage has been removed
#include "External/tely/tely_profile.h"
#include "External/tely/tely_platform_input.h"
#include "External/tely/tely_tools.h"
#include "External/tely/tely_asset.h"
#include "External/tely/tely_colour.h"
#include "External/tely/tely_render.h"
#include "External/tely/tely_audio.h"
#include "External/tely/tely_platform.h"
#include "External/tely/tely_ui.h"
#include "External/tely/tely_rfui.h"
#include "External/tely/tely_tools.cpp"
#include "External/tely/tely_asset.cpp"
#include "External/tely/tely_audio.cpp"
#include "External/tely/tely_render.cpp"
#include "External/tely/tely_platform_input.cpp"
#include "External/tely/tely_ui.cpp"
#include "External/tely/tely_rfui.cpp"
// NOTE: feely_pona ================================================================================
#include "feely_pona.h"
#include "feely_pona_stdlib.h"
#include "feely_pona_entity.h"
#include "feely_pona_game.h"
#include "feely_pona_game.cpp"
#include "feely_pona_entity_create.cpp"
#include "feely_pona_misc.cpp"
#include "feely_pona.cpp"
// NOTE: TELY_Platform =============================================================================
#define TELY_PLATFORM_NO_DLL
#include "External/tely/tely_platform.cpp"
#include "External/tely/tely_platform_raylib.cpp"
DQN_MSVC_WARNING_POP

Binary file not shown.