Allow build.zig scripts to define module definition files (.def) when building win32 dlls.

This commit is contained in:
antme0
2026-02-08 18:48:54 +01:00
committed by Andrew Kelley
parent f061c0dc28
commit fb18f2096a
3 changed files with 24 additions and 1 deletions
+17
View File
@@ -79,6 +79,10 @@ rc_includes: std.zig.RcIncludes = .any,
/// Set via options; intended to be read-only after that.
win32_manifest: ?LazyPath = null,
/// (Windows) .def file to embed in the compilation (dll)
/// Set via options; intended to be read-only after that.
win32_module_definition: ?LazyPath = null,
installed_path: ?[]const u8,
/// Base address for an executable image.
@@ -284,6 +288,8 @@ pub const Options = struct {
/// Can be set regardless of target. The `.manifest` file will be ignored
/// if the target object format does not support embedded manifests.
win32_manifest: ?LazyPath = null,
/// Win32 module definition file.
win32_module_definition: ?LazyPath = null,
};
pub const Kind = enum {
@@ -467,6 +473,13 @@ pub fn create(owner: *std.Build, options: Options) *Compile {
compile.win32_manifest = lp.dupe(compile.step.owner);
lp.addStepDependencies(&compile.step);
}
if (compile.kind == .lib and compile.linkage != null and compile.linkage.? == .dynamic) {
// Building a Win32 DLL, check for win32 .def file.
if (options.win32_module_definition) |lp| {
compile.win32_module_definition = lp.dupe(compile.step.owner);
lp.addStepDependencies(&compile.step);
}
}
}
if (compile.kind == .lib) {
@@ -1332,6 +1345,10 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 {
try zig_args.append(manifest_file.getPath2(b, step));
}
if (compile.win32_module_definition) |module_file| {
try zig_args.append(module_file.getPath2(b, step));
}
if (compile.image_base) |image_base| {
try zig_args.append("--image-base");
try zig_args.append(b.fmt("0x{x}", .{image_base}));