authorgravatar for noam@pixelhero.devNoam Preil <noam@pixelhero.dev> 2020-05-17 05:58:39-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-05-29 13:39:16-04:00
loge9f344dcd43dd2a725ab728b962d7627d6462d02
tree709da1bd34507a848769e68397a941a3d265f7e7
parent3b4e29f1ad690d4437aa4d0cb1c7f01c26b76c4a

Add include dirs to translate-c (close #5098)


1 files changed, 11 insertions(+), 0 deletions(-)

lib/std/build/translate_c.zig+11
......@@ -13,6 +13,7 @@ pub const TranslateCStep = struct {
1313 step: Step,
1414 builder: *Builder,
1515 source: build.FileSource,
16 include_dirs: std.ArrayList([]const u8),
1617 output_dir: ?[]const u8,
1718 out_basename: []const u8,
1819 target: CrossTarget = CrossTarget{},
......@@ -23,6 +24,7 @@ pub const TranslateCStep = struct {
2324 .step = Step.init(.TranslateC, "translate-c", builder.allocator, make),
2425 .builder = builder,
2526 .source = source,
27 .include_dirs = std.ArrayList([]const u8).init(builder.allocator),
2628 .output_dir = null,
2729 .out_basename = undefined,
2830 };
......@@ -49,6 +51,10 @@ pub const TranslateCStep = struct {
4951 return self.builder.addExecutableSource("translated_c", @as(build.FileSource, .{ .translate_c = self }));
5052 }
5153
54 pub fn addIncludeDir(self: *TranslateCStep, include_dir: []const u8) void {
55 self.include_dirs.append(include_dir) catch unreachable;
56 }
57
5258 pub fn addCheckFile(self: *TranslateCStep, expected_matches: []const []const u8) *CheckFileStep {
5359 return CheckFileStep.create(self.builder, .{ .translate_c = self }, expected_matches);
5460 }
......@@ -69,6 +75,11 @@ pub const TranslateCStep = struct {
6975 try argv_list.append(try self.target.zigTriple(self.builder.allocator));
7076 }
7177
78 for (self.include_dirs.items) |include_dir| {
79 try argv_list.append("-I");
80 try argv_list.append(include_dir);
81 }
82
7283 try argv_list.append(self.source.getPath(self.builder));
7384
7485 const output_path_nl = try self.builder.execFromStep(argv_list.span(), &self.step);