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 {...@@ -13,6 +13,7 @@ pub const TranslateCStep = struct {
13 step: Step,13 step: Step,
14 builder: *Builder,14 builder: *Builder,
15 source: build.FileSource,15 source: build.FileSource,
16 include_dirs: std.ArrayList([]const u8),
16 output_dir: ?[]const u8,17 output_dir: ?[]const u8,
17 out_basename: []const u8,18 out_basename: []const u8,
18 target: CrossTarget = CrossTarget{},19 target: CrossTarget = CrossTarget{},
...@@ -23,6 +24,7 @@ pub const TranslateCStep = struct {...@@ -23,6 +24,7 @@ pub const TranslateCStep = struct {
23 .step = Step.init(.TranslateC, "translate-c", builder.allocator, make),24 .step = Step.init(.TranslateC, "translate-c", builder.allocator, make),
24 .builder = builder,25 .builder = builder,
25 .source = source,26 .source = source,
27 .include_dirs = std.ArrayList([]const u8).init(builder.allocator),
26 .output_dir = null,28 .output_dir = null,
27 .out_basename = undefined,29 .out_basename = undefined,
28 };30 };
...@@ -49,6 +51,10 @@ pub const TranslateCStep = struct {...@@ -49,6 +51,10 @@ pub const TranslateCStep = struct {
49 return self.builder.addExecutableSource("translated_c", @as(build.FileSource, .{ .translate_c = self }));51 return self.builder.addExecutableSource("translated_c", @as(build.FileSource, .{ .translate_c = self }));
50 }52 }
5153
54 pub fn addIncludeDir(self: *TranslateCStep, include_dir: []const u8) void {
55 self.include_dirs.append(include_dir) catch unreachable;
56 }
57
52 pub fn addCheckFile(self: *TranslateCStep, expected_matches: []const []const u8) *CheckFileStep {58 pub fn addCheckFile(self: *TranslateCStep, expected_matches: []const []const u8) *CheckFileStep {
53 return CheckFileStep.create(self.builder, .{ .translate_c = self }, expected_matches);59 return CheckFileStep.create(self.builder, .{ .translate_c = self }, expected_matches);
54 }60 }
...@@ -69,6 +75,11 @@ pub const TranslateCStep = struct {...@@ -69,6 +75,11 @@ pub const TranslateCStep = struct {
69 try argv_list.append(try self.target.zigTriple(self.builder.allocator));75 try argv_list.append(try self.target.zigTriple(self.builder.allocator));
70 }76 }
7177
78 for (self.include_dirs.items) |include_dir| {
79 try argv_list.append("-I");
80 try argv_list.append(include_dir);
81 }
82
72 try argv_list.append(self.source.getPath(self.builder));83 try argv_list.append(self.source.getPath(self.builder));
7384
74 const output_path_nl = try self.builder.execFromStep(argv_list.span(), &self.step);85 const output_path_nl = try self.builder.execFromStep(argv_list.span(), &self.step);