C Header file not found

So I think this may be something weird on my system, but zig is unable to find C header files when I try to build.

I’m using zig 0.13 on a Mac (Arm), which was installed with brew.

Directory structure:

include /
    foo.h
src /
   foo.c
   main.zig
build.zig

I’ve added to the build.zig file the following:

    lib.addCSourceFiles(.{ .files = &[_][]const u8{"src/foo.c"} });
    exe.addIncludePath(b.path("include"));
    lib.linkLibC();

And my main.zig file looks like this:

const std = @import("std");
const c = @cImport({
    @cInclude("foo.h");
});

pub fn main() !void {
    const x = 5;
    const y = 3;
    const sum = c.foo_add(x, y);
    std.debug.print("the sum of x and y is: {d}\n", .{sum});
}

and I get the lovely error message when I do zig build:

install
└─ install bartok
   └─ zig build-lib bartok Debug native 1 errors
/Users/cianoconnor/bartok/src/foo.c:1:10: error: 'foo.h' file not found
#include "foo.h"
         ^~~~~~~~
error: warning(compilation): failed to delete '/Users/cianoconnor/bartok/.zig-cache/tmp/c16353757d2f0c38-foo.o.d': FileNotFound

error: the following command failed with 1 compilation errors:
/opt/homebrew/Cellar/zig/0.13.0/bin/zig build-lib /Users/cianoconnor/bartok/src/foo.c -ODebug -Mroot=/Users/cianoconnor/bartok/src/root.zig -lc --cache-dir /Users/cianoconnor/bartok/.zig-cache --global-cache-dir /Users/cianoconnor/.cache/zig --name bartok -static --listen=-
install
└─ install bartok
   └─ zig build-exe bartok Debug native 1 errors
error: undefined symbol: _foo_add
    note: referenced by /Users/cianoconnor/bartok/.zig-cache/o/23808cca3b67de4a6dc3672cc8478035/bartok.o:_main.main
error: the following command failed with 1 compilation errors:
/opt/homebrew/Cellar/zig/0.13.0/bin/zig build-exe -ODebug -I /Users/cianoconnor/bartok/include -Mroot=/Users/cianoconnor/bartok/src/main.zig --cache-dir /Users/cianoconnor/bartok/.zig-cache --global-cache-dir /Users/cianoconnor/.cache/zig --name bartok --listen=-
Build Summary: 0/5 steps succeeded; 2 failed (disable with --summary none)
install transitive failure
├─ install bartok transitive failure
│  └─ zig build-lib bartok Debug native 1 errors
└─ install bartok transitive failure
   └─ zig build-exe bartok Debug native 1 errors
error: the following build command failed with exit code 1:

I figure I’m doing something stupid, but I cannot for the life of me work out what.

Could you try this?

- lib.addCSourceFiles(.{ .files = &[_][]const u8{"src/foo.c"} });
+ exe.addCSourceFiles(.{ .files = &[_][]const u8{"src/foo.c"} });
exe.addIncludePath(b.path("include"));
- lib.linkLibC();
+ exe.linkLibC();

Thank you!