Skip to content

feat: auto-detect MSVC outside VS shell#1587

Open
peter-jerry-ye wants to merge 1 commit into
mainfrom
feat/find-msvc-tools-auto-detect
Open

feat: auto-detect MSVC outside VS shell#1587
peter-jerry-ye wants to merge 1 commit into
mainfrom
feat/find-msvc-tools-auto-detect

Conversation

@peter-jerry-ye

@peter-jerry-ye peter-jerry-ye commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

Summary

  • keep the existing PATH-based native compiler detection for cl, cc, gcc, and clang
  • on Windows, if none of those are available on PATH, use find-msvc-tools to discover cl.exe
  • capture the discovered MSVC environment and replay it only for the native C commands that need it
  • keep the scope narrow by threading only fallback native link syntax into build_plan
  • update docs, shell completion snapshots, and Windows CI to reflect the new default workflow

Why

Windows users should be able to build native targets without starting from a Visual Studio Developer Command Prompt.

Scope

  • explicit compiler overrides still win
  • PATH-based detection still wins when available
  • the MSVC environment overlay is only used for the auto-detected default MSVC toolchain
  • the change is isolated to native toolchain auto-detection and native C command execution

@semanticdiff-com

semanticdiff-com Bot commented Apr 1, 2026

Copy link
Copy Markdown

Review changes with  SemanticDiff

Changed Files
File Status
  crates/moonbuild-rupes-recta/src/build_lower/compiler/link_core.rs  58% smaller
  crates/moonbuild-rupes-recta/src/build_plan/builders.rs  37% smaller
  crates/moonbuild-rupes-recta/src/build_lower/lower_aux.rs  29% smaller
  crates/moonbuild-rupes-recta/src/build_lower/lower_build.rs  21% smaller
  crates/moonbuild-rupes-recta/src/compile/mod.rs  12% smaller
  crates/moonbuild-rupes-recta/src/build_lower/context.rs  9% smaller
  crates/moonutil/src/compiler_flags.rs  2% smaller
  crates/moonbuild-rupes-recta/src/build_lower/mod.rs  2% smaller
  .github/workflows/ci.yml  0% smaller
  Cargo.lock Unsupported file format
  crates/moon/src/cli/snapshots/shell_completion_bash.stdout Unsupported file format
  crates/moon/src/cli/snapshots/shell_completion_elvish.stdout Unsupported file format
  crates/moon/src/cli/snapshots/shell_completion_fish.stdout Unsupported file format
  crates/moon/src/cli/snapshots/shell_completion_powershell.stdout Unsupported file format
  crates/moon/src/cli/snapshots/shell_completion_zsh.stdout Unsupported file format
  crates/moon/src/cli/tool.rs  0% smaller
  crates/moon/src/cli/tool/env_exec.rs  0% smaller
  crates/moonbuild-rupes-recta/Cargo.toml Unsupported file format
  crates/moonbuild-rupes-recta/src/build_plan/mod.rs  0% smaller
  crates/moonutil/Cargo.toml Unsupported file format
  docs/dev/reference/native-c-toolchain-resolution.md Unsupported file format

@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: dddfc109de

ℹ️ 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 on lines +272 to +275
#[cfg(windows)]
if let Some(msvc_cc) = detect_msvc_with_find_msvc_tools() {
return msvc_cc;
}

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 Honor explicit compiler overrides before forcing MSVC

The new early return in DETECTED_CC makes cl.exe win whenever Visual Studio is installed, even if users set MOON_CC to a GCC/Clang toolchain. In this repo, propagate_link_config still consults DETECTED_CC when native.cc is unset (crates/moonbuild-rupes-recta/src/build_plan/builders.rs:1029), so this change can now emit MSVC-style link args (foo.lib, /LIBPATH:) while the actual compiler is non-MSVC, breaking native linking for mixed/MinGW setups that previously worked unless cl was already on PATH.

Useful? React with 👍 / 👎.

@tonyfettes tonyfettes Apr 1, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Confirmed:

$env:MOON_CC="clang"
moon test -v
failed: clang -o C:\Users\mbt\Workspace\tonyfettes-raylib\_build\native\debug\test\internal\raylib\raylib.blackbox_test.exe -IC:\Users\mbt\.moon\include -g -fwrapv -fno-strict-aliasing -Wno-unused-value C:\Users\mbt\Workspace\tonyfettes-raylib\_build\native\debug\test\internal\raylib\raylib.blackbox_test.c C:\Users\mbt\Workspace\tonyfettes-raylib\_build\native\debug\test\runtime.obj C:\Users\mbt\Workspace\tonyfettes-raylib\_build\native\debug\test\internal\raylib\libraylib.lib -lm opengl32.lib gdi32.lib winmm.lib user32.lib shell32.lib opengl32.lib gdi32.lib winmm.lib user32.lib shell32.lib
clang: error: no such file or directory: 'opengl32.lib'
clang: error: no such file or directory: 'gdi32.lib'
clang: error: no such file or directory: 'winmm.lib'
clang: error: no such file or directory: 'user32.lib'
clang: error: no such file or directory: 'shell32.lib'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This should have been fixed.

Comment thread crates/moonutil/src/compiler_flags.rs Outdated

@tonyfettes tonyfettes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Compile and link correctly on Windows when MSVC is configured but not added to path.

Reproduced the bug spotted by Codex. See above for more information.

@peter-jerry-ye peter-jerry-ye force-pushed the feat/find-msvc-tools-auto-detect branch 2 times, most recently from da8049a to 3cef384 Compare April 16, 2026 03:40
@peter-jerry-ye peter-jerry-ye force-pushed the feat/find-msvc-tools-auto-detect branch from 3cef384 to 75ccf3f Compare April 16, 2026 05:39
@peter-jerry-ye peter-jerry-ye changed the title feat: auto-detect MSVC toolchain with find-msvc-tools feat: auto-detect MSVC outside VS shell Apr 16, 2026
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.

2 participants