From aff3e683e274808c7344fdeae1acad6be8a21462 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Tue, 14 Apr 2026 12:45:34 +0300 Subject: [PATCH] checker: Cross compiling for windows on Linux Mint, openssh issue (fixes #13978) --- vlib/v/checker/checker.v | 7 +-- vlib/v/checker/pkgconfig_cross_compile_test.v | 43 +++++++++++++++++++ 2 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 vlib/v/checker/pkgconfig_cross_compile_test.v diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 54bb11f12..aec42c2e4 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -4075,9 +4075,10 @@ fn (mut c Checker) hash_stmt(mut node ast.HashStmt) { } } 'pkgconfig' { - if c.pref.output_cross_c { - // do not add any flags, since we do not know what the target platform is for the cross platform builds - // and it is better to be as conservative as possible + if c.pref.output_cross_c || c.pref.os != pref.get_host_os() { + // Do not add host pkg-config flags to cross-target builds. + // They frequently inject include/library paths for the host OS + // (for example Linux OpenSSL headers when targeting Windows). return } args := if node.main.contains('--') { diff --git a/vlib/v/checker/pkgconfig_cross_compile_test.v b/vlib/v/checker/pkgconfig_cross_compile_test.v new file mode 100644 index 000000000..58bb213bc --- /dev/null +++ b/vlib/v/checker/pkgconfig_cross_compile_test.v @@ -0,0 +1,43 @@ +module checker + +import os +import v.ast +import v.parser +import v.pref + +const pkgconfig_test_source = 'module main +#pkgconfig --cflags --libs sdl2 + +fn main() {} +' + +fn test_pkgconfig_is_skipped_for_cross_compilation() { + sample_dir := os.join_path(@VEXEROOT, 'vlib', 'v', 'pkgconfig', 'test_samples') + old_path := os.getenv('PKG_CONFIG_PATH') + old_defaults := os.getenv('PKG_CONFIG_PATH_DEFAULTS') + defer { + os.setenv('PKG_CONFIG_PATH', old_path, true) + os.setenv('PKG_CONFIG_PATH_DEFAULTS', old_defaults, true) + } + os.setenv('PKG_CONFIG_PATH', sample_dir, true) + os.setenv('PKG_CONFIG_PATH_DEFAULTS', '', true) + + native_flags := checked_pkgconfig_flags(pref.get_host_os()) + assert native_flags.any(it == '-lSDL2') + assert native_flags.any(it.starts_with('-I') && it.contains('SDL2')) + + cross_target := if pref.get_host_os() == .windows { pref.OS.linux } else { pref.OS.windows } + cross_flags := checked_pkgconfig_flags(cross_target) + assert cross_flags.len == 0 +} + +fn checked_pkgconfig_flags(target_os pref.OS) []string { + mut table := ast.new_table() + mut pref_ := pref.new_preferences() + pref_.os = target_os + mut file := parser.parse_text(pkgconfig_test_source, os.join_path('/virtual', 'main.v'), mut + table, .skip_comments, pref_) + mut chk := new_checker(table, pref_) + chk.check(mut file) + return table.cflags.map(it.format() or { '' }).filter(it != '') +} -- 2.39.5