Skip to content

Commit

Permalink
[Infrastructure] Use MSBuild v15 extension point to control CL parall…
Browse files Browse the repository at this point in the history
…elism, abstract MSBuild /maxcpucount switch (dotnet#14578)

This commit frees -ExtraParameters and uses MSBuild v15 extension point to control CL compiler parallelism.

If MSBuild 15.0 is available - installed with Visual Studio 2017 - CL parallelism control is achieved by using extension point in Microsoft.Common.props file which allows to include Directory.Build.props - for details see [Microsoft.Common.props] [1] file in MSBuild repo. https://github.com/Microsoft/msbuild/blob/b38e4ceeaaec36c5237ae698041e9b9f18c84876/src/Tasks/Microsoft.Common.props#L36.

MSBuild parallelism is controled via abstracted /maxcpucount command line switch
which now is available as -MSBuildNodeCount pass through run.cmd/run.sh command line
argument with default value equal to /maxcpucount (what defaults to number of logical processors).
This allows to control MSBuild parallelism on all supported platforms.

It is possible to control MSBuild parallelism programatically via MSBuild public
API using MaxNodeCount properties available on the following APIs:

Microsoft.Build.Evaluation.ProjectCollection.MaxNodeCount
Microsoft.Build.Execution.BuildParameters.MaxNodeCount
It's use in current build infrastructure would require creating unnecessary
complexity and was ruled out.
  • Loading branch information
4creators authored and weshaggard committed Nov 4, 2017
1 parent 9345244 commit 5a01d8a
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 16 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Require at least version 2.8.12 of CMake
# Verify minimum required version
cmake_minimum_required(VERSION 2.8.12)

if(CMAKE_VERSION VERSION_EQUAL 3.0 OR CMAKE_VERSION VERSION_GREATER 3.0)
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ if defined VisualStudioVersion (
goto :Run
)

echo %__MsgPrefix%"Searching for Visual Studio 2017 or 2015 installation"
echo %__MsgPrefix%Searching ^for Visual Studio 2017 or 2015 installation
set _VSWHERE="%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"
if exist %_VSWHERE% (
for /f "usebackq tokens=*" %%i in (`%_VSWHERE% -latest -prerelease -property installationPath`) do set _VSCOMNTOOLS=%%i\Common7\Tools
Expand Down Expand Up @@ -315,8 +315,8 @@ echo %__MsgPrefix%Checking prerequisites
:: Eval the output from probe-win1.ps1
for /f "delims=" %%a in ('powershell -NoProfile -ExecutionPolicy ByPass "& ""%__SourceDir%\pal\tools\probe-win.ps1"""') do %%a

REM NumberOfEnabledCore is an WMI property providing number of enabled cores on machine
REM processor(s) and later is used to set optimal level of CL parallelism during native build step
REM NumberOfCores is an WMI property providing number of physical cores on machine
REM processor(s). It is used to set optimal level of CL parallelism during native build step
if not defined NumberOfCores (
REM Determine number of physical processor cores available on machine
for /f "tokens=*" %%I in (
Expand Down Expand Up @@ -439,7 +439,7 @@ if %__BuildNative% EQU 1 (
set __MsbuildWrn=/flp1:WarningsOnly;LogFile=!__BuildWrn!
set __MsbuildErr=/flp2:ErrorsOnly;LogFile=!__BuildErr!

@call %__ProjectDir%\run.cmd build -Project=%__IntermediatesDir%\install.vcxproj -MsBuildLog=!__MsbuildLog! -MsBuildWrn=!__MsbuildWrn! -MsBuildErr=!__MsbuildErr! -configuration=%__BuildType% %__NativePlatformArgs% %__RunArgs% -ExtraParameters="/p:ForceImportBeforeCppTargets=%__ProjectDir%/clr.nativebuild.props /m:2" %__UnprocessedBuildArgs%
@call %__ProjectDir%\run.cmd build -Project=%__IntermediatesDir%\install.vcxproj -MsBuildLog=!__MsbuildLog! -MsBuildWrn=!__MsbuildWrn! -MsBuildErr=!__MsbuildErr! -configuration=%__BuildType% %__NativePlatformArgs% %__RunArgs% -MSBuildNodeCount="/m:2" %__UnprocessedBuildArgs%

if not !errorlevel! == 0 (
echo %__MsgPrefix%Error: native component build failed. Refer to the build log files for details:
Expand Down Expand Up @@ -509,7 +509,7 @@ if /i "%__DoCrossArchBuild%"=="1" (
set __MsbuildWrn=/flp1:WarningsOnly;LogFile=!__BuildWrn!
set __MsbuildErr=/flp2:ErrorsOnly;LogFile=!__BuildErr!

@call %__ProjectDir%\run.cmd build -Project=%__CrossCompIntermediatesDir%\install.vcxproj -configuration=%__BuildType% -platform=%__CrossArch% -MsBuildLog=!__MsbuildLog! -MsBuildWrn=!__MsbuildWrn! -MsBuildErr=!__MsbuildErr! %__RunArgs% -ExtraParameters="/p:ForceImportBeforeCppTargets=%__ProjectDir%/clr.nativebuild.props /m:2" %__UnprocessedBuildArgs%
@call %__ProjectDir%\run.cmd build -Project=%__CrossCompIntermediatesDir%\install.vcxproj -configuration=%__BuildType% -platform=%__CrossArch% -MsBuildLog=!__MsbuildLog! -MsBuildWrn=!__MsbuildWrn! -MsBuildErr=!__MsbuildErr! %__RunArgs% -MSBuildNodeCount="/m:2" %__UnprocessedBuildArgs%

if not !errorlevel! == 0 (
echo %__MsgPrefix%Error: cross-arch components build failed. Refer to the build log files for details:
Expand Down
13 changes: 10 additions & 3 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@
"values": [],
"defaultValue": "/t:GenerateVersionSourceFile /p:GenerateVersionSourceFile=true"
},
"MSBuildNodeCount": {
"description": "Sets the value of the number of processors available for MSBuild.",
"valueType": "passThrough",
"values": [],
"defaultValue": "/maxcpucount"
},
"NativeVersionSourceFile": {
"description": "Provides location for version.cpp",
"valueType": "property",
Expand Down Expand Up @@ -508,7 +514,8 @@
"MsBuildEventLogging": "default",
"RestoreDefaultOptimizationDataPackage": "false",
"PortableBuild": "true",
"UsePartialNGENOptimization": "false"
"UsePartialNGENOptimization": "false",
"MSBuildNodeCount": "default"
}
}
},
Expand Down Expand Up @@ -708,11 +715,11 @@
"msbuild": {
"osSpecific": {
"windows": {
"defaultParameters": "/nologo /verbosity:minimal /clp:Summary /maxcpucount /nodeReuse:false",
"defaultParameters": "/nologo /verbosity:minimal /clp:Summary /nodeReuse:false",
"path": "Tools/msbuild.cmd"
},
"unix": {
"defaultParameters": "/nologo /verbosity:minimal /clp:Summary /maxcpucount",
"defaultParameters": "/nologo /verbosity:minimal /clp:Summary",
"path": "Tools/msbuild.sh"
}
},
Expand Down
5 changes: 5 additions & 0 deletions crosscomponents.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ set (CLR_CROSS_COMPONENTS_LIST

if(NOT CLR_CMAKE_PLATFORM_LINUX)
list (APPEND CLR_CROSS_COMPONENTS_LIST
mcs
mscordaccore
mscordbi
sos
superpmi
superpmi-shim-collector
superpmi-shim-counter
superpmi-shim-simple
)
endif()
1 change: 0 additions & 1 deletion functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,3 @@ function(add_executable_clr)
_add_executable(${ARGV})
add_dependencies(${ARGV0} GeneratedEventingFiles)
endfunction()

2 changes: 1 addition & 1 deletion src/ToolBox/superpmi/mcs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ add_precompiled_header(
MCS_SOURCES
)

add_executable(mcs
_add_executable(mcs
${MCS_SOURCES}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ if (WIN32)
list(APPEND SUPERPMI_SHIM_COLLECTOR_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/superpmi-shim-collector.def)
endif (WIN32)

add_library(superpmi-shim-collector
_add_library(superpmi-shim-collector
SHARED
${SUPERPMI_SHIM_COLLECTOR_SOURCES}
)
Expand Down
2 changes: 1 addition & 1 deletion src/ToolBox/superpmi/superpmi-shim-counter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ if (WIN32)
list(APPEND SUPERPMI_SHIM_COUNTER_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/superpmi-shim-counter.def)
endif (WIN32)

add_library(superpmi-shim-counter
_add_library(superpmi-shim-counter
SHARED
${SUPERPMI_SHIM_COUNTER_SOURCES}
)
Expand Down
2 changes: 1 addition & 1 deletion src/ToolBox/superpmi/superpmi-shim-simple/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ if (WIN32)
list(APPEND SUPERPMI_SHIM_SIMPLE_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/superpmi-shim-simple.def)
endif (WIN32)

add_library(superpmi-shim-simple
_add_library(superpmi-shim-simple
SHARED
${SUPERPMI_SHIM_SIMPLE_SOURCES}
)
Expand Down
2 changes: 1 addition & 1 deletion src/ToolBox/superpmi/superpmi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ add_precompiled_header(
SUPERPMI_SOURCES
)

add_executable(superpmi
_add_executable(superpmi
${SUPERPMI_SOURCES}
)

Expand Down
2 changes: 1 addition & 1 deletion src/dlls/mscordac/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ endif(CLR_CMAKE_PLATFORM_DARWIN)

# Create object library to enable creation of proper dependency of mscordaccore.exp on mscordac.obj and
# mscordaccore on both the mscordaccore.exp and mscordac.obj.
add_library(mscordacobj OBJECT mscordac.cpp)
_add_library(mscordacobj OBJECT mscordac.cpp)

add_library_clr(mscordaccore SHARED ${CLR_DAC_SOURCES} $<TARGET_OBJECTS:mscordacobj>)

Expand Down

0 comments on commit 5a01d8a

Please sign in to comment.