diff --git a/src/imports.zig b/src/imports.zig index 1c1761e..25c909b 100644 --- a/src/imports.zig +++ b/src/imports.zig @@ -200,27 +200,29 @@ pub fn resolveImports( for (root.data.root.decls) |decl| { if (decl.data == .c_import_decl) { - const ci = decl.data.c_import_decl; - // Resolve `#source` / `#include` paths through the same chain // as `#import`: importing-file's directory → CWD → stdlib // search paths. This lets sx-library modules ship their own // C helpers (e.g. the Android JNI insets bridge) without // forcing every consumer to vendor an identically-named copy. - if (ci.sources.len > 0) { - var resolved = try allocator.alloc([]const u8, ci.sources.len); - for (ci.sources, 0..) |raw_src, idx| { - resolved[idx] = try resolveImportPath(allocator, io, base_dir, raw_src, null, stdlib_paths); + { + const ci_pre = decl.data.c_import_decl; + if (ci_pre.sources.len > 0) { + var resolved = try allocator.alloc([]const u8, ci_pre.sources.len); + for (ci_pre.sources, 0..) |raw_src, idx| { + resolved[idx] = try resolveImportPath(allocator, io, base_dir, raw_src, null, stdlib_paths); + } + decl.data.c_import_decl.sources = resolved; } - decl.data.c_import_decl.sources = resolved; - } - if (ci.includes.len > 0) { - var resolved = try allocator.alloc([]const u8, ci.includes.len); - for (ci.includes, 0..) |raw_inc, idx| { - resolved[idx] = try resolveImportPath(allocator, io, base_dir, raw_inc, null, stdlib_paths); + if (ci_pre.includes.len > 0) { + var resolved = try allocator.alloc([]const u8, ci_pre.includes.len); + for (ci_pre.includes, 0..) |raw_inc, idx| { + resolved[idx] = try resolveImportPath(allocator, io, base_dir, raw_inc, null, stdlib_paths); + } + decl.data.c_import_decl.includes = resolved; } - decl.data.c_import_decl.includes = resolved; } + const ci = decl.data.c_import_decl; // Parse headers to get synthetic function declarations const result = c_import.processCImport(