@@ -98,6 +98,10 @@ vcpkg_bin_path: ?[]const u8 = null,
98
98
/// none: Do not use any autodetected include paths.
99
99
rc_includes : enum { any , msvc , gnu , none } = .any ,
100
100
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
+
101
105
installed_path : ? []const u8 ,
102
106
103
107
/// Base address for an executable image.
@@ -319,6 +323,12 @@ pub const Options = struct {
319
323
use_lld : ? bool = null ,
320
324
zig_lib_dir : ? LazyPath = null ,
321
325
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 ,
322
332
323
333
/// deprecated; use `main_mod_path`.
324
334
main_pkg_path : ? LazyPath = null ,
@@ -525,6 +535,15 @@ pub fn create(owner: *std.Build, options: Options) *Compile {
525
535
lp .addStepDependencies (& self .step );
526
536
}
527
537
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
+
528
547
if (self .kind == .lib ) {
529
548
if (self .linkage != null and self .linkage .? == .static ) {
530
549
self .out_lib_filename = self .out_filename ;
@@ -957,6 +976,9 @@ pub fn addCSourceFile(self: *Compile, source: CSourceFile) void {
957
976
source .file .addStepDependencies (& self .step );
958
977
}
959
978
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.
960
982
pub fn addWin32ResourceFile (self : * Compile , source : RcSourceFile ) void {
961
983
// Only the PE/COFF format has a Resource Table, so for any other target
962
984
// the resource file is just ignored.
@@ -1593,6 +1615,10 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
1593
1615
}
1594
1616
}
1595
1617
1618
+ if (self .win32_manifest ) | manifest_file | {
1619
+ try zig_args .append (manifest_file .getPath (b ));
1620
+ }
1621
+
1596
1622
if (transitive_deps .is_linking_libcpp ) {
1597
1623
try zig_args .append ("-lc++" );
1598
1624
}
0 commit comments