From 1ffcf98bc8fceff36b52cd97f9228af4a3748f08 Mon Sep 17 00:00:00 2001 From: Jeremy Koritzinsky Date: Fri, 3 May 2019 17:56:20 -0700 Subject: Use our local-built instances of tools from Microsoft.DotNet.BuildTools.CoreClr instead of using the package. (#24347) * Use our local-built instances of tools from Microsoft.DotNet.BuildTools.CoreClr instead of using the package. * Fix const-correctness in InjectResource. * Build cross-arch native components before building native components for target arch. * Build InjectResource and GenClrDebugResource for the host arch when cross-building and import the targets into the cross-build. * install(EXPORT) in the directory where the target is created --- CMakeLists.txt | 4 - build.cmd | 127 ++++++++++++++------------- init-tools.msbuild | 3 - src/dlls/mscoree/coreclr/CMakeLists.txt | 15 +++- src/pal/tools/gen-buildsys-win.bat | 2 +- src/tools/CMakeLists.txt | 8 ++ src/tools/GenClrDebugResource/CMakeLists.txt | 2 + src/tools/InjectResource/CMakeLists.txt | 4 +- src/tools/InjectResource/InjectResource.cpp | 4 +- 9 files changed, 92 insertions(+), 77 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b7715d2b0d..d668a02ef3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -221,10 +221,6 @@ if (CLR_CMAKE_PLATFORM_UNIX) include_directories("src/pal/src/safecrt") endif (CLR_CMAKE_PLATFORM_UNIX) -# Microsoft.Dotnet.BuildTools.Coreclr version -set(BuildToolsVersion "1.0.4-prerelease") -set(BuildToolsDir "${CLR_CMAKE_PACKAGES_DIR}/Microsoft.DotNet.BuildTools.CoreCLR/${BuildToolsVersion}") - #------------------------------ # Add Product Directory #------------------------------ diff --git a/build.cmd b/build.cmd index bd6d355fd9..e9669ca36a 100644 --- a/build.cmd +++ b/build.cmd @@ -459,152 +459,155 @@ if %__BuildCrossArchNative% EQU 1 ( REM ========================================================================================= REM === -REM === Build the CLR VM +REM === Build Cross-Architecture Native Components (if applicable) REM === REM ========================================================================================= -if %__BuildNative% EQU 1 ( +if %__BuildCrossArchNative% EQU 1 ( REM Scope environment changes start { setlocal - echo %__MsgPrefix%Commencing build of native components for %__BuildOS%.%__BuildArch%.%__BuildType% + echo %__MsgPrefix%Commencing build of cross architecture native components for %__BuildOS%.%__BuildArch%.%__BuildType% - REM Set the environment for the native build + REM Set the environment for the cross-arch native build set __VCBuildArch=x86_amd64 - if /i "%__BuildArch%" == "x86" ( set __VCBuildArch=x86 ) - if /i "%__BuildArch%" == "arm" ( - set __VCBuildArch=x86_arm - - REM Make CMake pick the highest installed version in the 10.0.* range - set ___SDKVersion="-DCMAKE_SYSTEM_VERSION=10.0" - ) - if /i "%__BuildArch%" == "arm64" ( - set __VCBuildArch=x86_arm64 - - REM Make CMake pick the highest installed version in the 10.0.* range - set ___SDKVersion="-DCMAKE_SYSTEM_VERSION=10.0" - ) + if /i "%__CrossArch%" == "x86" ( set __VCBuildArch=x86 ) echo %__MsgPrefix%Using environment: "%__VCToolsRoot%\vcvarsall.bat" !__VCBuildArch! call "%__VCToolsRoot%\vcvarsall.bat" !__VCBuildArch! @if defined _echo @echo on - if not defined VSINSTALLDIR ( - echo %__MsgPrefix%Error: VSINSTALLDIR variable not defined. - exit /b 1 - ) - if not exist "!VSINSTALLDIR!DIA SDK" goto NoDIA - - if defined __SkipConfigure goto SkipConfigure - - echo %__MsgPrefix%Regenerating the Visual Studio solution + if not exist "%__CrossCompIntermediatesDir%" md "%__CrossCompIntermediatesDir%" + if defined __SkipConfigure goto SkipConfigureCrossBuild - pushd "%__IntermediatesDir%" - set __ExtraCmakeArgs=!___SDKVersion! "-DCLR_CMAKE_TARGET_OS=%__BuildOS%" "-DCLR_CMAKE_PACKAGES_DIR=%__PackagesDir%" "-DCLR_CMAKE_PGO_INSTRUMENT=%__PgoInstrument%" "-DCLR_CMAKE_OPTDATA_VERSION=%__PgoOptDataVersion%" "-DCLR_CMAKE_PGO_OPTIMIZE=%__PgoOptimize%" - call "%__SourceDir%\pal\tools\gen-buildsys-win.bat" "%__ProjectDir%" %__VSVersion% %__BuildArch% !__ExtraCmakeArgs! + pushd "%__CrossCompIntermediatesDir%" + set __CMakeBinDir=%__CrossComponentBinDir% + set "__CMakeBinDir=!__CMakeBinDir:\=/!" + set __ExtraCmakeArgs="-DCLR_CROSS_COMPONENTS_BUILD=1" "-DCLR_CMAKE_TARGET_ARCH=%__BuildArch%" "-DCLR_CMAKE_TARGET_OS=%__BuildOS%" "-DCLR_CMAKE_PACKAGES_DIR=%__PackagesDir%" "-DCLR_CMAKE_PGO_INSTRUMENT=%__PgoInstrument%" "-DCLR_CMAKE_OPTDATA_VERSION=%__PgoOptDataVersion%" "-DCLR_CMAKE_PGO_OPTIMIZE=%__PgoOptimize%" "-DCMAKE_SYSTEM_VERSION=10.0" + call "%__SourceDir%\pal\tools\gen-buildsys-win.bat" "%__ProjectDir%" %__VSVersion% %__CrossArch% !__ExtraCmakeArgs! @if defined _echo @echo on popd -:SkipConfigure - if not exist "%__IntermediatesDir%\install.vcxproj" ( - echo %__MsgPrefix%Error: failed to generate native component build project! +:SkipConfigureCrossBuild + if not exist "%__CrossCompIntermediatesDir%\install.vcxproj" ( + echo %__MsgPrefix%Error: failed to generate cross-arch components build project! exit /b 1 ) - if defined __ConfigureOnly goto SkipNativeBuild + if defined __ConfigureOnly goto SkipCrossCompBuild - set __BuildLogRootName=CoreCLR + set __BuildLogRootName=Cross set __BuildLog="%__LogsDir%\!__BuildLogRootName!_%__BuildOS%__%__BuildArch%__%__BuildType%.log" set __BuildWrn="%__LogsDir%\!__BuildLogRootName!_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn" set __BuildErr="%__LogsDir%\!__BuildLogRootName!_%__BuildOS%__%__BuildArch%__%__BuildType%.err" set __MsbuildLog=/flp:Verbosity=normal;LogFile=!__BuildLog! set __MsbuildWrn=/flp1:WarningsOnly;LogFile=!__BuildWrn! set __MsbuildErr=/flp2:ErrorsOnly;LogFile=!__BuildErr! - set __Logging=!__MsbuildLog! !__MsbuildWrn! !__MsbuildErr! + set __Logging=!_MsbuildLog! !__MsbuildWrn! !__MsbuildErr! call %__ProjectDir%\cmake_msbuild.cmd /nologo /verbosity:minimal /clp:Summary /nodeReuse:false^ /l:BinClashLogger,Tools/net46/Microsoft.DotNet.Build.Tasks.dll;LogFile=binclash.log^ /p:RestoreDefaultOptimizationDataPackage=false /p:PortableBuild=true^ - /p:UsePartialNGENOptimization=false /maxcpucount %__IntermediatesDir%\install.vcxproj^ - !__Logging! /p:Configuration=%__BuildType% /p:Platform=%__BuildArch% %__CommonMSBuildArgs% /m:2 %__UnprocessedBuildArgs% + /p:UsePartialNGENOptimization=false /maxcpucount^ + %__CrossCompIntermediatesDir%\install.vcxproj^ + !__Logging! /p:Configuration=%__BuildType% /p:Platform=%__CrossArch% %__CommonMSBuildArgs% /m:2 %__UnprocessedBuildArgs% if not !errorlevel! == 0 ( - echo %__MsgPrefix%Error: native component build failed. Refer to the build log files for details: + echo %__MsgPrefix%Error: cross-arch components build failed. Refer to the build log files for details: echo !__BuildLog! echo !__BuildWrn! echo !__BuildErr! exit /b 1 ) -:SkipNativeBuild +:SkipCrossCompBuild REM } Scope environment changes end endlocal ) REM ========================================================================================= REM === -REM === Build Cross-Architecture Native Components (if applicable) +REM === Build the CLR VM REM === REM ========================================================================================= -if %__BuildCrossArchNative% EQU 1 ( +if %__BuildNative% EQU 1 ( REM Scope environment changes start { setlocal - echo %__MsgPrefix%Commencing build of cross architecture native components for %__BuildOS%.%__BuildArch%.%__BuildType% + echo %__MsgPrefix%Commencing build of native components for %__BuildOS%.%__BuildArch%.%__BuildType% - REM Set the environment for the cross-arch native build + REM Set the environment for the native build set __VCBuildArch=x86_amd64 - if /i "%__CrossArch%" == "x86" ( set __VCBuildArch=x86 ) + if /i "%__BuildArch%" == "x86" ( set __VCBuildArch=x86 ) + if /i "%__BuildArch%" == "arm" ( + set __VCBuildArch=x86_arm + REM Make CMake pick the highest installed version in the 10.0.* range + set ___SDKVersion="-DCMAKE_SYSTEM_VERSION=10.0" + set ___CrossBuildDefine="-DCLR_CMAKE_CROSS_ARCH=1" "-DCLR_CMAKE_CROSS_HOST_ARCH=%__CrossArch%" + ) + if /i "%__BuildArch%" == "arm64" ( + set __VCBuildArch=x86_arm64 + + REM Make CMake pick the highest installed version in the 10.0.* range + set ___SDKVersion="-DCMAKE_SYSTEM_VERSION=10.0" + set ___CrossBuildDefine="-DCLR_CMAKE_CROSS_ARCH=1" "-DCLR_CMAKE_CROSS_HOST_ARCH=%__CrossArch%" + ) echo %__MsgPrefix%Using environment: "%__VCToolsRoot%\vcvarsall.bat" !__VCBuildArch! call "%__VCToolsRoot%\vcvarsall.bat" !__VCBuildArch! @if defined _echo @echo on - if not exist "%__CrossCompIntermediatesDir%" md "%__CrossCompIntermediatesDir%" - if defined __SkipConfigure goto SkipConfigureCrossBuild + if not defined VSINSTALLDIR ( + echo %__MsgPrefix%Error: VSINSTALLDIR variable not defined. + exit /b 1 + ) + if not exist "!VSINSTALLDIR!DIA SDK" goto NoDIA - pushd "%__CrossCompIntermediatesDir%" - set __CMakeBinDir=%__CrossComponentBinDir% - set "__CMakeBinDir=!__CMakeBinDir:\=/!" - set __ExtraCmakeArgs="-DCLR_CROSS_COMPONENTS_BUILD=1" "-DCLR_CMAKE_TARGET_ARCH=%__BuildArch%" "-DCLR_CMAKE_TARGET_OS=%__BuildOS%" "-DCLR_CMAKE_PACKAGES_DIR=%__PackagesDir%" "-DCLR_CMAKE_PGO_INSTRUMENT=%__PgoInstrument%" "-DCLR_CMAKE_OPTDATA_VERSION=%__PgoOptDataVersion%" "-DCLR_CMAKE_PGO_OPTIMIZE=%__PgoOptimize%" "-DCMAKE_SYSTEM_VERSION=10.0" - call "%__SourceDir%\pal\tools\gen-buildsys-win.bat" "%__ProjectDir%" %__VSVersion% %__CrossArch% !__ExtraCmakeArgs! + if defined __SkipConfigure goto SkipConfigure + + echo %__MsgPrefix%Regenerating the Visual Studio solution + + echo Cross Arch Defines !___CrossBuildDefine! + + pushd "%__IntermediatesDir%" + set __ExtraCmakeArgs=!___SDKVersion! !___CrossBuildDefine! "-DCLR_CMAKE_TARGET_OS=%__BuildOS%" "-DCLR_CMAKE_PACKAGES_DIR=%__PackagesDir%" "-DCLR_CMAKE_PGO_INSTRUMENT=%__PgoInstrument%" "-DCLR_CMAKE_OPTDATA_VERSION=%__PgoOptDataVersion%" "-DCLR_CMAKE_PGO_OPTIMIZE=%__PgoOptimize%" + call "%__SourceDir%\pal\tools\gen-buildsys-win.bat" "%__ProjectDir%" %__VSVersion% %__BuildArch% !__ExtraCmakeArgs! @if defined _echo @echo on popd -:SkipConfigureCrossBuild - if not exist "%__CrossCompIntermediatesDir%\install.vcxproj" ( - echo %__MsgPrefix%Error: failed to generate cross-arch components build project! +:SkipConfigure + if not exist "%__IntermediatesDir%\install.vcxproj" ( + echo %__MsgPrefix%Error: failed to generate native component build project! exit /b 1 ) - if defined __ConfigureOnly goto SkipCrossCompBuild + if defined __ConfigureOnly goto SkipNativeBuild - set __BuildLogRootName=Cross + set __BuildLogRootName=CoreCLR set __BuildLog="%__LogsDir%\!__BuildLogRootName!_%__BuildOS%__%__BuildArch%__%__BuildType%.log" set __BuildWrn="%__LogsDir%\!__BuildLogRootName!_%__BuildOS%__%__BuildArch%__%__BuildType%.wrn" set __BuildErr="%__LogsDir%\!__BuildLogRootName!_%__BuildOS%__%__BuildArch%__%__BuildType%.err" set __MsbuildLog=/flp:Verbosity=normal;LogFile=!__BuildLog! set __MsbuildWrn=/flp1:WarningsOnly;LogFile=!__BuildWrn! set __MsbuildErr=/flp2:ErrorsOnly;LogFile=!__BuildErr! - set __Logging=!_MsbuildLog! !__MsbuildWrn! !__MsbuildErr! + set __Logging=!__MsbuildLog! !__MsbuildWrn! !__MsbuildErr! call %__ProjectDir%\cmake_msbuild.cmd /nologo /verbosity:minimal /clp:Summary /nodeReuse:false^ /l:BinClashLogger,Tools/net46/Microsoft.DotNet.Build.Tasks.dll;LogFile=binclash.log^ /p:RestoreDefaultOptimizationDataPackage=false /p:PortableBuild=true^ - /p:UsePartialNGENOptimization=false /maxcpucount^ - %__CrossCompIntermediatesDir%\install.vcxproj^ - !__Logging! /p:Configuration=%__BuildType% /p:Platform=%__CrossArch% %__CommonMSBuildArgs% /m:2 %__UnprocessedBuildArgs% + /p:UsePartialNGENOptimization=false /maxcpucount %__IntermediatesDir%\install.vcxproj^ + !__Logging! /p:Configuration=%__BuildType% /p:Platform=%__BuildArch% %__CommonMSBuildArgs% /m:2 %__UnprocessedBuildArgs% if not !errorlevel! == 0 ( - echo %__MsgPrefix%Error: cross-arch components build failed. Refer to the build log files for details: + echo %__MsgPrefix%Error: native component build failed. Refer to the build log files for details: echo !__BuildLog! echo !__BuildWrn! echo !__BuildErr! exit /b 1 ) -:SkipCrossCompBuild +:SkipNativeBuild REM } Scope environment changes end endlocal ) diff --git a/init-tools.msbuild b/init-tools.msbuild index fcf9541ba2..e209e42963 100644 --- a/init-tools.msbuild +++ b/init-tools.msbuild @@ -11,9 +11,6 @@ $(BuildToolsPackageVersion) - - 1.0.4-prerelease - $(ILLinkTasksPackageVersion) diff --git a/src/dlls/mscoree/coreclr/CMakeLists.txt b/src/dlls/mscoree/coreclr/CMakeLists.txt index 380c8ddfde..a04ef21674 100644 --- a/src/dlls/mscoree/coreclr/CMakeLists.txt +++ b/src/dlls/mscoree/coreclr/CMakeLists.txt @@ -169,15 +169,22 @@ if(WIN32) set(DACTABLEGEN_EXE ${CMAKE_BINARY_DIR}/src/ToolBox/SOS/DacTableGen/dactablegen.exe) + if (CLR_CMAKE_CROSS_ARCH) + include(${CMAKE_INSTALL_PREFIX}/${CLR_CMAKE_CROSS_HOST_ARCH}/dactabletools/dactabletools.cmake) + endif() + + set(INJECT_RESOURCE_EXE $) + set(GEN_CLR_DEBUG_RESOURCE_EXE $) + add_custom_command( DEPENDS coreclr mscordaccore mscordbi ${CLR_DIR}/src/debug/daccess/daccess.cpp OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/inject_debug_resources.timestamp COMMAND ${CMAKE_CXX_COMPILER} /P /EP /TP ${PREPROCESS_DEFINITIONS} ${INC_DIR} /Fi${CMAKE_CURRENT_BINARY_DIR}/daccess.i ${CLR_DIR}/src/debug/daccess/daccess.cpp COMMAND ${DACTABLEGEN_EXE} /dac:${CMAKE_CURRENT_BINARY_DIR}/daccess.i /pdb:${CMAKE_CURRENT_BINARY_DIR}/$/coreclr.pdb /dll:$ /bin:${CMAKE_CURRENT_BINARY_DIR}/wks.bin - COMMAND ${BuildToolsDir}/InjectResource.exe /bin:${CMAKE_CURRENT_BINARY_DIR}/wks.bin /dll:$ - COMMAND ${BuildToolsDir}/GenClrDebugResource.exe /dac:$ /dbi:$ /sku:onecoreclr /out:${CMAKE_CURRENT_BINARY_DIR}/clrDebugResource.bin - COMMAND ${BuildToolsDir}/InjectResource.exe /bin:${CMAKE_CURRENT_BINARY_DIR}/clrDebugResource.bin /dll:$ /name:CLRDEBUGINFO - COMMAND ${BuildToolsDir}/InjectResource.exe /bin:${CMAKE_CURRENT_SOURCE_DIR}/dump_helper_resource.bin /dll:$ /name:MINIDUMP_AUXILIARY_PROVIDER + COMMAND ${INJECT_RESOURCE_EXE} /bin:${CMAKE_CURRENT_BINARY_DIR}/wks.bin /dll:$ + COMMAND ${GEN_CLR_DEBUG_RESOURCE_EXE} /dac:$ /dbi:$ /sku:onecoreclr /out:${CMAKE_CURRENT_BINARY_DIR}/clrDebugResource.bin + COMMAND ${INJECT_RESOURCE_EXE} /bin:${CMAKE_CURRENT_BINARY_DIR}/clrDebugResource.bin /dll:$ /name:CLRDEBUGINFO + COMMAND ${INJECT_RESOURCE_EXE} /bin:${CMAKE_CURRENT_SOURCE_DIR}/dump_helper_resource.bin /dll:$ /name:MINIDUMP_AUXILIARY_PROVIDER COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/inject_debug_resources.timestamp COMMENT Add dactable, debug resources, and dump helper resources to coreclr ) diff --git a/src/pal/tools/gen-buildsys-win.bat b/src/pal/tools/gen-buildsys-win.bat index 234c0cbfc6..a3df018d06 100644 --- a/src/pal/tools/gen-buildsys-win.bat +++ b/src/pal/tools/gen-buildsys-win.bat @@ -45,7 +45,7 @@ if defined CMakePath goto DoGen for /f "delims=" %%a in ('powershell -NoProfile -ExecutionPolicy ByPass "& "%basePath%\set-cmake-path.ps1""') do %%a :DoGen -"%CMakePath%" "-DCMAKE_USER_MAKE_RULES_OVERRIDE=%basePath%\windows-compiler-override.txt" "-DCMAKE_INSTALL_PREFIX:PATH=$ENV{__CMakeBinDir}" "-DCLR_CMAKE_HOST_ARCH=%__Arch%" %__ExtraCmakeParams% -G "%__CmakeGenerator%" %__SourceDir% +"%CMakePath%" "-DCMAKE_USER_MAKE_RULES_OVERRIDE=%basePath%\windows-compiler-override.txt" "-DCMAKE_INSTALL_PREFIX=%__CMakeBinDir%" "-DCLR_CMAKE_HOST_ARCH=%__Arch%" %__ExtraCmakeParams% -G "%__CmakeGenerator%" %__SourceDir% endlocal GOTO :DONE diff --git a/src/tools/CMakeLists.txt b/src/tools/CMakeLists.txt index 5443e0ddb6..cd6c9766aa 100644 --- a/src/tools/CMakeLists.txt +++ b/src/tools/CMakeLists.txt @@ -1 +1,9 @@ add_subdirectory(crossgen) +if (WIN32 AND NOT CLR_CMAKE_CROSS_ARCH) + add_subdirectory(GenClrDebugResource) + add_subdirectory(InjectResource) + + if (CLR_CROSS_COMPONENTS_BUILD) + install(EXPORT dactabletools DESTINATION dactabletools) + endif() +endif() diff --git a/src/tools/GenClrDebugResource/CMakeLists.txt b/src/tools/GenClrDebugResource/CMakeLists.txt index ad2598a373..9efed80ddc 100644 --- a/src/tools/GenClrDebugResource/CMakeLists.txt +++ b/src/tools/GenClrDebugResource/CMakeLists.txt @@ -5,3 +5,5 @@ target_link_libraries(GenClrDebugResource ${STATIC_MT_CRT_LIB} ${STATIC_MT_VCRT_LIB} ) + +install(TARGETS GenClrDebugResource EXPORT dactabletools DESTINATION dactabletools) diff --git a/src/tools/InjectResource/CMakeLists.txt b/src/tools/InjectResource/CMakeLists.txt index a4fd538662..71d871e295 100644 --- a/src/tools/InjectResource/CMakeLists.txt +++ b/src/tools/InjectResource/CMakeLists.txt @@ -7,4 +7,6 @@ add_executable(InjectResource InjectResource.cpp) target_link_libraries(InjectResource ${STATIC_MT_CRT_LIB} ${STATIC_MT_VCRT_LIB} -) \ No newline at end of file +) + +install(TARGETS InjectResource EXPORT dactabletools DESTINATION dactabletools) diff --git a/src/tools/InjectResource/InjectResource.cpp b/src/tools/InjectResource/InjectResource.cpp index 1d5470f3f9..9f4d483a8b 100644 --- a/src/tools/InjectResource/InjectResource.cpp +++ b/src/tools/InjectResource/InjectResource.cpp @@ -14,7 +14,7 @@ char* g_appName; void AddBinaryResourceToDll(__in_z char* dllName, - __in_z char* resName, + __in_z const char* resName, PVOID resData, ULONG resDataSize) { @@ -34,7 +34,7 @@ AddBinaryResourceToDll(__in_z char* dllName, } if (!UpdateResourceA(dllUpdate, - RT_RCDATA, + (LPCSTR)RT_RCDATA, resName, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), resData, -- cgit v1.2.3