fp: Support building via GCC on Windows

This commit is contained in:
doyle 2023-11-26 16:54:21 +11:00
parent 801b9051c9
commit bca013bf05
2 changed files with 47 additions and 32 deletions

2
External/tely vendored

@ -1 +1 @@
Subproject commit aa6076510f62f915bc9dbcbb1a954f5aefaf17df Subproject commit 3083971c14bd0dc54d2d0e62c05c3616f5e7eb44

View File

@ -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|--win|--linux]") #define PRINT_HELP Dqn_Print_StdLnF(Dqn_PrintStd_Out, "USAGE: feely_pona_build [--help|--dry-run|--web|--fast-dev-build|--msvc|--gcc]")
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,8 +88,8 @@ 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;
bool windows_build = false; bool msvc_build = false;
bool linux_build = false; bool gcc_build = false;
for (Dqn_isize arg_index = 1; arg_index < argc; arg_index++) { 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")) {
@ -101,10 +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")) { } else if (arg == DQN_STR8("--gcc")) {
linux_build = true; gcc_build = true;
} else if (arg == DQN_STR8("--win")) { } else if (arg == DQN_STR8("--msvc")) {
windows_build = true; msvc_build = true;
} else { } else {
PRINT_HELP; PRINT_HELP;
return 0; return 0;
@ -117,21 +117,21 @@ 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
if (windows_build && linux_build) { if (msvc_build && gcc_build) {
Dqn_Print_StdLnF(Dqn_PrintStd_Out, Dqn_Print_StdLnF(Dqn_PrintStd_Out,
"Both '--win' and '--linux' were specified but only one is supported at a time for this build program."); "Both '--msvc' and '--gcc' were specified but only one is supported at a time for this build program.");
return -1; return -1;
} }
if (!windows_build && !linux_build) { if (!msvc_build && !gcc_build) {
#if defined(DQN_OS_WIN32) #if defined(DQN_OS_WIN32)
windows_build = true; msvc_build = true;
#else #else
linux_build = true; gcc_build = true;
#endif #endif
} }
Dqn_Print_StdLnF(Dqn_PrintStd_Out, "Building for %s", windows_build ? "Windows" : "Linux"); Dqn_Print_StdLnF(Dqn_PrintStd_Out, "Building for %s", msvc_build ? "Windows" : "Linux");
uint64_t build_timings[2] = {}; uint64_t build_timings[2] = {};
build_timings[0] = Dqn_OS_PerfCounterNow(); build_timings[0] = Dqn_OS_PerfCounterNow();
@ -140,11 +140,11 @@ int main(int argc, char const **argv)
Dqn_Str8 const code_dir = exe_dir; 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 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_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_CPPBuildFlagsStyle flags_style = msvc_build ? Dqn_CPPBuildFlagsStyle_MSVC : Dqn_CPPBuildFlagsStyle_GCC;
Dqn_FArray32<Dqn_Str8> common_compile_flags = {}; Dqn_FArray32<Dqn_Str8> common_compile_flags = {};
Dqn_FArray32<Dqn_Str8> common_link_flags = {}; Dqn_FArray32<Dqn_Str8> common_link_flags = {};
if (windows_build) { if (msvc_build) {
Dqn_FArray_AddAssert(&common_compile_flags, DQN_STR8("cl")); 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("-W4"));
Dqn_FArray_AddAssert(&common_compile_flags, DQN_STR8("-Z7")); Dqn_FArray_AddAssert(&common_compile_flags, DQN_STR8("-Z7"));
@ -169,7 +169,7 @@ int main(int argc, char const **argv)
DQN_DEFER { robocopy_timings[1] = Dqn_OS_PerfCounterNow(); }; DQN_DEFER { robocopy_timings[1] = Dqn_OS_PerfCounterNow(); };
Dqn_FArray8<Dqn_Str8> common_copy_cmd_args = {}; Dqn_FArray8<Dqn_Str8> common_copy_cmd_args = {};
if (windows_build) { if (msvc_build) {
Dqn_FArray_AddCArrayAssert(&common_copy_cmd_args, { Dqn_FArray_AddCArrayAssert(&common_copy_cmd_args, {
DQN_STR8("robocopy"), DQN_STR8("robocopy"),
DQN_STR8("/NJH"), DQN_STR8("/NJH"),
@ -188,7 +188,7 @@ int main(int argc, char const **argv)
DQN_HARD_ASSERT(Dqn_Fs_MakeDir(textures_dest)); DQN_HARD_ASSERT(Dqn_Fs_MakeDir(textures_dest));
Dqn_FArray8<Dqn_FArray8<Dqn_Str8>> copy_cmd_list = {}; Dqn_FArray8<Dqn_FArray8<Dqn_Str8>> copy_cmd_list = {};
if (windows_build) { if (msvc_build) {
Dqn_FArray8<Dqn_Str8> copy_atlas = common_copy_cmd_args; Dqn_FArray8<Dqn_Str8> copy_atlas = common_copy_cmd_args;
Dqn_FArray_AddCArrayAssert(&copy_atlas, { 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", DQN_STR_FMT(exe_dir)),
@ -230,7 +230,7 @@ int main(int argc, char const **argv)
Dqn_Str8 rendered_line = Dqn_Slice_Str8Render(scratch.arena, copy_cmd_slice, DQN_STR8(" ")); 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)); Dqn_Print_StdLnF(Dqn_PrintStd_Out, "[BUILD] Executing '%.*s'", DQN_STR_FMT(rendered_line));
if (!dry_run) { if (!dry_run) {
if (windows_build) { if (msvc_build) {
// NOTE: Robocopy returns 1 on success so we don't use the ExecOrAbort function // NOTE: Robocopy returns 1 on success so we don't use the ExecOrAbort function
Dqn_OS_Exec(copy_cmd_slice, /*working_dir*/ {}); Dqn_OS_Exec(copy_cmd_slice, /*working_dir*/ {});
} else { } else {
@ -268,7 +268,7 @@ int main(int argc, char const **argv)
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)),
}); });
if (windows_build) { if (msvc_build) {
Dqn_FArray_AddCArrayAssert(&compile_flags, { Dqn_FArray_AddCArrayAssert(&compile_flags, {
DQN_STR8("cl"), DQN_STR8("cl"),
DQN_STR8("-w"), DQN_STR8("-w"),
@ -301,7 +301,7 @@ int main(int argc, char const **argv)
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.%s", DQN_STR_FMT(file_stem), windows_build ? "obj" : "o"); build_file.output_file_path = Dqn_Str8_InitF(scratch.allocator, "raylib_%.*s.%s", DQN_STR_FMT(file_stem), msvc_build ? "obj" : "o");
build_context.compile_files = Dqn_Slice_Init(&build_file, 1); build_context.compile_files = Dqn_Slice_Init(&build_file, 1);
Dqn_FArray_AddAssert(&raylib_pc_output_files, build_file.output_file_path); Dqn_FArray_AddAssert(&raylib_pc_output_files, build_file.output_file_path);
@ -315,7 +315,7 @@ 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/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.%s", windows_build ? "obj" : "o"); build_file.output_file_path = Dqn_Str8_InitF(scratch.allocator, "raylib_rglfw.%s", msvc_build ? "obj" : "o");
build_context.compile_files = Dqn_Slice_InitCArray(scratch.arena, {build_file}); build_context.compile_files = Dqn_Slice_InitCArray(scratch.arena, {build_file});
Dqn_FArray_AddAssert(&raylib_pc_output_files, build_file.output_file_path); Dqn_FArray_AddAssert(&raylib_pc_output_files, build_file.output_file_path);
@ -345,7 +345,7 @@ int main(int argc, char const **argv)
}, },
}); });
Dqn_FArray_AddAssert(&sokol_audio_pc_output_files, Dqn_Str8_InitF(scratch.allocator, "sokol_audio.%s", windows_build ? "obj" : "o")); Dqn_FArray_AddAssert(&sokol_audio_pc_output_files, Dqn_Str8_InitF(scratch.allocator, "sokol_audio.%s", msvc_build ? "obj" : "o"));
Dqn_FArray32<Dqn_Str8> compile_flags = common_compile_flags; Dqn_FArray32<Dqn_Str8> compile_flags = common_compile_flags;
Dqn_FArray_AddAssert(&compile_flags, DQN_STR8("-c")); Dqn_FArray_AddAssert(&compile_flags, DQN_STR8("-c"));
@ -361,7 +361,7 @@ int main(int argc, char const **argv)
// 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) { if (msvc_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(); };
@ -387,20 +387,35 @@ int main(int argc, char const **argv)
// NOTE: Link to raylib object files and windows libs ====================================== // NOTE: Link to raylib object files and windows libs ======================================
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, 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); Dqn_FArray_AddArrayAssert(&feely_pona_platform_link_flags, sokol_audio_pc_output_files.data, sokol_audio_pc_output_files.size);
if (windows_build) { if (msvc_build) {
Dqn_FArray_AddCArrayAssert(&feely_pona_platform_link_flags, { Dqn_FArray_AddCArrayAssert(&feely_pona_platform_link_flags, {
DQN_STR8("gdi32.lib"), DQN_STR8("gdi32.lib"), // raylib
DQN_STR8("opengl32.lib"), DQN_STR8("opengl32.lib"), // raylib
DQN_STR8("winmm.lib"), DQN_STR8("winmm.lib"), // raylib
DQN_STR8("user32.lib"), DQN_STR8("user32.lib"),
DQN_STR8("shell32.lib"), DQN_STR8("shell32.lib"),
}); });
} else { } else {
Dqn_FArray_AddCArrayAssert(&feely_pona_platform_link_flags, { Dqn_FArray_AddCArrayAssert(&feely_pona_platform_link_flags, {
DQN_STR8("-lpthread"), DQN_STR8("-lpthread"),
});
#if defined(DQN_OS_UNIX)
Dqn_FArray_AddCArrayAssert(&feely_pona_platform_link_flags, {
DQN_STR8("-ldl"), DQN_STR8("-ldl"),
DQN_STR8("-lasound"), DQN_STR8("-lasound"),
}); });
#else
Dqn_FArray_AddCArrayAssert(&feely_pona_platform_link_flags, {
DQN_STR8("-lgdi32"), // raylib
DQN_STR8("-lopengl32"), // raylib
DQN_STR8("-lwinmm"), // raylib
DQN_STR8("-lole32"), // sokol_audio
DQN_STR8("-lbcrypt"), // dqn
DQN_STR8("-lwininet"), // dqn
DQN_STR8("-ldbghelp"), // dqn
});
#endif
} }
} }
@ -413,7 +428,7 @@ 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");
if (windows_build) { if (msvc_build) {
build_file.prefix_flags = Dqn_Slice_InitCArray(scratch.arena, {DQN_STR8("-Tp")}); build_file.prefix_flags = Dqn_Slice_InitCArray(scratch.arena, {DQN_STR8("-Tp")});
} else { } else {
build_file.prefix_flags = Dqn_Slice_InitCArray(scratch.arena, {DQN_STR8("-xc++")}); build_file.prefix_flags = Dqn_Slice_InitCArray(scratch.arena, {DQN_STR8("-xc++")});
@ -442,7 +457,7 @@ int main(int argc, char const **argv)
// 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) { if (msvc_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(); };
@ -472,7 +487,7 @@ int main(int argc, char const **argv)
// 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) { if (msvc_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(); };
@ -515,7 +530,7 @@ 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 (windows_build && target_web) { if (msvc_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;