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 {
13841384 }
13851385
13861386 fn computeOutFileNames(self: *LibExeObjStep) void {
1387 // TODO make this call std.zig.binNameAlloc
13871388 switch (self.kind) {
13881389 .Obj => {
13891390 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 {
483483 else => false,
484484 };
485485 }
486
487 pub fn oFileExt(abi: Abi) [:0]const u8 {
488 return switch (abi) {
489 .msvc => ".obj",
490 else => ".o",
491 };
492 }
493486 };
494487
495488 pub const ObjectFormat = enum {
......@@ -1142,8 +1135,18 @@ pub const Target = struct {
11421135 return linuxTripleSimple(allocator, self.cpu.arch, self.os.tag, self.abi);
11431136 }
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
11451148 pub fn oFileExt(self: Target) [:0]const u8 {
1146 return self.abi.oFileExt();
1149 return oFileExt_cpu_arch_abi(self.cpu.arch, self.abi);
11471150 }
11481151
11491152 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
7979 const target = options.target;
8080 switch (options.object_format orelse target.getObjectFormat()) {
8181 .coff, .pe => switch (options.output_mode) {
82 .Exe => {
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 },
82 .Exe => return std.fmt.allocPrint(allocator, "{s}{s}", .{ root_name, target.exeFileExt() }),
8983 .Lib => {
9084 const suffix = switch (options.link_mode orelse .Static) {
9185 .Static => ".lib",
......@@ -93,7 +87,7 @@ pub fn binNameAlloc(allocator: *std.mem.Allocator, options: BinNameOptions) erro
9387 };
9488 return std.fmt.allocPrint(allocator, "{s}{s}", .{ root_name, suffix });
9589 },
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() }),
9791 },
9892 .elf => switch (options.output_mode) {
9993 .Exe => return allocator.dupe(u8, root_name),
......@@ -113,7 +107,7 @@ pub fn binNameAlloc(allocator: *std.mem.Allocator, options: BinNameOptions) erro
113107 },
114108 }
115109 },
116 .Obj => return std.fmt.allocPrint(allocator, "{s}.o", .{root_name}),
110 .Obj => return std.fmt.allocPrint(allocator, "{s}{s}", .{ root_name, target.oFileExt() }),
117111 },
118112 .macho => switch (options.output_mode) {
119113 .Exe => return allocator.dupe(u8, root_name),
......@@ -124,9 +118,13 @@ pub fn binNameAlloc(allocator: *std.mem.Allocator, options: BinNameOptions) erro
124118 };
125119 return std.fmt.allocPrint(allocator, "{s}{s}{s}", .{ target.libPrefix(), root_name, suffix });
126120 },
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}),
128127 },
129 .wasm => return std.fmt.allocPrint(allocator, "{s}.wasm", .{root_name}),
130128 .c => return std.fmt.allocPrint(allocator, "{s}.c", .{root_name}),
131129 .hex => return std.fmt.allocPrint(allocator, "{s}.ihex", .{root_name}),
132130 .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 {
466466 }
467467
468468 pub fn oFileExt(self: CrossTarget) [:0]const u8 {
469 return self.getAbi().oFileExt();
469 return Target.oFileExt_cpu_arch_abi(self.getCpuArch(), self.getAbi());
470470 }
471471
472472 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 {
15201520 comp.bin_file.options.root_name
15211521 else
15221522 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
15251525 const digest = if (!comp.disable_c_depfile and try man.hit()) man.final() else blk: {
15261526 var argv = std.ArrayList([]const u8).init(comp.gpa);
src/link.zig+1-1
......@@ -176,7 +176,7 @@ pub const File = struct {
176176 };
177177 }
178178 // 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() });
180180 } else emit.sub_path;
181181 errdefer if (use_lld) allocator.free(sub_path);
182182