From bb90b74e2c14f64595e388496a1781ddf925a74c Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Tue, 21 Apr 2026 15:29:10 +0300 Subject: [PATCH] builder: fix error building graphic app webview due to cflags (fixes #12445) --- vlib/v/cflag/cflags.v | 57 ++++++++++++++++++++++++++++++++++++++ vlib/v/cflag/cflags_test.v | 19 +++++++++++++ 2 files changed, 76 insertions(+) diff --git a/vlib/v/cflag/cflags.v b/vlib/v/cflag/cflags.v index 5b2128a8c..7af755640 100644 --- a/vlib/v/cflag/cflags.v +++ b/vlib/v/cflag/cflags.v @@ -150,6 +150,15 @@ pub fn (cflags []CFlag) defines_others_libs() ([]string, []string, []string) { } if copt.ends_with('.a') || copt.ends_with('.so') || copt.ends_with('.dylib') || copt.ends_with('.dll') || copt.ends_with('.lib') { + windows_import_libs := split_bare_windows_import_libs(copt) + if windows_import_libs.len > 0 { + libs << windows_import_libs.map(windows_import_lib_to_link_flag(it)) + continue + } + if is_bare_windows_import_lib(copt) { + libs << windows_import_lib_to_link_flag(copt) + continue + } libs << '"${copt}"' continue } @@ -172,6 +181,54 @@ pub fn (cflags []CFlag) defines_others_libs() ([]string, []string, []string) { return uniq_non_empty(defines), uniq_non_empty(others), uniq_non_empty(libs) } +fn split_bare_windows_import_libs(value string) []string { + parts := split_quoted_flags(value) + if parts.len < 2 { + return []string{} + } + for part in parts { + if !is_bare_windows_import_lib(part) { + return []string{} + } + } + return parts +} + +fn is_bare_windows_import_lib(value string) bool { + lib := value.trim_space() + return lib.len > '.lib'.len && lib.to_lower().ends_with('.lib') && !lib.contains('/') + && !lib.contains('\\') && !lib.contains(':') && !lib.contains(' ') && !lib.contains('\t') +} + +fn windows_import_lib_to_link_flag(value string) string { + lib := value.trim_space() + return '-l${lib[..lib.len - '.lib'.len]}' +} + +fn split_quoted_flags(value string) []string { + mut parts := []string{} + mut buf := []u8{} + mut in_quote := false + for ch in value { + if ch == `"` { + in_quote = !in_quote + continue + } + if !in_quote && ch in [` `, `\t`] { + if buf.len > 0 { + parts << buf.bytestr() + buf = []u8{} + } + continue + } + buf << ch + } + if buf.len > 0 { + parts << buf.bytestr() + } + return parts +} + fn uniq_non_empty(args []string) []string { mut uniq_args := []string{} for a in args { diff --git a/vlib/v/cflag/cflags_test.v b/vlib/v/cflag/cflags_test.v index e6d03fb42..4d680fba5 100644 --- a/vlib/v/cflag/cflags_test.v +++ b/vlib/v/cflag/cflags_test.v @@ -20,3 +20,22 @@ fn test_format_keeps_include_and_library_paths_with_spaces_in_one_argument() { value: library_dir }.format() or { panic(err) } == '-L"${os.real_path(library_dir)}"' } + +fn test_defines_others_libs_splits_bare_windows_import_lib_names() { + _, _, libs := [ + CFlag{ + value: 'Version.lib Advapi32.lib Shell32.lib' + }, + ].defines_others_libs() + assert libs == ['-lVersion', '-lAdvapi32', '-lShell32'] +} + +fn test_defines_others_libs_keeps_direct_windows_import_lib_paths() { + direct_path := 'C:/Program Files/Windows Kits/10/Lib/Version.lib' + _, _, libs := [ + CFlag{ + value: direct_path + }, + ].defines_others_libs() + assert libs == ['"${direct_path}"'] +} -- 2.39.5