Commit f69650a478

Andrew Kelley <andrew@ziglang.org>
2020-09-30 01:59:35
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.
1 parent b811a99
lib/std/zig/cross_target.zig
@@ -466,7 +466,7 @@ pub const CrossTarget = struct {
     }
 
     pub fn oFileExt(self: CrossTarget) [:0]const u8 {
-        return self.getAbi().oFileExt();
+        return Target.oFileExt_cpu_arch_abi(self.getCpuArch(), self.getAbi());
     }
 
     pub fn exeFileExt(self: CrossTarget) [:0]const u8 {
lib/std/build.zig
@@ -1384,6 +1384,7 @@ pub const LibExeObjStep = struct {
     }
 
     fn computeOutFileNames(self: *LibExeObjStep) void {
+        // TODO make this call std.zig.binNameAlloc
         switch (self.kind) {
             .Obj => {
                 self.out_filename = self.builder.fmt("{}{}", .{ self.name, self.target.oFileExt() });
lib/std/target.zig
@@ -483,13 +483,6 @@ pub const Target = struct {
                 else => false,
             };
         }
-
-        pub fn oFileExt(abi: Abi) [:0]const u8 {
-            return switch (abi) {
-                .msvc => ".obj",
-                else => ".o",
-            };
-        }
     };
 
     pub const ObjectFormat = enum {
@@ -1142,8 +1135,18 @@ pub const Target = struct {
         return linuxTripleSimple(allocator, self.cpu.arch, self.os.tag, self.abi);
     }
 
+    pub fn oFileExt_cpu_arch_abi(cpu_arch: Cpu.Arch, abi: Abi) [:0]const u8 {
+        if (cpu_arch.isWasm()) {
+            return ".o.wasm";
+        }
+        switch (abi) {
+            .msvc => return ".obj",
+            else => return ".o",
+        }
+    }
+
     pub fn oFileExt(self: Target) [:0]const u8 {
-        return self.abi.oFileExt();
+        return oFileExt_cpu_arch_abi(self.cpu.arch, self.abi);
     }
 
     pub fn exeFileExtSimple(cpu_arch: Cpu.Arch, os_tag: Os.Tag) [:0]const u8 {
lib/std/zig.zig
@@ -79,13 +79,7 @@ pub fn binNameAlloc(allocator: *std.mem.Allocator, options: BinNameOptions) erro
     const target = options.target;
     switch (options.object_format orelse target.getObjectFormat()) {
         .coff, .pe => switch (options.output_mode) {
-            .Exe => {
-                const suffix = switch (target.os.tag) {
-                    .uefi => ".efi",
-                    else => ".exe",
-                };
-                return std.fmt.allocPrint(allocator, "{s}{s}", .{ root_name, suffix });
-            },
+            .Exe => return std.fmt.allocPrint(allocator, "{s}{s}", .{ root_name, target.exeFileExt() }),
             .Lib => {
                 const suffix = switch (options.link_mode orelse .Static) {
                     .Static => ".lib",
@@ -93,7 +87,7 @@ pub fn binNameAlloc(allocator: *std.mem.Allocator, options: BinNameOptions) erro
                 };
                 return std.fmt.allocPrint(allocator, "{s}{s}", .{ root_name, suffix });
             },
-            .Obj => return std.fmt.allocPrint(allocator, "{s}{s}", .{ root_name, target.abi.oFileExt() }),
+            .Obj => return std.fmt.allocPrint(allocator, "{s}{s}", .{ root_name, target.oFileExt() }),
         },
         .elf => switch (options.output_mode) {
             .Exe => return allocator.dupe(u8, root_name),
@@ -113,7 +107,7 @@ pub fn binNameAlloc(allocator: *std.mem.Allocator, options: BinNameOptions) erro
                     },
                 }
             },
-            .Obj => return std.fmt.allocPrint(allocator, "{s}.o", .{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),
@@ -124,9 +118,13 @@ pub fn binNameAlloc(allocator: *std.mem.Allocator, options: BinNameOptions) erro
                 };
                 return std.fmt.allocPrint(allocator, "{s}{s}{s}", .{ target.libPrefix(), root_name, suffix });
             },
-            .Obj => return std.fmt.allocPrint(allocator, "{s}.o", .{root_name}),
+            .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}),
         },
-        .wasm => return std.fmt.allocPrint(allocator, "{s}.wasm", .{root_name}),
         .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}),
src/Compilation.zig
@@ -1520,7 +1520,7 @@ fn updateCObject(comp: *Compilation, c_object: *CObject) !void {
         comp.bin_file.options.root_name
     else
         mem.split(c_source_basename, ".").next().?;
-    const o_basename = try std.fmt.allocPrint(arena, "{}{}", .{ o_basename_noext, comp.getTarget().oFileExt() });
+    const o_basename = try std.fmt.allocPrint(arena, "{s}{s}", .{ o_basename_noext, comp.getTarget().oFileExt() });
 
     const digest = if (!comp.disable_c_depfile and try man.hit()) man.final() else blk: {
         var argv = std.ArrayList([]const u8).init(comp.gpa);
src/link.zig
@@ -176,7 +176,7 @@ pub const File = struct {
                 };
             }
             // Open a temporary object file, not the final output file because we want to link with LLD.
-            break :blk try std.fmt.allocPrint(allocator, "{}{}", .{ emit.sub_path, options.target.oFileExt() });
+            break :blk try std.fmt.allocPrint(allocator, "{s}{s}", .{ emit.sub_path, options.target.oFileExt() });
         } else emit.sub_path;
         errdefer if (use_lld) allocator.free(sub_path);