Skip to content

Commit

Permalink
Ensure that the correct VC++ toolset is selected in all build environ…
Browse files Browse the repository at this point in the history
…ments (#104763)

* Second attempt at fixing ARM64 cross compilation

* Update eng/native/init-vs-env.cmd

Co-authored-by: Jan Kotas <jkotas@microsoft.com>

* Remove x86 branch

* Revert to using __HostArch when determining toolset.

* Address feedback.

* Update eng/native/init-vs-env.cmd

Co-authored-by: Jan Kotas <jkotas@microsoft.com>

* Update eng/native/init-vs-env.cmd

Co-authored-by: Jan Kotas <jkotas@microsoft.com>

* Revert "Update eng/native/init-vs-env.cmd"

This reverts commit a1b95c1.

* Revert "Update eng/native/init-vs-env.cmd"

This reverts commit 1eeadb3.

* Set the correct arm64 assembler host

---------

Co-authored-by: Jan Kotas <jkotas@microsoft.com>
  • Loading branch information
eiriktsarpalis and jkotas authored Jul 13, 2024
1 parent 53a3624 commit 369db9a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 33 deletions.
26 changes: 6 additions & 20 deletions eng/native/configurecompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -976,27 +976,13 @@ endif()

# Ensure other tools are present
if (CLR_CMAKE_HOST_WIN32)
if(CLR_CMAKE_HOST_ARCH_ARM)

# Explicitly specify the assembler to be used for Arm32 compile
file(TO_CMAKE_PATH "$ENV{VCToolsInstallDir}\\bin\\HostX86\\arm\\armasm.exe" CMAKE_ASM_COMPILER)

set(CMAKE_ASM_MASM_COMPILER ${CMAKE_ASM_COMPILER})
message("CMAKE_ASM_MASM_COMPILER explicitly set to: ${CMAKE_ASM_MASM_COMPILER}")

# Enable generic assembly compilation to avoid CMake generate VS proj files that explicitly
# use ml[64].exe as the assembler.
enable_language(ASM)
set(CMAKE_ASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreaded "")
set(CMAKE_ASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDLL "")
set(CMAKE_ASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebug "")
set(CMAKE_ASM_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY_MultiThreadedDebugDLL "")
set(CMAKE_ASM_COMPILE_OBJECT "<CMAKE_ASM_COMPILER> -g <INCLUDES> <FLAGS> -o <OBJECT> <SOURCE>")

elseif(CLR_CMAKE_HOST_ARCH_ARM64)

if(CLR_CMAKE_HOST_ARCH_ARM64)
# Explicitly specify the assembler to be used for Arm64 compile
file(TO_CMAKE_PATH "$ENV{VCToolsInstallDir}\\bin\\HostX86\\arm64\\armasm64.exe" CMAKE_ASM_COMPILER)
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "ARM64")
file(TO_CMAKE_PATH "$ENV{VCToolsInstallDir}\\bin\\Hostarm64\\arm64\\armasm64.exe" CMAKE_ASM_COMPILER)
else()
file(TO_CMAKE_PATH "$ENV{VCToolsInstallDir}\\bin\\HostX64\\arm64\\armasm64.exe" CMAKE_ASM_COMPILER)
endif()

set(CMAKE_ASM_MASM_COMPILER ${CMAKE_ASM_COMPILER})
message("CMAKE_ASM_MASM_COMPILER explicitly set to: ${CMAKE_ASM_MASM_COMPILER}")
Expand Down
15 changes: 11 additions & 4 deletions eng/native/init-vs-env.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@
:: as an argument, it also initializes VC++ build environment and CMakePath.

set "__VCBuildArch="
if /i "%~1" == "x86" (set __VCBuildArch=x86)
if /i "%~1" == "x64" (set __VCBuildArch=x86_amd64)
if /i "%~1" == "arm64" (if /i "%PROCESSOR_ARCHITECTURE%" == "ARM64" (set __VCBuildArch=arm64) else (set __VCBuildArch=x86_arm64))
if /i "%~1" == "wasm" (if /i "%PROCESSOR_ARCHITECTURE%" == "ARM64" (set __VCBuildArch=arm64) else (set __VCBuildArch=x86_amd64))
if /i "%PROCESSOR_ARCHITECTURE%" == "ARM64" (
if /i "%~1" == "x64" ( set __VCBuildArch=arm64_amd64 )
if /i "%~1" == "x86" ( set __VCBuildArch=arm64_x86 )
if /i "%~1" == "arm64" ( set __VCBuildArch=arm64 )
if /i "%~1" == "wasm" ( set __VCBuildArch=arm64 )
) else (
if /i "%~1" == "x64" ( set __VCBuildArch=amd64 )
if /i "%~1" == "x86" ( set __VCBuildArch=amd64_x86 )
if /i "%~1" == "arm64" ( set __VCBuildArch=amd64_arm64 )
if /i "%~1" == "wasm" ( set __VCBuildArch=amd64 )
)

:: Default to highest Visual Studio version available that has Visual C++ tools.
::
Expand Down
19 changes: 10 additions & 9 deletions src/coreclr/build-runtime.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,6 @@ if %__TotalSpecifiedTargetArch% GTR 1 (
goto Usage
)

set __ProcessorArch=%PROCESSOR_ARCHITEW6432%
if "%__ProcessorArch%"=="" set __ProcessorArch=%PROCESSOR_ARCHITECTURE%

if %__TargetArchX64%==1 set __TargetArch=x64
if %__TargetArchX86%==1 set __TargetArch=x86
if %__TargetArchArm%==1 set __TargetArch=arm
Expand Down Expand Up @@ -361,15 +358,19 @@ if %__BuildNative% EQU 1 (
echo %__MsgPrefix%Commencing build of native components for %__TargetOS%.%__TargetArch%.%__BuildType%

REM Set the environment for the native build
set __VCTargetArch=amd64
if /i "%__HostArch%" == "x86" ( set __VCTargetArch=x86 )
if /i "%__HostArch%" == "arm64" (
if /i "%__ProcessorArch%" == "ARM64" (set __VCTargetArch=arm64) else (set __VCTargetArch=x86_arm64)
if /i "%PROCESSOR_ARCHITECTURE%" == "ARM64" (
set __VCBuildArch=arm64
if /i "%__HostArch%" == "x64" ( set __VCBuildArch=arm64_amd64 )
if /i "%__HostArch%" == "x86" ( set __VCBuildArch=arm64_x86 )
) else (
set __VCBuildArch=amd64
if /i "%__HostArch%" == "x86" ( set __VCBuildArch=amd64_x86 )
if /i "%__HostArch%" == "arm64" ( set __VCBuildArch=amd64_arm64 )
)

if NOT DEFINED SkipVCEnvInit (
echo %__MsgPrefix%Using environment: "%__VCToolsRoot%\vcvarsall.bat" !__VCTargetArch!
call "%__VCToolsRoot%\vcvarsall.bat" !__VCTargetArch!
echo %__MsgPrefix%Using environment: "%__VCToolsRoot%\vcvarsall.bat" !__VCBuildArch!
call "%__VCToolsRoot%\vcvarsall.bat" !__VCBuildArch!
)
@if defined _echo @echo on

Expand Down

0 comments on commit 369db9a

Please sign in to comment.