authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-11-24 17:47:56-08:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2021-11-24 17:47:56-08:00
log0581756453a98d4e1100c684896783606dc86374
tree865fcfffdc31cf0b7220d41198266f0627b2d118
parentfdcac5ecbd324170f7281f6704ead18b7d904e72
parent20cc7af8e6e47ba209ab0d462826f40516c86b9d
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #9347 from kkartaltepe/implib-support

Coff linker: Add IMPLIB support

7 files changed, 176 insertions(+), 60 deletions(-)

src/Compilation.zig+33-4
......@@ -654,6 +654,8 @@ pub const InitOptions = struct {
654654 emit_analysis: ?EmitLoc = null,
655655 /// `null` means to not emit docs.
656656 emit_docs: ?EmitLoc = null,
657 /// `null` means to not emit an import lib.
658 emit_implib: ?EmitLoc = null,
657659 link_mode: ?std.builtin.LinkMode = null,
658660 dll_export_fns: ?bool = false,
659661 /// Normally when using LLD to link, Zig uses a file named "lld.id" in the
......@@ -667,7 +669,6 @@ pub const InitOptions = struct {
667669 optimize_mode: std.builtin.Mode = .Debug,
668670 keep_source_files_loaded: bool = false,
669671 clang_argv: []const []const u8 = &[0][]const u8{},
670 lld_argv: []const []const u8 = &[0][]const u8{},
671672 lib_dirs: []const []const u8 = &[0][]const u8{},
672673 rpath_list: []const []const u8 = &[0][]const u8{},
673674 c_source_files: []const CSourceFile = &[0]CSourceFile{},
......@@ -735,6 +736,7 @@ pub const InitOptions = struct {
735736 linker_tsaware: bool = false,
736737 linker_nxcompat: bool = false,
737738 linker_dynamicbase: bool = false,
739 linker_optimization: ?u8 = null,
738740 major_subsystem_version: ?u32 = null,
739741 minor_subsystem_version: ?u32 = null,
740742 clang_passthrough_mode: bool = false,
......@@ -944,9 +946,9 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
944946 link_eh_frame_hdr or
945947 options.link_emit_relocs or
946948 options.output_mode == .Lib or
947 options.lld_argv.len != 0 or
948949 options.image_base_override != null or
949 options.linker_script != null or options.version_script != null)
950 options.linker_script != null or options.version_script != null or
951 options.emit_implib != null)
950952 {
951953 break :blk true;
952954 }
......@@ -1139,6 +1141,10 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
11391141 const strip = options.strip or !target_util.hasDebugInfo(options.target);
11401142 const red_zone = options.want_red_zone orelse target_util.hasRedZone(options.target);
11411143 const omit_frame_pointer = options.omit_frame_pointer orelse (options.optimize_mode != .Debug);
1144 const linker_optimization: u8 = options.linker_optimization orelse switch (options.optimize_mode) {
1145 .Debug => @as(u8, 0),
1146 else => @as(u8, 3),
1147 };
11421148
11431149 // We put everything into the cache hash that *cannot be modified during an incremental update*.
11441150 // For example, one cannot change the target between updates, but one can change source files,
......@@ -1182,6 +1188,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
11821188 cache.hash.add(options.output_mode);
11831189 cache.hash.add(options.machine_code_model);
11841190 cache.hash.addOptionalEmitLoc(options.emit_bin);
1191 cache.hash.addOptionalEmitLoc(options.emit_implib);
11851192 cache.hash.addBytes(options.root_name);
11861193 if (options.target.os.tag == .wasi) cache.hash.add(wasi_exec_model);
11871194 // TODO audit this and make sure everything is in it
......@@ -1338,18 +1345,21 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
13381345
13391346 const bin_file_emit: ?link.Emit = blk: {
13401347 const emit_bin = options.emit_bin orelse break :blk null;
1348
13411349 if (emit_bin.directory) |directory| {
13421350 break :blk link.Emit{
13431351 .directory = directory,
13441352 .sub_path = emit_bin.basename,
13451353 };
13461354 }
1355
13471356 if (module) |zm| {
13481357 break :blk link.Emit{
13491358 .directory = zm.zig_cache_artifact_directory,
13501359 .sub_path = emit_bin.basename,
13511360 };
13521361 }
1362
13531363 // We could use the cache hash as is no problem, however, we increase
13541364 // the likelihood of cache hits by adding the first C source file
13551365 // path name (not contents) to the hash. This way if the user is compiling
......@@ -1376,6 +1386,24 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
13761386 };
13771387 };
13781388
1389 const implib_emit: ?link.Emit = blk: {
1390 const emit_implib = options.emit_implib orelse break :blk null;
1391
1392 if (emit_implib.directory) |directory| {
1393 break :blk link.Emit{
1394 .directory = directory,
1395 .sub_path = emit_implib.basename,
1396 };
1397 }
1398
1399 // Use the same directory as the bin. The CLI already emits an
1400 // error if -fno-emit-bin is combined with -femit-implib.
1401 break :blk link.Emit{
1402 .directory = bin_file_emit.?.directory,
1403 .sub_path = emit_implib.basename,
1404 };
1405 };
1406
13791407 var system_libs: std.StringArrayHashMapUnmanaged(SystemLib) = .{};
13801408 errdefer system_libs.deinit(gpa);
13811409 try system_libs.ensureTotalCapacity(gpa, options.system_lib_names.len);
......@@ -1385,6 +1413,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
13851413
13861414 const bin_file = try link.File.openPath(gpa, .{
13871415 .emit = bin_file_emit,
1416 .implib_emit = implib_emit,
13881417 .root_name = root_name,
13891418 .module = module,
13901419 .target = options.target,
......@@ -1426,6 +1455,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
14261455 .tsaware = options.linker_tsaware,
14271456 .nxcompat = options.linker_nxcompat,
14281457 .dynamicbase = options.linker_dynamicbase,
1458 .linker_optimization = linker_optimization,
14291459 .major_subsystem_version = options.major_subsystem_version,
14301460 .minor_subsystem_version = options.minor_subsystem_version,
14311461 .stack_size_override = options.stack_size_override,
......@@ -1437,7 +1467,6 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
14371467 .eh_frame_hdr = link_eh_frame_hdr,
14381468 .emit_relocs = options.link_emit_relocs,
14391469 .rdynamic = options.rdynamic,
1440 .extra_lld_args = options.lld_argv,
14411470 .soname = options.soname,
14421471 .version = options.version,
14431472 .compatibility_version = options.compatibility_version,
src/link.zig+3-2
......@@ -47,6 +47,8 @@ pub const Options = struct {
4747 /// This is `null` when -fno-emit-bin is used. When `openPath` or `flush` is called,
4848 /// it will have already been null-checked.
4949 emit: ?Emit,
50 /// This is `null` not building a Windows DLL, or when -fno-emit-implib is used.
51 implib_emit: ?Emit,
5052 target: std.Target,
5153 output_mode: std.builtin.OutputMode,
5254 link_mode: std.builtin.LinkMode,
......@@ -97,6 +99,7 @@ pub const Options = struct {
9799 tsaware: bool,
98100 nxcompat: bool,
99101 dynamicbase: bool,
102 linker_optimization: u8,
100103 bind_global_refs_locally: bool,
101104 import_memory: bool,
102105 initial_memory: ?u64,
......@@ -131,8 +134,6 @@ pub const Options = struct {
131134 version_script: ?[]const u8,
132135 soname: ?[]const u8,
133136 llvm_cpu_features: ?[*:0]const u8,
134 /// Extra args passed directly to LLD. Ignored when not linking with LLD.
135 extra_lld_args: []const []const u8,
136137
137138 objects: []const []const u8,
138139 framework_dirs: []const []const u8,
src/link/Coff.zig+6-2
......@@ -927,7 +927,6 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void {
927927 try man.addOptionalFile(module_obj_path);
928928 man.hash.addOptional(self.base.options.stack_size_override);
929929 man.hash.addOptional(self.base.options.image_base_override);
930 man.hash.addListOfBytes(self.base.options.extra_lld_args);
931930 man.hash.addListOfBytes(self.base.options.lib_dirs);
932931 man.hash.add(self.base.options.skip_linker_dependencies);
933932 if (self.base.options.link_libc) {
......@@ -978,7 +977,6 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void {
978977 }
979978
980979 const full_out_path = try directory.join(arena, &[_][]const u8{self.base.options.emit.?.sub_path});
981
982980 if (self.base.options.output_mode == .Obj) {
983981 // LLD's COFF driver does not support the equivalent of `-r` so we do a simple file copy
984982 // here. TODO: think carefully about how we can avoid this redundant operation when doing
......@@ -1056,6 +1054,7 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void {
10561054 if (self.base.options.dynamicbase) {
10571055 try argv.append("-dynamicbase");
10581056 }
1057
10591058 const subsystem_suffix = ss: {
10601059 if (self.base.options.major_subsystem_version) |major| {
10611060 if (self.base.options.minor_subsystem_version) |minor| {
......@@ -1069,6 +1068,11 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void {
10691068
10701069 try argv.append(try allocPrint(arena, "-OUT:{s}", .{full_out_path}));
10711070
1071 if (self.base.options.implib_emit) |emit| {
1072 const implib_out_path = try emit.directory.join(arena, &[_][]const u8{emit.sub_path});
1073 try argv.append(try allocPrint(arena, "-IMPLIB:{s}", .{implib_out_path}));
1074 }
1075
10721076 if (self.base.options.link_libc) {
10731077 if (self.base.options.libc_installation) |libc_installation| {
10741078 try argv.append(try allocPrint(arena, "-LIBPATH:{s}", .{libc_installation.crt_dir.?}));
src/link/Elf.zig+6-5
......@@ -1322,7 +1322,6 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
13221322 man.hash.add(self.base.options.eh_frame_hdr);
13231323 man.hash.add(self.base.options.emit_relocs);
13241324 man.hash.add(self.base.options.rdynamic);
1325 man.hash.addListOfBytes(self.base.options.extra_lld_args);
13261325 man.hash.addListOfBytes(self.base.options.lib_dirs);
13271326 man.hash.addListOfBytes(self.base.options.rpath_list);
13281327 man.hash.add(self.base.options.each_lib_rpath);
......@@ -1350,6 +1349,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
13501349 man.hash.add(self.base.options.bind_global_refs_locally);
13511350 man.hash.add(self.base.options.tsan);
13521351 man.hash.addOptionalBytes(self.base.options.sysroot);
1352 man.hash.add(self.base.options.linker_optimization);
13531353
13541354 // We don't actually care whether it's a cache hit or miss; we just need the digest and the lock.
13551355 _ = try man.hit();
......@@ -1426,10 +1426,13 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
14261426 if (self.base.options.lto) {
14271427 switch (self.base.options.optimize_mode) {
14281428 .Debug => {},
1429 .ReleaseSmall => try argv.append("-O2"),
1430 .ReleaseFast, .ReleaseSafe => try argv.append("-O3"),
1429 .ReleaseSmall => try argv.append("--lto-O2"),
1430 .ReleaseFast, .ReleaseSafe => try argv.append("--lto-O3"),
14311431 }
14321432 }
1433 try argv.append(try std.fmt.allocPrint(arena, "-O{d}", .{
1434 self.base.options.linker_optimization,
1435 }));
14331436
14341437 if (self.base.options.output_mode == .Exe) {
14351438 try argv.append("-z");
......@@ -1461,8 +1464,6 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
14611464 try argv.append("--export-dynamic");
14621465 }
14631466
1464 try argv.appendSlice(self.base.options.extra_lld_args);
1465
14661467 if (self.base.options.z_nodelete) {
14671468 try argv.append("-z");
14681469 try argv.append("nodelete");
src/link/Wasm.zig-1
......@@ -714,7 +714,6 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {
714714 try man.addOptionalFile(module_obj_path);
715715 try man.addOptionalFile(compiler_rt_path);
716716 man.hash.addOptional(self.base.options.stack_size_override);
717 man.hash.addListOfBytes(self.base.options.extra_lld_args);
718717 man.hash.add(self.base.options.import_memory);
719718 man.hash.addOptional(self.base.options.initial_memory);
720719 man.hash.addOptional(self.base.options.max_memory);
src/main.zig+104-22
......@@ -317,6 +317,8 @@ const usage_build_generic =
317317 \\ -fno-emit-docs (default) Do not produce docs/ dir with html documentation
318318 \\ -femit-analysis[=path] Write analysis JSON file with type information
319319 \\ -fno-emit-analysis (default) Do not write analysis JSON file with type information
320 \\ -femit-implib[=path] (default) Produce an import .lib when building a Windows DLL
321 \\ -fno-emit-implib Do not produce an import .lib when building a Windows DLL
320322 \\ --show-builtin Output the source of @import("builtin") then exit
321323 \\ --cache-dir [path] Override the local cache directory
322324 \\ --global-cache-dir [path] Override the global cache directory
......@@ -585,6 +587,8 @@ fn buildOutputType(
585587 var emit_llvm_bc: Emit = .no;
586588 var emit_docs: Emit = .no;
587589 var emit_analysis: Emit = .no;
590 var emit_implib: Emit = .yes_default_path;
591 var emit_implib_arg_provided = false;
588592 var target_arch_os_abi: []const u8 = "native";
589593 var target_mcpu: ?[]const u8 = null;
590594 var target_dynamic_linker: ?[]const u8 = null;
......@@ -631,6 +635,7 @@ fn buildOutputType(
631635 var linker_tsaware = false;
632636 var linker_nxcompat = false;
633637 var linker_dynamicbase = false;
638 var linker_optimization: ?u8 = null;
634639 var test_evented_io = false;
635640 var test_no_exec = false;
636641 var stack_size_override: ?u64 = null;
......@@ -671,9 +676,6 @@ fn buildOutputType(
671676 var extra_cflags = std.ArrayList([]const u8).init(gpa);
672677 defer extra_cflags.deinit();
673678
674 var lld_argv = std.ArrayList([]const u8).init(gpa);
675 defer lld_argv.deinit();
676
677679 var lib_dirs = std.ArrayList([]const u8).init(gpa);
678680 defer lib_dirs.deinit();
679681
......@@ -1093,6 +1095,15 @@ fn buildOutputType(
10931095 emit_analysis = .{ .yes = arg["-femit-analysis=".len..] };
10941096 } else if (mem.eql(u8, arg, "-fno-emit-analysis")) {
10951097 emit_analysis = .no;
1098 } else if (mem.eql(u8, arg, "-femit-implib")) {
1099 emit_implib = .yes_default_path;
1100 emit_implib_arg_provided = true;
1101 } else if (mem.startsWith(u8, arg, "-femit-implib=")) {
1102 emit_implib = .{ .yes = arg["-femit-implib=".len..] };
1103 emit_implib_arg_provided = true;
1104 } else if (mem.eql(u8, arg, "-fno-emit-implib")) {
1105 emit_implib = .no;
1106 emit_implib_arg_provided = true;
10961107 } else if (mem.eql(u8, arg, "-dynamic")) {
10971108 link_mode = .Dynamic;
10981109 } else if (mem.eql(u8, arg, "-static")) {
......@@ -1473,8 +1484,18 @@ fn buildOutputType(
14731484 fatal("expected linker arg after '{s}'", .{arg});
14741485 }
14751486 version_script = linker_args.items[i];
1487 } else if (mem.eql(u8, arg, "-O")) {
1488 i += 1;
1489 if (i >= linker_args.items.len) {
1490 fatal("expected linker arg after '{s}'", .{arg});
1491 }
1492 linker_optimization = std.fmt.parseUnsigned(u8, linker_args.items[i], 10) catch |err| {
1493 fatal("unable to parse '{s}': {s}", .{ arg, @errorName(err) });
1494 };
14761495 } else if (mem.startsWith(u8, arg, "-O")) {
1477 try lld_argv.append(arg);
1496 linker_optimization = std.fmt.parseUnsigned(u8, arg["-O".len..], 10) catch |err| {
1497 fatal("unable to parse '{s}': {s}", .{ arg, @errorName(err) });
1498 };
14781499 } else if (mem.eql(u8, arg, "--gc-sections")) {
14791500 linker_gc_sections = true;
14801501 } else if (mem.eql(u8, arg, "--no-gc-sections")) {
......@@ -1637,6 +1658,15 @@ fn buildOutputType(
16371658 fatal("unable to parse -current_version '{s}': {s}", .{ linker_args.items[i], @errorName(err) });
16381659 };
16391660 have_version = true;
1661 } else if (mem.eql(u8, arg, "--out-implib") or
1662 mem.eql(u8, arg, "-implib"))
1663 {
1664 i += 1;
1665 if (i >= linker_args.items.len) {
1666 fatal("expected linker arg after '{s}'", .{arg});
1667 }
1668 emit_implib = .{ .yes = linker_args.items[i] };
1669 emit_implib_arg_provided = true;
16401670 } else {
16411671 warn("unsupported linker arg: {s}", .{arg});
16421672 }
......@@ -1984,11 +2014,15 @@ fn buildOutputType(
19842014 const default_h_basename = try std.fmt.allocPrint(arena, "{s}.h", .{root_name});
19852015 var emit_h_resolved = emit_h.resolve(default_h_basename) catch |err| {
19862016 switch (emit_h) {
1987 .yes => {
1988 fatal("unable to open directory from argument '-femit-h', '{s}': {s}", .{ emit_h.yes, @errorName(err) });
2017 .yes => |p| {
2018 fatal("unable to open directory from argument '-femit-h', '{s}': {s}", .{
2019 p, @errorName(err),
2020 });
19892021 },
19902022 .yes_default_path => {
1991 fatal("unable to open directory from arguments '--name' or '-fsoname', '{s}': {s}", .{ default_h_basename, @errorName(err) });
2023 fatal("unable to open directory from arguments '--name' or '-fsoname', '{s}': {s}", .{
2024 default_h_basename, @errorName(err),
2025 });
19922026 },
19932027 .no => unreachable,
19942028 }
......@@ -1998,11 +2032,15 @@ fn buildOutputType(
19982032 const default_asm_basename = try std.fmt.allocPrint(arena, "{s}.s", .{root_name});
19992033 var emit_asm_resolved = emit_asm.resolve(default_asm_basename) catch |err| {
20002034 switch (emit_asm) {
2001 .yes => {
2002 fatal("unable to open directory from argument '-femit-asm', '{s}': {s}", .{ emit_asm.yes, @errorName(err) });
2035 .yes => |p| {
2036 fatal("unable to open directory from argument '-femit-asm', '{s}': {s}", .{
2037 p, @errorName(err),
2038 });
20032039 },
20042040 .yes_default_path => {
2005 fatal("unable to open directory from arguments '--name' or '-fsoname', '{s}': {s}", .{ default_asm_basename, @errorName(err) });
2041 fatal("unable to open directory from arguments '--name' or '-fsoname', '{s}': {s}", .{
2042 default_asm_basename, @errorName(err),
2043 });
20062044 },
20072045 .no => unreachable,
20082046 }
......@@ -2012,11 +2050,15 @@ fn buildOutputType(
20122050 const default_llvm_ir_basename = try std.fmt.allocPrint(arena, "{s}.ll", .{root_name});
20132051 var emit_llvm_ir_resolved = emit_llvm_ir.resolve(default_llvm_ir_basename) catch |err| {
20142052 switch (emit_llvm_ir) {
2015 .yes => {
2016 fatal("unable to open directory from argument '-femit-llvm-ir', '{s}': {s}", .{ emit_llvm_ir.yes, @errorName(err) });
2053 .yes => |p| {
2054 fatal("unable to open directory from argument '-femit-llvm-ir', '{s}': {s}", .{
2055 p, @errorName(err),
2056 });
20172057 },
20182058 .yes_default_path => {
2019 fatal("unable to open directory from arguments '--name' or '-fsoname', '{s}': {s}", .{ default_llvm_ir_basename, @errorName(err) });
2059 fatal("unable to open directory from arguments '--name' or '-fsoname', '{s}': {s}", .{
2060 default_llvm_ir_basename, @errorName(err),
2061 });
20202062 },
20212063 .no => unreachable,
20222064 }
......@@ -2026,11 +2068,15 @@ fn buildOutputType(
20262068 const default_llvm_bc_basename = try std.fmt.allocPrint(arena, "{s}.bc", .{root_name});
20272069 var emit_llvm_bc_resolved = emit_llvm_bc.resolve(default_llvm_bc_basename) catch |err| {
20282070 switch (emit_llvm_bc) {
2029 .yes => {
2030 fatal("unable to open directory from argument '-femit-llvm-bc', '{s}': {s}", .{ emit_llvm_bc.yes, @errorName(err) });
2071 .yes => |p| {
2072 fatal("unable to open directory from argument '-femit-llvm-bc', '{s}': {s}", .{
2073 p, @errorName(err),
2074 });
20312075 },
20322076 .yes_default_path => {
2033 fatal("unable to open directory from arguments '--name' or '-fsoname', '{s}': {s}", .{ default_llvm_bc_basename, @errorName(err) });
2077 fatal("unable to open directory from arguments '--name' or '-fsoname', '{s}': {s}", .{
2078 default_llvm_bc_basename, @errorName(err),
2079 });
20342080 },
20352081 .no => unreachable,
20362082 }
......@@ -2040,11 +2086,15 @@ fn buildOutputType(
20402086 const default_analysis_basename = try std.fmt.allocPrint(arena, "{s}-analysis.json", .{root_name});
20412087 var emit_analysis_resolved = emit_analysis.resolve(default_analysis_basename) catch |err| {
20422088 switch (emit_analysis) {
2043 .yes => {
2044 fatal("unable to open directory from argument 'femit-analysis', '{s}': {s}", .{ emit_analysis.yes, @errorName(err) });
2089 .yes => |p| {
2090 fatal("unable to open directory from argument '-femit-analysis', '{s}': {s}", .{
2091 p, @errorName(err),
2092 });
20452093 },
20462094 .yes_default_path => {
2047 fatal("unable to open directory from arguments 'name' or 'soname', '{s}': {s}", .{ default_analysis_basename, @errorName(err) });
2095 fatal("unable to open directory from arguments 'name' or 'soname', '{s}': {s}", .{
2096 default_analysis_basename, @errorName(err),
2097 });
20482098 },
20492099 .no => unreachable,
20502100 }
......@@ -2053,8 +2103,10 @@ fn buildOutputType(
20532103
20542104 var emit_docs_resolved = emit_docs.resolve("docs") catch |err| {
20552105 switch (emit_docs) {
2056 .yes => {
2057 fatal("unable to open directory from argument 'femit-docs', '{s}': {s}", .{ emit_h.yes, @errorName(err) });
2106 .yes => |p| {
2107 fatal("unable to open directory from argument '-femit-docs', '{s}': {s}", .{
2108 p, @errorName(err),
2109 });
20582110 },
20592111 .yes_default_path => {
20602112 fatal("unable to open directory 'docs': {s}", .{@errorName(err)});
......@@ -2064,6 +2116,35 @@ fn buildOutputType(
20642116 };
20652117 defer emit_docs_resolved.deinit();
20662118
2119 const is_dyn_lib = switch (output_mode) {
2120 .Obj, .Exe => false,
2121 .Lib => (link_mode orelse .Static) == .Dynamic,
2122 };
2123 const implib_eligible = is_dyn_lib and
2124 emit_bin_loc != null and target_info.target.os.tag == .windows;
2125 if (!implib_eligible) {
2126 if (!emit_implib_arg_provided) {
2127 emit_implib = .no;
2128 } else if (emit_implib != .no) {
2129 fatal("the argument -femit-implib is allowed only when building a Windows DLL", .{});
2130 }
2131 }
2132 const default_implib_basename = try std.fmt.allocPrint(arena, "{s}.lib", .{root_name});
2133 var emit_implib_resolved = emit_implib.resolve(default_implib_basename) catch |err| {
2134 switch (emit_implib) {
2135 .yes => |p| {
2136 fatal("unable to open directory from argument '-femit-implib', '{s}': {s}", .{
2137 p, @errorName(err),
2138 });
2139 },
2140 .yes_default_path => {
2141 fatal("unable to open directory 'docs': {s}", .{@errorName(err)});
2142 },
2143 .no => unreachable,
2144 }
2145 };
2146 defer emit_implib_resolved.deinit();
2147
20672148 const main_pkg: ?*Package = if (root_src_file) |src_path| blk: {
20682149 if (main_pkg_path) |p| {
20692150 const rel_src_path = try fs.path.relative(gpa, p, src_path);
......@@ -2175,13 +2256,13 @@ fn buildOutputType(
21752256 .emit_llvm_bc = emit_llvm_bc_resolved.data,
21762257 .emit_docs = emit_docs_resolved.data,
21772258 .emit_analysis = emit_analysis_resolved.data,
2259 .emit_implib = emit_implib_resolved.data,
21782260 .link_mode = link_mode,
21792261 .dll_export_fns = dll_export_fns,
21802262 .object_format = object_format,
21812263 .optimize_mode = optimize_mode,
21822264 .keep_source_files_loaded = false,
21832265 .clang_argv = clang_argv.items,
2184 .lld_argv = lld_argv.items,
21852266 .lib_dirs = lib_dirs.items,
21862267 .rpath_list = rpath_list.items,
21872268 .c_source_files = c_source_files.items,
......@@ -2231,6 +2312,7 @@ fn buildOutputType(
22312312 .linker_tsaware = linker_tsaware,
22322313 .linker_nxcompat = linker_nxcompat,
22332314 .linker_dynamicbase = linker_dynamicbase,
2315 .linker_optimization = linker_optimization,
22342316 .major_subsystem_version = major_subsystem_version,
22352317 .minor_subsystem_version = minor_subsystem_version,
22362318 .link_eh_frame_hdr = link_eh_frame_hdr,
test/standalone/install_raw_hex/build.zig+24-24
......@@ -35,7 +35,7 @@ pub fn build(b: *Builder) void {
3535 ":1001140000000000000000000000000000000000DB",
3636 ":1001240000000000000000000000000000000000CB",
3737 ":1001340000000000000000000000000000000000BB",
38 ":10014400830202006C020100090000002102010088",
38 ":1001440083020200F401010009000000FE01010025",
3939 ":100154000900000001000000000000000000000091",
4040 ":1001640000080002008001010004000010000000EB",
4141 ":100174000000000000000000000000001F0000005C",
......@@ -44,17 +44,17 @@ pub fn build(b: *Builder) void {
4444 ":1001A40000000000000000001F000000000000002C",
4545 ":1001B400000000000000000000000000000000003B",
4646 ":1001C400000000000000000000000000000000002B",
47 ":1001D4005B02010010000000F40101002C0000008B",
48 ":1001E4003F0201001B0000002B020100130000006D",
49 ":1001F40072656D61696E646572206469766973699C",
50 ":100204006F6E206279207A65726F206F72206E653E",
51 ":100214006761746976652076616C756500636F72D9",
52 ":100224007465782D6D3400696E646578206F75741B",
53 ":10023400206F6620626F756E647300696E74656703",
54 ":1002440065722063617374207472756E6361746582",
55 ":10025400642062697473006469766973696F6E20DF",
56 ":100264006279207A65726F00636F727465785F6D6E",
57 ":100274003400000081B00091FFE700BEFDE7D0B577",
47 ":1001D4000802010010000000190201002C000000B8",
48 ":1001E400460201001B00000062020100130000002F",
49 ":1001F400636F727465785F6D3400636F72746578D1",
50 ":100204002D6D34006469766973696F6E206279209C",
51 ":100214007A65726F0072656D61696E6465722064DF",
52 ":1002240069766973696F6E206279207A65726F20CE",
53 ":100234006F72206E656761746976652076616C758E",
54 ":100244006500696E746567657220636173742074F8",
55 ":1002540072756E6361746564206269747300696E9B",
56 ":10026400646578206F7574206F6620626F756E64A4",
57 ":100274007300000081B00091FFE700BEFDE7D0B538",
5858 ":1002840002AF90B00391029007A800F029F80399F7",
5959 ":100294000020069048680490FFE7049906980190AE",
6060 ":1002A40088420FD2FFE7019903980068405C07F881",
......@@ -89,7 +89,7 @@ pub fn build(b: *Builder) void {
8989 ":1001140000000000000000000000000000000000DB",
9090 ":1001240000000000000000000000000000000000CB",
9191 ":1001340000000000000000000000000000000000BB",
92 ":10014400830202006C020100090000002102010088",
92 ":1001440083020200F401010009000000FE01010025",
9393 ":100154000900000001000000000000000000000091",
9494 ":1001640000080002008001010004000010000000EB",
9595 ":100174000000000000000000000000001F0000005C",
......@@ -98,17 +98,17 @@ pub fn build(b: *Builder) void {
9898 ":1001A40000000000000000001F000000000000002C",
9999 ":1001B400000000000000000000000000000000003B",
100100 ":1001C400000000000000000000000000000000002B",
101 ":1001D4005B02010010000000F40101002C0000008B",
102 ":1001E4003F0201001B0000002B020100130000006D",
103 ":1001F40072656D61696E646572206469766973699C",
104 ":100204006F6E206279207A65726F206F72206E653E",
105 ":100214006761746976652076616C756500636F72D9",
106 ":100224007465782D6D3400696E646578206F75741B",
107 ":10023400206F6620626F756E647300696E74656703",
108 ":1002440065722063617374207472756E6361746582",
109 ":10025400642062697473006469766973696F6E20DF",
110 ":100264006279207A65726F00636F727465785F6D6E",
111 ":100274003400000081B00091FFE700BEFDE7D0B577",
101 ":1001D4000802010010000000190201002C000000B8",
102 ":1001E400460201001B00000062020100130000002F",
103 ":1001F400636F727465785F6D3400636F72746578D1",
104 ":100204002D6D34006469766973696F6E206279209C",
105 ":100214007A65726F0072656D61696E6465722064DF",
106 ":1002240069766973696F6E206279207A65726F20CE",
107 ":100234006F72206E656761746976652076616C758E",
108 ":100244006500696E746567657220636173742074F8",
109 ":1002540072756E6361746564206269747300696E9B",
110 ":10026400646578206F7574206F6620626F756E64A4",
111 ":100274007300000081B00091FFE700BEFDE7D0B538",
112112 ":1002840002AF90B00391029007A800F029F80399F7",
113113 ":100294000020069048680490FFE7049906980190AE",
114114 ":1002A40088420FD2FFE7019903980068405C07F881",