Use our local-built instances of tools from Microsoft.DotNet.BuildTools.CoreClr inste...
authorJeremy Koritzinsky <jekoritz@microsoft.com>
Sat, 4 May 2019 00:56:20 +0000 (17:56 -0700)
committerGitHub <noreply@github.com>
Sat, 4 May 2019 00:56:20 +0000 (17:56 -0700)
* 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
build.cmd
init-tools.msbuild
src/dlls/mscoree/coreclr/CMakeLists.txt
src/pal/tools/gen-buildsys-win.bat
src/tools/CMakeLists.txt
src/tools/GenClrDebugResource/CMakeLists.txt
src/tools/InjectResource/CMakeLists.txt
src/tools/InjectResource/InjectResource.cpp

index b7715d2..d668a02 100644 (file)
@@ -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
 #------------------------------
index bd6d355..e9669ca 100644 (file)
--- 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
 )
index fcf9541..e209e42 100644 (file)
@@ -11,9 +11,6 @@
     <PackageReference Include="microsoft.dotnet.buildtools">
       <Version>$(BuildToolsPackageVersion)</Version>
     </PackageReference>
-    <PackageReference Include="microsoft.dotnet.buildtools.coreclr">
-      <Version>1.0.4-prerelease</Version>
-    </PackageReference>
     <PackageReference Include="$(ILLinkTasksPackage)">
       <Version>$(ILLinkTasksPackageVersion)</Version>
     </PackageReference>
index 380c8dd..a04ef21 100644 (file)
@@ -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 $<TARGET_FILE:InjectResource>)
+    set(GEN_CLR_DEBUG_RESOURCE_EXE $<TARGET_FILE:GenClrDebugResource>)
+
     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}/$<CONFIG>/coreclr.pdb /dll:$<TARGET_FILE:coreclr> /bin:${CMAKE_CURRENT_BINARY_DIR}/wks.bin
-        COMMAND ${BuildToolsDir}/InjectResource.exe /bin:${CMAKE_CURRENT_BINARY_DIR}/wks.bin /dll:$<TARGET_FILE:coreclr>
-        COMMAND ${BuildToolsDir}/GenClrDebugResource.exe /dac:$<TARGET_FILE:mscordaccore> /dbi:$<TARGET_FILE:mscordbi> /sku:onecoreclr /out:${CMAKE_CURRENT_BINARY_DIR}/clrDebugResource.bin
-        COMMAND ${BuildToolsDir}/InjectResource.exe /bin:${CMAKE_CURRENT_BINARY_DIR}/clrDebugResource.bin /dll:$<TARGET_FILE:coreclr> /name:CLRDEBUGINFO
-        COMMAND ${BuildToolsDir}/InjectResource.exe /bin:${CMAKE_CURRENT_SOURCE_DIR}/dump_helper_resource.bin /dll:$<TARGET_FILE:coreclr> /name:MINIDUMP_AUXILIARY_PROVIDER
+        COMMAND ${INJECT_RESOURCE_EXE} /bin:${CMAKE_CURRENT_BINARY_DIR}/wks.bin /dll:$<TARGET_FILE:coreclr>
+        COMMAND ${GEN_CLR_DEBUG_RESOURCE_EXE} /dac:$<TARGET_FILE:mscordaccore> /dbi:$<TARGET_FILE:mscordbi> /sku:onecoreclr /out:${CMAKE_CURRENT_BINARY_DIR}/clrDebugResource.bin
+        COMMAND ${INJECT_RESOURCE_EXE} /bin:${CMAKE_CURRENT_BINARY_DIR}/clrDebugResource.bin /dll:$<TARGET_FILE:coreclr> /name:CLRDEBUGINFO
+        COMMAND ${INJECT_RESOURCE_EXE} /bin:${CMAKE_CURRENT_SOURCE_DIR}/dump_helper_resource.bin /dll:$<TARGET_FILE:coreclr> /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
     )
index 234c0cb..a3df018 100644 (file)
@@ -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
 
index 5443e0d..cd6c976 100644 (file)
@@ -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()
index ad2598a..9efed80 100644 (file)
@@ -5,3 +5,5 @@ target_link_libraries(GenClrDebugResource
     ${STATIC_MT_CRT_LIB}
     ${STATIC_MT_VCRT_LIB}
 )
+
+install(TARGETS GenClrDebugResource EXPORT dactabletools DESTINATION dactabletools)
index a4fd538..71d871e 100644 (file)
@@ -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)
index 1d5470f..9f4d483 100644 (file)
@@ -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,