@@ -98,6 +98,10 @@ vcpkg_bin_path: ?[]const u8 = null,
9898/// none: Do not use any autodetected include paths.
9999rc_includes : enum { any , msvc , gnu , none } = .any ,
100100
101+ /// (Windows) .manifest file to embed in the compilation
102+ /// Set via options; intended to be read-only after that.
103+ win32_manifest : ? LazyPath = null ,
104+
101105installed_path : ? []const u8 ,
102106
103107/// Base address for an executable image.
@@ -319,6 +323,12 @@ pub const Options = struct {
319323 use_lld : ? bool = null ,
320324 zig_lib_dir : ? LazyPath = null ,
321325 main_mod_path : ? LazyPath = null ,
326+ /// Embed a `.manifest` file in the compilation if the object format supports it.
327+ /// https://learn.microsoft.com/en-us/windows/win32/sbscs/manifest-files-reference
328+ /// Manifest files must have the extension `.manifest`.
329+ /// Can be set regardless of target. The `.manifest` file will be ignored
330+ /// if the target object format does not support embedded manifests.
331+ win32_manifest : ? LazyPath = null ,
322332
323333 /// deprecated; use `main_mod_path`.
324334 main_pkg_path : ? LazyPath = null ,
@@ -525,6 +535,15 @@ pub fn create(owner: *std.Build, options: Options) *Compile {
525535 lp .addStepDependencies (& self .step );
526536 }
527537
538+ // Only the PE/COFF format has a Resource Table which is where the manifest
539+ // gets embedded, so for any other target the manifest file is just ignored.
540+ if (self .target .getObjectFormat () == .coff ) {
541+ if (options .win32_manifest ) | lp | {
542+ self .win32_manifest = lp .dupe (self .step .owner );
543+ lp .addStepDependencies (& self .step );
544+ }
545+ }
546+
528547 if (self .kind == .lib ) {
529548 if (self .linkage != null and self .linkage .? == .static ) {
530549 self .out_lib_filename = self .out_filename ;
@@ -957,6 +976,9 @@ pub fn addCSourceFile(self: *Compile, source: CSourceFile) void {
957976 source .file .addStepDependencies (& self .step );
958977}
959978
979+ /// Resource files must have the extension `.rc`.
980+ /// Can be called regardless of target. The .rc file will be ignored
981+ /// if the target object format does not support embedded resources.
960982pub fn addWin32ResourceFile (self : * Compile , source : RcSourceFile ) void {
961983 // Only the PE/COFF format has a Resource Table, so for any other target
962984 // the resource file is just ignored.
@@ -1593,6 +1615,10 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
15931615 }
15941616 }
15951617
1618+ if (self .win32_manifest ) | manifest_file | {
1619+ try zig_args .append (manifest_file .getPath (b ));
1620+ }
1621+
15961622 if (transitive_deps .is_linking_libcpp ) {
15971623 try zig_args .append ("-lc++" );
15981624 }
0 commit comments