Skip to content

Translator: add depfile generation #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

.fingerprint = 0x1c84f6455a54f043, // Changing this has security and trust implications.

.minimum_zig_version = "0.15.0-dev.1145+3ae0ba096",
.minimum_zig_version = "0.15.0-dev.1262+e12dc4947",

.dependencies = .{
.aro = .{
.url = "git+https://github.com/Vexu/arocc#e9ea4aabfd39cd5e5f7b69bd9c85b878ea0c6f43",
.hash = "aro-0.0.0-JSD1QmmYJwCdKUjcL-Ltj5xDC6AjprNc79REvndGfAKE",
.url = "git+https://github.com/Vexu/arocc#d0ebb5915074348fc7c8494415efaa569537ba2b",
.hash = "aro-0.0.0-JSD1QreaJwAaUgJOp3h4ZfiTG_gDocaYVqGEefWihgOQ",
},
},

Expand Down
4 changes: 3 additions & 1 deletion build/Translator.zig
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,14 @@ pub fn initInner(
// Try our best to get a reasonable name; we need one to name the steps and the output file.
const name = options.name orelse std.fs.path.stem(options.c_source_file.getDisplayName());

// We start with the basic command: 'path/to/translate-c in.c -o out.zig'
// We start with the basic command: 'path/to/translate-c in.c -o out.zig -MD -MV -MF deps.d'
const run = b.addRunArtifact(tc_conf.exe);
run.setName(b.fmt("translate-c {s}", .{name}));
run.addFileArg(options.c_source_file);
run.addArg("-o");
const output_file = run.addOutputFileArg(b.fmt("{s}.zig", .{name}));
run.addArgs(&.{ "-MD", "-MV", "-MF" });
_ = run.addDepFileOutputArg("deps.d");
// Now we are free to add extra args to `run` as needed.

const mod = b.createModule(.{
Expand Down
2 changes: 1 addition & 1 deletion src/Translator.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3883,7 +3883,7 @@ fn createNumberNode(t: *Translator, num: anytype, num_kind: enum { int, float })

fn createCharLiteralNode(t: *Translator, narrow: bool, val: u32) TransError!ZigNode {
return ZigTag.char_literal.create(t.arena, if (narrow)
try std.fmt.allocPrint(t.arena, "'{f}'", .{std.zig.fmtChar(&.{@as(u8, @intCast(val))})})
try std.fmt.allocPrint(t.arena, "'{f}'", .{std.zig.fmtChar(@as(u8, @intCast(val)))})
else
try std.fmt.allocPrint(t.arena, "'\\u{{{x}}}'", .{val}));
}
Expand Down
Loading