build: Use try_compile for robust RVV toolchain detection #3905
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Description
This PR significantly improves the reliability of the RISC-V Vector (RVV) feature detection in the CMake build system. It replaces the previous brittle architecture name check with a robust
try_compile-based toolchain validation.Motivation and Context
The existing method for enabling RVV optimizations relied solely on checking if the target architecture string matched
riscv64. This approach is fragile and can cause the build to fail in several common scenarios:The goal of this PR is to prevent these build failures by verifying the compiler's capabilities directly, ensuring a smoother and more reliable experience for developers targeting RISC-V.
Key Changes
if (... MATCHES "riscv64")logic has been replaced with a more intelligenttry_compileblock.-march=rv64gcvflag and defines the__riscv_vmacro, which is the standard-compliant way to verify vector support.STATUSandWARNINGmessages are now provided to inform the user about the result of the toolchain check.CMakeFiles/CMakeTmp) used bytry_compileis now removed after the check, ensuring a clean build directory.How Has This Been Tested?
I have tested this new logic on my development environment:
This change should make the build process much more robust for all developers working with the RISC-V backend.