-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Fix Windows metadata validation for cross-compilation targets #22703
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
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 <[email protected]>
Updated 5:12 PM PT - Sep 15th, 2025
❌ Your commit
🧪 To try this PR locally: bunx bun-pr 22703 That installs a local version of the PR into your bun-22703 --bun |
WalkthroughRemoved per-flag host OS checks for Windows metadata flags and added BuildCommand-scoped validation. During compile, target OS is derived (explicit compile target or current environment). If Windows metadata is used with non-Windows target, or non-Windows host targets Windows, the command crashes. No public API changes. Changes
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
src/cli/Arguments.zig (3)
970-996
: Drop redundant comptime guard.This block sits inside an enclosing BuildCommand branch already; the inner
if (comptime cmd == .BuildCommand)
is noise.Apply:
- if (comptime cmd == .BuildCommand) { - const has_windows_metadata = ctx.bundler_options.windows.title != null or + // Validate Windows metadata usage (BuildCommand context) + 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; @@ - }
977-983
: Optional debug trace to aid support.Add a scoped debug log showing derived target/host only when crash tracing is enabled. Aligns with repo logging guidance.
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 (Environment.show_crash_trace) { + const log = Output.scoped(.cli, false); + log("validate windows metadata: target_os={s}, host_is_windows={}", .{ @tagName(target_os), Environment.isWindows }); + }
984-994
: Tighten wording of errors (nit).Avoid “etc.” and say “OS” to be precise; add a brief remediation hint for cross-compiles.
- 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)}); + if (target_os != .windows) { + Output.errGeneric("Windows metadata flags can only be used when targeting Windows. Current target OS: {s}", .{@tagName(target_os)}); Global.crash(); } @@ - if (!Environment.isWindows and target_os == .windows) { - Output.errGeneric("Windows metadata flags can only be used when compiling on Windows", .{}); + if (!Environment.isWindows and target_os == .windows) { + Output.errGeneric("Windows metadata flags can only be used when compiling on Windows. Run this build on a Windows host.", .{}); Global.crash(); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
src/cli/Arguments.zig
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/**/*.zig
📄 CodeRabbit inference engine (.cursor/rules/building-bun.mdc)
Implement debug logs in Zig using
const log = bun.Output.scoped(.${SCOPE}, false);
and invokinglog("...", .{})
Files:
src/cli/Arguments.zig
**/*.zig
📄 CodeRabbit inference engine (.cursor/rules/javascriptcore-class.mdc)
**/*.zig
: Declare the extern C symbol in Zig and export a Zig-friendly alias for use
Wrap the Bun____toJS extern in a Zig method that takes a JSGlobalObject and returns JSC.JSValue
**/*.zig
: Format Zig files with zig-format (bun run zig-format)
In Zig, manage memory carefully with allocators and use defer for cleanup
Files:
src/cli/Arguments.zig
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Format
🔇 Additional comments (1)
src/cli/Arguments.zig (1)
969-996
: Validation logic LGTM; matches PR intent.Correctly derives target OS, gates on --compile, and emits clear errors for non-Windows targets and non-Windows hosts. Nice placement after options are parsed.
Please confirm the two user-visible error strings are exactly what your tests assert against (including punctuation/casing).
Summary
Problem
When using Windows metadata flags (
--windows-title
,--windows-publisher
, etc.) with a non-Windows compile target (e.g.,--target bun-linux-x64
), the error message was unclear:Solution
Added proper validation that checks:
Now provides clear error messages:
"Windows metadata flags... can only be used when targeting Windows. Current target platform: linux"
"Windows metadata flags can only be used when compiling on Windows"
Test Status
✅ The failing test
"windows flags with non-Windows target should error"
now passes✅ Verified both error scenarios work correctly
🤖 Generated with Claude Code