Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/std/Build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,12 @@ pub const ExecutableOptions = struct {
use_lld: ?bool = null,
zig_lib_dir: ?LazyPath = null,
main_mod_path: ?LazyPath = null,
/// Embed a `.manifest` file in the compilation if the object format supports it.
/// https://learn.microsoft.com/en-us/windows/win32/sbscs/manifest-files-reference
/// Manifest files must have the extension `.manifest`.
/// 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,

/// Deprecated; use `main_mod_path`.
main_pkg_path: ?LazyPath = null,
Expand All @@ -656,6 +662,7 @@ pub fn addExecutable(b: *Build, options: ExecutableOptions) *Step.Compile {
.use_lld = options.use_lld,
.zig_lib_dir = options.zig_lib_dir orelse b.zig_lib_dir,
.main_mod_path = options.main_mod_path orelse options.main_pkg_path,
.win32_manifest = options.win32_manifest,
});
}

Expand Down Expand Up @@ -706,6 +713,12 @@ pub const SharedLibraryOptions = struct {
use_lld: ?bool = null,
zig_lib_dir: ?LazyPath = null,
main_mod_path: ?LazyPath = null,
/// Embed a `.manifest` file in the compilation if the object format supports it.
/// https://learn.microsoft.com/en-us/windows/win32/sbscs/manifest-files-reference
/// Manifest files must have the extension `.manifest`.
/// 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,

/// Deprecated; use `main_mod_path`.
main_pkg_path: ?LazyPath = null,
Expand All @@ -727,6 +740,7 @@ pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *Step.Compile
.use_lld = options.use_lld,
.zig_lib_dir = options.zig_lib_dir orelse b.zig_lib_dir,
.main_mod_path = options.main_mod_path orelse options.main_pkg_path,
.win32_manifest = options.win32_manifest,
});
}

Expand Down
26 changes: 26 additions & 0 deletions lib/std/Build/Step/Compile.zig
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ vcpkg_bin_path: ?[]const u8 = null,
/// none: Do not use any autodetected include paths.
rc_includes: enum { any, msvc, gnu, none } = .any,

/// (Windows) .manifest file to embed in the compilation
/// Set via options; intended to be read-only after that.
win32_manifest: ?LazyPath = null,

installed_path: ?[]const u8,

/// Base address for an executable image.
Expand Down Expand Up @@ -319,6 +323,12 @@ pub const Options = struct {
use_lld: ?bool = null,
zig_lib_dir: ?LazyPath = null,
main_mod_path: ?LazyPath = null,
/// Embed a `.manifest` file in the compilation if the object format supports it.
/// https://learn.microsoft.com/en-us/windows/win32/sbscs/manifest-files-reference
/// Manifest files must have the extension `.manifest`.
/// 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,

/// deprecated; use `main_mod_path`.
main_pkg_path: ?LazyPath = null,
Expand Down Expand Up @@ -525,6 +535,15 @@ pub fn create(owner: *std.Build, options: Options) *Compile {
lp.addStepDependencies(&self.step);
}

// Only the PE/COFF format has a Resource Table which is where the manifest
// gets embedded, so for any other target the manifest file is just ignored.
if (self.target.getObjectFormat() == .coff) {
if (options.win32_manifest) |lp| {
self.win32_manifest = lp.dupe(self.step.owner);
lp.addStepDependencies(&self.step);
}
}

if (self.kind == .lib) {
if (self.linkage != null and self.linkage.? == .static) {
self.out_lib_filename = self.out_filename;
Expand Down Expand Up @@ -957,6 +976,9 @@ pub fn addCSourceFile(self: *Compile, source: CSourceFile) void {
source.file.addStepDependencies(&self.step);
}

/// Resource files must have the extension `.rc`.
/// Can be called regardless of target. The .rc file will be ignored
/// if the target object format does not support embedded resources.
pub fn addWin32ResourceFile(self: *Compile, source: RcSourceFile) void {
// Only the PE/COFF format has a Resource Table, so for any other target
// the resource file is just ignored.
Expand Down Expand Up @@ -1593,6 +1615,10 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
}
}

if (self.win32_manifest) |manifest_file| {
try zig_args.append(manifest_file.getPath(b));
}

if (transitive_deps.is_linking_libcpp) {
try zig_args.append("-lc++");
}
Expand Down
Loading