| author | |
| committer | |
| log | 6d5002028a2fe71b67d8106b30c6602bc8e44121 |
| tree | 7f8bce9ad733d2ec5a5e472df13e02b001c96fdb |
| parent | f102a5800c90dfec5a4f619dca94af1b7d7e9a62 |
6 files changed, 31 insertions(+), 8 deletions(-)
lib/std/target.zig-3| ... | ... | @@ -1307,9 +1307,6 @@ pub const Target = struct { |
| 1307 | 1307 | } |
| 1308 | 1308 | |
| 1309 | 1309 | pub fn libPrefix_cpu_arch_abi(cpu_arch: Cpu.Arch, abi: Abi) [:0]const u8 { |
| 1310 | if (cpu_arch.isWasm()) { | |
| 1311 | return ""; | |
| 1312 | } | |
| 1313 | 1310 | switch (abi) { |
| 1314 | 1311 | .msvc => return "", |
| 1315 | 1312 | else => return "lib", |
lib/std/zig.zig+10-1| ... | ... | @@ -160,8 +160,17 @@ pub fn binNameAlloc(allocator: *std.mem.Allocator, options: BinNameOptions) erro |
| 160 | 160 | }, |
| 161 | 161 | .wasm => switch (options.output_mode) { |
| 162 | 162 | .Exe => return std.fmt.allocPrint(allocator, "{s}{s}", .{ root_name, target.exeFileExt() }), |
| 163 | .Lib => { | |
| 164 | switch (options.link_mode orelse .Static) { | |
| 165 | .Static => return std.fmt.allocPrint(allocator, "{s}{s}.a", .{ | |
| 166 | target.libPrefix(), root_name, | |
| 167 | }), | |
| 168 | .Dynamic => return std.fmt.allocPrint(allocator, "{s}{s}.wasm", .{ | |
| 169 | target.libPrefix(), root_name, | |
| 170 | }), | |
| 171 | } | |
| 172 | }, | |
| 163 | 173 | .Obj => return std.fmt.allocPrint(allocator, "{s}{s}", .{ root_name, target.oFileExt() }), |
| 164 | .Lib => return std.fmt.allocPrint(allocator, "{s}.wasm", .{root_name}), | |
| 165 | 174 | }, |
| 166 | 175 | .c => return std.fmt.allocPrint(allocator, "{s}.c", .{root_name}), |
| 167 | 176 | .spirv => return std.fmt.allocPrint(allocator, "{s}.spv", .{root_name}), |
src/Compilation.zig+2-1| ... | ... | @@ -3262,7 +3262,8 @@ fn detectLibCFromLibCInstallation(arena: *Allocator, target: Target, lci: *const |
| 3262 | 3262 | pub fn get_libc_crt_file(comp: *Compilation, arena: *Allocator, basename: []const u8) ![]const u8 { |
| 3263 | 3263 | if (comp.wantBuildGLibCFromSource() or |
| 3264 | 3264 | comp.wantBuildMuslFromSource() or |
| 3265 | comp.wantBuildMinGWFromSource()) | |
| 3265 | comp.wantBuildMinGWFromSource() or | |
| 3266 | comp.wantBuildWASILibcSysrootFromSource()) | |
| 3266 | 3267 | { |
| 3267 | 3268 | return comp.crt_files.get(basename).?.full_object_path; |
| 3268 | 3269 | } |
src/link.zig+1-3| ... | ... | @@ -412,9 +412,7 @@ pub const File = struct { |
| 412 | 412 | return; |
| 413 | 413 | } |
| 414 | 414 | const use_lld = build_options.have_llvm and base.options.use_lld; |
| 415 | if (use_lld and base.options.output_mode == .Lib and base.options.link_mode == .Static and | |
| 416 | !base.options.target.isWasm()) | |
| 417 | { | |
| 415 | if (use_lld and base.options.output_mode == .Lib and base.options.link_mode == .Static) { | |
| 418 | 416 | return base.linkAsArchive(comp); |
| 419 | 417 | } |
| 420 | 418 | switch (base.tag) { |
src/link/Wasm.zig+13| ... | ... | @@ -573,6 +573,7 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void { |
| 573 | 573 | null; |
| 574 | 574 | |
| 575 | 575 | const target = self.base.options.target; |
| 576 | const link_in_crt = self.base.options.link_libc and self.base.options.output_mode == .Exe; | |
| 576 | 577 | |
| 577 | 578 | const id_symlink_basename = "lld.id"; |
| 578 | 579 | |
| ... | ... | @@ -695,6 +696,18 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void { |
| 695 | 696 | full_out_path, |
| 696 | 697 | }); |
| 697 | 698 | |
| 699 | if (link_in_crt) { | |
| 700 | // TODO work out if we want standard crt, a reactor or a command | |
| 701 | try argv.append(try comp.get_libc_crt_file(arena, "crt.o.wasm")); | |
| 702 | } | |
| 703 | ||
| 704 | if (!is_obj and self.base.options.link_libc) { | |
| 705 | try argv.append(try comp.get_libc_crt_file(arena, switch (self.base.options.link_mode) { | |
| 706 | .Static => "libc.a", | |
| 707 | .Dynamic => unreachable, | |
| 708 | })); | |
| 709 | } | |
| 710 | ||
| 698 | 711 | // Positional arguments to the linker such as object files. |
| 699 | 712 | try argv.appendSlice(self.base.options.objects); |
| 700 | 713 |
src/wasi_libc.zig+5| ... | ... | @@ -17,6 +17,7 @@ pub fn buildWASILibcSysroot(comp: *Compilation) !void { |
| 17 | 17 | const arena = &arena_allocator.allocator; |
| 18 | 18 | |
| 19 | 19 | { |
| 20 | // Compile crt sources. | |
| 20 | 21 | var args = std.ArrayList([]const u8).init(arena); |
| 21 | 22 | try addCCArgs(comp, arena, &args, false); |
| 22 | 23 | try args.appendSlice(&[_][]const u8{ |
| ... | ... | @@ -62,9 +63,11 @@ pub fn buildWASILibcSysroot(comp: *Compilation) !void { |
| 62 | 63 | } |
| 63 | 64 | |
| 64 | 65 | { |
| 66 | // Compile WASI libc (sysroot). | |
| 65 | 67 | var comp_sources = std.ArrayList(Compilation.CSourceFile).init(arena); |
| 66 | 68 | |
| 67 | 69 | { |
| 70 | // Compile dlmalloc. | |
| 68 | 71 | var args = std.ArrayList([]const u8).init(arena); |
| 69 | 72 | try addCCArgs(comp, arena, &args, true); |
| 70 | 73 | try args.appendSlice(&[_][]const u8{ |
| ... | ... | @@ -88,6 +91,7 @@ pub fn buildWASILibcSysroot(comp: *Compilation) !void { |
| 88 | 91 | } |
| 89 | 92 | |
| 90 | 93 | { |
| 94 | // Compile libc-bottom-half. | |
| 91 | 95 | var args = std.ArrayList([]const u8).init(arena); |
| 92 | 96 | try addCCArgs(comp, arena, &args, true); |
| 93 | 97 | try args.appendSlice(&[_][]const u8{ |
| ... | ... | @@ -131,6 +135,7 @@ pub fn buildWASILibcSysroot(comp: *Compilation) !void { |
| 131 | 135 | } |
| 132 | 136 | |
| 133 | 137 | { |
| 138 | // Compile libc-top-half. | |
| 134 | 139 | var args = std.ArrayList([]const u8).init(arena); |
| 135 | 140 | try addCCArgs(comp, arena, &args, true); |
| 136 | 141 | try args.appendSlice(&[_][]const u8{ |