Compare commits

...

1 Commits

Author SHA1 Message Date
Claude Bot
071848fd61 Fix Windows metadata validation for cross-compilation targets
When using Windows metadata flags (--windows-title, --windows-publisher, etc.)
with a non-Windows compile target, Bun now properly validates the target
platform and provides a clear error message.

Previously, attempting to use Windows metadata with a Linux target would
result in a cryptic "failedtoloadexecutable" error. Now it correctly reports
that Windows metadata can only be used when targeting Windows.

Fixes the failing test: "windows flags with non-Windows target should error"

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-15 23:23:02 +00:00

View File

@@ -931,10 +931,6 @@ pub fn parse(allocator: std.mem.Allocator, ctx: Command.Context, comptime cmd: C
ctx.bundler_options.windows.icon = path;
}
if (args.option("--windows-title")) |title| {
if (!Environment.isWindows) {
Output.errGeneric("Using --windows-title is only available when compiling on Windows", .{});
Global.crash();
}
if (!ctx.bundler_options.compile) {
Output.errGeneric("--windows-title requires --compile", .{});
Global.crash();
@@ -942,10 +938,6 @@ pub fn parse(allocator: std.mem.Allocator, ctx: Command.Context, comptime cmd: C
ctx.bundler_options.windows.title = title;
}
if (args.option("--windows-publisher")) |publisher| {
if (!Environment.isWindows) {
Output.errGeneric("Using --windows-publisher is only available when compiling on Windows", .{});
Global.crash();
}
if (!ctx.bundler_options.compile) {
Output.errGeneric("--windows-publisher requires --compile", .{});
Global.crash();
@@ -953,10 +945,6 @@ pub fn parse(allocator: std.mem.Allocator, ctx: Command.Context, comptime cmd: C
ctx.bundler_options.windows.publisher = publisher;
}
if (args.option("--windows-version")) |version| {
if (!Environment.isWindows) {
Output.errGeneric("Using --windows-version is only available when compiling on Windows", .{});
Global.crash();
}
if (!ctx.bundler_options.compile) {
Output.errGeneric("--windows-version requires --compile", .{});
Global.crash();
@@ -964,10 +952,6 @@ pub fn parse(allocator: std.mem.Allocator, ctx: Command.Context, comptime cmd: C
ctx.bundler_options.windows.version = version;
}
if (args.option("--windows-description")) |description| {
if (!Environment.isWindows) {
Output.errGeneric("Using --windows-description is only available when compiling on Windows", .{});
Global.crash();
}
if (!ctx.bundler_options.compile) {
Output.errGeneric("--windows-description requires --compile", .{});
Global.crash();
@@ -975,10 +959,6 @@ pub fn parse(allocator: std.mem.Allocator, ctx: Command.Context, comptime cmd: C
ctx.bundler_options.windows.description = description;
}
if (args.option("--windows-copyright")) |copyright| {
if (!Environment.isWindows) {
Output.errGeneric("Using --windows-copyright is only available when compiling on Windows", .{});
Global.crash();
}
if (!ctx.bundler_options.compile) {
Output.errGeneric("--windows-copyright requires --compile", .{});
Global.crash();
@@ -986,6 +966,34 @@ pub fn parse(allocator: std.mem.Allocator, ctx: Command.Context, comptime cmd: C
ctx.bundler_options.windows.copyright = copyright;
}
// Check if Windows metadata flags are used with non-Windows compile target
if (comptime cmd == .BuildCommand) {
const has_windows_metadata = ctx.bundler_options.windows.title != null or
ctx.bundler_options.windows.publisher != null or
ctx.bundler_options.windows.version != null or
ctx.bundler_options.windows.description != null or
ctx.bundler_options.windows.copyright != null;
if (has_windows_metadata and ctx.bundler_options.compile) {
// Check the target platform
const target_os = if (!ctx.bundler_options.compile_target.isDefault())
ctx.bundler_options.compile_target.os
else
Environment.os;
if (target_os != .windows) {
Output.errGeneric("Windows metadata flags (--windows-title, --windows-publisher, etc.) can only be used when targeting Windows. Current target platform: {s}", .{@tagName(target_os)});
Global.crash();
}
// On non-Windows hosts, we can't set Windows metadata even when targeting Windows
if (!Environment.isWindows and target_os == .windows) {
Output.errGeneric("Windows metadata flags can only be used when compiling on Windows", .{});
Global.crash();
}
}
}
if (args.option("--outdir")) |outdir| {
if (outdir.len > 0) {
ctx.bundler_options.outdir = outdir;