| ... | @@ -16,6 +16,7 @@ step: Step, | ... | @@ -16,6 +16,7 @@ step: Step, |
| 16 | builder: *Builder, | 16 | builder: *Builder, |
| 17 | source: build.FileSource, | 17 | source: build.FileSource, |
| 18 | include_dirs: std.ArrayList([]const u8), | 18 | include_dirs: std.ArrayList([]const u8), |
| | 19 | c_macros: std.ArrayList([]const u8), |
| 19 | output_dir: ?[]const u8, | 20 | output_dir: ?[]const u8, |
| 20 | out_basename: []const u8, | 21 | out_basename: []const u8, |
| 21 | target: CrossTarget = CrossTarget{}, | 22 | target: CrossTarget = CrossTarget{}, |
| ... | @@ -28,6 +29,7 @@ pub fn create(builder: *Builder, source: build.FileSource) *TranslateCStep { | ... | @@ -28,6 +29,7 @@ pub fn create(builder: *Builder, source: build.FileSource) *TranslateCStep { |
| 28 | .builder = builder, | 29 | .builder = builder, |
| 29 | .source = source, | 30 | .source = source, |
| 30 | .include_dirs = std.ArrayList([]const u8).init(builder.allocator), | 31 | .include_dirs = std.ArrayList([]const u8).init(builder.allocator), |
| | 32 | .c_macros = std.ArrayList([]const u8).init(builder.allocator), |
| 31 | .output_dir = null, | 33 | .output_dir = null, |
| 32 | .out_basename = undefined, | 34 | .out_basename = undefined, |
| 33 | .output_file = build.GeneratedFile{ .step = &self.step }, | 35 | .output_file = build.GeneratedFile{ .step = &self.step }, |
| ... | @@ -53,6 +55,18 @@ pub fn addCheckFile(self: *TranslateCStep, expected_matches: []const []const u8) | ... | @@ -53,6 +55,18 @@ pub fn addCheckFile(self: *TranslateCStep, expected_matches: []const []const u8) |
| 53 | return CheckFileStep.create(self.builder, .{ .generated = &self.output_file }, self.builder.dupeStrings(expected_matches)); | 55 | return CheckFileStep.create(self.builder, .{ .generated = &self.output_file }, self.builder.dupeStrings(expected_matches)); |
| 54 | } | 56 | } |
| 55 | | 57 | |
| | 58 | /// If the value is omitted, it is set to 1. |
| | 59 | /// `name` and `value` need not live longer than the function call. |
| | 60 | pub fn defineCMacro(self: *TranslateCStep, name: []const u8, value: ?[]const u8) void { |
| | 61 | const macro = build.constructCMacro(self.builder.allocator, name, value); |
| | 62 | self.c_macros.append(macro) catch unreachable; |
| | 63 | } |
| | 64 | |
| | 65 | /// name_and_value looks like [name]=[value]. If the value is omitted, it is set to 1. |
| | 66 | pub fn defineCMacroRaw(self: *TranslateCStep, name_and_value: []const u8) void { |
| | 67 | self.c_macros.append(self.builder.dupe(name_and_value)) catch unreachable; |
| | 68 | } |
| | 69 | |
| 56 | fn make(step: *Step) !void { | 70 | fn make(step: *Step) !void { |
| 57 | const self = @fieldParentPtr(TranslateCStep, "step", step); | 71 | const self = @fieldParentPtr(TranslateCStep, "step", step); |
| 58 | | 72 | |
| ... | @@ -73,6 +87,11 @@ fn make(step: *Step) !void { | ... | @@ -73,6 +87,11 @@ fn make(step: *Step) !void { |
| 73 | try argv_list.append(include_dir); | 87 | try argv_list.append(include_dir); |
| 74 | } | 88 | } |
| 75 | | 89 | |
| | 90 | for (self.c_macros.items) |c_macro| { |
| | 91 | try argv_list.append("-D"); |
| | 92 | try argv_list.append(c_macro); |
| | 93 | } |
| | 94 | |
| 76 | try argv_list.append(self.source.getPath(self.builder)); | 95 | try argv_list.append(self.source.getPath(self.builder)); |
| 77 | | 96 | |
| 78 | const output_path_nl = try self.builder.execFromStep(argv_list.items, &self.step); | 97 | const output_path_nl = try self.builder.execFromStep(argv_list.items, &self.step); |