Skip to content

Conversation

robobun
Copy link
Collaborator

@robobun robobun commented Sep 15, 2025

Summary

  • Fixed validation for Windows metadata flags when cross-compiling to non-Windows targets
  • Provides clear error messages when Windows metadata is used with incompatible targets

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:

error: expect(received).toContain(expected)
Expected to contain: "target platform"
Received: "failed to set windows metadata: failedtoloadexecutable\n"

Solution

Added proper validation that checks:

  1. Whether Windows metadata flags are being used with a non-Windows compile target
  2. Whether the host platform supports setting Windows metadata (must be Windows)

Now provides clear error messages:

  • When targeting non-Windows: "Windows metadata flags... can only be used when targeting Windows. Current target platform: linux"
  • When cross-compiling to Windows from non-Windows: "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

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]>
@robobun
Copy link
Collaborator Author

robobun commented Sep 15, 2025

Updated 5:12 PM PT - Sep 15th, 2025

❌ Your commit 071848fd has 2 failures in Build #26110 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 22703

That installs a local version of the PR into your bun-22703 executable, so you can run:

bun-22703 --bun

Copy link
Contributor

coderabbitai bot commented Sep 15, 2025

Walkthrough

Removed 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

Cohort / File(s) Summary
CLI argument validation
src/cli/Arguments.zig
Removed per-flag Windows-only checks. Added BuildCommand-scoped validation: resolves target OS (from compile_target.os or environment), and errors if Windows metadata is used for non-Windows targets or when targeting Windows from a non-Windows host during --compile. No exported/public signatures changed.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title "Fix Windows metadata validation for cross-compilation targets" succinctly and accurately summarizes the primary change—correcting validation and error messages for Windows metadata flags when targeting or building for non-Windows platforms. It directly matches the PR objectives and raw summary about validating Windows metadata usage during cross-compilation and hosts. The title is concise, specific, and appropriate for a teammate scanning commit history.
Description Check ✅ Passed The description provides a clear Summary, Problem, Solution, and Test Status that explain what the PR does and reports verification that the failing test now passes, so the core information required by the template is present. It does not strictly use the repository's exact template headings ("What does this PR do?" and "How did you verify your code works?") and the verification details are brief rather than step-by-step. Because the essential details and test outcomes are included, the check passes but the description should be aligned to the template for clarity and reproducibility.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch claude/fix-windows-metadata-validation

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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.

📥 Commits

Reviewing files that changed from the base of the PR and between 0351bd5 and 071848f.

📒 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 invoking log("...", .{})

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).

@markovejnovic markovejnovic self-requested a review September 16, 2025 00:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant