authorgravatar for lacc97@protonmail.chLuis Cáceres <lacc97@protonmail.ch> 2023-09-28 23:30:42+00:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-09-28 19:30:42-04:00
logacac685621fc427e4e962f9b54b7f822a3d00dd0
tree465d2bb87c4d463b45737c3698929eed22f5048f
parent8f2f12f94080ede762df4a5018249160eedc7f09
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

std.Build.ConfigHeader: override include guard option for blank style (#17310)

This commit adds an option to allow for overriding the default header guard that is generated from the output file path.

1 files changed, 15 insertions(+), 8 deletions(-)

lib/std/Build/Step/ConfigHeader.zig+15-8
......@@ -42,6 +42,7 @@ output_file: std.Build.GeneratedFile,
4242style: Style,
4343max_bytes: usize,
4444include_path: []const u8,
45include_guard_override: ?[]const u8,
4546
4647pub const base_id: Step.Id = .config_header;
4748
......@@ -50,6 +51,7 @@ pub const Options = struct {
5051 max_bytes: usize = 2 * 1024 * 1024,
5152 include_path: ?[]const u8 = null,
5253 first_ret_addr: ?usize = null,
54 include_guard_override: ?[]const u8 = null,
5355};
5456
5557pub fn create(owner: *std.Build, options: Options) *ConfigHeader {
......@@ -91,6 +93,7 @@ pub fn create(owner: *std.Build, options: Options) *ConfigHeader {
9193
9294 .max_bytes = options.max_bytes,
9395 .include_path = include_path,
96 .include_guard_override = options.include_guard_override,
9497 .output_file = .{ .step = &self.step },
9598 };
9699
......@@ -201,7 +204,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
201204 },
202205 .blank => {
203206 try output.appendSlice(c_generated_line);
204 try render_blank(&output, self.values, self.include_path);
207 try render_blank(&output, self.values, self.include_path, self.include_guard_override);
205208 },
206209 .nasm => {
207210 try output.appendSlice(asm_generated_line);
......@@ -415,15 +418,19 @@ fn render_blank(
415418 output: *std.ArrayList(u8),
416419 defines: std.StringArrayHashMap(Value),
417420 include_path: []const u8,
421 include_guard_override: ?[]const u8,
418422) !void {
419 const include_guard_name = try output.allocator.dupe(u8, include_path);
420 for (include_guard_name) |*byte| {
421 switch (byte.*) {
422 'a'...'z' => byte.* = byte.* - 'a' + 'A',
423 'A'...'Z', '0'...'9' => continue,
424 else => byte.* = '_',
423 const include_guard_name = include_guard_override orelse blk: {
424 const name = try output.allocator.dupe(u8, include_path);
425 for (name) |*byte| {
426 switch (byte.*) {
427 'a'...'z' => byte.* = byte.* - 'a' + 'A',
428 'A'...'Z', '0'...'9' => continue,
429 else => byte.* = '_',
430 }
425431 }
426 }
432 break :blk name;
433 };
427434
428435 try output.appendSlice("#ifndef ");
429436 try output.appendSlice(include_guard_name);