commit e9f344dcd43dd2a725ab728b962d7627d6462d02 (tree)
parent 3b4e29f1ad690d4437aa4d0cb1c7f01c26b76c4a
Author: Noam Preil <pleasantatk@gmail.com>
Date: Sun, 17 May 2020 05:58:39 -0400
Add include dirs to translate-c (close #5098)
Diffstat:
1 file changed, 11 insertions(+), 0 deletions(-)
diff --git a/lib/std/build/translate_c.zig b/lib/std/build/translate_c.zig
@@ -13,6 +13,7 @@ pub const TranslateCStep = struct {
step: Step,
builder: *Builder,
source: build.FileSource,
+ include_dirs: std.ArrayList([]const u8),
output_dir: ?[]const u8,
out_basename: []const u8,
target: CrossTarget = CrossTarget{},
@@ -23,6 +24,7 @@ pub const TranslateCStep = struct {
.step = Step.init(.TranslateC, "translate-c", builder.allocator, make),
.builder = builder,
.source = source,
+ .include_dirs = std.ArrayList([]const u8).init(builder.allocator),
.output_dir = null,
.out_basename = undefined,
};
@@ -49,6 +51,10 @@ pub const TranslateCStep = struct {
return self.builder.addExecutableSource("translated_c", @as(build.FileSource, .{ .translate_c = self }));
}
+ pub fn addIncludeDir(self: *TranslateCStep, include_dir: []const u8) void {
+ self.include_dirs.append(include_dir) catch unreachable;
+ }
+
pub fn addCheckFile(self: *TranslateCStep, expected_matches: []const []const u8) *CheckFileStep {
return CheckFileStep.create(self.builder, .{ .translate_c = self }, expected_matches);
}
@@ -69,6 +75,11 @@ pub const TranslateCStep = struct {
try argv_list.append(try self.target.zigTriple(self.builder.allocator));
}
+ for (self.include_dirs.items) |include_dir| {
+ try argv_list.append("-I");
+ try argv_list.append(include_dir);
+ }
+
try argv_list.append(self.source.getPath(self.builder));
const output_path_nl = try self.builder.execFromStep(argv_list.span(), &self.step);