Compare commits

..

4 Commits

7 changed files with 350 additions and 252 deletions

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
Build/ Build/
Nocheckin/ Nocheckin/
feely_pona_build.exe feely_pona_build.exe
feely_pona_build
feely_pona_version.txt feely_pona_version.txt
Tools/emsdk Tools/emsdk

2
External/tely vendored

@ -1 +1 @@
Subproject commit f6c96fb65331e2829a43e0375cb8fc1bd0969c06 Subproject commit 2cc8b2d7b2a255eccad747ea6a91187093eb64f7

View File

@ -1,5 +1,5 @@
@echo off @echo off
setlocal setlocal
call build_all.bat %* --fast-dev-build || exit /b 1 call build_all.bat %* || exit /b 1

21
build.sh Executable file
View File

@ -0,0 +1,21 @@
#!/bin/bash
set -e
script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
build_dir=${script_dir}/Build
code_dir=${script_dir}
# Bootstrap a version
git show -s --date=format:%Y-%m-%d --format=%cd HEAD> feely_pona_version.txt
git rev-parse --short=8 HEAD>> feely_pona_version.txt
git rev-list --count HEAD>> feely_pona_version.txt
# Bootstrap the build program
mkdir --parents ${build_dir}
pushd ${build_dir}
g++ -g -Wall -o feely_pona_build ${code_dir}/feely_pona_build.cpp -lm
cp --force feely_pona_build ${code_dir}
popd
# Run the build program
${code_dir}/feely_pona_build $@

View File

@ -245,7 +245,10 @@ static void FP_PlayReset(FP_Game *game, TELY_OS *os)
} }
// NOTE: Fisher yates shuffle the list // NOTE: Fisher yates shuffle the list
DQN_MSVC_WARNING_PUSH
DQN_MSVC_WARNING_DISABLE(6293) // Ill-formed for loop (potential wrapping index)
for (Dqn_usize index = DQN_ARRAY_UCOUNT(play->monkey_spawn_shuffled_list) - 1; index < DQN_ARRAY_UCOUNT(play->monkey_spawn_shuffled_list); index--) { for (Dqn_usize index = DQN_ARRAY_UCOUNT(play->monkey_spawn_shuffled_list) - 1; index < DQN_ARRAY_UCOUNT(play->monkey_spawn_shuffled_list); index--) {
DQN_MSVC_WARNING_POP
uint32_t swap_index = Dqn_PCG32_Range(&play->rng, 0, DQN_CAST(uint32_t)index + 1); uint32_t swap_index = Dqn_PCG32_Range(&play->rng, 0, DQN_CAST(uint32_t)index + 1);
DQN_SWAP(play->monkey_spawn_shuffled_list[swap_index], play->monkey_spawn_shuffled_list[index]); DQN_SWAP(play->monkey_spawn_shuffled_list[swap_index], play->monkey_spawn_shuffled_list[index]);
} }

View File

@ -49,7 +49,7 @@ void RebuildProgramIfRequired(int argc, char const **argv)
} }
// NOTE: Rebuild the build program because a change was detected =============== // NOTE: Rebuild the build program because a change was detected ===============
Dqn_Str8 rebuild_cmd = Dqn_Str8_InitF(scratch.allocator, "cl /Z7 /W4 /nologo %s /incremental:no /link", __FILE__); Dqn_Str8 rebuild_cmd = Dqn_Str8_InitF(scratch.allocator, "cl -Z7 -W4 -nologo %s /incremental:no /link", __FILE__);
Dqn_OSExecResult rebuild_result = Dqn_OS_Exec(rebuild_cmd, exe_dir /*working_dir*/); Dqn_OSExecResult rebuild_result = Dqn_OS_Exec(rebuild_cmd, exe_dir /*working_dir*/);
if (rebuild_result.os_error_code) { if (rebuild_result.os_error_code) {
Dqn_WinError error = Dqn_Win_LastError(scratch.arena); Dqn_WinError error = Dqn_Win_LastError(scratch.arena);
@ -80,7 +80,7 @@ void RebuildProgramIfRequired(int argc, char const **argv)
} }
#endif #endif
#define PRINT_HELP Dqn_Print_StdLnF(Dqn_PrintStd_Out, "USAGE: feely_pona_build [--help|--dry-run|--web|--fast-dev-build]") #define PRINT_HELP Dqn_Print_StdLnF(Dqn_PrintStd_Out, "USAGE: feely_pona_build [--help|--dry-run|--web|--fast-dev-build|--win|--linux]")
int main(int argc, char const **argv) int main(int argc, char const **argv)
{ {
Dqn_Library_Init(Dqn_LibraryOnInit_Nil); Dqn_Library_Init(Dqn_LibraryOnInit_Nil);
@ -88,7 +88,9 @@ int main(int argc, char const **argv)
bool dry_run = false; bool dry_run = false;
bool target_web = false; bool target_web = false;
bool dev_fast_build = false; bool dev_fast_build = false;
for (Dqn_usize arg_index = 1; arg_index < argc; arg_index++) { bool windows_build = false;
bool linux_build = false;
for (Dqn_isize arg_index = 1; arg_index < argc; arg_index++) {
Dqn_Str8 arg = Dqn_Str8_InitCStr8(argv[arg_index]); Dqn_Str8 arg = Dqn_Str8_InitCStr8(argv[arg_index]);
if (arg == DQN_STR8("--help")) { if (arg == DQN_STR8("--help")) {
PRINT_HELP; PRINT_HELP;
@ -99,6 +101,10 @@ int main(int argc, char const **argv)
target_web = true; target_web = true;
} else if (arg == DQN_STR8("--fast-dev-build")) { } else if (arg == DQN_STR8("--fast-dev-build")) {
dev_fast_build = true; dev_fast_build = true;
} else if (arg == DQN_STR8("--linux")) {
linux_build = true;
} else if (arg == DQN_STR8("--win")) {
windows_build = true;
} else { } else {
PRINT_HELP; PRINT_HELP;
return 0; return 0;
@ -111,50 +117,132 @@ int main(int argc, char const **argv)
Dqn_Print_StdLnF(Dqn_PrintStd_Out, "-- Dqn_CPPBuild v0"); Dqn_Print_StdLnF(Dqn_PrintStd_Out, "-- Dqn_CPPBuild v0");
#endif #endif
uint64_t build_timings[2] = {}; if (windows_build && linux_build) {
build_timings[0] = Dqn_OS_PerfCounterNow(); Dqn_Print_StdLnF(Dqn_PrintStd_Out,
Dqn_ThreadScratch scratch = Dqn_Thread_GetScratch(nullptr); "Both '--win' and '--linux' were specified but only one is supported at a time for this build program.");
Dqn_Str8 const exe_dir = Dqn_OS_EXEDir(scratch.arena); return -1;
Dqn_Str8 const code_dir = exe_dir; }
Dqn_Str8 const build_dir = Dqn_FsPath_ConvertF(scratch.arena, "%.*s/Build", DQN_STR_FMT(exe_dir));
Dqn_Str8 const tely_dir = Dqn_FsPath_ConvertF(scratch.arena, "%.*s/External/tely", DQN_STR_FMT(exe_dir));
Dqn_Slice<Dqn_Str8> common_compile_flags = Dqn_Slice_InitCArrayCopy(scratch.arena, { if (!windows_build && !linux_build) {
DQN_STR8("cl"), #if defined(DQN_OS_WIN32)
DQN_STR8("/W4"), windows_build = true;
DQN_STR8("/Z7"), #else
DQN_STR8("/MT"), linux_build = true;
DQN_STR8("/EHsc"), #endif
DQN_STR8("/nologo"), }
});
Dqn_Slice<Dqn_Str8> common_link_flags = Dqn_Slice_InitCArrayCopy(scratch.arena, { Dqn_Print_StdLnF(Dqn_PrintStd_Out, "Building for %s", windows_build ? "Windows" : "Linux");
DQN_STR8("/link"),
DQN_STR8("/incremental:no"), uint64_t build_timings[2] = {};
}); build_timings[0] = Dqn_OS_PerfCounterNow();
Dqn_ThreadScratch scratch = Dqn_Thread_GetScratch(nullptr);
Dqn_Str8 const exe_dir = Dqn_OS_EXEDir(scratch.arena);
Dqn_Str8 const code_dir = exe_dir;
Dqn_Str8 const build_dir = Dqn_FsPath_ConvertF(scratch.arena, "%.*s/Build", DQN_STR_FMT(exe_dir));
Dqn_Str8 const tely_dir = Dqn_FsPath_ConvertF(scratch.arena, "%.*s/External/tely", DQN_STR_FMT(exe_dir));
Dqn_CPPBuildFlagsStyle flags_style = windows_build ? Dqn_CPPBuildFlagsStyle_MSVC : Dqn_CPPBuildFlagsStyle_GCC;
Dqn_FArray32<Dqn_Str8> common_compile_flags = {};
Dqn_FArray32<Dqn_Str8> common_link_flags = {};
if (windows_build) {
Dqn_FArray_AddAssert(&common_compile_flags, DQN_STR8("cl"));
Dqn_FArray_AddAssert(&common_compile_flags, DQN_STR8("-W4"));
Dqn_FArray_AddAssert(&common_compile_flags, DQN_STR8("-Z7"));
Dqn_FArray_AddAssert(&common_compile_flags, DQN_STR8("-MT"));
Dqn_FArray_AddAssert(&common_compile_flags, DQN_STR8("-EHsc"));
Dqn_FArray_AddAssert(&common_compile_flags, DQN_STR8("-nologo"));
Dqn_FArray_AddAssert(&common_link_flags, DQN_STR8("-link"));
Dqn_FArray_AddAssert(&common_link_flags, DQN_STR8("-incremental:no"));
} else {
Dqn_FArray_AddAssert(&common_compile_flags, DQN_STR8("g++"));
Dqn_FArray_AddAssert(&common_compile_flags, DQN_STR8("-Wall"));
Dqn_FArray_AddAssert(&common_compile_flags, DQN_STR8("-g"));
Dqn_FArray_AddAssert(&common_link_flags, DQN_STR8("-lm"));
}
// NOTE: Assets ================================================================================ // NOTE: Assets ================================================================================
uint64_t robocopy_timings[2] = {}; uint64_t robocopy_timings[2] = {};
{ {
robocopy_timings[0] = Dqn_OS_PerfCounterNow(); robocopy_timings[0] = Dqn_OS_PerfCounterNow();
DQN_DEFER { robocopy_timings[1] = Dqn_OS_PerfCounterNow(); }; DQN_DEFER { robocopy_timings[1] = Dqn_OS_PerfCounterNow(); };
Dqn_Str8 robocopy_cmd[] = {
Dqn_Str8_InitF(scratch.allocator, "robocopy /NJH /NJS /NDL /NP %.*s\\Data\\Textures %.*s\\Data\\Textures atlas.*", DQN_STR_FMT(exe_dir), DQN_STR_FMT(build_dir)),
Dqn_Str8_InitF(scratch.allocator, "robocopy /MIR /NJH /NJS /NDL /NP %.*s\\Data\\Fonts %.*s\\Data\\Fonts", DQN_STR_FMT(exe_dir), DQN_STR_FMT(build_dir)),
Dqn_Str8_InitF(scratch.allocator, "robocopy /MIR /NJH /NJS /NDL /NP %.*s\\Data\\Audio %.*s\\Data\\Audio", DQN_STR_FMT(exe_dir), DQN_STR_FMT(build_dir)),
};
for (Dqn_Str8 cmd : robocopy_cmd) { Dqn_FArray8<Dqn_Str8> common_copy_cmd_args = {};
if (dry_run) if (windows_build) {
Dqn_Print_StdLnF(Dqn_PrintStd_Out, "%.*s\n", DQN_STR_FMT(cmd)); Dqn_FArray_AddCArrayAssert(&common_copy_cmd_args, {
else DQN_STR8("robocopy"),
Dqn_OS_Exec(cmd, /*working_dir*/ {}); DQN_STR8("/NJH"),
DQN_STR8("/NJS"),
DQN_STR8("/NDL"),
DQN_STR8("/NP"),
});
} else {
Dqn_FArray_AddCArrayAssert(&common_copy_cmd_args, {
DQN_STR8("cp"),
DQN_STR8("--recursive"),
});
}
Dqn_Str8 textures_dest = Dqn_FsPath_ConvertF(scratch.arena, "%.*s/Data/Textures", DQN_STR_FMT(build_dir));
DQN_HARD_ASSERT(Dqn_Fs_MakeDir(textures_dest));
Dqn_FArray8<Dqn_FArray8<Dqn_Str8>> copy_cmd_list = {};
if (windows_build) {
Dqn_FArray8<Dqn_Str8> copy_atlas = common_copy_cmd_args;
Dqn_FArray_AddCArrayAssert(&copy_atlas, {
Dqn_FsPath_ConvertF(scratch.arena, "%.*s/Data/Textures", DQN_STR_FMT(exe_dir)),
Dqn_FsPath_ConvertF(scratch.arena, "%.*s/Data/Textures atlas.*", DQN_STR_FMT(build_dir)),
});
Dqn_FArray_Add(&copy_cmd_list, copy_atlas);
} else {
Dqn_FArray8<Dqn_Str8> copy_atlas_txt = common_copy_cmd_args;
Dqn_FArray_AddCArrayAssert(&copy_atlas_txt, {
Dqn_FsPath_ConvertF(scratch.arena, "%.*s/Data/Textures/atlas.txt", DQN_STR_FMT(exe_dir)),
textures_dest,
});
Dqn_FArray_Add(&copy_cmd_list, copy_atlas_txt);
Dqn_FArray8<Dqn_Str8> copy_atlas_png = common_copy_cmd_args;
Dqn_FArray_AddCArrayAssert(&copy_atlas_png, {
Dqn_FsPath_ConvertF(scratch.arena, "%.*s/Data/Textures/atlas.png", DQN_STR_FMT(exe_dir)),
textures_dest,
});
Dqn_FArray_Add(&copy_cmd_list, copy_atlas_png);
}
Dqn_FArray8<Dqn_Str8> copy_fonts_cmd = common_copy_cmd_args;
Dqn_FArray_AddCArrayAssert(&copy_fonts_cmd, {
Dqn_FsPath_ConvertF(scratch.arena, "%.*s/Data/Fonts", DQN_STR_FMT(exe_dir)),
Dqn_FsPath_ConvertF(scratch.arena, "%.*s/Data/Fonts", DQN_STR_FMT(build_dir)),
});
Dqn_FArray_Add(&copy_cmd_list, copy_fonts_cmd);
Dqn_FArray8<Dqn_Str8> copy_audio_cmd = common_copy_cmd_args;
Dqn_FArray_AddCArrayAssert(&copy_audio_cmd, {
Dqn_FsPath_ConvertF(scratch.arena, "%.*s/Data/Audio", DQN_STR_FMT(exe_dir)),
Dqn_FsPath_ConvertF(scratch.arena, "%.*s/Data/Audio", DQN_STR_FMT(build_dir)),
});
Dqn_FArray_Add(&copy_cmd_list, copy_audio_cmd);
for (Dqn_FArray8<Dqn_Str8> const &copy_cmd : copy_cmd_list) {
Dqn_Slice<Dqn_Str8> copy_cmd_slice = Dqn_FArray_Slice(&copy_cmd);
Dqn_Str8 rendered_line = Dqn_Slice_Str8Render(scratch.arena, copy_cmd_slice, DQN_STR8(" "));
Dqn_Print_StdLnF(Dqn_PrintStd_Out, "[BUILD] Executing '%.*s'", DQN_STR_FMT(rendered_line));
if (!dry_run) {
if (windows_build) {
// NOTE: Robocopy returns 1 on success so we don't use the ExecOrAbort function
Dqn_OS_Exec(copy_cmd_slice, /*working_dir*/ {});
} else {
Dqn_OS_ExecOrAbort(copy_cmd_slice, /*working_dir*/ {});
}
}
} }
} }
// NOTE: Raylib ================================================================================ // NOTE: Raylib ================================================================================
Dqn_Str8 const raylib_dir = Dqn_FsPath_ConvertF(scratch.arena, "%.*s/External/tely/external/raylib", DQN_STR_FMT(exe_dir)); Dqn_Str8 const raylib_dir = Dqn_FsPath_ConvertF(scratch.arena, "%.*s/External/tely/External/raylib", DQN_STR_FMT(exe_dir));
Dqn_Slice<Dqn_Str8> const raylib_base_files = Dqn_Slice_InitCArrayCopy(scratch.arena, { Dqn_Slice<Dqn_Str8> const raylib_base_files = Dqn_Slice_InitCArray(scratch.arena, {
Dqn_FsPath_ConvertF(scratch.arena, "%.*s/rcore.c", DQN_STR_FMT(raylib_dir)), Dqn_FsPath_ConvertF(scratch.arena, "%.*s/rcore.c", DQN_STR_FMT(raylib_dir)),
Dqn_FsPath_ConvertF(scratch.arena, "%.*s/utils.c", DQN_STR_FMT(raylib_dir)), Dqn_FsPath_ConvertF(scratch.arena, "%.*s/utils.c", DQN_STR_FMT(raylib_dir)),
Dqn_FsPath_ConvertF(scratch.arena, "%.*s/raudio.c", DQN_STR_FMT(raylib_dir)), Dqn_FsPath_ConvertF(scratch.arena, "%.*s/raudio.c", DQN_STR_FMT(raylib_dir)),
@ -164,169 +252,156 @@ int main(int argc, char const **argv)
Dqn_FsPath_ConvertF(scratch.arena, "%.*s/rshapes.c", DQN_STR_FMT(raylib_dir)), Dqn_FsPath_ConvertF(scratch.arena, "%.*s/rshapes.c", DQN_STR_FMT(raylib_dir)),
}); });
Dqn_List<Dqn_Str8> raylib_pc_output_files = Dqn_List_Init<Dqn_Str8>(scratch.arena, 16); Dqn_FArray32<Dqn_Str8> raylib_pc_output_files = {};
uint64_t raylib_pc_timings[2] = {}; uint64_t raylib_pc_timings[2] = {};
{ {
raylib_pc_timings[0] = Dqn_OS_PerfCounterNow(); raylib_pc_timings[0] = Dqn_OS_PerfCounterNow();
DQN_DEFER { raylib_pc_timings[1] = Dqn_OS_PerfCounterNow(); }; DQN_DEFER { raylib_pc_timings[1] = Dqn_OS_PerfCounterNow(); };
// NOTE: Setup raylib build context ======================================================== // NOTE: Setup raylib build context ========================================================
Dqn_FArray32<Dqn_Str8> compile_flags = {};
Dqn_CPPBuildContext build_context = {}; Dqn_CPPBuildContext build_context = {};
{ {
build_context.include_dirs = Dqn_Slice_InitCArrayCopy(scratch.arena, { build_context.include_dirs = Dqn_Slice_InitCArray(scratch.arena, {
Dqn_FsPath_ConvertF(scratch.arena, "%.*s", DQN_STR_FMT(raylib_dir)), Dqn_FsPath_ConvertF(scratch.arena, "%.*s", DQN_STR_FMT(raylib_dir)),
Dqn_FsPath_ConvertF(scratch.arena, "%.*s/external/glfw/include", DQN_STR_FMT(raylib_dir)), Dqn_FsPath_ConvertF(scratch.arena, "%.*s/external/glfw/include", DQN_STR_FMT(raylib_dir)),
Dqn_FsPath_ConvertF(scratch.arena, "%.*s/glfw/deps/mingw", DQN_STR_FMT(raylib_dir)), Dqn_FsPath_ConvertF(scratch.arena, "%.*s/glfw/deps/mingw", DQN_STR_FMT(raylib_dir)),
}); });
build_context.compile_flags = Dqn_Slice_InitCArrayCopy(scratch.arena, { if (windows_build) {
DQN_STR8("cl"), Dqn_FArray_AddCArrayAssert(&compile_flags, {
DQN_STR8("/w"), DQN_STR8("cl"),
DQN_STR8("/c"), DQN_STR8("-w"),
DQN_STR8("/D _DEFAULT_SOURCE"), DQN_STR8("-Z7"),
DQN_STR8("/D PLATFORM_DESKTOP"), DQN_STR8("-MT"),
DQN_STR8("/Z7"), DQN_STR8("-EHsc"),
DQN_STR8("/MT"), DQN_STR8("-nologo"),
DQN_STR8("/EHsc"), });
DQN_STR8("/nologo"), } else {
Dqn_FArray_AddCArrayAssert(&compile_flags, {
DQN_STR8("gcc"),
DQN_STR8("-g"),
});
}
Dqn_FArray_AddCArrayAssert(&compile_flags, {
DQN_STR8("-c"), // Compile object files only
DQN_STR8("-D"), DQN_STR8("_DEFAULT_SOURCE"),
DQN_STR8("-D"), DQN_STR8("PLATFORM_DESKTOP"),
}); });
build_context.build_dir = build_dir;
build_context.compiler = Dqn_CPPBuildCompiler_MSVC; build_context.build_dir = build_dir;
build_context.compile_flags = Dqn_FArray_Slice(&compile_flags);
build_context.flags_style = flags_style;
} }
// NOTE: Compile each file separately with a custom output name ============================ // NOTE: Compile each file separately with a custom output name ============================
for (Dqn_Str8 base_file : raylib_base_files) { for (Dqn_Str8 base_file : raylib_base_files) {
Dqn_Str8 file_stem = Dqn_Str8_FileNameNoExtension(base_file); Dqn_Str8 file_stem = Dqn_Str8_FileNameNoExtension(base_file);
Dqn_CPPBuildCompileFile build_file = {}; Dqn_CPPBuildCompileFile build_file = {};
build_file.input_file_path = base_file; build_file.input_file_path = base_file;
build_file.output_file_path = Dqn_Str8_InitF(scratch.allocator, "raylib_%.*s.obj", DQN_STR_FMT(file_stem)); build_file.output_file_path = Dqn_Str8_InitF(scratch.allocator, "raylib_%.*s.%s", DQN_STR_FMT(file_stem), windows_build ? "obj" : "o");
build_context.compile_files = Dqn_Slice_InitCArrayCopy(scratch.arena, {build_file}); build_context.compile_files = Dqn_Slice_Init(&build_file, 1);
Dqn_List_Add(&raylib_pc_output_files, build_file.output_file_path); Dqn_FArray_AddAssert(&raylib_pc_output_files, build_file.output_file_path);
if (dry_run) { Dqn_Str8 cmd = Dqn_CPPBuild_ToCommandLineStr8(build_context, Dqn_CPPBuildMode_AlwaysRebuild, scratch.arena);
Dqn_Str8 cmd = Dqn_CPPBuild_ToCommandLine(build_context, Dqn_CPPBuildMode_AlwaysRebuild, scratch.allocator); Dqn_Print_StdLnF(Dqn_PrintStd_Out, "[BUILD] Executing '%.*s'", DQN_STR_FMT(cmd));
Dqn_Print_StdLnF(Dqn_PrintStd_Out, "%.*s\n", DQN_STR_FMT(cmd)); if (!dry_run)
} else {
Dqn_CPPBuild_ExecOrAbort(build_context, Dqn_CPPBuildMode_CacheBuild); Dqn_CPPBuild_ExecOrAbort(build_context, Dqn_CPPBuildMode_CacheBuild);
}
} }
// NOTE: Build rlgfw ======================================================================= // NOTE: Build rlgfw =======================================================================
{ {
Dqn_CPPBuildCompileFile build_file = {}; Dqn_CPPBuildCompileFile build_file = {};
build_file.input_file_path = Dqn_FsPath_ConvertF(scratch.arena, "%.*s/rglfw.c", DQN_STR_FMT(raylib_dir)); build_file.input_file_path = Dqn_FsPath_ConvertF(scratch.arena, "%.*s/rglfw.c", DQN_STR_FMT(raylib_dir));
build_file.output_file_path = Dqn_Str8_InitF(scratch.allocator, "raylib_rglfw.obj"); build_file.output_file_path = Dqn_Str8_InitF(scratch.allocator, "raylib_rglfw.%s", windows_build ? "obj" : "o");
build_context.compile_files = Dqn_Slice_InitCArrayCopy(scratch.arena, {build_file}); build_context.compile_files = Dqn_Slice_InitCArray(scratch.arena, {build_file});
Dqn_List_Add(&raylib_pc_output_files, build_file.output_file_path); Dqn_FArray_AddAssert(&raylib_pc_output_files, build_file.output_file_path);
if (dry_run) { Dqn_Str8 cmd = Dqn_CPPBuild_ToCommandLineStr8(build_context, Dqn_CPPBuildMode_AlwaysRebuild, scratch.arena);
Dqn_Str8 cmd = Dqn_CPPBuild_ToCommandLine(build_context, Dqn_CPPBuildMode_AlwaysRebuild, scratch.allocator); Dqn_Print_StdLnF(Dqn_PrintStd_Out, "[BUILD] Executing '%.*s'", DQN_STR_FMT(cmd));
Dqn_Print_StdLnF(Dqn_PrintStd_Out, "%.*s\n", DQN_STR_FMT(cmd)); if (!dry_run)
} else {
Dqn_CPPBuild_ExecOrAbort(build_context, Dqn_CPPBuildMode_CacheBuild); Dqn_CPPBuild_ExecOrAbort(build_context, Dqn_CPPBuildMode_CacheBuild);
}
} }
} }
// NOTE: sokol_audio ================================================================================ // NOTE: sokol_audio ================================================================================
Dqn_Str8 sokol_audio_source_code_file = Dqn_FsPath_ConvertF(scratch.arena, "%.*s/External/sokol/sokol_audio.c", DQN_STR_FMT(tely_dir)); Dqn_Str8 sokol_audio_source_code_file = Dqn_FsPath_ConvertF(scratch.arena, "%.*s/External/sokol/sokol_audio.c", DQN_STR_FMT(tely_dir));
uint64_t sokol_audio_pc_timings[2] = {}; uint64_t sokol_audio_pc_timings[2] = {};
Dqn_List<Dqn_Str8> sokol_audio_pc_output_files = Dqn_List_Init<Dqn_Str8>(scratch.arena, 16); Dqn_FArray32<Dqn_Str8> sokol_audio_pc_output_files = {};
{ {
sokol_audio_pc_timings[0] = Dqn_OS_PerfCounterNow(); sokol_audio_pc_timings[0] = Dqn_OS_PerfCounterNow();
DQN_DEFER { sokol_audio_pc_timings[1] = Dqn_OS_PerfCounterNow(); }; DQN_DEFER { sokol_audio_pc_timings[1] = Dqn_OS_PerfCounterNow(); };
Dqn_CPPBuildContext build_context = {}; Dqn_CPPBuildContext build_context = {};
build_context.compiler = Dqn_CPPBuildCompiler_MSVC; build_context.flags_style = flags_style;
build_context.compile_files = Dqn_Slice_InitCArrayCopy(scratch.arena, { build_context.compile_files = Dqn_Slice_InitCArray(scratch.arena, {
Dqn_CPPBuildCompileFile{ Dqn_CPPBuildCompileFile{
{}, // Args {}, // Prefix flags
{}, // Suffix flags
sokol_audio_source_code_file, sokol_audio_source_code_file,
}, },
}); });
Dqn_List_Add(&sokol_audio_pc_output_files, DQN_STR8("sokol_audio.obj")); Dqn_FArray_AddAssert(&sokol_audio_pc_output_files, Dqn_Str8_InitF(scratch.allocator, "sokol_audio.%s", windows_build ? "obj" : "o"));
Dqn_List<Dqn_Str8> compile_flags = Dqn_List_InitSliceCopy(scratch.arena, 16, common_compile_flags); Dqn_FArray32<Dqn_Str8> compile_flags = common_compile_flags;
Dqn_List_Add(&compile_flags, DQN_STR8("/c")); Dqn_FArray_AddAssert(&compile_flags, DQN_STR8("-c"));
build_context.compile_flags = Dqn_List_ToSliceCopy(&compile_flags, scratch.arena);
build_context.compile_flags = Dqn_FArray_Slice(&compile_flags);
build_context.build_dir = build_dir; build_context.build_dir = build_dir;
if (dry_run) { Dqn_Str8 cmd = Dqn_CPPBuild_ToCommandLineStr8(build_context, Dqn_CPPBuildMode_AlwaysRebuild, scratch.arena);
Dqn_Str8 cmd = Dqn_CPPBuild_ToCommandLine(build_context, Dqn_CPPBuildMode_AlwaysRebuild, scratch.allocator); Dqn_Print_StdLnF(Dqn_PrintStd_Out, "[BUILD] Executing '%.*s'", DQN_STR_FMT(cmd));
Dqn_Print_StdLnF(Dqn_PrintStd_Out, "%.*s\n", DQN_STR_FMT(cmd)); if (!dry_run)
} else {
Dqn_CPPBuild_ExecOrAbort(build_context, Dqn_CPPBuildMode_CacheBuild); Dqn_CPPBuild_ExecOrAbort(build_context, Dqn_CPPBuildMode_CacheBuild);
}
}
// NOTE: QOI Converter =========================================================================
uint64_t qoi_converter_timings[2] = {};
{
qoi_converter_timings[0] = Dqn_OS_PerfCounterNow();
DQN_DEFER { qoi_converter_timings[1] = Dqn_OS_PerfCounterNow(); };
Dqn_CPPBuildContext build_context = {};
build_context.compiler = Dqn_CPPBuildCompiler_MSVC;
build_context.compile_files = Dqn_Slice_InitCArrayCopy(scratch.arena, {
Dqn_CPPBuildCompileFile{{}, Dqn_FsPath_ConvertF(scratch.arena, "%.*s/External/qoiconv.c", DQN_STR_FMT(code_dir)) },
});
build_context.compile_flags = Dqn_Slice_InitCArrayCopy(scratch.arena, {DQN_STR8("cl"), DQN_STR8("-O2"), DQN_STR8("-MT"), DQN_STR8("/nologo")});
build_context.link_flags = Dqn_Slice_InitCArrayCopy(scratch.arena, {DQN_STR8("/link"), DQN_STR8("/incremental:no")});
build_context.include_dirs = Dqn_Slice_InitCArrayCopy(scratch.arena, {Dqn_FsPath_ConvertF(scratch.arena, "%.*s/External/stb", DQN_STR_FMT(tely_dir))});
build_context.build_dir = build_dir;
if (dry_run) {
Dqn_Str8 cmd = Dqn_CPPBuild_ToCommandLine(build_context, Dqn_CPPBuildMode_AlwaysRebuild, scratch.allocator);
Dqn_Print_StdLnF(Dqn_PrintStd_Out, "%.*s\n", DQN_STR_FMT(cmd));
} else {
Dqn_CPPBuild_ExecOrAbort(build_context, Dqn_CPPBuildMode_CacheBuild);
}
} }
// NOTE: Feely Pona Sprite Packer ============================================================== // NOTE: Feely Pona Sprite Packer ==============================================================
uint64_t feely_pona_sprite_packer_timings[2] = {}; uint64_t feely_pona_sprite_packer_timings[2] = {};
{ if (windows_build) {
feely_pona_sprite_packer_timings[0] = Dqn_OS_PerfCounterNow(); feely_pona_sprite_packer_timings[0] = Dqn_OS_PerfCounterNow();
DQN_DEFER { feely_pona_sprite_packer_timings[1] = Dqn_OS_PerfCounterNow(); }; DQN_DEFER { feely_pona_sprite_packer_timings[1] = Dqn_OS_PerfCounterNow(); };
Dqn_CPPBuildContext build_context = {}; Dqn_CPPBuildContext build_context = {};
build_context.compiler = Dqn_CPPBuildCompiler_MSVC; build_context.flags_style = flags_style;
build_context.compile_files = Dqn_Slice_InitCArrayCopy(scratch.arena, { build_context.compile_files = Dqn_Slice_InitCArray(scratch.arena, {
Dqn_CPPBuildCompileFile{{}, Dqn_FsPath_ConvertF(scratch.arena, "%.*s/feely_pona_sprite_packer.cpp", DQN_STR_FMT(code_dir)) }, Dqn_CPPBuildCompileFile{{} /*Prefix flags*/, {} /*Suffix flags*/, Dqn_FsPath_ConvertF(scratch.arena, "%.*s/feely_pona_sprite_packer.cpp", DQN_STR_FMT(code_dir)) },
}); });
build_context.compile_flags = common_compile_flags; build_context.compile_flags = Dqn_FArray_Slice(&common_compile_flags);
build_context.link_flags = common_link_flags; build_context.link_flags = Dqn_FArray_Slice(&common_link_flags);
build_context.build_dir = build_dir; build_context.build_dir = build_dir;
if (dry_run) { Dqn_Str8 cmd = Dqn_CPPBuild_ToCommandLineStr8(build_context, Dqn_CPPBuildMode_AlwaysRebuild, scratch.arena);
Dqn_Str8 cmd = Dqn_CPPBuild_ToCommandLine(build_context, Dqn_CPPBuildMode_AlwaysRebuild, scratch.allocator); Dqn_Print_StdLnF(Dqn_PrintStd_Out, "[BUILD] Executing '%.*s'", DQN_STR_FMT(cmd));
Dqn_Print_StdLnF(Dqn_PrintStd_Out, "%.*s\n", DQN_STR_FMT(cmd)); if (!dry_run)
} else {
Dqn_CPPBuild_ExecOrAbort(build_context, Dqn_CPPBuildMode_CacheBuild); Dqn_CPPBuild_ExecOrAbort(build_context, Dqn_CPPBuildMode_CacheBuild);
}
} }
// NOTE: Feely Pona Link Flags ================================================================= // NOTE: Feely Pona Link Flags =================================================================
Dqn_Slice<Dqn_Str8> feely_pona_platform_link_flags = {}; Dqn_FArray32<Dqn_Str8> feely_pona_platform_link_flags = common_link_flags;
{ {
// NOTE: Link to raylib object files and windows libs ====================================== // NOTE: Link to raylib object files and windows libs ======================================
Dqn_List<Dqn_Str8> link_flags = Dqn_List_InitSliceCopy(scratch.arena, 128, common_link_flags); Dqn_FArray_AddArrayAssert(&feely_pona_platform_link_flags, raylib_pc_output_files.data, raylib_pc_output_files.size);
{ Dqn_FArray_AddArrayAssert(&feely_pona_platform_link_flags, sokol_audio_pc_output_files.data, sokol_audio_pc_output_files.size);
for (Dqn_ListIterator<Dqn_Str8> it = {}; Dqn_List_Iterate(&raylib_pc_output_files, &it, 0); ) if (windows_build) {
Dqn_List_Add(&link_flags, *it.data); Dqn_FArray_AddCArrayAssert(&feely_pona_platform_link_flags, {
for (Dqn_ListIterator<Dqn_Str8> it = {}; Dqn_List_Iterate(&sokol_audio_pc_output_files, &it, 0); ) DQN_STR8("gdi32.lib"),
Dqn_List_Add(&link_flags, *it.data); DQN_STR8("opengl32.lib"),
Dqn_List_Add(&link_flags, DQN_STR8("gdi32.lib")); DQN_STR8("winmm.lib"),
Dqn_List_Add(&link_flags, DQN_STR8("opengl32.lib")); DQN_STR8("user32.lib"),
Dqn_List_Add(&link_flags, DQN_STR8("winmm.lib")); DQN_STR8("shell32.lib"),
Dqn_List_Add(&link_flags, DQN_STR8("user32.lib")); });
Dqn_List_Add(&link_flags, DQN_STR8("shell32.lib")); } else {
Dqn_FArray_AddCArrayAssert(&feely_pona_platform_link_flags, {
DQN_STR8("-lpthread"),
DQN_STR8("-ldl"),
DQN_STR8("-lasound"),
});
} }
feely_pona_platform_link_flags = Dqn_List_ToSliceCopy(&link_flags, scratch.arena);
} }
// NOTE: Feely Pona No DLL ===================================================================== // NOTE: Feely Pona No DLL =====================================================================
@ -338,94 +413,91 @@ int main(int argc, char const **argv)
Dqn_CPPBuildCompileFile build_file = {}; Dqn_CPPBuildCompileFile build_file = {};
build_file.input_file_path = Dqn_FsPath_ConvertF(scratch.arena, "%.*s/feely_pona_unity.h", DQN_STR_FMT(code_dir)); build_file.input_file_path = Dqn_FsPath_ConvertF(scratch.arena, "%.*s/feely_pona_unity.h", DQN_STR_FMT(code_dir));
build_file.output_file_path = Dqn_FsPath_ConvertF(scratch.arena, "terry_cherry"); build_file.output_file_path = Dqn_FsPath_ConvertF(scratch.arena, "terry_cherry");
build_file.flags = Dqn_Slice_InitCArrayCopy(scratch.arena, {DQN_STR8("/Tp")}); if (windows_build) {
build_file.prefix_flags = Dqn_Slice_InitCArray(scratch.arena, {DQN_STR8("-Tp")});
} else {
build_file.prefix_flags = Dqn_Slice_InitCArray(scratch.arena, {DQN_STR8("-xc++")});
build_file.suffix_flags = Dqn_Slice_InitCArray(scratch.arena, {DQN_STR8("-xnone")});
}
Dqn_List<Dqn_Str8> compile_flags = Dqn_List_InitSliceCopy(scratch.arena, 16, common_compile_flags); Dqn_FArray32<Dqn_Str8> compile_flags = common_compile_flags;
Dqn_List_AddCArray(&compile_flags, { Dqn_FArray_AddCArrayAssert(&compile_flags, {
DQN_STR8("/D TELY_WITH_PLATFORM"), DQN_STR8("-D"), DQN_STR8("TELY_WITH_PLATFORM"),
DQN_STR8("/D FEELY_PONA_IMPLEMENTATION"), DQN_STR8("-D"), DQN_STR8("FEELY_PONA_IMPLEMENTATION"),
}); });
Dqn_CPPBuildContext feely_pona_no_dll_build_context = {}; Dqn_CPPBuildContext feely_pona_no_dll_build_context = {};
feely_pona_no_dll_build_context.compiler = Dqn_CPPBuildCompiler_MSVC; feely_pona_no_dll_build_context.flags_style = flags_style;
feely_pona_no_dll_build_context.compile_files = Dqn_Slice_InitCArrayCopy(scratch.arena, {build_file}); feely_pona_no_dll_build_context.compile_files = Dqn_Slice_Init(&build_file, 1);
feely_pona_no_dll_build_context.include_dirs = Dqn_Slice_InitCArrayCopy(scratch.arena, {raylib_dir}); feely_pona_no_dll_build_context.include_dirs = Dqn_Slice_Init(DQN_CAST(Dqn_Str8 *)&raylib_dir, 1);
feely_pona_no_dll_build_context.compile_flags = Dqn_List_ToSliceCopy(&compile_flags, scratch.arena); feely_pona_no_dll_build_context.compile_flags = Dqn_FArray_Slice(&compile_flags);
feely_pona_no_dll_build_context.build_dir = build_dir; feely_pona_no_dll_build_context.build_dir = build_dir;
feely_pona_no_dll_build_context.link_flags = feely_pona_platform_link_flags; feely_pona_no_dll_build_context.link_flags = Dqn_FArray_Slice(&feely_pona_platform_link_flags);
if (dry_run) { Dqn_Str8 cmd = Dqn_CPPBuild_ToCommandLineStr8(feely_pona_no_dll_build_context, Dqn_CPPBuildMode_AlwaysRebuild, scratch.arena);
Dqn_Str8 cmd = Dqn_CPPBuild_ToCommandLine(feely_pona_no_dll_build_context, Dqn_CPPBuildMode_AlwaysRebuild, scratch.allocator); Dqn_Print_StdLnF(Dqn_PrintStd_Out, "[BUILD] Executing '%.*s'", DQN_STR_FMT(cmd));
Dqn_Print_StdLnF(Dqn_PrintStd_Out, "%.*s\n", DQN_STR_FMT(cmd)); if (!dry_run)
} else {
Dqn_CPPBuild_ExecOrAbort(feely_pona_no_dll_build_context, Dqn_CPPBuildMode_AlwaysRebuild); Dqn_CPPBuild_ExecOrAbort(feely_pona_no_dll_build_context, Dqn_CPPBuildMode_AlwaysRebuild);
}
} }
// NOTE: Feely Pona DLL ======================================================================== // NOTE: Feely Pona DLL ========================================================================
uint64_t feely_pona_dll_timings[2] = {}; uint64_t feely_pona_dll_timings[2] = {};
{ if (windows_build) {
feely_pona_dll_timings[0] = Dqn_OS_PerfCounterNow(); feely_pona_dll_timings[0] = Dqn_OS_PerfCounterNow();
DQN_DEFER { feely_pona_dll_timings[1] = Dqn_OS_PerfCounterNow(); }; DQN_DEFER { feely_pona_dll_timings[1] = Dqn_OS_PerfCounterNow(); };
Dqn_CPPBuildCompileFile build_file = {}; Dqn_CPPBuildCompileFile build_file = {};
build_file.input_file_path = Dqn_FsPath_ConvertF(scratch.arena, "%.*s/feely_pona_unity.h", DQN_STR_FMT(code_dir)); build_file.input_file_path = Dqn_FsPath_ConvertF(scratch.arena, "%.*s/feely_pona_unity.h", DQN_STR_FMT(code_dir));
build_file.output_file_path = Dqn_FsPath_ConvertF(scratch.arena, "terry_cherry_dev_dll"); build_file.output_file_path = Dqn_FsPath_ConvertF(scratch.arena, "terry_cherry_dev_dll");
build_file.flags = Dqn_Slice_InitCArrayCopy(scratch.arena, {DQN_STR8("/Tp")}); build_file.prefix_flags = Dqn_Slice_InitCArray(scratch.arena, {DQN_STR8("-Tp")});
Dqn_List<Dqn_Str8> compile_flags = Dqn_List_InitSliceCopy(scratch.arena, 16, common_compile_flags);
Dqn_List_AddCArray(&compile_flags, {
DQN_STR8("/LD"),
DQN_STR8("/D FEELY_PONA_IMPLEMENTATION"),
});
Dqn_FArray32<Dqn_Str8> compile_flags = common_compile_flags;
Dqn_FArray_AddAssert(&compile_flags, DQN_STR8("-LD"));
Dqn_FArray_AddAssert(&compile_flags, DQN_STR8("-D FEELY_PONA_IMPLEMENTATION"));
if (!dev_fast_build) if (!dev_fast_build)
Dqn_List_Add(&compile_flags, DQN_STR8("/analyze")); Dqn_FArray_AddAssert(&compile_flags, DQN_STR8("-analyze"));
Dqn_CPPBuildContext build_context = {}; Dqn_CPPBuildContext build_context = {};
build_context.compiler = Dqn_CPPBuildCompiler_MSVC; build_context.flags_style = flags_style;
build_context.compile_files = Dqn_Slice_InitCArrayCopy(scratch.arena, {build_file}); build_context.compile_files = Dqn_Slice_Init(&build_file, 1);
build_context.compile_flags = Dqn_List_ToSliceCopy(&compile_flags, scratch.arena); build_context.compile_flags = Dqn_FArray_Slice(&compile_flags);
build_context.link_flags = {}; build_context.link_flags = {};
build_context.build_dir = build_dir; build_context.build_dir = build_dir;
if (dry_run) { Dqn_Str8 cmd = Dqn_CPPBuild_ToCommandLineStr8(build_context, Dqn_CPPBuildMode_AlwaysRebuild, scratch.arena);
Dqn_Str8 cmd = Dqn_CPPBuild_ToCommandLine(build_context, Dqn_CPPBuildMode_AlwaysRebuild, scratch.allocator); Dqn_Print_StdLnF(Dqn_PrintStd_Out, "[BUILD] Executing '%.*s'", DQN_STR_FMT(cmd));
Dqn_Print_StdLnF(Dqn_PrintStd_Out, "%.*s\n", DQN_STR_FMT(cmd)); if (!dry_run)
} else {
Dqn_CPPBuild_ExecOrAbort(build_context, Dqn_CPPBuildMode_AlwaysRebuild); Dqn_CPPBuild_ExecOrAbort(build_context, Dqn_CPPBuildMode_AlwaysRebuild);
}
} }
// NOTE: Feely Pona platform =================================================================== // NOTE: Feely Pona platform ===================================================================
uint64_t feely_pona_platform_timings[2] = {}; uint64_t feely_pona_platform_timings[2] = {};
{ if (windows_build) {
feely_pona_platform_timings[0] = Dqn_OS_PerfCounterNow(); feely_pona_platform_timings[0] = Dqn_OS_PerfCounterNow();
DQN_DEFER { feely_pona_platform_timings[1] = Dqn_OS_PerfCounterNow(); }; DQN_DEFER { feely_pona_platform_timings[1] = Dqn_OS_PerfCounterNow(); };
Dqn_CPPBuildCompileFile build_file = {}; Dqn_CPPBuildCompileFile build_file = {};
build_file.input_file_path = Dqn_FsPath_ConvertF(scratch.arena, "%.*s/feely_pona_unity.h", DQN_STR_FMT(code_dir)); build_file.input_file_path = Dqn_FsPath_ConvertF(scratch.arena, "%.*s/feely_pona_unity.h", DQN_STR_FMT(code_dir));
build_file.output_file_path = Dqn_FsPath_ConvertF(scratch.arena, "terry_cherry_dev", DQN_STR_FMT(code_dir)); build_file.output_file_path = Dqn_FsPath_ConvertF(scratch.arena, "terry_cherry_dev", DQN_STR_FMT(code_dir));
build_file.flags = Dqn_Slice_InitCArrayCopy(scratch.arena, {DQN_STR8("/Tp")}); build_file.prefix_flags = Dqn_Slice_InitCArray(scratch.arena, {DQN_STR8("-Tp")});
Dqn_List<Dqn_Str8> compile_flags = Dqn_List_InitSliceCopy(scratch.arena, 128, common_compile_flags); Dqn_FArray32<Dqn_Str8> compile_flags = common_compile_flags;
Dqn_List_AddCArray(&compile_flags, { Dqn_FArray_AddCArrayAssert(&compile_flags, {
DQN_STR8("/D TELY_WITH_PLATFORM"), DQN_STR8("-D"), DQN_STR8("TELY_WITH_PLATFORM"),
DQN_STR8("/D TELY_WITH_PLATFORM_DLL"), DQN_STR8("-D"), DQN_STR8("TELY_WITH_PLATFORM_DLL"),
}); });
Dqn_CPPBuildContext build_context = {}; Dqn_CPPBuildContext build_context = {};
build_context.compiler = Dqn_CPPBuildCompiler_MSVC; build_context.flags_style = flags_style;
build_context.compile_files = Dqn_Slice_InitCArrayCopy(scratch.arena, {build_file}); build_context.compile_files = Dqn_Slice_Init(&build_file, 1);
build_context.compile_flags = Dqn_List_ToSliceCopy(&compile_flags, scratch.arena); build_context.compile_flags = Dqn_FArray_Slice(&compile_flags);
build_context.link_flags = feely_pona_platform_link_flags; build_context.link_flags = Dqn_FArray_Slice(&feely_pona_platform_link_flags);
build_context.build_dir = build_dir; build_context.build_dir = build_dir;
build_context.include_dirs = Dqn_Slice_InitCArrayCopy(scratch.arena, {raylib_dir}); build_context.include_dirs = Dqn_Slice_InitCArray(scratch.arena, {raylib_dir});
if (dry_run) { Dqn_Str8 cmd = Dqn_CPPBuild_ToCommandLineStr8(build_context, Dqn_CPPBuildMode_AlwaysRebuild, scratch.arena);
Dqn_Str8 cmd = Dqn_CPPBuild_ToCommandLine(build_context, Dqn_CPPBuildMode_AlwaysRebuild, scratch.allocator); Dqn_Print_StdLnF(Dqn_PrintStd_Out, "[BUILD] Executing '%.*s'", DQN_STR_FMT(cmd));
Dqn_Print_StdLnF(Dqn_PrintStd_Out, "%.*s\n", DQN_STR_FMT(cmd)); if (!dry_run) {
} else {
Dqn_Str8 exe_path = Dqn_FsPath_ConvertF(scratch.arena, "%.*s/terry_cherry_dev.exe", DQN_STR_FMT(build_dir)); Dqn_Str8 exe_path = Dqn_FsPath_ConvertF(scratch.arena, "%.*s/terry_cherry_dev.exe", DQN_STR_FMT(build_dir));
bool exe_is_locked = false; bool exe_is_locked = false;
if (Dqn_Fs_Exists(exe_path)) { if (Dqn_Fs_Exists(exe_path)) {
@ -443,23 +515,19 @@ int main(int argc, char const **argv)
// NOTE: raylib emscripten ===================================================================== // NOTE: raylib emscripten =====================================================================
uint64_t raylib_emscripten_timings[2] = {}; uint64_t raylib_emscripten_timings[2] = {};
uint64_t feely_pona_emscripten_timings[2] = {}; uint64_t feely_pona_emscripten_timings[2] = {};
if (target_web) { if (windows_build && target_web) {
Dqn_Str8 const raylib_emscripten_lib_name = DQN_STR8("raylib_emscripten.a"); Dqn_Str8 const raylib_emscripten_lib_name = DQN_STR8("raylib_emscripten.a");
bool debug_build = false; bool debug_build = false;
Dqn_List<Dqn_Str8> build_specific_compile_flags = {}; Dqn_FArray32<Dqn_Str8> build_specific_compile_flags = {};
if (debug_build) { if (debug_build) {
build_specific_compile_flags = Dqn_List_InitCArrayCopy<Dqn_Str8>(scratch.arena, 32, { Dqn_FArray_AddCArrayAssert(&build_specific_compile_flags, {DQN_STR8("-s"), DQN_STR8("ASSERTIONS=2")});
DQN_STR8("-s"), DQN_STR8("ASSERTIONS=2"), Dqn_FArray_AddCArrayAssert(&build_specific_compile_flags, {DQN_STR8("-s"), DQN_STR8("SAFE_HEAP=0")});
DQN_STR8("-s"), DQN_STR8("SAFE_HEAP=0"), Dqn_FArray_AddCArrayAssert(&build_specific_compile_flags, {DQN_STR8("-s"), DQN_STR8("STACK_OVERFLOW_CHECK=2")});
DQN_STR8("-s"), DQN_STR8("STACK_OVERFLOW_CHECK=2"), Dqn_FArray_AddCArrayAssert(&build_specific_compile_flags, {DQN_STR8("--profiling-funcs")}); // Expose function names in stack trace
DQN_STR8("--profiling-funcs"), // Expose function names in stack trace Dqn_FArray_AddCArrayAssert(&build_specific_compile_flags, {DQN_STR8("-g")}); // Debug symbols
DQN_STR8("-g"), // Debug symbols
});
} else { } else {
build_specific_compile_flags = Dqn_List_InitCArrayCopy<Dqn_Str8>(scratch.arena, 32, { Dqn_FArray_AddCArrayAssert(&build_specific_compile_flags, {DQN_STR8("-Os")}); // Optimise for size
DQN_STR8("-Os"), // Optimise for size
});
} }
// NOTE: Compile each raylib file separately with emcc ===================================== // NOTE: Compile each raylib file separately with emcc =====================================
@ -468,9 +536,9 @@ int main(int argc, char const **argv)
DQN_DEFER { raylib_emscripten_timings[1] = Dqn_OS_PerfCounterNow(); }; DQN_DEFER { raylib_emscripten_timings[1] = Dqn_OS_PerfCounterNow(); };
// NOTE: Setup build context =========================================================== // NOTE: Setup build context ===========================================================
Dqn_List<Dqn_Str8> emscripten_obj_files = Dqn_List_Init<Dqn_Str8>(scratch.arena, 16); Dqn_FArray32<Dqn_Str8> emscripten_obj_files = {};
Dqn_CPPBuildContext raylib_emscripten_build_context = {}; Dqn_CPPBuildContext raylib_emscripten_build_context = {};
raylib_emscripten_build_context.compiler = Dqn_CPPBuildCompiler_GCC; raylib_emscripten_build_context.flags_style = flags_style;
for (Dqn_Str8 base_file : raylib_base_files) { for (Dqn_Str8 base_file : raylib_base_files) {
Dqn_Str8 file_stem = Dqn_Str8_FileNameNoExtension(base_file); Dqn_Str8 file_stem = Dqn_Str8_FileNameNoExtension(base_file);
@ -480,7 +548,8 @@ int main(int argc, char const **argv)
build_file.input_file_path = base_file; build_file.input_file_path = base_file;
build_file.output_file_path = Dqn_Str8_InitF(scratch.allocator, "raylib_%.*s_emscripten.o", DQN_STR_FMT(file_stem)); build_file.output_file_path = Dqn_Str8_InitF(scratch.allocator, "raylib_%.*s_emscripten.o", DQN_STR_FMT(file_stem));
Dqn_List<Dqn_Str8> compile_flags = Dqn_List_InitCArrayCopy(scratch.arena, 32, { Dqn_FArray32<Dqn_Str8> compile_flags = {};
Dqn_FArray_AddCArrayAssert(&compile_flags, {
DQN_STR8("cmd"), DQN_STR8("cmd"),
DQN_STR8("/C"), DQN_STR8("/C"),
DQN_STR8("emcc.bat"), DQN_STR8("emcc.bat"),
@ -490,31 +559,28 @@ int main(int argc, char const **argv)
DQN_STR8("-D PLATFORM_WEB"), DQN_STR8("-D PLATFORM_WEB"),
DQN_STR8("-D GRAPHICS_API_OPENGL_ES2"), DQN_STR8("-D GRAPHICS_API_OPENGL_ES2"),
}); });
Dqn_List_AddList(&compile_flags, build_specific_compile_flags); Dqn_FArray_AddArrayAssert(&compile_flags, build_specific_compile_flags.data, build_specific_compile_flags.size);
raylib_emscripten_build_context.compile_files = Dqn_Slice_InitCArrayCopy(scratch.arena, {build_file}); raylib_emscripten_build_context.compile_files = Dqn_Slice_Init(&build_file, 1);
raylib_emscripten_build_context.compile_flags = Dqn_List_ToSliceCopy(&compile_flags, scratch.arena); raylib_emscripten_build_context.compile_flags = Dqn_FArray_Slice(&compile_flags);
raylib_emscripten_build_context.build_dir = build_dir; raylib_emscripten_build_context.build_dir = build_dir;
Dqn_List_Add(&emscripten_obj_files, build_file.output_file_path); Dqn_FArray_AddAssert(&emscripten_obj_files, build_file.output_file_path);
if (dry_run) { Dqn_Str8 cmd = Dqn_CPPBuild_ToCommandLineStr8(raylib_emscripten_build_context, Dqn_CPPBuildMode_AlwaysRebuild, scratch.arena);
Dqn_Str8 cmd = Dqn_CPPBuild_ToCommandLine(raylib_emscripten_build_context, Dqn_CPPBuildMode_AlwaysRebuild, scratch.allocator); Dqn_Print_StdLnF(Dqn_PrintStd_Out, "[BUILD] Executing '%.*s'", DQN_STR_FMT(cmd));
Dqn_Print_StdLnF(Dqn_PrintStd_Out, "%.*s\n", DQN_STR_FMT(cmd)); if (!dry_run)
} else {
Dqn_CPPBuild_ExecOrAbort(raylib_emscripten_build_context, Dqn_CPPBuildMode_CacheBuild); Dqn_CPPBuild_ExecOrAbort(raylib_emscripten_build_context, Dqn_CPPBuildMode_CacheBuild);
}
} }
{ {
Dqn_Str8 base_file = sokol_audio_source_code_file; Dqn_Str8 base_file = sokol_audio_source_code_file;
Dqn_Str8 file_stem = Dqn_Str8_FileNameNoExtension(base_file);
// NOTE: Append "emscripten" suffix to the object files // NOTE: Append "emscripten" suffix to the object files
Dqn_CPPBuildCompileFile build_file = {}; Dqn_CPPBuildCompileFile build_file = {};
build_file.input_file_path = base_file; build_file.input_file_path = base_file;
build_file.output_file_path = Dqn_Str8_InitF(scratch.allocator, "sokol_audio_emscripten.o"); build_file.output_file_path = Dqn_Str8_InitF(scratch.allocator, "sokol_audio_emscripten.o");
Dqn_List<Dqn_Str8> compile_flags = Dqn_List_InitCArrayCopy(scratch.arena, 32, { Dqn_FArray32<Dqn_Str8> compile_flags = Dqn_FArray_InitCArray<Dqn_Str8, 32>({
DQN_STR8("cmd"), DQN_STR8("cmd"),
DQN_STR8("/C"), DQN_STR8("/C"),
DQN_STR8("emcc.bat"), DQN_STR8("emcc.bat"),
@ -522,36 +588,36 @@ int main(int argc, char const **argv)
DQN_STR8("-Wall"), DQN_STR8("-Wall"),
DQN_STR8("-Os"), // Optimize for size DQN_STR8("-Os"), // Optimize for size
}); });
Dqn_List_AddList(&compile_flags, build_specific_compile_flags); Dqn_FArray_AddArrayAssert(&compile_flags, build_specific_compile_flags.data, build_specific_compile_flags.size);
raylib_emscripten_build_context.compile_files = Dqn_Slice_InitCArrayCopy(scratch.arena, {build_file}); raylib_emscripten_build_context.compile_files = Dqn_Slice_Init(&build_file, 1);
raylib_emscripten_build_context.compile_flags = Dqn_List_ToSliceCopy(&compile_flags, scratch.arena); raylib_emscripten_build_context.compile_flags = Dqn_FArray_Slice(&compile_flags);
raylib_emscripten_build_context.build_dir = build_dir; raylib_emscripten_build_context.build_dir = build_dir;
Dqn_List_Add(&emscripten_obj_files, build_file.output_file_path); Dqn_FArray_AddAssert(&emscripten_obj_files, build_file.output_file_path);
if (dry_run) { Dqn_Str8 cmd = Dqn_CPPBuild_ToCommandLineStr8(raylib_emscripten_build_context, Dqn_CPPBuildMode_AlwaysRebuild, scratch.arena);
Dqn_Str8 cmd = Dqn_CPPBuild_ToCommandLine(raylib_emscripten_build_context, Dqn_CPPBuildMode_AlwaysRebuild, scratch.allocator); Dqn_Print_StdLnF(Dqn_PrintStd_Out, "[BUILD] Executing '%.*s'", DQN_STR_FMT(cmd));
Dqn_Print_StdLnF(Dqn_PrintStd_Out, "%.*s\n", DQN_STR_FMT(cmd)); if (!dry_run)
} else {
Dqn_CPPBuild_ExecOrAbort(raylib_emscripten_build_context, Dqn_CPPBuildMode_CacheBuild); Dqn_CPPBuild_ExecOrAbort(raylib_emscripten_build_context, Dqn_CPPBuildMode_CacheBuild);
}
} }
// NOTE: Build the wasm raylib+sokol_audio library ===================================== // NOTE: Build the wasm raylib+sokol_audio library =====================================
{ {
Dqn_Str8Builder builder = {}; Dqn_FArray32<Dqn_Str8> cmd_args = Dqn_FArray_InitCArray<Dqn_Str8, 32>({
builder.allocator = scratch.allocator; DQN_STR8("cmd"),
Dqn_Str8Builder_AppendF(&builder, "cmd /C emar.bat rcs %.*s", DQN_STR_FMT(raylib_emscripten_lib_name)); DQN_STR8("/C"),
DQN_STR8("emar.bat"),
DQN_STR8("rcs"),
raylib_emscripten_lib_name,
});
for (Dqn_ListIterator<Dqn_Str8> it = {}; Dqn_List_Iterate(&emscripten_obj_files, &it, 0); ) Dqn_FArray_AddArrayAssert(&cmd_args, emscripten_obj_files.data, emscripten_obj_files.size);
Dqn_Str8Builder_AppendF(&builder, " %.*s", DQN_STR_FMT(*it.data)); Dqn_Slice<Dqn_Str8> cmd_slice = Dqn_FArray_Slice(&cmd_args);
Dqn_Str8 cmd = Dqn_Str8Builder_Build(&builder, scratch.allocator); Dqn_Str8 cmd = Dqn_Slice_Str8Render(scratch.arena, cmd_slice, DQN_STR8(" ") /*separator*/);
if (dry_run) { Dqn_Print_StdLnF(Dqn_PrintStd_Out, "[BUILD] Executing '%.*s'", DQN_STR_FMT(cmd));
Dqn_Print_StdLnF(Dqn_PrintStd_Out, "%.*s\n", DQN_STR_FMT(cmd)); if (!dry_run)
} else { Dqn_OS_ExecOrAbort(cmd_slice, build_dir);
Dqn_OS_ExecOrAbort(cmd, build_dir);
}
} }
} }
@ -605,12 +671,12 @@ int main(int argc, char const **argv)
// NOTE: Compile with emcc ============================================================= // NOTE: Compile with emcc =============================================================
Dqn_CPPBuildContext build_context = {}; Dqn_CPPBuildContext build_context = {};
build_context.compile_file_obj_suffix = DQN_CPP_BUILD_OBJ_SUFFIX_O; build_context.compile_file_obj_suffix = DQN_CPP_BUILD_OBJ_SUFFIX_O;
build_context.compile_files = Dqn_Slice_InitCArrayCopy(scratch.arena, { build_context.compile_files = Dqn_Slice_InitCArray(scratch.arena, {
Dqn_CPPBuildCompileFile{{}, Dqn_FsPath_ConvertF(scratch.arena, "%.*s/feely_pona_unity.cpp", DQN_STR_FMT(code_dir)) }, Dqn_CPPBuildCompileFile{{}, {}, Dqn_FsPath_ConvertF(scratch.arena, "%.*s/feely_pona_unity.cpp", DQN_STR_FMT(code_dir)) },
}); });
Dqn_Str8 output_name = DQN_STR8("Terry_Cherry"); Dqn_Str8 output_name = DQN_STR8("Terry_Cherry");
Dqn_List<Dqn_Str8> compile_flags = Dqn_List_InitCArrayCopy(scratch.arena, 32, { Dqn_FArray32<Dqn_Str8> compile_flags = Dqn_FArray_InitCArray<Dqn_Str8, 32>({
DQN_STR8("cmd"), DQN_STR8("/C"), DQN_STR8("emcc.bat"), DQN_STR8("cmd"), DQN_STR8("/C"), DQN_STR8("emcc.bat"),
DQN_STR8("-o"), Dqn_Str8_InitF(scratch.allocator, "%.*s.html", DQN_STR_FMT(output_name)), DQN_STR8("-o"), Dqn_Str8_InitF(scratch.allocator, "%.*s.html", DQN_STR_FMT(output_name)),
DQN_STR8("-Wall"), DQN_STR8("-Wall"),
@ -626,23 +692,23 @@ int main(int argc, char const **argv)
DQN_STR8("-D"), DQN_STR8("TELY_WITH_PLATFORM"), DQN_STR8("-D"), DQN_STR8("TELY_WITH_PLATFORM"),
DQN_STR8("-D"), DQN_STR8("FEELY_PONA_IMPLEMENTATION"), DQN_STR8("-D"), DQN_STR8("FEELY_PONA_IMPLEMENTATION"),
}); });
Dqn_List_AddList(&compile_flags, build_specific_compile_flags); Dqn_FArray_AddArrayAssert(&compile_flags, build_specific_compile_flags.data, build_specific_compile_flags.size);
build_context.compile_flags = Dqn_List_ToSliceCopy(&compile_flags, scratch.arena); build_context.compile_flags = Dqn_FArray_Slice(&compile_flags);
build_context.build_dir = build_dir; build_context.build_dir = build_dir;
if (dry_run) { Dqn_Str8 cmd = Dqn_CPPBuild_ToCommandLineStr8(build_context, Dqn_CPPBuildMode_AlwaysRebuild, scratch.arena);
Dqn_Str8 cmd = Dqn_CPPBuild_ToCommandLine(build_context, Dqn_CPPBuildMode_AlwaysRebuild, scratch.allocator); Dqn_Print_StdLnF(Dqn_PrintStd_Out, "[BUILD] Executing '%.*s'", DQN_STR_FMT(cmd));
Dqn_Print_StdLnF(Dqn_PrintStd_Out, "%.*s\n", DQN_STR_FMT(cmd)); if (!dry_run)
} else {
Dqn_CPPBuild_ExecOrAbort(build_context, Dqn_CPPBuildMode_CacheBuild); Dqn_CPPBuild_ExecOrAbort(build_context, Dqn_CPPBuildMode_CacheBuild);
}
// NOTE: Move the files to a directory // NOTE: Move the files to a directory
Dqn_Str8 folder_path = Dqn_FsPath_ConvertF(scratch.arena, "%.*s/%.*s", DQN_STR_FMT(build_dir), DQN_STR_FMT(output_name)); Dqn_Str8 folder_path = Dqn_FsPath_ConvertF(scratch.arena, "%.*s/%.*s", DQN_STR_FMT(build_dir), DQN_STR_FMT(output_name));
if (!Dqn_Fs_DirExists(folder_path)) { if (!Dqn_Fs_DirExists(folder_path)) {
Dqn_Str8 mkdir_cmd = Dqn_Str8_InitF(scratch.allocator, "mkdir %.*s", DQN_STR_FMT(folder_path)); Dqn_FArray32<Dqn_Str8> mkdir_cmd = {};
Dqn_OS_ExecOrAbort(mkdir_cmd, {}); Dqn_FArray_AddAssert(&mkdir_cmd, DQN_STR8("mkdir"));
Dqn_FArray_AddAssert(&mkdir_cmd, folder_path);
Dqn_OS_ExecOrAbort(Dqn_FArray_Slice(&mkdir_cmd), {});
} }
Dqn_Str8 const generated_file_extension[] = { Dqn_Str8 const generated_file_extension[] = {
@ -655,12 +721,20 @@ int main(int argc, char const **argv)
for (Dqn_Str8 file_ext : generated_file_extension) { for (Dqn_Str8 file_ext : generated_file_extension) {
Dqn_Str8 src_path = Dqn_FsPath_ConvertF(scratch.arena, "%.*s/%.*s.%.*s", DQN_STR_FMT(build_dir), DQN_STR_FMT(output_name), DQN_STR_FMT(file_ext)); Dqn_Str8 src_path = Dqn_FsPath_ConvertF(scratch.arena, "%.*s/%.*s.%.*s", DQN_STR_FMT(build_dir), DQN_STR_FMT(output_name), DQN_STR_FMT(file_ext));
Dqn_Str8 dest_path = Dqn_FsPath_ConvertF(scratch.arena, "%.*s/%.*s.%.*s", DQN_STR_FMT(folder_path), DQN_STR_FMT(output_name), DQN_STR_FMT(file_ext)); Dqn_Str8 dest_path = Dqn_FsPath_ConvertF(scratch.arena, "%.*s/%.*s.%.*s", DQN_STR_FMT(folder_path), DQN_STR_FMT(output_name), DQN_STR_FMT(file_ext));
Dqn_Str8 cmd = Dqn_Str8_InitF(scratch.allocator, "cmd /C move /Y %.*s %.*s", DQN_STR_FMT(src_path), DQN_STR_FMT(dest_path));
if (dry_run) { Dqn_FArray32<Dqn_Str8> cmd_args = {};
Dqn_Print_StdLnF(Dqn_PrintStd_Out, "%.*s\n", DQN_STR_FMT(cmd)); Dqn_FArray_AddAssert(&cmd_args, DQN_STR8("cmd"));
} else { Dqn_FArray_AddAssert(&cmd_args, DQN_STR8("/C"));
Dqn_OS_ExecOrAbort(cmd, build_dir); Dqn_FArray_AddAssert(&cmd_args, DQN_STR8("move"));
} Dqn_FArray_AddAssert(&cmd_args, DQN_STR8("/Y"));
Dqn_FArray_AddAssert(&cmd_args, src_path);
Dqn_FArray_AddAssert(&cmd_args, dest_path);
Dqn_Slice<Dqn_Str8> cmd_slice = Dqn_FArray_Slice(&cmd_args);
Dqn_Str8 cmd_rendered = Dqn_Slice_Str8Render(scratch.arena, cmd_slice, DQN_STR8(" "));
Dqn_Print_StdLnF(Dqn_PrintStd_Out, "[BUILD] Executing '%.*s'", DQN_STR_FMT(cmd_rendered));
if (!dry_run)
Dqn_OS_ExecOrAbort(cmd_slice, build_dir);
} }
} }
} }
@ -670,7 +744,6 @@ int main(int argc, char const **argv)
Dqn_Print_StdLnF(Dqn_PrintStd_Out, " robocopy: %.2fms", Dqn_OS_PerfCounterMs(robocopy_timings[0], robocopy_timings[1])); Dqn_Print_StdLnF(Dqn_PrintStd_Out, " robocopy: %.2fms", Dqn_OS_PerfCounterMs(robocopy_timings[0], robocopy_timings[1]));
Dqn_Print_StdLnF(Dqn_PrintStd_Out, " raylib: %.2fms", Dqn_OS_PerfCounterMs(raylib_pc_timings[0], raylib_pc_timings[1])); Dqn_Print_StdLnF(Dqn_PrintStd_Out, " raylib: %.2fms", Dqn_OS_PerfCounterMs(raylib_pc_timings[0], raylib_pc_timings[1]));
Dqn_Print_StdLnF(Dqn_PrintStd_Out, " sokol_audio: %.2fms", Dqn_OS_PerfCounterMs(sokol_audio_pc_timings[0], sokol_audio_pc_timings[1])); Dqn_Print_StdLnF(Dqn_PrintStd_Out, " sokol_audio: %.2fms", Dqn_OS_PerfCounterMs(sokol_audio_pc_timings[0], sokol_audio_pc_timings[1]));
Dqn_Print_StdLnF(Dqn_PrintStd_Out, " qoi_converter: %.2fms", Dqn_OS_PerfCounterMs(qoi_converter_timings[0], qoi_converter_timings[1]));
Dqn_Print_StdLnF(Dqn_PrintStd_Out, " feely pona sprite packer: %.2fms", Dqn_OS_PerfCounterMs(feely_pona_sprite_packer_timings[0], feely_pona_sprite_packer_timings[1])); Dqn_Print_StdLnF(Dqn_PrintStd_Out, " feely pona sprite packer: %.2fms", Dqn_OS_PerfCounterMs(feely_pona_sprite_packer_timings[0], feely_pona_sprite_packer_timings[1]));
Dqn_Print_StdLnF(Dqn_PrintStd_Out, " feely pona (no dll): %.2fms", Dqn_OS_PerfCounterMs(feely_pona_no_dll_timings[0], feely_pona_no_dll_timings[1])); Dqn_Print_StdLnF(Dqn_PrintStd_Out, " feely pona (no dll): %.2fms", Dqn_OS_PerfCounterMs(feely_pona_no_dll_timings[0], feely_pona_no_dll_timings[1]));
Dqn_Print_StdLnF(Dqn_PrintStd_Out, " feely pona (dll): %.2fms", Dqn_OS_PerfCounterMs(feely_pona_dll_timings[0], feely_pona_dll_timings[1])); Dqn_Print_StdLnF(Dqn_PrintStd_Out, " feely pona (dll): %.2fms", Dqn_OS_PerfCounterMs(feely_pona_dll_timings[0], feely_pona_dll_timings[1]));

View File

@ -15,13 +15,13 @@
DQN_MSVC_WARNING_PUSH DQN_MSVC_WARNING_PUSH
DQN_MSVC_WARNING_DISABLE(4244) // warning C4244: 'argument': conversion from 'int' to 'short', possible loss of data DQN_MSVC_WARNING_DISABLE(4244) // warning C4244: 'argument': conversion from 'int' to 'short', possible loss of data
#define STB_RECT_PACK_IMPLEMENTATION #define STB_RECT_PACK_IMPLEMENTATION
#include "External/tely/external/stb/stb_rect_pack.h" #include "External/tely/External/stb/stb_rect_pack.h"
#define STB_IMAGE_WRITE_IMPLEMENTATION #define STB_IMAGE_WRITE_IMPLEMENTATION
#include "External/tely/external/stb/stb_image_write.h" #include "External/tely/External/stb/stb_image_write.h"
#define STB_IMAGE_IMPLEMENTATION #define STB_IMAGE_IMPLEMENTATION
#include "External/tely/external/stb/stb_image.h" #include "External/tely/External/stb/stb_image.h"
DQN_MSVC_WARNING_POP DQN_MSVC_WARNING_POP
DQN_MSVC_WARNING_PUSH DQN_MSVC_WARNING_PUSH