diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-09-30 02:55:41 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-09-30 02:55:41 -0700 |
| commit | 7067764ed3f85eca17be7310b848ad97bd8af52e (patch) | |
| tree | e61901ce753c541d3c3778c544bd98826691efb8 /lib/std/zig.zig | |
| parent | e2d1f9874df2a9221aaa9ec55bd2974b70601f64 (diff) | |
| parent | fe117d9961c3622fda5c359733d01de686509af0 (diff) | |
| download | zig-7067764ed3f85eca17be7310b848ad97bd8af52e.tar.gz zig-7067764ed3f85eca17be7310b848ad97bd8af52e.zip | |
Merge remote-tracking branch 'origin/master' into llvm11
The changes to install_files.h needed to put into src/libcxx.zig
Diffstat (limited to 'lib/std/zig.zig')
| -rw-r--r-- | lib/std/zig.zig | 88 |
1 files changed, 74 insertions, 14 deletions
diff --git a/lib/std/zig.zig b/lib/std/zig.zig index 1dedce4067..cc1815e8e5 100644 --- a/lib/std/zig.zig +++ b/lib/std/zig.zig @@ -64,24 +64,84 @@ pub fn lineDelta(source: []const u8, start: usize, end: usize) isize { return line; } -/// Returns the standard file system basename of a binary generated by the Zig compiler. -pub fn binNameAlloc( - allocator: *std.mem.Allocator, +pub const BinNameOptions = struct { root_name: []const u8, target: std.Target, output_mode: std.builtin.OutputMode, - link_mode: ?std.builtin.LinkMode, -) error{OutOfMemory}![]u8 { - switch (output_mode) { - .Exe => return std.fmt.allocPrint(allocator, "{}{}", .{ root_name, target.exeFileExt() }), - .Lib => { - const suffix = switch (link_mode orelse .Static) { - .Static => target.staticLibSuffix(), - .Dynamic => target.dynamicLibSuffix(), - }; - return std.fmt.allocPrint(allocator, "{}{}{}", .{ target.libPrefix(), root_name, suffix }); + link_mode: ?std.builtin.LinkMode = null, + object_format: ?std.Target.ObjectFormat = null, + version: ?std.builtin.Version = null, +}; + +/// Returns the standard file system basename of a binary generated by the Zig compiler. +pub fn binNameAlloc(allocator: *std.mem.Allocator, options: BinNameOptions) error{OutOfMemory}![]u8 { + const root_name = options.root_name; + const target = options.target; + switch (options.object_format orelse target.getObjectFormat()) { + .coff, .pe => switch (options.output_mode) { + .Exe => return std.fmt.allocPrint(allocator, "{s}{s}", .{ root_name, target.exeFileExt() }), + .Lib => { + const suffix = switch (options.link_mode orelse .Static) { + .Static => ".lib", + .Dynamic => ".dll", + }; + return std.fmt.allocPrint(allocator, "{s}{s}", .{ root_name, suffix }); + }, + .Obj => return std.fmt.allocPrint(allocator, "{s}{s}", .{ root_name, target.oFileExt() }), + }, + .elf => switch (options.output_mode) { + .Exe => return allocator.dupe(u8, root_name), + .Lib => { + switch (options.link_mode orelse .Static) { + .Static => return std.fmt.allocPrint(allocator, "{s}{s}.a", .{ + target.libPrefix(), root_name, + }), + .Dynamic => { + if (options.version) |ver| { + return std.fmt.allocPrint(allocator, "{s}{s}.so.{d}.{d}.{d}", .{ + target.libPrefix(), root_name, ver.major, ver.minor, ver.patch, + }); + } else { + return std.fmt.allocPrint(allocator, "{s}{s}.so", .{ + target.libPrefix(), root_name, + }); + } + }, + } + }, + .Obj => return std.fmt.allocPrint(allocator, "{s}{s}", .{ root_name, target.oFileExt() }), + }, + .macho => switch (options.output_mode) { + .Exe => return allocator.dupe(u8, root_name), + .Lib => { + switch (options.link_mode orelse .Static) { + .Static => return std.fmt.allocPrint(allocator, "{s}{s}.a", .{ + target.libPrefix(), root_name, + }), + .Dynamic => { + if (options.version) |ver| { + return std.fmt.allocPrint(allocator, "{s}{s}.{d}.{d}.{d}.dylib", .{ + target.libPrefix(), root_name, ver.major, ver.minor, ver.patch, + }); + } else { + return std.fmt.allocPrint(allocator, "{s}{s}.dylib", .{ + target.libPrefix(), root_name, + }); + } + }, + } + return std.fmt.allocPrint(allocator, "{s}{s}{s}", .{ target.libPrefix(), root_name, suffix }); + }, + .Obj => return std.fmt.allocPrint(allocator, "{s}{s}", .{ root_name, target.oFileExt() }), + }, + .wasm => switch (options.output_mode) { + .Exe => return std.fmt.allocPrint(allocator, "{s}{s}", .{ root_name, target.exeFileExt() }), + .Obj => return std.fmt.allocPrint(allocator, "{s}{s}", .{ root_name, target.oFileExt() }), + .Lib => return std.fmt.allocPrint(allocator, "{s}.wasm", .{root_name}), }, - .Obj => return std.fmt.allocPrint(allocator, "{}{}", .{ root_name, target.oFileExt() }), + .c => return std.fmt.allocPrint(allocator, "{s}.c", .{root_name}), + .hex => return std.fmt.allocPrint(allocator, "{s}.ihex", .{root_name}), + .raw => return std.fmt.allocPrint(allocator, "{s}.bin", .{root_name}), } } |
