aboutsummaryrefslogtreecommitdiff
path: root/src/Compilation.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-11-24 17:47:56 -0800
committerGitHub <noreply@github.com>2021-11-24 17:47:56 -0800
commit0581756453a98d4e1100c684896783606dc86374 (patch)
tree865fcfffdc31cf0b7220d41198266f0627b2d118 /src/Compilation.zig
parentfdcac5ecbd324170f7281f6704ead18b7d904e72 (diff)
parent20cc7af8e6e47ba209ab0d462826f40516c86b9d (diff)
downloadzig-0581756453a98d4e1100c684896783606dc86374.tar.gz
zig-0581756453a98d4e1100c684896783606dc86374.zip
Merge pull request #9347 from kkartaltepe/implib-support
Coff linker: Add IMPLIB support
Diffstat (limited to 'src/Compilation.zig')
-rw-r--r--src/Compilation.zig37
1 files changed, 33 insertions, 4 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig
index 48899f6f6e..4196eb634d 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -654,6 +654,8 @@ pub const InitOptions = struct {
emit_analysis: ?EmitLoc = null,
/// `null` means to not emit docs.
emit_docs: ?EmitLoc = null,
+ /// `null` means to not emit an import lib.
+ emit_implib: ?EmitLoc = null,
link_mode: ?std.builtin.LinkMode = null,
dll_export_fns: ?bool = false,
/// Normally when using LLD to link, Zig uses a file named "lld.id" in the
@@ -667,7 +669,6 @@ pub const InitOptions = struct {
optimize_mode: std.builtin.Mode = .Debug,
keep_source_files_loaded: bool = false,
clang_argv: []const []const u8 = &[0][]const u8{},
- lld_argv: []const []const u8 = &[0][]const u8{},
lib_dirs: []const []const u8 = &[0][]const u8{},
rpath_list: []const []const u8 = &[0][]const u8{},
c_source_files: []const CSourceFile = &[0]CSourceFile{},
@@ -735,6 +736,7 @@ pub const InitOptions = struct {
linker_tsaware: bool = false,
linker_nxcompat: bool = false,
linker_dynamicbase: bool = false,
+ linker_optimization: ?u8 = null,
major_subsystem_version: ?u32 = null,
minor_subsystem_version: ?u32 = null,
clang_passthrough_mode: bool = false,
@@ -944,9 +946,9 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
link_eh_frame_hdr or
options.link_emit_relocs or
options.output_mode == .Lib or
- options.lld_argv.len != 0 or
options.image_base_override != null or
- options.linker_script != null or options.version_script != null)
+ options.linker_script != null or options.version_script != null or
+ options.emit_implib != null)
{
break :blk true;
}
@@ -1139,6 +1141,10 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
const strip = options.strip or !target_util.hasDebugInfo(options.target);
const red_zone = options.want_red_zone orelse target_util.hasRedZone(options.target);
const omit_frame_pointer = options.omit_frame_pointer orelse (options.optimize_mode != .Debug);
+ const linker_optimization: u8 = options.linker_optimization orelse switch (options.optimize_mode) {
+ .Debug => @as(u8, 0),
+ else => @as(u8, 3),
+ };
// We put everything into the cache hash that *cannot be modified during an incremental update*.
// 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 {
cache.hash.add(options.output_mode);
cache.hash.add(options.machine_code_model);
cache.hash.addOptionalEmitLoc(options.emit_bin);
+ cache.hash.addOptionalEmitLoc(options.emit_implib);
cache.hash.addBytes(options.root_name);
if (options.target.os.tag == .wasi) cache.hash.add(wasi_exec_model);
// TODO audit this and make sure everything is in it
@@ -1338,18 +1345,21 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
const bin_file_emit: ?link.Emit = blk: {
const emit_bin = options.emit_bin orelse break :blk null;
+
if (emit_bin.directory) |directory| {
break :blk link.Emit{
.directory = directory,
.sub_path = emit_bin.basename,
};
}
+
if (module) |zm| {
break :blk link.Emit{
.directory = zm.zig_cache_artifact_directory,
.sub_path = emit_bin.basename,
};
}
+
// We could use the cache hash as is no problem, however, we increase
// the likelihood of cache hits by adding the first C source file
// 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 {
};
};
+ const implib_emit: ?link.Emit = blk: {
+ const emit_implib = options.emit_implib orelse break :blk null;
+
+ if (emit_implib.directory) |directory| {
+ break :blk link.Emit{
+ .directory = directory,
+ .sub_path = emit_implib.basename,
+ };
+ }
+
+ // Use the same directory as the bin. The CLI already emits an
+ // error if -fno-emit-bin is combined with -femit-implib.
+ break :blk link.Emit{
+ .directory = bin_file_emit.?.directory,
+ .sub_path = emit_implib.basename,
+ };
+ };
+
var system_libs: std.StringArrayHashMapUnmanaged(SystemLib) = .{};
errdefer system_libs.deinit(gpa);
try system_libs.ensureTotalCapacity(gpa, options.system_lib_names.len);
@@ -1385,6 +1413,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
const bin_file = try link.File.openPath(gpa, .{
.emit = bin_file_emit,
+ .implib_emit = implib_emit,
.root_name = root_name,
.module = module,
.target = options.target,
@@ -1426,6 +1455,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
.tsaware = options.linker_tsaware,
.nxcompat = options.linker_nxcompat,
.dynamicbase = options.linker_dynamicbase,
+ .linker_optimization = linker_optimization,
.major_subsystem_version = options.major_subsystem_version,
.minor_subsystem_version = options.minor_subsystem_version,
.stack_size_override = options.stack_size_override,
@@ -1437,7 +1467,6 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
.eh_frame_hdr = link_eh_frame_hdr,
.emit_relocs = options.link_emit_relocs,
.rdynamic = options.rdynamic,
- .extra_lld_args = options.lld_argv,
.soname = options.soname,
.version = options.version,
.compatibility_version = options.compatibility_version,