Filter tests using zig build?

I can do this

zig test --test-filter "foo" src/main.zig

but I can’t do this

zig build test --test-filter "foo"

Is there a way with zig build to filter tests?

I don’t have a direct answer for you unfortunately, but as an indirect one, all that build.zig does is call into test, so it either offers a way to wire that flag to the build CLI, or it’s a missing feature that can be implemented without too much fuss.