From 8dc4eca4d2940500de30dfb8fd2ec25f7c31eba7 Mon Sep 17 00:00:00 2001 From: Jeroen van Rijn Date: Tue, 9 Jul 2024 20:03:50 +0200 Subject: Allow using precompiled .res file. --- src/linker.cpp | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) (limited to 'src/linker.cpp') diff --git a/src/linker.cpp b/src/linker.cpp index 890a74e5a..ac3e32851 100644 --- a/src/linker.cpp +++ b/src/linker.cpp @@ -305,30 +305,35 @@ gb_internal i32 linker_stage(LinkerData *gen) { defer (gb_free(heap_allocator(), windows_sdk_bin_path.text)); if (!build_context.use_lld) { // msvc - String res_path = {}; + String temp_res_path = path_to_string(heap_allocator(), build_context.build_paths[BuildPath_RES]); + String temp_rc_path = path_to_string(heap_allocator(), build_context.build_paths[BuildPath_RC]); + defer (gb_free(heap_allocator(), temp_res_path.text)); + defer (gb_free(heap_allocator(), temp_rc_path.text)); + + String res_path = concatenate3_strings(heap_allocator(), str_lit("\""), temp_res_path, str_lit("\"")); + String rc_path = concatenate3_strings(heap_allocator(), str_lit("\""), temp_rc_path, str_lit("\"")); defer (gb_free(heap_allocator(), res_path.text)); + defer (gb_free(heap_allocator(), rc_path.text)); - // TODO(Jeroen): Add ability to reuse .res file instead of recompiling, if `-resource:file.res` is given. if (build_context.has_resource) { - String temp_res_path = path_to_string(heap_allocator(), build_context.build_paths[BuildPath_RES]); - res_path = concatenate3_strings(heap_allocator(), str_lit("\""), temp_res_path, str_lit("\"")); - gb_free(heap_allocator(), temp_res_path.text); - - String temp_rc_path = path_to_string(heap_allocator(), build_context.build_paths[BuildPath_RC]); - String rc_path = concatenate3_strings(heap_allocator(), str_lit("\""), temp_rc_path, str_lit("\"")); - gb_free(heap_allocator(), temp_rc_path.text); - defer (gb_free(heap_allocator(), rc_path.text)); - - result = system_exec_command_line_app("msvc-link", - "\"%.*src.exe\" /nologo /fo %.*s %.*s", - LIT(windows_sdk_bin_path), - LIT(res_path), - LIT(rc_path) - ); - - if (result) { - return result; + if (temp_rc_path == "") { + debugf("Using precompiled resource %.*s\n", LIT(res_path)); + } else { + debugf("Compiling resource %.*s\n", LIT(res_path)); + + result = system_exec_command_line_app("msvc-link", + "\"%.*src.exe\" /nologo /fo %.*s %.*s", + LIT(windows_sdk_bin_path), + LIT(res_path), + LIT(rc_path) + ); + + if (result) { + return result; + } } + } else { + res_path = {}; } String linker_name = str_lit("link.exe"); -- cgit v1.2.3