Skip to content

Commit

Permalink
Target: Add objFileExt() convenience wrapper
Browse files Browse the repository at this point in the history
Added the `objFileExt()` function to Target, streamlining access to target-specific data in a manner consistent with other convenience functions.
  • Loading branch information
Doekin committed Jan 6, 2025
1 parent c50926a commit 9bd0a5d
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/compiler/aro/aro/Driver.zig
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ fn processSource(
const fmt_template = "{s}{s}";
const fmt_args = .{
std.fs.path.stem(source.path),
d.comp.target.ofmt.fileExt(d.comp.target.abi, d.comp.target.cpu.arch),
d.comp.target.objFileExt(),
};
break :blk d.output_name orelse
std.fmt.bufPrint(&name_buf, fmt_template, fmt_args) catch return d.fatal("Filename too long for filesystem: " ++ fmt_template, fmt_args);
Expand All @@ -781,7 +781,7 @@ fn processSource(
const fmt_template = "/tmp/{s}{s}";
const fmt_args = .{
random_name,
d.comp.target.ofmt.fileExt(d.comp.target.abi, d.comp.target.cpu.arch),
d.comp.target.objFileExt(),
};
break :blk std.fmt.bufPrint(&name_buf, fmt_template, fmt_args) catch return d.fatal("Filename too long for filesystem: " ++ fmt_template, fmt_args);
};
Expand Down
4 changes: 4 additions & 0 deletions lib/std/Target.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2045,6 +2045,10 @@ pub fn exeFileExt(target: Target) [:0]const u8 {
return target.os.tag.exeFileExt(target.cpu.arch);
}

pub fn objFileExt(target: Target) [:0]const u8 {
return target.ofmt.fileExt(target.abi, target.cpu.arch);
}

pub fn staticLibSuffix(target: Target) [:0]const u8 {
return target.os.tag.staticLibSuffix(target.abi);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/std/zig.zig
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ pub fn binNameAlloc(allocator: Allocator, options: BinNameOptions) error{OutOfMe
.plan9 => switch (options.output_mode) {
.Exe => return allocator.dupe(u8, root_name),
.Obj => return std.fmt.allocPrint(allocator, "{s}{s}", .{
root_name, t.ofmt.fileExt(t.abi, t.cpu.arch),
root_name, t.objFileExt(),
}),
.Lib => return std.fmt.allocPrint(allocator, "{s}{s}.a", .{
t.libPrefix(), root_name,
Expand Down
4 changes: 2 additions & 2 deletions src/Compilation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4714,7 +4714,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr
c_source_basename[0 .. c_source_basename.len - std.fs.path.extension(c_source_basename).len];

const target = comp.getTarget();
const o_ext = target.ofmt.fileExt(target.abi, target.cpu.arch);
const o_ext = target.objFileExt();
const digest = if (!comp.disable_c_depfile and try man.hit()) man.final() else blk: {
var argv = std.ArrayList([]const u8).init(gpa);
defer argv.deinit();
Expand Down Expand Up @@ -5972,7 +5972,7 @@ pub const FileExt = enum {
.assembly => ".s",
.assembly_with_cpp => ".S",
.shared_library => target.dynamicLibSuffix(),
.object => target.ofmt.fileExt(target.abi, target.cpu.arch),
.object => target.objFileExt(),
.static_library => target.staticLibSuffix(),
.zig => ".zig",
.def => ".def",
Expand Down
2 changes: 1 addition & 1 deletion tools/docgen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const fatal = std.zig.fatal;

const max_doc_file_size = 10 * 1024 * 1024;

const obj_ext = builtin.object_format.fileExt(builtin.abi, builtin.cpu.arch);
const obj_ext = builtin.target.objFileExt();

const usage =
\\Usage: docgen [options] input output
Expand Down
2 changes: 1 addition & 1 deletion tools/doctest.zig
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ fn printOutput(
try env_map.put("CLICOLOR_FORCE", "1");

const host = try std.zig.system.resolveTargetQuery(.{});
const obj_ext = builtin.object_format.fileExt(builtin.abi, builtin.cpu.arch);
const obj_ext = builtin.target.objFileExt();
const print = std.debug.print;

var shell_buffer = std.ArrayList(u8).init(arena);
Expand Down

0 comments on commit 9bd0a5d

Please sign in to comment.