authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-29 16:59:35-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-29 17:01:05-07:00
logf69650a4788c57ec20348e9c002884ba39339d1c
treef371e3bc00656c8aacba0dda88141eb97bb41179
parentb811a99af9b5549fd0f0940dafddc63040af01ac

update wasm to use ".o.wasm" extension for objects

This is convenient for debugging purposes, as well as simplifying the caching system since executable basenames will not conflict with their corresponding object files.

6 files changed, 24 insertions(+), 22 deletions(-)

lib/std/build.zig+1
...@@ -1384,6 +1384,7 @@ pub const LibExeObjStep = struct {...@@ -1384,6 +1384,7 @@ pub const LibExeObjStep = struct {
1384 }1384 }
13851385
1386 fn computeOutFileNames(self: *LibExeObjStep) void {1386 fn computeOutFileNames(self: *LibExeObjStep) void {
1387 // TODO make this call std.zig.binNameAlloc
1387 switch (self.kind) {1388 switch (self.kind) {
1388 .Obj => {1389 .Obj => {
1389 self.out_filename = self.builder.fmt("{}{}", .{ self.name, self.target.oFileExt() });1390 self.out_filename = self.builder.fmt("{}{}", .{ self.name, self.target.oFileExt() });
lib/std/target.zig+11-8
...@@ -483,13 +483,6 @@ pub const Target = struct {...@@ -483,13 +483,6 @@ pub const Target = struct {
483 else => false,483 else => false,
484 };484 };
485 }485 }
486
487 pub fn oFileExt(abi: Abi) [:0]const u8 {
488 return switch (abi) {
489 .msvc => ".obj",
490 else => ".o",
491 };
492 }
493 };486 };
494487
495 pub const ObjectFormat = enum {488 pub const ObjectFormat = enum {
...@@ -1142,8 +1135,18 @@ pub const Target = struct {...@@ -1142,8 +1135,18 @@ pub const Target = struct {
1142 return linuxTripleSimple(allocator, self.cpu.arch, self.os.tag, self.abi);1135 return linuxTripleSimple(allocator, self.cpu.arch, self.os.tag, self.abi);
1143 }1136 }
11441137
1138 pub fn oFileExt_cpu_arch_abi(cpu_arch: Cpu.Arch, abi: Abi) [:0]const u8 {
1139 if (cpu_arch.isWasm()) {
1140 return ".o.wasm";
1141 }
1142 switch (abi) {
1143 .msvc => return ".obj",
1144 else => return ".o",
1145 }
1146 }
1147
1145 pub fn oFileExt(self: Target) [:0]const u8 {1148 pub fn oFileExt(self: Target) [:0]const u8 {
1146 return self.abi.oFileExt();1149 return oFileExt_cpu_arch_abi(self.cpu.arch, self.abi);
1147 }1150 }
11481151
1149 pub fn exeFileExtSimple(cpu_arch: Cpu.Arch, os_tag: Os.Tag) [:0]const u8 {1152 pub fn exeFileExtSimple(cpu_arch: Cpu.Arch, os_tag: Os.Tag) [:0]const u8 {
lib/std/zig.zig+9-11
...@@ -79,13 +79,7 @@ pub fn binNameAlloc(allocator: *std.mem.Allocator, options: BinNameOptions) erro...@@ -79,13 +79,7 @@ pub fn binNameAlloc(allocator: *std.mem.Allocator, options: BinNameOptions) erro
79 const target = options.target;79 const target = options.target;
80 switch (options.object_format orelse target.getObjectFormat()) {80 switch (options.object_format orelse target.getObjectFormat()) {
81 .coff, .pe => switch (options.output_mode) {81 .coff, .pe => switch (options.output_mode) {
82 .Exe => {82 .Exe => return std.fmt.allocPrint(allocator, "{s}{s}", .{ root_name, target.exeFileExt() }),
83 const suffix = switch (target.os.tag) {
84 .uefi => ".efi",
85 else => ".exe",
86 };
87 return std.fmt.allocPrint(allocator, "{s}{s}", .{ root_name, suffix });
88 },
89 .Lib => {83 .Lib => {
90 const suffix = switch (options.link_mode orelse .Static) {84 const suffix = switch (options.link_mode orelse .Static) {
91 .Static => ".lib",85 .Static => ".lib",
...@@ -93,7 +87,7 @@ pub fn binNameAlloc(allocator: *std.mem.Allocator, options: BinNameOptions) erro...@@ -93,7 +87,7 @@ pub fn binNameAlloc(allocator: *std.mem.Allocator, options: BinNameOptions) erro
93 };87 };
94 return std.fmt.allocPrint(allocator, "{s}{s}", .{ root_name, suffix });88 return std.fmt.allocPrint(allocator, "{s}{s}", .{ root_name, suffix });
95 },89 },
96 .Obj => return std.fmt.allocPrint(allocator, "{s}{s}", .{ root_name, target.abi.oFileExt() }),90 .Obj => return std.fmt.allocPrint(allocator, "{s}{s}", .{ root_name, target.oFileExt() }),
97 },91 },
98 .elf => switch (options.output_mode) {92 .elf => switch (options.output_mode) {
99 .Exe => return allocator.dupe(u8, root_name),93 .Exe => return allocator.dupe(u8, root_name),
...@@ -113,7 +107,7 @@ pub fn binNameAlloc(allocator: *std.mem.Allocator, options: BinNameOptions) erro...@@ -113,7 +107,7 @@ pub fn binNameAlloc(allocator: *std.mem.Allocator, options: BinNameOptions) erro
113 },107 },
114 }108 }
115 },109 },
116 .Obj => return std.fmt.allocPrint(allocator, "{s}.o", .{root_name}),110 .Obj => return std.fmt.allocPrint(allocator, "{s}{s}", .{ root_name, target.oFileExt() }),
117 },111 },
118 .macho => switch (options.output_mode) {112 .macho => switch (options.output_mode) {
119 .Exe => return allocator.dupe(u8, root_name),113 .Exe => return allocator.dupe(u8, root_name),
...@@ -124,9 +118,13 @@ pub fn binNameAlloc(allocator: *std.mem.Allocator, options: BinNameOptions) erro...@@ -124,9 +118,13 @@ pub fn binNameAlloc(allocator: *std.mem.Allocator, options: BinNameOptions) erro
124 };118 };
125 return std.fmt.allocPrint(allocator, "{s}{s}{s}", .{ target.libPrefix(), root_name, suffix });119 return std.fmt.allocPrint(allocator, "{s}{s}{s}", .{ target.libPrefix(), root_name, suffix });
126 },120 },
127 .Obj => return std.fmt.allocPrint(allocator, "{s}.o", .{root_name}),121 .Obj => return std.fmt.allocPrint(allocator, "{s}{s}", .{ root_name, target.oFileExt() }),
122 },
123 .wasm => switch (options.output_mode) {
124 .Exe => return std.fmt.allocPrint(allocator, "{s}{s}", .{ root_name, target.exeFileExt() }),
125 .Obj => return std.fmt.allocPrint(allocator, "{s}{s}", .{ root_name, target.oFileExt() }),
126 .Lib => return std.fmt.allocPrint(allocator, "{s}.wasm", .{root_name}),
128 },127 },
129 .wasm => return std.fmt.allocPrint(allocator, "{s}.wasm", .{root_name}),
130 .c => return std.fmt.allocPrint(allocator, "{s}.c", .{root_name}),128 .c => return std.fmt.allocPrint(allocator, "{s}.c", .{root_name}),
131 .hex => return std.fmt.allocPrint(allocator, "{s}.ihex", .{root_name}),129 .hex => return std.fmt.allocPrint(allocator, "{s}.ihex", .{root_name}),
132 .raw => return std.fmt.allocPrint(allocator, "{s}.bin", .{root_name}),130 .raw => return std.fmt.allocPrint(allocator, "{s}.bin", .{root_name}),
lib/std/zig/cross_target.zig+1-1
...@@ -466,7 +466,7 @@ pub const CrossTarget = struct {...@@ -466,7 +466,7 @@ pub const CrossTarget = struct {
466 }466 }
467467
468 pub fn oFileExt(self: CrossTarget) [:0]const u8 {468 pub fn oFileExt(self: CrossTarget) [:0]const u8 {
469 return self.getAbi().oFileExt();469 return Target.oFileExt_cpu_arch_abi(self.getCpuArch(), self.getAbi());
470 }470 }
471471
472 pub fn exeFileExt(self: CrossTarget) [:0]const u8 {472 pub fn exeFileExt(self: CrossTarget) [:0]const u8 {
src/Compilation.zig+1-1
...@@ -1520,7 +1520,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject) !void {...@@ -1520,7 +1520,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject) !void {
1520 comp.bin_file.options.root_name1520 comp.bin_file.options.root_name
1521 else1521 else
1522 mem.split(c_source_basename, ".").next().?;1522 mem.split(c_source_basename, ".").next().?;
1523 const o_basename = try std.fmt.allocPrint(arena, "{}{}", .{ o_basename_noext, comp.getTarget().oFileExt() });1523 const o_basename = try std.fmt.allocPrint(arena, "{s}{s}", .{ o_basename_noext, comp.getTarget().oFileExt() });
15241524
1525 const digest = if (!comp.disable_c_depfile and try man.hit()) man.final() else blk: {1525 const digest = if (!comp.disable_c_depfile and try man.hit()) man.final() else blk: {
1526 var argv = std.ArrayList([]const u8).init(comp.gpa);1526 var argv = std.ArrayList([]const u8).init(comp.gpa);
src/link.zig+1-1
...@@ -176,7 +176,7 @@ pub const File = struct {...@@ -176,7 +176,7 @@ pub const File = struct {
176 };176 };
177 }177 }
178 // Open a temporary object file, not the final output file because we want to link with LLD.178 // Open a temporary object file, not the final output file because we want to link with LLD.
179 break :blk try std.fmt.allocPrint(allocator, "{}{}", .{ emit.sub_path, options.target.oFileExt() });179 break :blk try std.fmt.allocPrint(allocator, "{s}{s}", .{ emit.sub_path, options.target.oFileExt() });
180 } else emit.sub_path;180 } else emit.sub_path;
181 errdefer if (use_lld) allocator.free(sub_path);181 errdefer if (use_lld) allocator.free(sub_path);
182182