Skip to content

Commit 5bf9dc3

Browse files
authored
Merge pull request #21157 from mlugg/kill-cimport
`std.Build.Step.TranslateC` fixes
2 parents 7bbbbf8 + a0b03d7 commit 5bf9dc3

File tree

2 files changed

+36
-16
lines changed

2 files changed

+36
-16
lines changed

lib/std/Build/Step/TranslateC.zig

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub const Options = struct {
2929
pub fn create(owner: *std.Build, options: Options) *TranslateC {
3030
const translate_c = owner.allocator.create(TranslateC) catch @panic("OOM");
3131
const source = options.root_source_file.dupe(owner);
32-
translate_c.* = TranslateC{
32+
translate_c.* = .{
3333
.step = Step.init(.{
3434
.id = base_id,
3535
.name = "translate-c",
@@ -42,7 +42,7 @@ pub fn create(owner: *std.Build, options: Options) *TranslateC {
4242
.out_basename = undefined,
4343
.target = options.target,
4444
.optimize = options.optimize,
45-
.output_file = std.Build.GeneratedFile{ .step = &translate_c.step },
45+
.output_file = .{ .step = &translate_c.step },
4646
.link_libc = options.link_libc,
4747
.use_clang = options.use_clang,
4848
};
@@ -89,6 +89,9 @@ pub fn addModule(translate_c: *TranslateC, name: []const u8) *std.Build.Module {
8989
pub fn createModule(translate_c: *TranslateC) *std.Build.Module {
9090
return translate_c.step.owner.createModule(.{
9191
.root_source_file = translate_c.getOutput(),
92+
.target = translate_c.target,
93+
.optimize = translate_c.optimize,
94+
.link_libc = translate_c.link_libc,
9295
});
9396
}
9497

src/main.zig

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4526,7 +4526,12 @@ fn cmdTranslateC(
45264526
Compilation.dump_argv(argv.items);
45274527
}
45284528

4529-
const formatted = switch (comp.config.c_frontend) {
4529+
const Result = union(enum) {
4530+
success: []const u8,
4531+
error_bundle: std.zig.ErrorBundle,
4532+
};
4533+
4534+
const result: Result = switch (comp.config.c_frontend) {
45304535
.aro => f: {
45314536
var stdout: []u8 = undefined;
45324537
try jitCmd(comp.gpa, arena, argv.items, .{
@@ -4536,7 +4541,7 @@ fn cmdTranslateC(
45364541
.capture = &stdout,
45374542
.progress_node = prog_node,
45384543
});
4539-
break :f stdout;
4544+
break :f .{ .success = stdout };
45404545
},
45414546
.clang => f: {
45424547
if (!build_options.have_llvm) unreachable;
@@ -4564,31 +4569,43 @@ fn cmdTranslateC(
45644569
c_headers_dir_path_z,
45654570
) catch |err| switch (err) {
45664571
error.OutOfMemory => return error.OutOfMemory,
4567-
error.SemanticAnalyzeFail => {
4568-
if (fancy_output) |p| {
4569-
p.errors = errors;
4570-
return;
4571-
} else {
4572-
errors.renderToStdErr(color.renderOptions());
4573-
process.exit(1);
4574-
}
4575-
},
4572+
error.SemanticAnalyzeFail => break :f .{ .error_bundle = errors },
45764573
};
45774574
defer tree.deinit(comp.gpa);
4578-
break :f try tree.render(arena);
4575+
break :f .{ .success = try tree.render(arena) };
45794576
},
45804577
};
45814578

4582-
if (out_dep_path) |dep_file_path| {
4579+
if (out_dep_path) |dep_file_path| add_deps: {
45834580
const dep_basename = fs.path.basename(dep_file_path);
45844581
// Add the files depended on to the cache system.
4585-
try man.addDepFilePost(zig_cache_tmp_dir, dep_basename);
4582+
man.addDepFilePost(zig_cache_tmp_dir, dep_basename) catch |err| switch (err) {
4583+
error.FileNotFound => {
4584+
// Clang didn't emit the dep file; nothing to add to the manifest.
4585+
break :add_deps;
4586+
},
4587+
else => |e| return e,
4588+
};
45864589
// Just to save disk space, we delete the file because it is never needed again.
45874590
zig_cache_tmp_dir.deleteFile(dep_basename) catch |err| {
45884591
warn("failed to delete '{s}': {s}", .{ dep_file_path, @errorName(err) });
45894592
};
45904593
}
45914594

4595+
const formatted = switch (result) {
4596+
.success => |formatted| formatted,
4597+
.error_bundle => |eb| {
4598+
if (file_system_inputs) |buf| try man.populateFileSystemInputs(buf);
4599+
if (fancy_output) |p| {
4600+
p.errors = eb;
4601+
return;
4602+
} else {
4603+
eb.renderToStdErr(color.renderOptions());
4604+
process.exit(1);
4605+
}
4606+
},
4607+
};
4608+
45924609
const bin_digest = man.finalBin();
45934610
const hex_digest = Cache.binToHex(bin_digest);
45944611

0 commit comments

Comments
 (0)