Skip to content

Commit a7a9f7c

Browse files
feat(build): automate compile flags path insertion
1 parent 0f8c4de commit a7a9f7c

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

build.zig

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,24 @@ pub fn build(b: *STD.Build) !void {
7171
cflags.addIncludePath(b.path("src"));
7272
cflags.addIncludePath(DEP_GTEST.path("include"));
7373

74-
// TODO: automate libcc path
75-
// $ clang++ -E -x c++ - -v < /dev/null
76-
cflags.addIncludePath(.{ .cwd_relative = "/nix/store/a3c2pnnyycikxs9gnxgakvilajyxhyv2-lldb-19.1.7-dev/include" });
77-
cflags.addIncludePath(.{ .cwd_relative = "/nix/store/82kmz7r96navanrc2fgckh2bamiqrgsw-gcc-14.3.0/include" });
78-
cflags.addIncludePath(.{ .cwd_relative = "/nix/store/n7p5cdg3d55fr659qm8h0vynl3rcf26h-compiler-rt-libc-19.1.7-dev/include" });
79-
cflags.addIncludePath(.{ .cwd_relative = "/nix/store/82kmz7r96navanrc2fgckh2bamiqrgsw-gcc-14.3.0/include/c++/14.3.0" });
80-
cflags.addIncludePath(.{ .cwd_relative = "/nix/store/82kmz7r96navanrc2fgckh2bamiqrgsw-gcc-14.3.0/include/c++/14.3.0/x86_64-unknown-linux-gnu" });
81-
cflags.addIncludePath(.{ .cwd_relative = "/nix/store/fbfcll570w9vimfbh41f9b4rrwnp33f3-clang-wrapper-19.1.7/resource-root/include" });
82-
cflags.addIncludePath(.{ .cwd_relative = "/nix/store/gf3wh0x0rzb1dkx0wx1jvmipydwfzzd5-glibc-2.40-66-dev/include" });
74+
const CLANG_PLUS_PLUS = try STD.process.Child.run(.{ .allocator = b.allocator, .argv = &[_][]const u8{ "zig", "c++", "-E", "-x", "c++", "-", "-v" } });
75+
var clang_plus_plus_output = STD.mem.splitScalar(u8, CLANG_PLUS_PLUS.stderr, '\n');
76+
var start_capture = false;
77+
78+
while (clang_plus_plus_output.next()) |line| {
79+
if (STD.mem.startsWith(u8, line, "#include <...> search starts here:")) {
80+
start_capture = true;
81+
continue;
82+
}
83+
84+
if (STD.mem.startsWith(u8, line, "End of search list.")) {
85+
break;
86+
}
87+
88+
if (start_capture) {
89+
cflags.addIncludePath(.{ .cwd_relative = STD.mem.trim(u8, line, " ") });
90+
}
91+
}
8392

8493
const CFLAGS_STEP = b.step("compile-flags", "Generate compile_flags.txt for C/C++ IDE support");
8594
CFLAGS_STEP.dependOn(&cflags.step);

0 commit comments

Comments
 (0)