From 1645327551e7058659cd767269aea6053546c95d Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Wed, 15 Apr 2026 14:59:52 +0300 Subject: [PATCH] cgen: fix local headers not found (fixes #14706) --- vlib/v/gen/c/cgen.v | 25 ++++++++++++++++++- .../project_with_c_code_2/modc/wrapper.c.v | 1 - 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 0727e3f3e..dc73383c9 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -8260,10 +8260,33 @@ fn matching_generated_shader_source(node ast.HashStmt) ?string { return shader_source } +fn resolved_existing_local_include_path(node ast.HashStmt) ?string { + if !node.main.starts_with('"') || !node.main.ends_with('"') { + return none + } + header_path := node.main.trim('"') + if os.is_abs_path(header_path) { + return none + } + resolved_header_path := os.join_path(os.dir(node.source_file), header_path) + if !os.is_file(resolved_header_path) { + return none + } + return os.real_path(resolved_header_path).replace('\\', '/') +} + +fn include_path_for_generated_c(node ast.HashStmt) string { + if resolved_header_path := resolved_existing_local_include_path(node) { + return '"${resolved_header_path}"' + } + return node.main +} + fn (mut g Gen) hash_stmt_guarded_include(node ast.HashStmt) string { mut missing_message := 'Header file ${node.main}, needed for module `${node.mod}` was not found.' missing_message += ' ${missing_shader_header_message(node)}' - mut guarded_include := get_guarded_include_text(node.main, missing_message) + mut guarded_include := get_guarded_include_text(include_path_for_generated_c(node), + missing_message) if node.main == '' { // fails with musl-gcc and msvc; but an unguarded include works: guarded_include = '#include ${node.main}' diff --git a/vlib/v/tests/project_with_c_code_2/modc/wrapper.c.v b/vlib/v/tests/project_with_c_code_2/modc/wrapper.c.v index 465d4cb45..903a03136 100644 --- a/vlib/v/tests/project_with_c_code_2/modc/wrapper.c.v +++ b/vlib/v/tests/project_with_c_code_2/modc/wrapper.c.v @@ -1,6 +1,5 @@ module modc -#flag -I @VMODROOT/modc #flag @VMODROOT/modc/impl.o #include "header.h" -- 2.39.5