authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-08-21 22:16:56+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-08-21 22:16:56+01:00
log5bf9dc3850117c85fb124cc481d4a284e2c8504d
tree9a25388910f75228d1ccec53da19a1ef803c8115
parent7bbbbf8ffa3fa9be085cef8e8237cd94ce342483
parenta0b03d7ffffdf89b14ad6f1d5cd6537935996338
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #21157 from mlugg/kill-cimport

`std.Build.Step.TranslateC` fixes

2 files changed, 36 insertions(+), 16 deletions(-)

lib/std/Build/Step/TranslateC.zig+5-2
...@@ -29,7 +29,7 @@ pub const Options = struct {...@@ -29,7 +29,7 @@ pub const Options = struct {
29pub fn create(owner: *std.Build, options: Options) *TranslateC {29pub fn create(owner: *std.Build, options: Options) *TranslateC {
30 const translate_c = owner.allocator.create(TranslateC) catch @panic("OOM");30 const translate_c = owner.allocator.create(TranslateC) catch @panic("OOM");
31 const source = options.root_source_file.dupe(owner);31 const source = options.root_source_file.dupe(owner);
32 translate_c.* = TranslateC{32 translate_c.* = .{
33 .step = Step.init(.{33 .step = Step.init(.{
34 .id = base_id,34 .id = base_id,
35 .name = "translate-c",35 .name = "translate-c",
...@@ -42,7 +42,7 @@ pub fn create(owner: *std.Build, options: Options) *TranslateC {...@@ -42,7 +42,7 @@ pub fn create(owner: *std.Build, options: Options) *TranslateC {
42 .out_basename = undefined,42 .out_basename = undefined,
43 .target = options.target,43 .target = options.target,
44 .optimize = options.optimize,44 .optimize = options.optimize,
45 .output_file = std.Build.GeneratedFile{ .step = &translate_c.step },45 .output_file = .{ .step = &translate_c.step },
46 .link_libc = options.link_libc,46 .link_libc = options.link_libc,
47 .use_clang = options.use_clang,47 .use_clang = options.use_clang,
48 };48 };
...@@ -89,6 +89,9 @@ pub fn addModule(translate_c: *TranslateC, name: []const u8) *std.Build.Module {...@@ -89,6 +89,9 @@ pub fn addModule(translate_c: *TranslateC, name: []const u8) *std.Build.Module {
89pub fn createModule(translate_c: *TranslateC) *std.Build.Module {89pub fn createModule(translate_c: *TranslateC) *std.Build.Module {
90 return translate_c.step.owner.createModule(.{90 return translate_c.step.owner.createModule(.{
91 .root_source_file = translate_c.getOutput(),91 .root_source_file = translate_c.getOutput(),
92 .target = translate_c.target,
93 .optimize = translate_c.optimize,
94 .link_libc = translate_c.link_libc,
92 });95 });
93}96}
9497
src/main.zig+31-14
...@@ -4526,7 +4526,12 @@ fn cmdTranslateC(...@@ -4526,7 +4526,12 @@ fn cmdTranslateC(
4526 Compilation.dump_argv(argv.items);4526 Compilation.dump_argv(argv.items);
4527 }4527 }
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) {
4530 .aro => f: {4535 .aro => f: {
4531 var stdout: []u8 = undefined;4536 var stdout: []u8 = undefined;
4532 try jitCmd(comp.gpa, arena, argv.items, .{4537 try jitCmd(comp.gpa, arena, argv.items, .{
...@@ -4536,7 +4541,7 @@ fn cmdTranslateC(...@@ -4536,7 +4541,7 @@ fn cmdTranslateC(
4536 .capture = &stdout,4541 .capture = &stdout,
4537 .progress_node = prog_node,4542 .progress_node = prog_node,
4538 });4543 });
4539 break :f stdout;4544 break :f .{ .success = stdout };
4540 },4545 },
4541 .clang => f: {4546 .clang => f: {
4542 if (!build_options.have_llvm) unreachable;4547 if (!build_options.have_llvm) unreachable;
...@@ -4564,31 +4569,43 @@ fn cmdTranslateC(...@@ -4564,31 +4569,43 @@ fn cmdTranslateC(
4564 c_headers_dir_path_z,4569 c_headers_dir_path_z,
4565 ) catch |err| switch (err) {4570 ) catch |err| switch (err) {
4566 error.OutOfMemory => return error.OutOfMemory,4571 error.OutOfMemory => return error.OutOfMemory,
4567 error.SemanticAnalyzeFail => {4572 error.SemanticAnalyzeFail => break :f .{ .error_bundle = errors },
4568 if (fancy_output) |p| {
4569 p.errors = errors;
4570 return;
4571 } else {
4572 errors.renderToStdErr(color.renderOptions());
4573 process.exit(1);
4574 }
4575 },
4576 };4573 };
4577 defer tree.deinit(comp.gpa);4574 defer tree.deinit(comp.gpa);
4578 break :f try tree.render(arena);4575 break :f .{ .success = try tree.render(arena) };
4579 },4576 },
4580 };4577 };
45814578
4582 if (out_dep_path) |dep_file_path| {4579 if (out_dep_path) |dep_file_path| add_deps: {
4583 const dep_basename = fs.path.basename(dep_file_path);4580 const dep_basename = fs.path.basename(dep_file_path);
4584 // Add the files depended on to the cache system.4581 // 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 };
4586 // Just to save disk space, we delete the file because it is never needed again.4589 // Just to save disk space, we delete the file because it is never needed again.
4587 zig_cache_tmp_dir.deleteFile(dep_basename) catch |err| {4590 zig_cache_tmp_dir.deleteFile(dep_basename) catch |err| {
4588 warn("failed to delete '{s}': {s}", .{ dep_file_path, @errorName(err) });4591 warn("failed to delete '{s}': {s}", .{ dep_file_path, @errorName(err) });
4589 };4592 };
4590 }4593 }
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
4592 const bin_digest = man.finalBin();4609 const bin_digest = man.finalBin();
4593 const hex_digest = Cache.binToHex(bin_digest);4610 const hex_digest = Cache.binToHex(bin_digest);
45944611