commit 5bf9dc3850117c85fb124cc481d4a284e2c8504d (tree)
parent 7bbbbf8ffa3fa9be085cef8e8237cd94ce342483
Author: Matthew Lugg <mlugg@mlugg.co.uk>
Date: Wed, 21 Aug 2024 22:16:56 +0100
Merge pull request #21157 from mlugg/kill-cimport
`std.Build.Step.TranslateC` fixes
Diffstat:
2 files changed, 36 insertions(+), 16 deletions(-)
diff --git a/lib/std/Build/Step/TranslateC.zig b/lib/std/Build/Step/TranslateC.zig
@@ -29,7 +29,7 @@ pub const Options = struct {
pub fn create(owner: *std.Build, options: Options) *TranslateC {
const translate_c = owner.allocator.create(TranslateC) catch @panic("OOM");
const source = options.root_source_file.dupe(owner);
- translate_c.* = TranslateC{
+ translate_c.* = .{
.step = Step.init(.{
.id = base_id,
.name = "translate-c",
@@ -42,7 +42,7 @@ pub fn create(owner: *std.Build, options: Options) *TranslateC {
.out_basename = undefined,
.target = options.target,
.optimize = options.optimize,
- .output_file = std.Build.GeneratedFile{ .step = &translate_c.step },
+ .output_file = .{ .step = &translate_c.step },
.link_libc = options.link_libc,
.use_clang = options.use_clang,
};
@@ -89,6 +89,9 @@ pub fn addModule(translate_c: *TranslateC, name: []const u8) *std.Build.Module {
pub fn createModule(translate_c: *TranslateC) *std.Build.Module {
return translate_c.step.owner.createModule(.{
.root_source_file = translate_c.getOutput(),
+ .target = translate_c.target,
+ .optimize = translate_c.optimize,
+ .link_libc = translate_c.link_libc,
});
}
diff --git a/src/main.zig b/src/main.zig
@@ -4526,7 +4526,12 @@ fn cmdTranslateC(
Compilation.dump_argv(argv.items);
}
- const formatted = switch (comp.config.c_frontend) {
+ const Result = union(enum) {
+ success: []const u8,
+ error_bundle: std.zig.ErrorBundle,
+ };
+
+ const result: Result = switch (comp.config.c_frontend) {
.aro => f: {
var stdout: []u8 = undefined;
try jitCmd(comp.gpa, arena, argv.items, .{
@@ -4536,7 +4541,7 @@ fn cmdTranslateC(
.capture = &stdout,
.progress_node = prog_node,
});
- break :f stdout;
+ break :f .{ .success = stdout };
},
.clang => f: {
if (!build_options.have_llvm) unreachable;
@@ -4564,31 +4569,43 @@ fn cmdTranslateC(
c_headers_dir_path_z,
) catch |err| switch (err) {
error.OutOfMemory => return error.OutOfMemory,
- error.SemanticAnalyzeFail => {
- if (fancy_output) |p| {
- p.errors = errors;
- return;
- } else {
- errors.renderToStdErr(color.renderOptions());
- process.exit(1);
- }
- },
+ error.SemanticAnalyzeFail => break :f .{ .error_bundle = errors },
};
defer tree.deinit(comp.gpa);
- break :f try tree.render(arena);
+ break :f .{ .success = try tree.render(arena) };
},
};
- if (out_dep_path) |dep_file_path| {
+ if (out_dep_path) |dep_file_path| add_deps: {
const dep_basename = fs.path.basename(dep_file_path);
// Add the files depended on to the cache system.
- try man.addDepFilePost(zig_cache_tmp_dir, dep_basename);
+ man.addDepFilePost(zig_cache_tmp_dir, dep_basename) catch |err| switch (err) {
+ error.FileNotFound => {
+ // Clang didn't emit the dep file; nothing to add to the manifest.
+ break :add_deps;
+ },
+ else => |e| return e,
+ };
// Just to save disk space, we delete the file because it is never needed again.
zig_cache_tmp_dir.deleteFile(dep_basename) catch |err| {
warn("failed to delete '{s}': {s}", .{ dep_file_path, @errorName(err) });
};
}
+ const formatted = switch (result) {
+ .success => |formatted| formatted,
+ .error_bundle => |eb| {
+ if (file_system_inputs) |buf| try man.populateFileSystemInputs(buf);
+ if (fancy_output) |p| {
+ p.errors = eb;
+ return;
+ } else {
+ eb.renderToStdErr(color.renderOptions());
+ process.exit(1);
+ }
+ },
+ };
+
const bin_digest = man.finalBin();
const hex_digest = Cache.binToHex(bin_digest);