Skip to content

cmd: validate explicit C compiler before dispatch#27871

Open
GitHackerz wants to merge 2 commits into
vlang:masterfrom
GitHackerz:fix-cc-validation-order
Open

cmd: validate explicit C compiler before dispatch#27871
GitHackerz wants to merge 2 commits into
vlang:masterfrom
GitHackerz:fix-cc-validation-order

Conversation

@GitHackerz

Copy link
Copy Markdown

What

Validate an explicitly selected C compiler before command dispatch on Windows.

Why

An invalid -cc value could reach command handling first when no command or an invalid command was supplied, hiding the useful missing-compiler diagnostic. This reuses the existing Windows C-compiler validation and adds a regression test for both cases.

Fixes #27868

Tests

  • v test-all
  • v test cmd/v/v_windows_test.v

@medvednikov

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e470ea5181

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread cmd/v/v.v Outdated
Comment on lines +122 to +123
if builder.should_find_windows_host_c_compiler(prefs) && prefs.ccompiler_set_by_flag
&& prefs.ccompiler != 'msvc' {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Do not validate -cc before non-build commands

On Windows this probe runs immediately after parsing, before the dispatch below decides whether the command is help, version, or an external tool such as fmt. As a result, v -cc missing help, v -cc missing version, or a stale VFLAGS=-cc missing now exits with a missing-C-compiler error even though those commands do not compile user code and previously reached their normal handlers; scope the early check to build/source/unknown-command paths that actually need this precedence.

Useful? React with 👍 / 👎.

@medvednikov

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b28e283703

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread cmd/v/v.v
if builder.should_find_windows_host_c_compiler(prefs) && prefs.ccompiler_set_by_flag
&& prefs.ccompiler != 'msvc' {
mut probe := builder.Builder{
pref: unsafe { prefs }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Avoid initializing Builder private fields from cmd/v

On Windows this $if windows block is type-checked from module main, but Builder.pref is a private field declared in vlib/v/builder/builder.v; cross-module struct initialization of private fields is rejected by the checker. As a result, rebuilding the compiler on Windows fails here before the new -cc diagnostic can run, so the probe needs to be exposed through a builder-side helper or otherwise avoid setting private fields from cmd/v.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review. This is not a visibility issue: Builder.pref is declared under pub mut: in vlib/v/builder/builder.v, so it is accessible from cmd/v.
I rebuilt the compiler from this PR on Windows successfully (v -g -keepc -o vreview.exe cmd/v) and ran v test-all on the current commit. No checker error occurs for this struct initialization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI validates commands before checking -cc flag validity, resulting in "unknown command ''"

2 participants