diff --git a/eng/pipelines/coreclr/templates/build-job.yml b/eng/pipelines/coreclr/templates/build-job.yml index 367baffb04dc8..f80391da8ed52 100644 --- a/eng/pipelines/coreclr/templates/build-job.yml +++ b/eng/pipelines/coreclr/templates/build-job.yml @@ -98,7 +98,7 @@ jobs: # and FreeBSD builds use a build agent with dependencies # preinstalled, so we only need this step for OSX and Windows. - ${{ if eq(parameters.osGroup, 'OSX') }}: - - script: sh $(coreClrRepoRoot)/eng/install-native-dependencies.sh $(osGroup) + - script: sh $(Build.SourcesDirectory)/eng/install-native-dependencies.sh $(osGroup) displayName: Install native dependencies - ${{ if eq(parameters.osGroup, 'Windows_NT') }}: # Necessary to install python diff --git a/eng/pipelines/coreclr/templates/build-test-job.yml b/eng/pipelines/coreclr/templates/build-test-job.yml index 5347978875f89..880ee2935feb8 100644 --- a/eng/pipelines/coreclr/templates/build-test-job.yml +++ b/eng/pipelines/coreclr/templates/build-test-job.yml @@ -63,7 +63,7 @@ jobs: # Install test build dependencies - ${{ if eq(parameters.osGroup, 'OSX') }}: - - script: sh $(coreClrRepoRootDir)eng/install-native-dependencies.sh $(osGroup) + - script: sh $(Build.SourcesDirectory)/eng/install-native-dependencies.sh $(osGroup) displayName: Install native dependencies - ${{ if eq(parameters.osGroup, 'Windows_NT') }}: # Necessary to install correct cmake version diff --git a/eng/pipelines/coreclr/templates/job.yml b/eng/pipelines/coreclr/templates/job.yml index 757eb8713f475..ecebd0f03eb77 100644 --- a/eng/pipelines/coreclr/templates/job.yml +++ b/eng/pipelines/coreclr/templates/job.yml @@ -119,8 +119,7 @@ jobs: itemPattern: ${{ coalesce(parameters.artifacts.download.pattern, '**') }} - ${{ each step in parameters.steps }}: - - ${{ if ne(step, '') }}: - - ${{ step }} + - ${{ step }} - ${{ if eq(parameters.enableMicrobuild, 'true') }}: - ${{ if and(eq(parameters.runAsPublic, 'false'), ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}: diff --git a/eng/pipelines/coreclr/templates/send-to-helix-step.yml b/eng/pipelines/coreclr/templates/send-to-helix-step.yml index 46cd65cfd13ca..cb4a0a24c90ba 100644 --- a/eng/pipelines/coreclr/templates/send-to-helix-step.yml +++ b/eng/pipelines/coreclr/templates/send-to-helix-step.yml @@ -24,7 +24,7 @@ parameters: steps: - ${{ if eq(parameters.osGroup, 'Windows_NT') }}: # TODO: Remove and consolidate this when we move to arcade via init-tools.cmd. - - powershell: $(Build.SourcesDirectory)\eng\common\build.ps1 /p:DotNetPublishToBlobFeed=true -ci -restore -projects ${{ parameters.coreClrRepoRoot }}\eng\empty.csproj + - powershell: $(Build.SourcesDirectory)\eng\common\build.ps1 /p:DotNetPublishToBlobFeed=true -ci -restore -projects $(Build.SourcesDirectory)\eng\empty.csproj displayName: Restore blob feed tasks ${{ if ne(parameters.condition, '') }}: condition: ${{ parameters.condition }} @@ -58,7 +58,7 @@ steps: - ${{ if ne(parameters.osGroup, 'Windows_NT') }}: # TODO: Remove and consolidate this when we move to arcade via init-tools.sh. - - script: $(Build.SourcesDirectory)/eng/common/build.sh /p:DotNetPublishToBlobFeed=true --ci --restore --projects ${{ parameters.coreClrRepoRoot }}/eng/empty.csproj + - script: $(Build.SourcesDirectory)/eng/common/build.sh /p:DotNetPublishToBlobFeed=true --ci --restore --projects $(Build.SourcesDirectory)/eng/empty.csproj displayName: Restore blob feed tasks ${{ if ne(parameters.condition, '') }}: condition: ${{ parameters.condition }} diff --git a/eng/pipelines/coreclr/templates/xplat-pipeline-job.yml b/eng/pipelines/coreclr/templates/xplat-pipeline-job.yml index b8d3c70b1e2d7..ffc806edf8714 100644 --- a/eng/pipelines/coreclr/templates/xplat-pipeline-job.yml +++ b/eng/pipelines/coreclr/templates/xplat-pipeline-job.yml @@ -80,7 +80,12 @@ jobs: value: '/' - name: coreClrRepoRoot - value: '$(Build.SourcesDirectory)' + value: '$(Build.SourcesDirectory)/src/coreclr + + - ${{ if not(startsWith(variables['Build.DefinitionName'], 'runtime')) }}:' + + - name: coreClrRepoRoot + value: '$(Build.SourcesDirectory)' - name: coreClrRepoRootDir value: '$(coreClrRepoRoot)$(dir)' diff --git a/src/coreclr/build-test.sh b/src/coreclr/build-test.sh index a40ebb8ac1c8b..9f178bfa84fad 100755 --- a/src/coreclr/build-test.sh +++ b/src/coreclr/build-test.sh @@ -505,7 +505,7 @@ build_native_projects() __versionSourceFile="$intermediatesForBuild/version.c" if [ $__SkipGenerateVersion == 0 ]; then pwd - $__RepoRootDir/eng/common/msbuild.sh $__ProjectRoot/eng/empty.csproj \ + $__RepoRootDir/eng/common/msbuild.sh $__RepoRootDir/eng/empty.csproj \ /p:NativeVersionFile=$__versionSourceFile \ /t:GenerateNativeVersionFile /restore \ $__CommonMSBuildArgs $__UnprocessedBuildArgs @@ -537,7 +537,7 @@ build_native_projects() extraCmakeArguments="$extraCmakeArguments -DCLR_CMAKE_ENABLE_CODE_COVERAGE=1" fi - nextCommand="CONFIG_DIR=\"$__RepoRootDir/eng/common/cross\" \"$scriptDir/gen-buildsys.sh\" \"$__TestDir\" \"$intermediatesForBuild\" $platformArch $__BuildType $generator $extraCmakeArguments $__cmakeargs" + nextCommand="\"$scriptDir/gen-buildsys.sh\" \"$__TestDir\" \"$intermediatesForBuild\" $platformArch $__BuildType $generator $extraCmakeArguments $__cmakeargs" echo "Invoking $nextCommand" eval $nextCommand diff --git a/src/coreclr/build.cmd b/src/coreclr/build.cmd new file mode 100644 index 0000000000000..e2a66636b3971 --- /dev/null +++ b/src/coreclr/build.cmd @@ -0,0 +1,1085 @@ +@if not defined _echo @echo off +setlocal EnableDelayedExpansion EnableExtensions + +:: Define a prefix for most output progress messages that come from this script. That makes +:: it easier to see where these are coming from. Note that there is a trailing space here. +set "__MsgPrefix=BUILD: " + +echo %__MsgPrefix%Starting Build at %TIME% + +set __ThisScriptFull="%~f0" +set __ThisScriptDir="%~dp0" + +call "%__ThisScriptDir%"\setup_vs_tools.cmd +if NOT '%ERRORLEVEL%' == '0' exit /b 1 + +if defined VS160COMNTOOLS ( + set "__VSToolsRoot=%VS160COMNTOOLS%" + set "__VCToolsRoot=%VS160COMNTOOLS%\..\..\VC\Auxiliary\Build" + set __VSVersion=vs2019 +) else if defined VS150COMNTOOLS ( + set "__VSToolsRoot=%VS150COMNTOOLS%" + set "__VCToolsRoot=%VS150COMNTOOLS%\..\..\VC\Auxiliary\Build" + set __VSVersion=vs2017 +) + +:: Work around Jenkins CI + msbuild problem: Jenkins sometimes creates very large environment +:: variables, and msbuild can't handle environment blocks with such large variables. So clear +:: out the variables that might be too large. +set ghprbCommentBody= + +:: Note that the msbuild project files (specifically, dir.proj) will use the following variables, if set: +:: __BuildArch -- default: x64 +:: __BuildType -- default: Debug +:: __BuildOS -- default: Windows_NT +:: __ProjectDir -- default: directory of the dir.props file +:: __RepoRootDir -- default: directory two levels above the dir.props file +:: __SourceDir -- default: %__ProjectDir%\src\ +:: __RootBinDir -- default: %__RepoRootDir%\artifacts\ +:: __BinDir -- default: %__RootBinDir%\%__BuildOS%.%__BuildArch.%__BuildType%\ +:: __IntermediatesDir +:: __PackagesBinDir -- default: %__BinDir%\.nuget +:: +:: Thus, these variables are not simply internal to this script! + +:: Set the default arguments for build +set __BuildArch=x64 +set __BuildType=Debug +set __BuildOS=Windows_NT + +:: Set the various build properties here so that CMake and MSBuild can pick them up +set "__ProjectDir=%~dp0" +:: remove trailing slash +if %__ProjectDir:~-1%==\ set "__ProjectDir=%__ProjectDir:~0,-1%" +set "__RepoRootDir=%__ProjectDir%\..\.." + +rem Remove after repo consolidation +if not exist "%__RepoRootDir%\.dotnet-runtime-placeholder" ( set "__RepoRootDir=!__ProjectDir!" ) + +set "__ProjectFilesDir=%__ProjectDir%" +set "__SourceDir=%__ProjectDir%\src" +set "__RootBinDir=%__ProjectDir%\bin" +set "__LogsDir=%__RootBinDir%\Logs" +set "__MsbuildDebugLogsDir=%__LogsDir%\MsbuildDebugLogs" + +set __BuildAll= + +set __BuildArchX64=0 +set __BuildArchX86=0 +set __BuildArchArm=0 +set __BuildArchArm64=0 + +set __BuildTypeDebug=0 +set __BuildTypeChecked=0 +set __BuildTypeRelease=0 + +set __PgoInstrument=0 +set __PgoOptimize=1 +set __EnforcePgo=0 +set __IbcTuning= +set __IbcOptimize=0 +set __IbcOnly=0 + +REM __PassThroughArgs is a set of things that will be passed through to nested calls to build.cmd +REM when using "all". +set __PassThroughArgs= + +REM __UnprocessedBuildArgs are args that we pass to msbuild (e.g. /p:__BuildArch=x64) +set "__args= %*" +set processedArgs= +set __UnprocessedBuildArgs= +set __CommonMSBuildArgs= + +set __BuildCoreLib=1 +set __BuildNative=1 +set __BuildCrossArchNative=0 +set __SkipCrossArchNative=0 +set __BuildTests=1 +set __BuildPackages=1 +set __BuildNativeCoreLib=1 +set __BuildManagedTools=1 +set __RestoreOptData=1 +set __GenerateLayout=0 +set __CrossgenAltJit= +set __SkipRestoreArg=/p:RestoreDuringBuild=true +set __OfficialBuildIdArg= +set __CrossArch= +set __PgoOptDataPath= +set __IbcOptDataPath= +set __IbcMergePath= + +@REM CMD has a nasty habit of eating "=" on the argument list, so passing: +@REM -priority=1 +@REM appears to CMD parsing as "-priority 1". Handle -priority specially to avoid problems, +@REM and allow the "-priority=1" syntax. +set __Priority= + +:Arg_Loop +if "%1" == "" goto ArgsDone + +if /i "%1" == "/?" goto Usage +if /i "%1" == "-?" goto Usage +if /i "%1" == "/h" goto Usage +if /i "%1" == "-h" goto Usage +if /i "%1" == "/help" goto Usage +if /i "%1" == "-help" goto Usage +if /i "%1" == "--help" goto Usage + +if /i "%1" == "-all" (set __BuildAll=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "-x64" (set __BuildArchX64=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "-x86" (set __BuildArchX86=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "-arm" (set __BuildArchArm=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "-arm64" (set __BuildArchArm64=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) + +if /i "%1" == "-debug" (set __BuildTypeDebug=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "-checked" (set __BuildTypeChecked=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "-release" (set __BuildTypeRelease=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) + +if /i "%1" == "-ci" (set __ArcadeScriptArgs="-ci"&set __ErrMsgPrefix=##vso[task.logissue type=error]&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) + +REM TODO these are deprecated remove them eventually +REM don't add more, use the - syntax instead +if /i "%1" == "all" (set __BuildAll=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "x64" (set __BuildArchX64=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "x86" (set __BuildArchX86=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "arm" (set __BuildArchArm=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "arm64" (set __BuildArchArm64=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) + +if /i "%1" == "debug" (set __BuildTypeDebug=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "checked" (set __BuildTypeChecked=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "release" (set __BuildTypeRelease=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) + +if /i "%1" == "-priority" (set __Priority=%2&shift&set processedArgs=!processedArgs! %1=%2&shift&goto Arg_Loop) + +REM Explicitly block -Rebuild. +if /i "%1" == "Rebuild" ( + echo "ERROR: 'Rebuild' is not supported. Please remove it." + goto Usage +) +if /i "%1" == "-Rebuild" ( + echo "ERROR: 'Rebuild' is not supported. Please remove it." + goto Usage +) + + +REM All arguments after this point will be passed through directly to build.cmd on nested invocations +REM using the "all" argument, and must be added to the __PassThroughArgs variable. +if [!__PassThroughArgs!]==[] ( + set __PassThroughArgs=%1 +) else ( + set __PassThroughArgs=%__PassThroughArgs% %1 +) + +if /i "%1" == "-freebsdmscorlib" (set __BuildNativeCoreLib=0&set __BuildNative=0&set __BuildTests=0&set __BuildPackages=0&set __BuildManagedTools=0&set __BuildOS=FreeBSD&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "-linuxmscorlib" (set __BuildNativeCoreLib=0&set __BuildNative=0&set __BuildTests=0&set __BuildPackages=0&set __BuildManagedTools=0&set __BuildOS=Linux&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "-netbsdmscorlib" (set __BuildNativeCoreLib=0&set __BuildNative=0&set __BuildTests=0&set __BuildPackages=0&set __BuildManagedTools=0&set __BuildOS=NetBSD&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "-osxmscorlib" (set __BuildNativeCoreLib=0&set __BuildNative=0&set __BuildTests=0&set __BuildPackages=0&set __BuildManagedTools=0&set __BuildOS=OSX&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "-windowsmscorlib" (set __BuildNativeCoreLib=0&set __BuildNative=0&set __BuildTests=0&set __BuildPackages=0&set __BuildManagedTools=0&set __BuildOS=Windows_NT&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "-nativemscorlib" (set __BuildNativeCoreLib=1&set __BuildCoreLib=0&set __BuildNative=0&set __BuildTests=0&set __BuildPackages=0&set __BuildManagedTools=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "-configureonly" (set __ConfigureOnly=1&set __BuildNative=1&set __BuildNativeCoreLib=0&set __BuildCoreLib=0&set __BuildTests=0&set __BuildPackages=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "-skipconfigure" (set __SkipConfigure=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "-skipmscorlib" (set __BuildCoreLib=0&set __BuildNativeCoreLib=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "-skipnative" (set __BuildNative=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "-skipcrossarchnative" (set __SkipCrossArchNative=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "-skiptests" (set __BuildTests=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "-skipbuildpackages" (set __BuildPackages=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "-skipmanagedtools" (set __BuildManagedTools=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "-skiprestoreoptdata" (set __RestoreOptData=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "-generatelayout" (set __GenerateLayout=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "-usenmakemakefiles" (set __NMakeMakefiles=1&set __ConfigureOnly=1&set __BuildNative=1&set __BuildNativeCoreLib=0&set __BuildCoreLib=0&set __BuildTests=0&set __BuildPackages=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "-pgoinstrument" (set __PgoInstrument=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "-enforcepgo" (set __EnforcePgo=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "-nopgooptimize" (set __PgoOptimize=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "-ibcoptimize" (set __IbcOptimize=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "-ibconly" (set __IbcOptimize=1&set __IbcOnly=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "-ibcinstrument" (set __IbcTuning=/Tuning&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "-crossgenaltjit" (set __CrossgenAltJit=%2&set processedArgs=!processedArgs! %1 %2&shift&shift&goto Arg_Loop) +REM TODO remove these once they are no longer used in buildpipeline +if /i "%1" == "-skiprestore" (set __SkipRestoreArg=/p:RestoreDuringBuild=false&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "-OfficialBuildId" (set __OfficialBuildIdArg=/p:OfficialBuildId=%2&set processedArgs=!processedArgs! %1=%2&shift&shift&goto Arg_Loop) + +REM TODO these are deprecated remove them eventually +REM don't add more, use the - syntax instead +if /i "%1" == "freebsdmscorlib" (set __BuildNativeCoreLib=0&set __BuildNative=0&set __BuildTests=0&set __BuildPackages=0&set __BuildManagedTools=0&set __BuildOS=FreeBSD&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "linuxmscorlib" (set __BuildNativeCoreLib=0&set __BuildNative=0&set __BuildTests=0&set __BuildPackages=0&set __BuildManagedTools=0&set __BuildOS=Linux&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "netbsdmscorlib" (set __BuildNativeCoreLib=0&set __BuildNative=0&set __BuildTests=0&set __BuildPackages=0&set __BuildManagedTools=0&set __BuildOS=NetBSD&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "osxmscorlib" (set __BuildNativeCoreLib=0&set __BuildNative=0&set __BuildTests=0&set __BuildPackages=0&set __BuildManagedTools=0&set __BuildOS=OSX&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "windowsmscorlib" (set __BuildNativeCoreLib=0&set __BuildNative=0&set __BuildTests=0&set __BuildPackages=0&set __BuildManagedTools=0&set __BuildOS=Windows_NT&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "nativemscorlib" (set __BuildNativeCoreLib=1&set __BuildCoreLib=0&set __BuildNative=0&set __BuildTests=0&set __BuildPackages=0&set __BuildManagedTools=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "configureonly" (set __ConfigureOnly=1&set __BuildNative=1&set __BuildNativeCoreLib=0&set __BuildCoreLib=0&set __BuildTests=0&set __BuildPackages=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "skipconfigure" (set __SkipConfigure=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "skipmscorlib" (set __BuildCoreLib=0&set __BuildNativeCoreLib=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "skipnative" (set __BuildNative=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "skipcrossarchnative" (set __SkipCrossArchNative=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "skiptests" (set __BuildTests=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "skipbuildpackages" (set __BuildPackages=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "skiprestoreoptdata" (set __RestoreOptData=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "generatelayout" (set __GenerateLayout=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "usenmakemakefiles" (set __NMakeMakefiles=1&set __ConfigureOnly=1&set __BuildNative=1&set __BuildNativeCoreLib=0&set __BuildCoreLib=0&set __BuildTests=0&set __BuildPackages=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "pgoinstrument" (set __PgoInstrument=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "nopgooptimize" (set __PgoOptimize=0&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "enforcepgo" (set __EnforcePgo=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "ibcoptimize" (set __IbcOptimize=1&set __PartialNgen=1&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "ibcinstrument" (set __IbcTuning=/Tuning&set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) +if /i "%1" == "crossgenaltjit" (set __CrossgenAltJit=%2&set processedArgs=!processedArgs! %1 %2&shift&shift&goto Arg_Loop) +REM TODO remove this once it's no longer used in buildpipeline +if /i "%1" == "--" (set processedArgs=!processedArgs! %1&shift&goto Arg_Loop) + +if [!processedArgs!]==[] ( + set __UnprocessedBuildArgs=%__args% +) else ( + set __UnprocessedBuildArgs=%__args% + for %%t in (!processedArgs!) do ( + set __UnprocessedBuildArgs=!__UnprocessedBuildArgs:*%%t=! + ) +) + +:ArgsDone + +@REM Special handling for -priority=N argument. +if defined __Priority ( + if defined __PassThroughArgs ( + set __PassThroughArgs=%__PassThroughArgs% -priority=%__Priority% + ) else ( + set __PassThroughArgs=-priority=%__Priority% + ) +) + +if defined __BuildAll goto BuildAll + +set /A __TotalSpecifiedBuildArch=__BuildArchX64 + __BuildArchX86 + __BuildArchArm + __BuildArchArm64 +if %__TotalSpecifiedBuildArch% GTR 1 ( + echo Error: more than one build architecture specified, but "all" not specified. + goto Usage +) + +if %__BuildArchX64%==1 set __BuildArch=x64 +if %__BuildArchX86%==1 set __BuildArch=x86 +if %__BuildArchArm%==1 ( + set __BuildArch=arm + set __CrossArch=x86 +) +if %__BuildArchArm64%==1 ( + set __BuildArch=arm64 + set __CrossArch=x64 +) + +set /A __TotalSpecifiedBuildType=__BuildTypeDebug + __BuildTypeChecked + __BuildTypeRelease +if %__TotalSpecifiedBuildType% GTR 1 ( + echo Error: more than one build type specified, but "all" not specified. + goto Usage +) + +if %__BuildTypeDebug%==1 set __BuildType=Debug +if %__BuildTypeChecked%==1 set __BuildType=Checked +if %__BuildTypeRelease%==1 set __BuildType=Release + +set __CommonMSBuildArgs=/p:__BuildOS=%__BuildOS% /p:__BuildType=%__BuildType% /p:__BuildArch=%__BuildArch% !__SkipRestoreArg! !__OfficialBuildIdArg! + +if %__EnforcePgo%==1 ( + if %__BuildArchArm%==1 ( + echo NOTICE: enforcepgo does nothing on arm architecture + ) + if %__BuildArchArm64%==1 ( + echo NOTICE: enforcepgo does nothing on arm64 architecture + ) +) + +REM Determine if this is a cross-arch build. Only do cross-arch build if we're also building native. + +if %__SkipCrossArchNative% EQU 0 ( + if %__BuildNative% EQU 1 ( + if /i "%__BuildArch%"=="arm64" ( + set __BuildCrossArchNative=1 + ) + if /i "%__BuildArch%"=="arm" ( + set __BuildCrossArchNative=1 + ) + ) +) + +REM Set the remaining variables based upon the determined build configuration + +if %__PgoOptimize%==0 ( + if %__IbcOptimize% == 0 ( + set __RestoreOptData=0 + ) +) + +set "__BinDir=%__RootBinDir%\Product\%__BuildOS%.%__BuildArch%.%__BuildType%" +set "__IntermediatesDir=%__RootBinDir%\obj\%__BuildOS%.%__BuildArch%.%__BuildType%" +set "__ArtifactsIntermediatesDir=%__RepoRootDir%\artifacts\obj\" +if "%__NMakeMakefiles%"=="1" (set "__IntermediatesDir=%__RootBinDir%\nmakeobj\%__BuildOS%.%__BuildArch%.%__BuildType%") +set "__PackagesBinDir=%__BinDir%\.nuget" +set "__CrossComponentBinDir=%__BinDir%" +set "__CrossCompIntermediatesDir=%__IntermediatesDir%\crossgen" + + +if NOT "%__CrossArch%" == "" set __CrossComponentBinDir=%__CrossComponentBinDir%\%__CrossArch% +set "__CrossGenCoreLibLog=%__LogsDir%\CrossgenCoreLib_%__BuildOS%__%__BuildArch%__%__BuildType%.log" +set "__CrossgenExe=%__CrossComponentBinDir%\crossgen.exe" + +REM Generate path to be set for CMAKE_INSTALL_PREFIX to contain forward slash +set "__CMakeBinDir=%__BinDir%" +set "__CMakeBinDir=%__CMakeBinDir:\=/%" + +if not exist "%__BinDir%" md "%__BinDir%" +if not exist "%__IntermediatesDir%" md "%__IntermediatesDir%" +if not exist "%__LogsDir%" md "%__LogsDir%" +if not exist "%__MsbuildDebugLogsDir%" md "%__MsbuildDebugLogsDir%" + +if not exist "%__RootBinDir%\Directory.Build.props" copy %__ProjectDir%\EmptyProps.props %__RootBinDir%\Directory.Build.props +if not exist "%__RootBinDir%\Directory.Build.targets" copy %__ProjectDir%\EmptyProps.props %__RootBinDir%\Directory.Build.targets + +REM Set up the directory for MSBuild debug logs. +set MSBUILDDEBUGPATH=%__MsbuildDebugLogsDir% + +REM It is convenient to have your Nuget search path include the location where the build +REM will place packages. However nuget used during the build will fail if that directory +REM does not exist. Avoid this in at least one case by aggressively creating the directory. +if not exist "%__BinDir%\.nuget\pkg" md "%__BinDir%\.nuget\pkg" + +echo %__MsgPrefix%Commencing CoreCLR product build + +REM Set the remaining variables based upon the determined build configuration + +echo %__MsgPrefix%Checking prerequisites + +set __CMakeNeeded=1 +if %__BuildNative%==0 if %__BuildNativeCoreLib%==0 if %__BuildTests%==0 set __CMakeNeeded=0 +if %__CMakeNeeded%==1 ( + REM Eval the output from set-cmake-path.ps1 + for /f "delims=" %%a in ('powershell -NoProfile -ExecutionPolicy ByPass "& ""%__SourceDir%\pal\tools\set-cmake-path.ps1"""') do %%a + REM echo Using CMake from %CMakePath% +) + +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 + set TotalNumberOfCores=0 + for /f "tokens=*" %%I in ( + 'wmic cpu get NumberOfCores /value ^| find "=" 2^>NUL' + ) do set %%I & set /a TotalNumberOfCores=TotalNumberOfCores+NumberOfCores + set NumberOfCores=!TotalNumberOfCores! +) +echo %__MsgPrefix%Number of processor cores %NumberOfCores% + +REM ========================================================================================= +REM === +REM === Start the build steps +REM === +REM ========================================================================================= + +@if defined _echo @echo on + +powershell -NoProfile -ExecutionPolicy ByPass -NoLogo -File "%__RepoRootDir%\eng\common\msbuild.ps1" %__ArcadeScriptArgs%^ + %__RepoRootDir%\eng\empty.csproj /p:NativeVersionFile="%__RootBinDir%\obj\_version.h"^ + /t:GenerateNativeVersionFile /restore^ + %__CommonMSBuildArgs% %__UnprocessedBuildArgs% +if not !errorlevel! == 0 ( + echo %__ErrMsgPrefix%%__MsgPrefix%Error: Failed to generate version headers. + exit /b !errorlevel! +) + +REM ========================================================================================= +REM === +REM === Restore optimization profile data +REM === +REM ========================================================================================= + +set OptDataProjectFilePath=%__ProjectDir%\src\.nuget\optdata\optdata.csproj +if %__RestoreOptData% EQU 1 ( + echo %__MsgPrefix%Restoring the OptimizationData Package + powershell -NoProfile -ExecutionPolicy ByPass -NoLogo -File "%__RepoRootDir%\eng\common\msbuild.ps1" %__ArcadeScriptArgs%^ + %OptDataProjectFilePath% /t:Restore^ + %__CommonMSBuildArgs% %__UnprocessedBuildArgs% + if not !errorlevel! == 0 ( + echo %__ErrMsgPrefix%%__MsgPrefix%Error: Failed to restore the optimization data package. + exit /b !errorlevel! + ) +) + +set PgoDataPackagePathOutputFile="%__IntermediatesDir%\optdatapath.txt" +set IbcDataPackagePathOutputFile="%__IntermediatesDir%\ibcoptdatapath.txt" + +REM Parse the optdata package versions out of msbuild so that we can pass them on to CMake +powershell -NoProfile -ExecutionPolicy ByPass -NoLogo -File "%__RepoRootDir%\eng\common\msbuild.ps1" %__ArcadeScriptArgs%^ + "%OptDataProjectFilePath%" /t:DumpPgoDataPackagePath %__CommonMSBuildArgs% /p:PgoDataPackagePathOutputFile="!PgoDataPackagePathOutputFile!" + + if not !errorlevel! == 0 ( + echo %__ErrMsgPrefix%Failed to get PGO data package path. + exit /b !errorlevel! +) +if not exist "!PgoDataPackagePathOutputFile!" ( + echo %__ErrMsgPrefix%Failed to get PGO data package path. + exit /b 1 +) + +set /p __PgoOptDataPath=<"!PgoDataPackagePathOutputFile!" + +powershell -NoProfile -ExecutionPolicy ByPass -NoLogo -File "%__RepoRootDir%\eng\common\msbuild.ps1" %__ArcadeScriptArgs%^ + "%OptDataProjectFilePath%" /t:DumpIbcDataPackagePath /nologo %__CommonMSBuildArgs% /p:IbcDataPackagePathOutputFile="!IbcDataPackagePathOutputFile!" + + if not !errorlevel! == 0 ( + echo %__ErrMsgPrefix%Failed to get IBC data package path. + exit /b !errorlevel! +) + +if not exist "!IbcDataPackagePathOutputFile!" ( + echo %__ErrMsgPrefix%Failed to get IBC data package path. + exit /b 1 +) + +set /p __IbcOptDataPath=<"!IbcDataPackagePathOutputFile!" + +REM ========================================================================================= +REM === +REM === Generate source files for eventing +REM === +REM ========================================================================================= + +set __IntermediatesIncDir=%__IntermediatesDir%\src\inc +set __IntermediatesEventingDir=%__ArtifactsIntermediatesDir%\Eventing\%__BuildArch%\%__BuildType% + +REM Find python and set it to the variable PYTHON +set _C=-c "import sys; sys.stdout.write(sys.executable)" +(py -3 %_C% || py -2 %_C% || python3 %_C% || python2 %_C% || python %_C%) > %TEMP%\pythonlocation.txt 2> NUL +set _C= +set /p PYTHON=<%TEMP%\pythonlocation.txt + +if NOT DEFINED PYTHON ( + echo %__ErrMsgPrefix%%__MsgPrefix%Error: Could not find a python installation + exit /b 1 +) + +if %__BuildCoreLib% EQU 1 ( + echo %__MsgPrefix%Laying out dynamically generated EventSource classes + "!PYTHON!" -B -Wall %__SourceDir%\scripts\genRuntimeEventSources.py --man %__SourceDir%\vm\ClrEtwAll.man --intermediate %__IntermediatesEventingDir% || exit /b 1 +) + +REM ========================================================================================= +REM === +REM === Build Cross-Architecture Native Components (if applicable) +REM === +REM ========================================================================================= + +if %__BuildCrossArchNative% EQU 1 ( + REM Scope environment changes start { + setlocal + + echo %__MsgPrefix%Commencing build of cross architecture native components for %__BuildOS%.%__BuildArch%.%__BuildType% + + REM Set the environment for the cross-arch native build + set __VCBuildArch=x86_amd64 + 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 exist "%__CrossCompIntermediatesDir%" md "%__CrossCompIntermediatesDir%" + if defined __SkipConfigure goto SkipConfigureCrossBuild + + set __CMakeBinDir=%__CrossComponentBinDir% + set "__CMakeBinDir=!__CMakeBinDir:\=/!" + set __ExtraCmakeArgs="-DCLR_CROSS_COMPONENTS_BUILD=1" "-DCLR_CMAKE_TARGET_ARCH=%__BuildArch%" "-DCLR_CMAKE_PGO_INSTRUMENT=%__PgoInstrument%" "-DCLR_CMAKE_OPTDATA_PATH=%__PgoOptDataPath%" "-DCLR_CMAKE_PGO_OPTIMIZE=%__PgoOptimize%" "-DCMAKE_SYSTEM_VERSION=10.0" + call "%__SourceDir%\pal\tools\gen-buildsys.cmd" "%__ProjectDir%" "%__CrossCompIntermediatesDir%" %__VSVersion% %__CrossArch% !__ExtraCmakeArgs! + + if not !errorlevel! == 0 ( + echo %__ErrMsgPrefix%%__MsgPrefix%Error: failed to generate native component build project! + exit /b 1 + ) + @if defined _echo @echo on + +:SkipConfigureCrossBuild + if not exist "%__CrossCompIntermediatesDir%\CMakeCache.txt" ( + echo %__ErrMsgPrefix%%__MsgPrefix%Error: unable to find generated native component build project! + exit /b 1 + ) + + if defined __ConfigureOnly goto SkipCrossCompBuild + + 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! + + REM We pass the /m flag directly to MSBuild so that we can get both MSBuild and CL parallelism, which is fastest for our builds. + "%CMakePath%" --build %__CrossCompIntermediatesDir% --target install --config %__BuildType% -- /m !__Logging! + + if not !errorlevel! == 0 ( + echo %__ErrMsgPrefix%%__MsgPrefix%Error: cross-arch components build failed. + exit /b !errorlevel! + ) + +:SkipCrossCompBuild + REM } Scope environment changes end + endlocal +) + +REM ========================================================================================= +REM === +REM === Build the CLR VM +REM === +REM ========================================================================================= + +if %__BuildNative% EQU 1 ( + REM Scope environment changes start { + setlocal + + echo %__MsgPrefix%Commencing build of native components for %__BuildOS%.%__BuildArch%.%__BuildType% + + REM Set the environment for the 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" + 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 defined VSINSTALLDIR ( + echo %__ErrMsgPrefix%%__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 + + set __ExtraCmakeArgs=!___SDKVersion! !___CrossBuildDefine! "-DCLR_CMAKE_PGO_INSTRUMENT=%__PgoInstrument%" "-DCLR_CMAKE_OPTDATA_PATH=%__PgoOptDataPath%" "-DCLR_CMAKE_PGO_OPTIMIZE=%__PgoOptimize%" + call "%__SourceDir%\pal\tools\gen-buildsys.cmd" "%__ProjectDir%" "%__IntermediatesDir%" %__VSVersion% %__BuildArch% !__ExtraCmakeArgs! + if not !errorlevel! == 0 ( + echo %__ErrMsgPrefix%%__MsgPrefix%Error: failed to generate native component build project! + exit /b 1 + ) + + @if defined _echo @echo on + +:SkipConfigure + if not exist "%__IntermediatesDir%\CMakeCache.txt" ( + echo %__ErrMsgPrefix%%__MsgPrefix%Error: unable to find generated native component build project! + exit /b 1 + ) + + if defined __ConfigureOnly goto SkipNativeBuild + + 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! + + REM We pass the /m flag directly to MSBuild so that we can get both MSBuild and CL parallelism, which is fastest for our builds. + "%CMakePath%" --build %__IntermediatesDir% --target install --config %__BuildType% -- /m !__Logging! + + if not !errorlevel! == 0 ( + echo %__ErrMsgPrefix%%__MsgPrefix%Error: native component build failed. + exit /b !errorlevel! + ) + +:SkipNativeBuild + REM } Scope environment changes end + endlocal +) + +REM ========================================================================================= +REM === +REM === CoreLib and NuGet package build section. +REM === +REM ========================================================================================= + +if %__BuildCoreLib% EQU 1 ( + REM Scope environment changes start { + setlocal + + if %__IbcOnly% EQU 0 ( + echo %__MsgPrefix%Commencing build of System.Private.CoreLib for %__BuildOS%.%__BuildArch%.%__BuildType% + rem Explicitly set Platform causes conflicts in CoreLib project files. Clear it to allow building from VS x64 Native Tools Command Prompt + set Platform= + + set __ExtraBuildArgs= + + if "%__BuildManagedTools%" == "1" ( + set __ExtraBuildArgs=!__ExtraBuildArgs! /p:BuildManagedTools=true + ) + + set __BuildLogRootName=System.Private.CoreLib + 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! + + powershell -NoProfile -ExecutionPolicy ByPass -NoLogo -File "%__RepoRootDir%\eng\common\msbuild.ps1" %__ArcadeScriptArgs%^ + %__ProjectDir%\src\build.proj /t:Restore^ + /nodeReuse:false /p:PortableBuild=true /maxcpucount /p:IncludeRestoreOnlyProjects=true^ + !__Logging! %__CommonMSBuildArgs% !__ExtraBuildArgs! %__UnprocessedBuildArgs% + if not !errorlevel! == 0 ( + echo %__ErrMsgPrefix%%__MsgPrefix%Error: Managed Product assemblies restore failed. Refer to the build log files for details. + echo !__BuildLog! + echo !__BuildWrn! + echo !__BuildErr! + exit /b !errorlevel! + ) + + REM Disable warnAsError to work around VS bug (948084) where ucrt lib path is not set properly, resulting in CS1668 + powershell -NoProfile -ExecutionPolicy ByPass -NoLogo -Command "%__RepoRootDir%\eng\common\msbuild.ps1" %__ArcadeScriptArgs%^ + %__ProjectDir%\src\build.proj -warnAsError:0^ + /nodeReuse:false /p:PortableBuild=true /maxcpucount^ + '!__MsbuildLog!' '!__MsbuildWrn!' '!__MsbuildErr!' %__CommonMSBuildArgs% !__ExtraBuildArgs! %__UnprocessedBuildArgs% + if not !errorlevel! == 0 ( + echo %__ErrMsgPrefix%%__MsgPrefix%Error: Managed Product assemblies build failed. Refer to the build log files for details. + echo !__BuildLog! + echo !__BuildWrn! + echo !__BuildErr! + exit /b !errorlevel! + ) + + if "%__BuildManagedTools%" == "1" ( + echo %__MsgPrefix%Publishing crossgen2... + call %__ProjectDir%\dotnet.cmd publish --self-contained -r win-%__BuildArch% -c %__BuildType% -o "%__BinDir%\crossgen2" "%__ProjectDir%\src\tools\crossgen2\crossgen2\crossgen2.csproj" /p:BuildArch=%__BuildArch% + + if not !errorlevel! == 0 ( + echo %__ErrMsgPrefix%%__MsgPrefix%Error: Failed to build crossgen2. + echo !__BuildLog! + echo !__BuildWrn! + echo !__BuildErr! + exit /b !errorlevel! + ) + + copy /Y "%__BinDir%\clrjit.dll" "%__BinDir%\crossgen2\clrjitilc.dll" + copy /Y "%__BinDir%\jitinterface.dll" "%__BinDir%\crossgen2\jitinterface.dll" + ) + ) + if %__IbcOptimize% EQU 1 ( + echo %__MsgPrefix%Commencing IBCMerge of System.Private.CoreLib for %__BuildOS%.%__BuildArch%.%__BuildType% + set IbcMergeProjectFilePath=%__ProjectDir%\src\.nuget\optdata\ibcmerge.csproj + set IbcMergePackagePathOutputFile="%__IntermediatesDir%\ibcmergepath.txt" + powershell -NoProfile -ExecutionPolicy ByPass -NoLogo -File "%__RepoRootDir%\eng\common\msbuild.ps1" %__ArcadeScriptArgs%^ + "!IbcMergeProjectFilePath!" /t:DumpIbcMergePackagePath /nologo %__CommonMSBuildArgs% /p:IbcMergePackagePathOutputFile="!IbcMergePackagePathOutputFile!" + + if not !errorlevel! == 0 ( + echo %__ErrMsgPrefix%Failed to determine IBC Merge path. + exit /b !errorlevel! + ) + if not exist "!IbcMergePackagePathOutputFile!" ( + echo %__ErrMsgPrefix%Failed to determine IBC Merge path. + exit /b 1 + ) + + set /p __IbcMergePath=<"!IbcMergePackagePathOutputFile!" + + set IbcMergePath=!__IbcMergePath!\tools\netcoreapp2.0\ibcmerge.dll + if exist !IbcMergePath! ( + echo %__MsgPrefix%Optimizing using IBC training data + set OptimizationDataDir=!__IbcOptDataPath!\data\System.Private.CoreLib.dll\ + set InputAssemblyFile=!OptimizationDataDir!System.Private.CoreLib.dll + set TargetOptimizationDataFile=!OptimizationDataDir!System.Private.CoreLib.pgo + + if exist "!InputAssemblyFile!" ( + set RawOptimizationDataFilePattern=!OptimizationDataDir!*.ibc + set RawOptimizationDataFile= + for %%x in (!RawOptimizationDataFilePattern!) do @( + if [!RawOptimizationDataFile!] == [] ( + set RawOptimizationDataFile="%%x" + ) else ( + set RawOptimizationDataFile=!RawOptimizationDataFile! "%%x" + ) + ) + + set IBCMergeCommand=%__ProjectDir%\dotnet.cmd --roll-forward-on-no-candidate-fx 2 "!IbcMergePath!" + + REM Merge the optimization data into the source DLL + set NEXTCMD=!IBCMergeCommand! -q -f -delete -mo "!InputAssemblyFile!" !RawOptimizationDataFile! + echo %__MsgPrefix%!NEXTCMD! >> "%__CrossGenCoreLibLog%" + call !NEXTCMD! >> "%__CrossGenCoreLibLog%" 2>&1 + if NOT !errorlevel! == 0 ( + echo %__ErrMsgPrefix%%__MsgPrefix%Error: IbcMerge of System.Private.CoreLib build failed. Refer to %__CrossGenCoreLibLog% + REM Put it in the same log, helpful for Jenkins + type %__CrossGenCoreLibLog% + goto CrossgenFailure + ) + + REM Verify that the optimization data has been merged + set NEXTCMD=!IBCMergeCommand! -mi "!InputAssemblyFile!" + echo %__MsgPrefix%!NEXTCMD! >> "%__CrossGenCoreLibLog%" + call !NEXTCMD! >> "%__CrossGenCoreLibLog%" 2>&1 + if NOT !errorlevel! == 0 ( + echo %__ErrMsgPrefix%%__MsgPrefix%Error: IbcMerge of System.Private.CoreLib build failed. Refer to %__CrossGenCoreLibLog% + REM Put it in the same log, helpful for Jenkins + type %__CrossGenCoreLibLog% + goto CrossgenFailure + ) + + REM Save the module as *.pgo to match the convention expected + copy /y !InputAssemblyFile! !TargetOptimizationDataFile! + ) + + if exist "!TargetOptimizationDataFile!" ( + REM Customize IBCMerge's arguments depending on input props + set IBCMergeArguments=-q -f -delete -mo "%__BinDir%\IL\System.Private.CoreLib.dll" -incremental "!TargetOptimizationDataFile!" + + REM Apply optimization data to the compiled assembly + set NEXTCMD=!IBCMergeCommand! !IBCMergeArguments! + echo %__MsgPrefix%!NEXTCMD! >> "%__CrossGenCoreLibLog%" + call !NEXTCMD! >> "%__CrossGenCoreLibLog%" 2>&1 + if NOT !errorlevel! == 0 ( + echo %__ErrMsgPrefix%%__MsgPrefix%Error: IbcMerge of System.Private.CoreLib build failed. Refer to %__CrossGenCoreLibLog% + REM Put it in the same log, helpful for Jenkins + type %__CrossGenCoreLibLog% + goto CrossgenFailure + ) + + REM Verify that the optimization data has been applied + set NEXTCMD=!IBCMergeCommand! -mi "%__BinDir%\IL\System.Private.CoreLib.dll" + echo %__MsgPrefix%!NEXTCMD! >> "%__CrossGenCoreLibLog%" + call !NEXTCMD! >> "%__CrossGenCoreLibLog%" 2>&1 + if NOT !errorlevel! == 0 ( + echo %__ErrMsgPrefix%%__MsgPrefix%Error: IbcMerge of System.Private.CoreLib build failed. Refer to %__CrossGenCoreLibLog% + REM Put it in the same log, helpful for Jenkins + type %__CrossGenCoreLibLog% + goto CrossgenFailure + ) + ) else ( + echo %__MsgPrefix%!TargetOptimizationDataFile! does not exist >> %__CrossGenCoreLibLog% + echo %__ErrMsgPrefix%%__MsgPrefix%Error: IbcMerge of System.Private.CoreLib build failed. Refer to %__CrossGenCoreLibLog% + REM Put it in the same log, helpful for Jenkins + type %__CrossGenCoreLibLog% + goto CrossgenFailure + ) + ) else ( + echo Could not find IBCMerge at !IbcMergePath!. Have you restored src/.nuget/optdata/ibcmerge.csproj? + goto CrossgenFailure + ) + ) + + REM } Scope environment changes end + endlocal +) + +REM ========================================================================================= +REM === +REM === Build native System.Private.CoreLib. +REM === +REM ========================================================================================= + +REM Scope environment changes start { +setlocal + +REM Need diasymreader.dll on your path for /CreatePdb +set PATH=%PATH%;%WinDir%\Microsoft.Net\Framework64\V4.0.30319;%WinDir%\Microsoft.Net\Framework\V4.0.30319 + +if %__BuildNativeCoreLib% EQU 1 ( + echo %__MsgPrefix%Generating native image of System.Private.CoreLib for %__BuildOS%.%__BuildArch%.%__BuildType%. Logging to "%__CrossGenCoreLibLog%". + if exist "%__CrossGenCoreLibLog%" del "%__CrossGenCoreLibLog%" + + REM Need VS native tools environment for the **target** arch when running instrumented binaries + if %__PgoInstrument% EQU 1 ( + set __VCExecArch=%__BuildArch% + if /i [%__BuildArch%] == [x64] set __VCExecArch=amd64 + echo %__MsgPrefix%Using environment: "%__VCToolsRoot%\vcvarsall.bat" !__VCExecArch! + call "%__VCToolsRoot%\vcvarsall.bat" !__VCExecArch! + @if defined _echo @echo on + if NOT !errorlevel! == 0 ( + echo %__ErrMsgPrefix%%__MsgPrefix%Error: Failed to load native tools environment for !__VCExecArch! + goto CrossgenFailure + ) + + REM HACK: Workaround for [dotnet/coreclr#13970](https://github.com/dotnet/coreclr/issues/13970) + set __PgoRtPath= + for /f "tokens=*" %%f in ('where pgort*.dll') do ( + if not defined __PgoRtPath set "__PgoRtPath=%%~f" + ) + echo %__MsgPrefix%Copying "!__PgoRtPath!" into "%__BinDir%" + copy /y "!__PgoRtPath!" "%__BinDir%" || ( + echo %__ErrMsgPrefix%%__MsgPrefix%Error: copy failed + goto CrossgenFailure + ) + REM End HACK + ) + + if defined __CrossgenAltJit ( + REM Set altjit flags for the crossgen run. Note that this entire crossgen section is within a setlocal/endlocal scope, + REM so we don't need to save or unset these afterwards. + echo %__MsgPrefix%Setting altjit environment variables for %__CrossgenAltJit%. + echo %__MsgPrefix%Setting altjit environment variables for %__CrossgenAltJit%. >> "%__CrossGenCoreLibLog%" + set COMPlus_AltJit=* + set COMPlus_AltJitNgen=* + set COMPlus_AltJitName=%__CrossgenAltJit% + set COMPlus_AltJitAssertOnNYI=1 + set COMPlus_NoGuiOnAssert=1 + set COMPlus_ContinueOnAssert=0 + ) + + set NEXTCMD="%__CrossgenExe%" %__IbcTuning% /Platform_Assemblies_Paths "%__BinDir%\IL" /out "%__BinDir%\System.Private.CoreLib.dll" "%__BinDir%\IL\System.Private.CoreLib.dll" + echo %__MsgPrefix%!NEXTCMD! + echo %__MsgPrefix%!NEXTCMD! >> "%__CrossGenCoreLibLog%" + !NEXTCMD! >> "%__CrossGenCoreLibLog%" 2>&1 + if NOT !errorlevel! == 0 ( + echo %__ErrMsgPrefix%%__MsgPrefix%Error: CrossGen System.Private.CoreLib build failed. Refer to %__CrossGenCoreLibLog% + REM Put it in the same log, helpful for Jenkins + type %__CrossGenCoreLibLog% + goto CrossgenFailure + ) + + set NEXTCMD="%__CrossgenExe%" /Platform_Assemblies_Paths "%__BinDir%" /CreatePdb "%__BinDir%\PDB" "%__BinDir%\System.Private.CoreLib.dll" + echo %__MsgPrefix%!NEXTCMD! + echo %__MsgPrefix%!NEXTCMD! >> "%__CrossGenCoreLibLog%" + !NEXTCMD! >> "%__CrossGenCoreLibLog%" 2>&1 + if NOT !errorlevel! == 0 ( + echo %__ErrMsgPrefix%%__MsgPrefix%Error: CrossGen /CreatePdb System.Private.CoreLib build failed. Refer to %__CrossGenCoreLibLog% + REM Put it in the same log, helpful for Jenkins + type %__CrossGenCoreLibLog% + goto CrossgenFailure + ) +) + +REM } Scope environment changes end +endlocal + +REM ========================================================================================= +REM === +REM === Build packages +REM === +REM ========================================================================================= + +if %__BuildPackages% EQU 1 ( + REM Scope environment changes start { + setlocal + + echo %__MsgPrefix%Building Packages for %__BuildOS%.%__BuildArch%.%__BuildType% + + set __BuildLog="%__LogsDir%\Nuget_%__BuildOS%__%__BuildArch%__%__BuildType%.binlog" + + REM The conditions as to what to build are captured in the builds file. + REM Package build uses the Arcade system and scripts, relying on it to restore required toolsets as part of build + powershell -NoProfile -ExecutionPolicy ByPass -NoLogo -File "%__RepoRootDir%\eng\common\build.ps1"^ + -r -b -projects %__SourceDir%\.nuget\packages.builds^ + -verbosity minimal /nodeReuse:false /bl:!__BuildLog!^ + /p:PortableBuild=true^ + /p:Platform=%__BuildArch% %__CommonMSBuildArgs% %__UnprocessedBuildArgs% + if not !errorlevel! == 0 ( + echo %__ErrMsgPrefix%%__MsgPrefix%Error: Nuget package generation failed. Refer to the build log file for details. + echo !__BuildLog! + exit /b !errorlevel! + ) + + REM } Scope environment changes end + endlocal +) + +REM ========================================================================================= +REM === +REM === Test build section +REM === +REM ========================================================================================= + +if %__BuildTests% EQU 1 ( + echo %__MsgPrefix%Commencing build of tests for %__BuildOS%.%__BuildArch%.%__BuildType% + + set __PriorityArg= + if defined __Priority ( + set __PriorityArg=-priority=%__Priority% + ) + set NEXTCMD=call %__ProjectDir%\build-test.cmd %__BuildArch% %__BuildType% !__PriorityArg! %__UnprocessedBuildArgs% + echo %__MsgPrefix%!NEXTCMD! + !NEXTCMD! + + if not !errorlevel! == 0 ( + REM buildtest.cmd has already emitted an error message and mentioned the build log file to examine. + exit /b 1 + ) +) else if %__GenerateLayout% EQU 1 ( + echo %__MsgPrefix%Generating layout for %__BuildOS%.%__BuildArch%.%__BuildType% + + set NEXTCMD=call %__ProjectDir%\tests\runtest.cmd %__BuildArch% %__BuildType% GenerateLayoutOnly msbuildargs %__UnprocessedBuildArgs% + echo %__MsgPrefix%!NEXTCMD! + !NEXTCMD! + + if not !errorlevel! == 0 ( + REM runtest.cmd has already emitted an error message and mentioned the build log file to examine. + exit /b 1 + ) +) + +REM ========================================================================================= +REM === +REM === All builds complete! +REM === +REM ========================================================================================= + +echo %__MsgPrefix%Build succeeded. Finished at %TIME% +echo %__MsgPrefix%Product binaries are available at !__BinDir! +exit /b 0 + +REM ========================================================================================= +REM === +REM === Handle the "all" case. +REM === +REM ========================================================================================= + +:BuildAll + +set __BuildArchList= + +set /A __TotalSpecifiedBuildArch=__BuildArchX64 + __BuildArchX86 + __BuildArchArm + __BuildArchArm64 +if %__TotalSpecifiedBuildArch% EQU 0 ( + REM Nothing specified means we want to build all architectures. + set __BuildArchList=x64 x86 arm arm64 +) + +REM Otherwise, add all the specified architectures to the list. + +if %__BuildArchX64%==1 set __BuildArchList=%__BuildArchList% x64 +if %__BuildArchX86%==1 set __BuildArchList=%__BuildArchList% x86 +if %__BuildArchArm%==1 set __BuildArchList=%__BuildArchList% arm +if %__BuildArchArm64%==1 set __BuildArchList=%__BuildArchList% arm64 + +set __BuildTypeList= + +set /A __TotalSpecifiedBuildType=__BuildTypeDebug + __BuildTypeChecked + __BuildTypeRelease +if %__TotalSpecifiedBuildType% EQU 0 ( + REM Nothing specified means we want to build all build types. + set __BuildTypeList=Debug Checked Release +) + +if %__BuildTypeDebug%==1 set __BuildTypeList=%__BuildTypeList% Debug +if %__BuildTypeChecked%==1 set __BuildTypeList=%__BuildTypeList% Checked +if %__BuildTypeRelease%==1 set __BuildTypeList=%__BuildTypeList% Release + +REM Create a temporary file to collect build results. We always build all flavors specified, and +REM report a summary of the results at the end. + +set __AllBuildSuccess=true +set __BuildResultFile=%TEMP%\build-all-summary-%RANDOM%.txt +if exist %__BuildResultFile% del /f /q %__BuildResultFile% + +for %%i in (%__BuildArchList%) do ( + for %%j in (%__BuildTypeList%) do ( + call :BuildOne %%i %%j + ) +) + +if %__AllBuildSuccess%==true ( + echo %__MsgPrefix%All builds succeeded! + exit /b 0 +) else ( + echo %__MsgPrefix%Builds failed: + type %__BuildResultFile% + del /f /q %__BuildResultFile% + exit /b 1 +) + +REM This code is unreachable, but leaving it nonetheless, just in case things change. +exit /b 99 + +:BuildOne +set __BuildArch=%1 +set __BuildType=%2 +set __NextCmd=call %__ThisScriptFull% %__BuildArch% %__BuildType% %__PassThroughArgs% +echo %__MsgPrefix%Invoking: %__NextCmd% +%__NextCmd% +if not !errorlevel! == 0 ( + echo %__MsgPrefix% %__BuildArch% %__BuildType% %__PassThroughArgs% >> %__BuildResultFile% + set __AllBuildSuccess=false +) +exit /b 0 + +REM ========================================================================================= +REM === +REM === Helper routines +REM === +REM ========================================================================================= + +:CrossgenFailure +exit /b 1 + +:Usage +echo. +echo Build the CoreCLR repo. +echo. +echo Usage: +echo build.cmd [option1] [option2] +echo or: +echo build.cmd all [option1] [option2] +echo. +echo All arguments are optional. The options are: +echo. +echo.-? -h -help --help: view this message. +echo -all: Builds all configurations and platforms. +echo Build architecture: one of -x64, -x86, -arm, -arm64 ^(default: -x64^). +echo Build type: one of -Debug, -Checked, -Release ^(default: -Debug^). +echo mscorlib version: one of -freebsdmscorlib, -linuxmscorlib, -netbsdmscorlib, -osxmscorlib, +echo or -windowsmscorlib. If one of these is passed, only System.Private.CoreLib is built, +echo for the specified platform ^(FreeBSD, Linux, NetBSD, OS X or Windows, +echo respectively^). +echo add nativemscorlib to go further and build the native image for designated mscorlib. +echo -nopgooptimize: do not use profile guided optimizations. +echo -enforcepgo: verify after the build that PGO was used for key DLLs, and fail the build if not +echo -pgoinstrument: generate instrumented code for profile guided optimization enabled binaries. +echo -ibcinstrument: generate IBC-tuning-enabled native images when invoking crossgen. +echo -ibcoptimize: use IBC data to optimize System.Private.CoreLib.dll +echo -ibconly: only run the ibcoptimize step. Assumes an appropriate build already exists +echo -configureonly: skip all builds; only run CMake ^(default: CMake and builds are run^) +echo -skipconfigure: skip CMake ^(default: CMake is run^) +echo -skipmscorlib: skip building System.Private.CoreLib ^(default: System.Private.CoreLib is built^). +echo -skipnative: skip building native components ^(default: native components are built^). +echo -skipcrossarchnative: skip building cross-architecture native components ^(default: components are built^). +echo -skiptests: skip building tests ^(default: tests are built^). +echo -skipbuildpackages: skip building nuget packages ^(default: packages are built^). +echo -skipmanagedtools: skip build tools such as R2R dump and RunInContext +echo -skiprestoreoptdata: skip restoring optimization data used by profile-based optimizations. +echo -skiprestore: skip restoring packages ^(default: packages are restored during build^). +echo -disableoss: Disable Open Source Signing for System.Private.CoreLib. +echo -priority=^ : specify a set of test that will be built and run, with priority N. +echo -officialbuildid=^: specify the official build ID to be used by this build. +echo -crossgenaltjit ^: run crossgen using specified altjit ^(used for JIT testing^). +echo portable : build for portable RID. +echo. +echo If "all" is specified, then all build architectures and types are built. If, in addition, +echo one or more build architectures or types is specified, then only those build architectures +echo and types are built. +echo. +echo For example: +echo build -all +echo -- builds all architectures, and all build types per architecture +echo build -all -x86 +echo -- builds all build types for x86 +echo build -all -x64 -x86 -Checked -Release +echo -- builds x64 and x86 architectures, Checked and Release build types for each +exit /b 1 + +:NoDIA +echo Error: DIA SDK is missing at "%VSINSTALLDIR%DIA SDK". ^ +This is due to a bug in the Visual Studio installer. It does not install DIA SDK at "%VSINSTALLDIR%" but rather ^ +at the install location of previous Visual Studio version. The workaround is to copy the DIA SDK folder from the Visual Studio install location ^ +of the previous version to "%VSINSTALLDIR%" and then build. +REM DIA SDK not included in Express editions +echo Visual Studio Express does not include the DIA SDK. ^ +You need Visual Studio 2017 or 2019 (Community is free). +echo See: https://github.com/dotnet/coreclr/blob/master/Documentation/project-docs/developer-guide.md#prerequisites +exit /b 1 diff --git a/src/coreclr/build.sh b/src/coreclr/build.sh new file mode 100755 index 0000000000000..d2d3dad1f5ee4 --- /dev/null +++ b/src/coreclr/build.sh @@ -0,0 +1,1153 @@ +#!/usr/bin/env bash + +# Work around Jenkins CI + msbuild problem: Jenkins sometimes creates very large environment +# variables, and msbuild can't handle environment blocks with such large variables. So clear +# out the variables that might be too large. +export ghprbCommentBody= + +# resolve python-version to use +if [ "$PYTHON" == "" ] ; then + if ! PYTHON=$(command -v python3 || command -v python2 || command -v python || command -v py) + then + echo "Unable to locate build-dependency python!" 1>&2 + exit 1 + fi +fi +# validate python-dependency +# useful in case of explicitly set option. +if ! command -v $PYTHON > /dev/null +then + echo "Unable to locate build-dependency python ($PYTHON)!" 1>&2 + exit 1 +fi + +export PYTHON + +usage() +{ + echo "Usage: $0 [BuildArch] [BuildType] [-verbose] [-coverage] [-cross] [-gccx.y] [-clangx.y] [-ninja] [-configureonly] [-skipconfigure] [-skipnative] [-skipcrossarchnative] [-skipmanaged] [-skipmscorlib] [-stripsymbols] [-ignorewarnings] [-cmakeargs] [-bindir]" + echo "BuildArch can be: -x64, -x86, -arm, -armel, -arm64" + echo "BuildType can be: -debug, -checked, -release" + echo "-coverage - optional argument to enable code coverage build (currently supported only for Linux and OSX)." + echo "-ninja - target ninja instead of GNU make" + echo "-gccx.y - optional argument to build using gcc version x.y." + echo "-clangx.y - optional argument to build using clang version x.y." + echo "-cross - optional argument to signify cross compilation," + echo " - will use ROOTFS_DIR environment variable if set." + echo "-nopgooptimize - do not use profile guided optimizations." + echo "-pgoinstrument - generate instrumented code for profile guided optimization enabled binaries." + echo "-ibcinstrument - generate IBC-tuning-enabled native images when invoking crossgen." + echo "-configureonly - do not perform any builds; just configure the build." + echo "-skipconfigure - skip build configuration." + echo "-skipnative - do not build native components." + echo "-skipcrossarchnative - do not build cross-architecture native components." + echo "-skipmanaged - do not build managed components." + echo "-skipmscorlib - do not build mscorlib.dll." + echo "-skipnuget - skip building nuget packages." + echo "-skiprestoreoptdata - skip restoring optimization data used by profile-based optimizations." + echo "-skipcrossgen - skip native image generation" + echo "-skipmanagedtools -- skip build tools such as R2Rdump and RunInContext" + echo "-crossgenonly - only run native image generation" + echo "-partialngen - build CoreLib as PartialNGen" + echo "-verbose - optional argument to enable verbose build output." + echo "-skiprestore: skip restoring packages ^(default: packages are restored during build^)." + echo "-disableoss: Disable Open Source Signing for System.Private.CoreLib." + echo "-officialbuildid=^: specify the official build ID to be used by this build." + echo "-stripSymbols - Optional argument to strip native symbols during the build." + echo "-skipgenerateversion - disable version generation even if MSBuild is supported." + echo "-ignorewarnings - do not treat warnings as errors" + echo "-cmakeargs - user-settable additional arguments passed to CMake." + echo "-bindir - output directory (defaults to $__ProjectRoot/bin)" + echo "-msbuildonunsupportedplatform - build managed binaries even if distro is not officially supported." + echo "-numproc - set the number of build processes." + echo "-portablebuild - pass -portablebuild=false to force a non-portable build." + echo "-staticanalyzer - build with clang static analyzer enabled." + exit 1 +} + +initTargetDistroRid() +{ + source ${__ProjectDir}/init-distro-rid.sh + + local passedRootfsDir="" + + # Only pass ROOTFS_DIR if cross is specified. + if (( ${__CrossBuild} == 1 )); then + passedRootfsDir=${ROOTFS_DIR} + elif [ "${__BuildArch}" != "${__HostArch}" ]; then + echo "Error, you are building a cross scenario without passing -cross." + exit 1 + fi + + initDistroRidGlobal ${__BuildOS} ${__BuildArch} ${__PortableBuild} ${passedRootfsDir} +} + +setup_dirs() +{ + echo Setting up directories for build + + mkdir -p "$__RootBinDir" + mkdir -p "$__BinDir" + mkdir -p "$__LogsDir" + mkdir -p "$__MsbuildDebugLogsDir" + mkdir -p "$__IntermediatesDir" + + if [ $__CrossBuild == 1 ]; then + mkdir -p "$__CrossComponentBinDir" + fi +} + +# Check the system to ensure the right prereqs are in place + +check_prereqs() +{ + echo "Checking prerequisites..." + + # Check presence of CMake on the path + hash cmake 2>/dev/null || { echo >&2 "Please install cmake before running this script"; exit 1; } + + function version { echo "$@" | awk -F. '{ printf("%d%02d%02d\n", $1,$2,$3); }'; } + + local cmake_version=$(cmake --version | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+") + + if [[ $(version $cmake_version) -lt $(version 3.14.0) ]]; then + echo "Please install CMake 3.14 or newer from http://www.cmake.org/download/ or https://apt.kitware.com and ensure it is on your path."; exit 1; + fi + + # Minimum required version of clang is version 4.0 for arm/armel cross build + if [[ $__CrossBuild == 1 && $__GccBuild == 0 && ("$__BuildArch" == "arm" || "$__BuildArch" == "armel") ]]; then + if ! [[ "$__ClangMajorVersion" -ge "4" ]]; then + echo "Please install clang4.0 or latest for arm/armel cross build"; exit 1; + fi + fi + + # Check for clang + if [[ $__GccBuild == 0 ]]; then + __ClangCombinedDottedVersion=$__ClangMajorVersion; + if [[ "$__ClangMinorVersion" != "" ]]; then + __ClangCombinedDottedVersion=$__ClangCombinedDottedVersion.$__ClangMinorVersion + fi + hash clang-$__ClangCombinedDottedVersion 2>/dev/null || hash clang$__ClangMajorVersion$__ClangMinorVersion 2>/dev/null || hash clang 2>/dev/null || { echo >&2 "Please install clang-$__ClangMajorVersion.$__ClangMinorVersion before running this script"; exit 1; } + else + __GccCombinedDottedVersion=$__GccMajorVersion; + if [[ "$__GccMinorVersion" != "" ]]; then + __GccCombinedDottedVersion=$__GccCombinedDottedVersion.$__GccMinorVersion + fi + hash gcc-$__GccCombinedDottedVersion 2>/dev/null || hash gcc$__GccMajorVersion$__GccMinorVersion 2>/dev/null || hash gcc 2>/dev/null || { echo >&2 "Please install gcc-$__GccMajorVersion.$__GccMinorVersion before running this script"; exit 1; } + fi + +} + +restore_optdata() +{ + local OptDataProjectFilePath="$__ProjectRoot/src/.nuget/optdata/optdata.csproj" + if [[ ( $__SkipRestoreOptData == 0 ) && ( $__isMSBuildOnNETCoreSupported == 1 ) ]]; then + echo "Restoring the OptimizationData package" + "$__RepoRootDir/eng/common/msbuild.sh" $__ArcadeScriptArgs \ + $OptDataProjectFilePath /t:Restore /m \ + $__CommonMSBuildArgs $__UnprocessedBuildArgs + local exit_code=$? + if [ $exit_code != 0 ]; then + echo "${__ErrMsgPrefix}Failed to restore the optimization data package." + exit $exit_code + fi + fi + + if [ $__isMSBuildOnNETCoreSupported == 1 ]; then + # Parse the optdata package versions out of msbuild so that we can pass them on to CMake + + local PgoDataPackagePathOutputFile="${__IntermediatesDir}/optdatapath.txt" + local IbcDataPackagePathOutputFile="${__IntermediatesDir}/ibcoptdatapath.txt" + + # Writes into ${PgoDataPackagePathOutputFile} + "$__RepoRootDir/eng/common/msbuild.sh" $__ArcadeScriptArgs $OptDataProjectFilePath /t:DumpPgoDataPackagePath ${__CommonMSBuildArgs} /p:PgoDataPackagePathOutputFile=${PgoDataPackagePathOutputFile} 2>&1 > /dev/null + local exit_code=$? + if [ $exit_code != 0 ] || [ ! -f "${PgoDataPackagePathOutputFile}" ]; then + echo "${__ErrMsgPrefix}Failed to get PGO data package path." + exit $exit_code + fi + + __PgoOptDataPath=$(<"${PgoDataPackagePathOutputFile}") + + # Writes into ${IbcDataPackagePathOutputFile} + "$__RepoRootDir/eng/common/msbuild.sh" $__ArcadeScriptArgs $OptDataProjectFilePath /t:DumpIbcDataPackagePath ${__CommonMSBuildArgs} /p:IbcDataPackagePathOutputFile=${IbcDataPackagePathOutputFile} 2>&1 > /dev/null + local exit_code=$? + if [ $exit_code != 0 ] || [ ! -f "${IbcDataPackagePathOutputFile}" ]; then + echo "${__ErrMsgPrefix}Failed to get IBC data package path." + exit $exit_code + fi + + __IbcOptDataPath=$(<"${IbcDataPackagePathOutputFile}") + fi +} + +generate_event_logging_sources() +{ + __OutputEventingDir=$1 + + __PythonWarningFlags="-Wall" + if [[ $__IgnoreWarnings == 0 ]]; then + __PythonWarningFlags="$__PythonWarningFlags -Werror" + fi + + echo "Laying out dynamically generated EventSource classes" + $PYTHON -B $__PythonWarningFlags "$__ProjectRoot/src/scripts/genRuntimeEventSources.py" --man "$__ProjectRoot/src/vm/ClrEtwAll.man" --intermediate "$__OutputEventingDir" +} + +generate_event_logging() +{ + # Event Logging Infrastructure + if [[ $__SkipMSCorLib == 0 ]]; then + generate_event_logging_sources "$__ArtifactsIntermediatesDir/Eventing/$__BuildArch/$__BuildType" + fi +} + +build_native() +{ + skipCondition=$1 + platformArch="$2" + intermediatesForBuild="$3" + extraCmakeArguments="$4" + message="$5" + + if [ $skipCondition == 1 ]; then + echo "Skipping $message build." + return + fi + + # All set to commence the build + echo "Commencing build of $message for $__BuildOS.$__BuildArch.$__BuildType in $intermediatesForBuild" + + generator="" + buildTool="make" + if [ $__UseNinja == 1 ]; then + generator="ninja" + if ! buildTool=$(command -v ninja || command -v ninja-build); then + echo "Unable to locate ninja!" 1>&2 + exit 1 + fi + fi + + if [ $__SkipConfigure == 0 ]; then + # if msbuild is not supported, then set __SkipGenerateVersion to 1 + if [ $__isMSBuildOnNETCoreSupported == 0 ]; then __SkipGenerateVersion=1; fi + # Drop version.c file + __versionSourceFile="$intermediatesForBuild/version.c" + if [ $__SkipGenerateVersion == 0 ]; then + pwd + "$__RepoRootDir/eng/common/msbuild.sh" $__ArcadeScriptArgs $__ProjectRoot/eng/empty.csproj \ + /p:NativeVersionFile=$__versionSourceFile \ + /t:GenerateNativeVersionFile /restore \ + $__CommonMSBuildArgs $__UnprocessedBuildArgs + local exit_code=$? + if [ $exit_code != 0 ]; then + echo "${__ErrMsgPrefix}Failed to generate native version file." + exit $exit_code + fi + else + # Generate the dummy version.c, but only if it didn't exist to make sure we don't trigger unnecessary rebuild + __versionSourceLine="static char sccsid[] __attribute__((used)) = \"@(#)No version information produced\";" + if [ -e $__versionSourceFile ]; then + read existingVersionSourceLine < $__versionSourceFile + fi + if [ "$__versionSourceLine" != "$existingVersionSourceLine" ]; then + echo $__versionSourceLine > $__versionSourceFile + fi + fi + + # Regenerate the CMake solution + + scriptDir="$__ProjectRoot/src/pal/tools" + if [[ $__GccBuild == 0 ]]; then + echo "Invoking \"$scriptDir/find-clang.sh\" $__ClangMajorVersion \"$__ClangMinorVersion\"" + source "$scriptDir/find-clang.sh" $__ClangMajorVersion "$__ClangMinorVersion" + if [[ $__StaticAnalyzer == 1 ]]; then + scan_build=scan-build + fi + else + echo "Invoking \"$scriptDir/find-gcc.sh\" \"$__GccMajorVersion\" \"$__GccMinorVersion\"" + source "$scriptDir/find-gcc.sh" "$__GccMajorVersion" "$__GccMinorVersion" + fi + + if [[ -n "$__CodeCoverage" ]]; then + extraCmakeArguments="$extraCmakeArguments -DCLR_CMAKE_ENABLE_CODE_COVERAGE=1" + fi + + echo "Invoking \"$scriptDir/gen-buildsys.sh\" \"$__ProjectRoot\" \"$intermediatesForBuild\" $platformArch $__BuildType $generator $scan_build $extraCmakeArguments $__cmakeargs" + source "$scriptDir/gen-buildsys.sh" "$__ProjectRoot" "$intermediatesForBuild" $platformArch $__BuildType $generator $scan_build "$extraCmakeArguments" "$__cmakeargs" + + if [ $? != 0 ]; then + echo "${__ErrMsgPrefix}Failed to generate $message build project!" + exit 1 + fi + fi + + if [ ! -f "$intermediatesForBuild/CMakeCache.txt" ]; then + echo "${__ErrMsgPrefix}Unable to find generated build files for $message project!" + exit 1 + fi + + # Build + if [ $__ConfigureOnly == 1 ]; then + echo "Finish configuration & skipping $message build." + return + fi + + # Check that the makefiles were created. + + if [ $__StaticAnalyzer == 1 ]; then + pushd "$intermediatesForBuild" + + buildTool="$SCAN_BUILD_COMMAND $buildTool" + echo "Executing $buildTool install -j $__NumProc" + $buildTool install -j $__NumProc + + popd + else + echo "Executing cmake --build \"$intermediatesForBuild\" --target install -j $__NumProc" + + cmake --build "$intermediatesForBuild" --target install -j $__NumProc + fi + + local exit_code=$? + if [ $exit_code != 0 ]; then + echo "${__ErrMsgPrefix}Failed to build $message." + exit $exit_code + fi + +} + +build_cross_architecture_components() +{ + local intermediatesForBuild="$__IntermediatesDir/Host$__CrossArch/crossgen" + local crossArchBinDir="$__BinDir/$__CrossArch" + + mkdir -p "$intermediatesForBuild" + mkdir -p "$crossArchBinDir" + + generate_event_logging_sources "$intermediatesForBuild" "the crossarch build system" + + __SkipCrossArchBuild=1 + # check supported cross-architecture components host(__HostArch)/target(__BuildArch) pair + if [[ ("$__BuildArch" == "arm" || "$__BuildArch" == "armel") && ("$__CrossArch" == "x86" || "$__CrossArch" == "x64") ]]; then + __SkipCrossArchBuild=0 + elif [[ "$__BuildArch" == "arm64" && "$__CrossArch" == "x64" ]]; then + __SkipCrossArchBuild=0 + else + # not supported + return + fi + + export __CMakeBinDir="$crossArchBinDir" + export CROSSCOMPILE=0 + + __ExtraCmakeArgs="-DCLR_CMAKE_TARGET_ARCH=$__BuildArch -DCLR_CMAKE_PGO_INSTRUMENT=$__PgoInstrument -DCLR_CMAKE_OPTDATA_PATH=$__PgoOptDataPath -DCLR_CMAKE_PGO_OPTIMIZE=$__PgoOptimize -DCLR_CROSS_COMPONENTS_BUILD=1" + build_native $__SkipCrossArchBuild "$__CrossArch" "$intermediatesForBuild" "$__ExtraCmakeArgs" "cross-architecture components" + + export CROSSCOMPILE=1 +} + +isMSBuildOnNETCoreSupported() +{ + __isMSBuildOnNETCoreSupported=$__msbuildonunsupportedplatform + + if [ $__isMSBuildOnNETCoreSupported == 1 ]; then + return + fi + + if [ $__SkipManaged == 1 ]; then + __isMSBuildOnNETCoreSupported=0 + return + fi + + if [[ ("$__HostOS" == "Linux") && ("$__HostArch" == "x64" || "$__HostArch" == "arm" || "$__HostArch" == "arm64") ]]; then + __isMSBuildOnNETCoreSupported=1 + fi + if [ "$__HostArch" == "x64" ]; then + if [ "$__HostOS" == "OSX" ]; then + __isMSBuildOnNETCoreSupported=1 + elif [ "$__HostOS" == "FreeBSD" ]; then + __isMSBuildOnNETCoreSupported=1 + fi + fi +} + + +build_CoreLib_ni() +{ + local __CrossGenExec=$1 + local __CoreLibILDir=$2 + + if [ $__PartialNgen == 1 ]; then + export COMPlus_PartialNGen=1 + fi + + if [ -e $__CrossGenCoreLibLog ]; then + rm $__CrossGenCoreLibLog + fi + echo "Generating native image of System.Private.CoreLib.dll for $__BuildOS.$__BuildArch.$__BuildType. Logging to \"$__CrossGenCoreLibLog\"." + echo "$__CrossGenExec /Platform_Assemblies_Paths $__CoreLibILDir $__IbcTuning /out $__BinDir/System.Private.CoreLib.dll $__CoreLibILDir/System.Private.CoreLib.dll" + $__CrossGenExec /Platform_Assemblies_Paths $__CoreLibILDir $__IbcTuning /out $__BinDir/System.Private.CoreLib.dll $__CoreLibILDir/System.Private.CoreLib.dll >> $__CrossGenCoreLibLog 2>&1 + local exit_code=$? + if [ $exit_code != 0 ]; then + echo "${__ErrMsgPrefix}Failed to generate native image for System.Private.CoreLib. Refer to $__CrossGenCoreLibLog" + exit $exit_code + fi + + if [ "$__BuildOS" == "Linux" ]; then + echo "Generating symbol file for System.Private.CoreLib.dll" + echo "$__CrossGenExec /Platform_Assemblies_Paths $__BinDir /CreatePerfMap $__BinDir $__BinDir/System.Private.CoreLib.dll" + $__CrossGenExec /Platform_Assemblies_Paths $__BinDir /CreatePerfMap $__BinDir $__BinDir/System.Private.CoreLib.dll >> $__CrossGenCoreLibLog 2>&1 + local exit_code=$? + if [ $exit_code != 0 ]; then + echo "${__ErrMsgPrefix}Failed to generate symbol file for System.Private.CoreLib. Refer to $__CrossGenCoreLibLog" + exit $exit_code + fi + fi +} + +build_CoreLib() +{ + if [ $__isMSBuildOnNETCoreSupported == 0 ]; then + echo "System.Private.CoreLib.dll build unsupported." + return + fi + + if [ $__SkipMSCorLib == 1 ]; then + echo "Skipping building System.Private.CoreLib." + return + fi + + echo "Commencing build of managed components for $__BuildOS.$__BuildArch.$__BuildType" + + # Invoke MSBuild + __ExtraBuildArgs="" + if [[ "$__IbcTuning" == "" ]]; then + __ExtraBuildArgs="$__ExtraBuildArgs /p:OptimizationDataDir=\"$__IbcOptDataPath/data\"" + __ExtraBuildArgs="$__ExtraBuildArgs /p:EnableProfileGuidedOptimization=true" + fi + + if [[ "$__BuildManagedTools" -eq "1" ]]; then + __ExtraBuildArgs="$__ExtraBuildArgs /p:BuildManagedTools=true" + fi + + "$__RepoRootDir/eng/common/msbuild.sh" $__ArcadeScriptArgs \ + $__ProjectDir/src/build.proj /t:Restore \ + /p:PortableBuild=true /maxcpucount /p:IncludeRestoreOnlyProjects=true \ + /flp:Verbosity=normal\;LogFile=$__LogsDir/System.Private.CoreLib_$__BuildOS__$__BuildArch__$__BuildType.log \ + /p:__IntermediatesDir=$__IntermediatesDir /p:__RootBinDir=$__RootBinDir \ + $__CommonMSBuildArgs $__ExtraBuildArgs $__UnprocessedBuildArgs + + local exit_code=$? + if [ $exit_code != 0 ]; then + echo "${__ErrMsgPrefix}Failed to restore managed components." + exit $exit_code + fi + + "$__RepoRootDir/eng/common/msbuild.sh" $__ArcadeScriptArgs \ + $__ProjectDir/src/build.proj \ + /p:PortableBuild=true /maxcpucount \ + /flp:Verbosity=normal\;LogFile=$__LogsDir/System.Private.CoreLib_$__BuildOS__$__BuildArch__$__BuildType.log \ + /p:__IntermediatesDir=$__IntermediatesDir /p:__RootBinDir=$__RootBinDir \ + $__CommonMSBuildArgs $__ExtraBuildArgs $__UnprocessedBuildArgs + + local exit_code=$? + if [ $exit_code != 0 ]; then + echo "${__ErrMsgPrefix}Failed to build managed components." + exit $exit_code + fi + + if [[ "$__BuildManagedTools" -eq "1" ]]; then + echo "Publishing crossgen2 for $__DistroRid" + "$__ProjectRoot/dotnet.sh" publish --self-contained -r $__DistroRid -c $__BuildType -o "$__BinDir/crossgen2" "$__ProjectRoot/src/tools/crossgen2/crossgen2/crossgen2.csproj" /p:BuildArch=$__BuildArch + + local exit_code=$? + if [ $exit_code != 0 ]; then + echo "${__ErrMsgPrefix}Failed to build crossgen2." + exit $exit_code + fi + + if [ "$__HostOS" == "OSX" ]; then + cp "$__BinDir/libclrjit.dylib" "$__BinDir/crossgen2/libclrjitilc.dylib" + cp "$__BinDir/libjitinterface.dylib" "$__BinDir/crossgen2/libjitinterface.dylib" + else + cp "$__BinDir/libclrjit.so" "$__BinDir/crossgen2/libclrjitilc.so" + cp "$__BinDir/libjitinterface.so" "$__BinDir/crossgen2/libjitinterface.so" + fi + fi + + local __CoreLibILDir=$__BinDir/IL + + if [ $__SkipCrossgen == 1 ]; then + echo "Skipping generating native image" + + if [ $__CrossBuild == 1 ]; then + # Crossgen not performed, so treat the IL version as the final version + cp $__CoreLibILDir/System.Private.CoreLib.dll $__BinDir/System.Private.CoreLib.dll + fi + + return + fi + + # The cross build generates a crossgen with the target architecture. + if [ $__CrossBuild == 0 ]; then + if [ $__SkipCoreCLR == 1 ]; then + return + fi + + # The architecture of host pc must be same architecture with target. + if [[ ( "$__HostArch" == "$__BuildArch" ) ]]; then + build_CoreLib_ni "$__BinDir/crossgen" $__CoreLibILDir + elif [[ ( "$__HostArch" == "x64" ) && ( "$__BuildArch" == "x86" ) ]]; then + build_CoreLib_ni "$__BinDir/crossgen" $__CoreLibILDir + elif [[ ( "$__HostArch" == "arm64" ) && ( "$__BuildArch" == "arm" ) ]]; then + build_CoreLib_ni "$__BinDir/crossgen" $__CoreLibILDir + else + exit 1 + fi + else + if [[ ( "$__CrossArch" == "x86" ) && ( "$__BuildArch" == "arm" ) ]]; then + build_CoreLib_ni "$__CrossComponentBinDir/crossgen" $__CoreLibILDir + elif [[ ( "$__CrossArch" == "x64" ) && ( "$__BuildArch" == "arm" ) ]]; then + build_CoreLib_ni "$__CrossComponentBinDir/crossgen" $__CoreLibILDir + elif [[ ( "$__HostArch" == "x64" ) && ( "$__BuildArch" == "arm64" ) ]]; then + build_CoreLib_ni "$__CrossComponentBinDir/crossgen" $__CoreLibILDir + else + # Crossgen not performed, so treat the IL version as the final version + cp $__CoreLibILDir/System.Private.CoreLib.dll $__BinDir/System.Private.CoreLib.dll + fi + fi +} + +generate_NugetPackages() +{ + # We can only generate nuget package if we also support building mscorlib as part of this build. + if [ $__isMSBuildOnNETCoreSupported == 0 ]; then + echo "Nuget package generation unsupported." + return + fi + + # Since we can build mscorlib for this OS, did we build the native components as well? + if [[ $__SkipCoreCLR == 1 && $__CrossgenOnly == 0 ]]; then + echo "Unable to generate nuget packages since native components were not built." + return + fi + + echo "Generating nuget packages for "$__BuildOS + echo "DistroRid is "$__DistroRid + echo "ROOTFS_DIR is "$ROOTFS_DIR + # Build the packages + # Package build uses the Arcade system and scripts, relying on it to restore required toolsets as part of build + $__RepoRootDir/eng/common/build.sh -r -b -projects $__SourceDir/.nuget/packages.builds \ + -verbosity minimal -bl:$__LogsDir/Nuget_$__BuildOS__$__BuildArch__$__BuildType.binlog \ + /p:PortableBuild=true \ + /p:__IntermediatesDir=$__IntermediatesDir /p:__RootBinDir=$__RootBinDir /p:__DoCrossArchBuild=$__CrossBuild \ + $__CommonMSBuildArgs $__UnprocessedBuildArgs + + local exit_code=$? + if [ $exit_code != 0 ]; then + echo "${__ErrMsgPrefix}Failed to generate Nuget packages." + exit $exit_code + fi +} + +echo "Commencing CoreCLR Repo build" + +# Argument types supported by this script: +# +# Build architecture - valid values are: x64, ARM. +# Build Type - valid values are: Debug, Checked, Release +# +# Set the default arguments for build + +# Obtain the location of the bash script to figure out where the root of the subrepo is. +__ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +# Some paths are relative to the main repo root +__RepoRootDir="${__ProjectRoot}/../.." + +# BEGIN SECTION to remove after repo consolidation +if [ ! -f "${__RepoRootDir}/.dotnet-runtime-placeholder" ]; then + __RepoRootDir=${__ProjectRoot} +fi +# END SECTION to remove after repo consolidation + +# Use uname to determine what the CPU is. +CPUName=$(uname -p) +# Some Linux platforms report unknown for platform, but the arch for machine. +if [ "$CPUName" == "unknown" ]; then + CPUName=$(uname -m) +fi + +case $CPUName in + i686) + echo "Unsupported CPU $CPUName detected, build might not succeed!" + __BuildArch=x86 + __HostArch=x86 + ;; + + x86_64) + __BuildArch=x64 + __HostArch=x64 + ;; + + armv7l) + echo "Unsupported CPU $CPUName detected, build might not succeed!" + __BuildArch=arm + __HostArch=arm + ;; + + aarch64) + __BuildArch=arm64 + __HostArch=arm64 + ;; + + amd64) + __BuildArch=x64 + __HostArch=x64 + ;; + *) + echo "Unknown CPU $CPUName detected, configuring as if for x64" + __BuildArch=x64 + __HostArch=x64 + ;; +esac + +# Use uname to determine what the OS is. +OSName=$(uname -s) +case $OSName in + Linux) + __BuildOS=Linux + __HostOS=Linux + ;; + + Darwin) + __BuildOS=OSX + __HostOS=OSX + ;; + + FreeBSD) + __BuildOS=FreeBSD + __HostOS=FreeBSD + ;; + + OpenBSD) + __BuildOS=OpenBSD + __HostOS=OpenBSD + ;; + + NetBSD) + __BuildOS=NetBSD + __HostOS=NetBSD + ;; + + SunOS) + __BuildOS=SunOS + __HostOS=SunOS + ;; + + *) + echo "Unsupported OS $OSName detected, configuring as if for Linux" + __BuildOS=Linux + __HostOS=Linux + ;; +esac + +__BuildType=Debug +__CodeCoverage= +__IgnoreWarnings=0 + +# Set the various build properties here so that CMake and MSBuild can pick them up +__ProjectDir="$__ProjectRoot" +__SourceDir="$__ProjectDir/src" +__RootBinDir="$__ProjectDir/bin" +__UnprocessedBuildArgs= +__CommonMSBuildArgs= +__MSBCleanBuildArgs= +__UseNinja=0 +__VerboseBuild=0 +__PgoInstrument=0 +__PgoOptimize=1 +__IbcTuning="" +__ConfigureOnly=0 +__SkipConfigure=0 +__SkipManaged=0 +__SkipRestore="" +__SkipNuget=0 +__SkipCoreCLR=0 +__SkipCrossArchNative=0 +__SkipMSCorLib=0 +__SkipRestoreOptData=0 +__SkipCrossgen=0 +__CrossgenOnly=0 +__PartialNgen=0 +__CrossBuild=0 +__ClangMajorVersion=0 +__ClangMinorVersion=0 +__GccBuild=0 +__GccMajorVersion=0 +__GccMinorVersion=0 +__DistroRid="" +__cmakeargs="" +__SkipGenerateVersion=0 +__PortableBuild=1 +__msbuildonunsupportedplatform=0 +__PgoOptDataPath="" +__IbcOptDataPath="" +__BuildManagedTools=1 +__SkipRestoreArg="/p:RestoreDuringBuild=true" +__SignTypeArg="" +__OfficialBuildIdArg="" +__StaticAnalyzer=0 + +# Get the number of processors available to the scheduler +# Other techniques such as `nproc` only get the number of +# processors available to a single process. +if [ `uname` = "FreeBSD" ]; then + __NumProc=`sysctl hw.ncpu | awk '{ print $2+1 }'` +elif [ `uname` = "NetBSD" ]; then + __NumProc=$(($(getconf NPROCESSORS_ONLN)+1)) +elif [ `uname` = "Darwin" ]; then + __NumProc=$(($(getconf _NPROCESSORS_ONLN)+1)) +else + __NumProc=$(nproc --all) +fi + +while :; do + if [ $# -le 0 ]; then + break + fi + + lowerI="$(echo $1 | awk '{print tolower($0)}')" + case $lowerI in + -\?|-h|--help) + usage + exit 1 + ;; + + x86|-x86) + __BuildArch=x86 + ;; + + x64|-x64) + __BuildArch=x64 + ;; + + arm|-arm) + __BuildArch=arm + ;; + + armel|-armel) + __BuildArch=armel + ;; + + arm64|-arm64) + __BuildArch=arm64 + ;; + + debug|-debug) + __BuildType=Debug + ;; + + checked|-checked) + __BuildType=Checked + ;; + + release|-release) + __BuildType=Release + ;; + + ci|-ci) + __ArcadeScriptArgs="--ci" + __ErrMsgPrefix="##vso[task.logissue type=error]" + ;; + + coverage|-coverage) + __CodeCoverage=Coverage + ;; + + cross|-cross) + __CrossBuild=1 + ;; + + -portablebuild=false) + __PortableBuild=0 + ;; + + verbose|-verbose) + __VerboseBuild=1 + ;; + + stripsymbols|-stripsymbols) + __cmakeargs="$__cmakeargs -DSTRIP_SYMBOLS=true" + ;; + + clang3.5|-clang3.5) + __ClangMajorVersion=3 + __ClangMinorVersion=5 + ;; + + clang3.6|-clang3.6) + __ClangMajorVersion=3 + __ClangMinorVersion=6 + ;; + + clang3.7|-clang3.7) + __ClangMajorVersion=3 + __ClangMinorVersion=7 + ;; + + clang3.8|-clang3.8) + __ClangMajorVersion=3 + __ClangMinorVersion=8 + ;; + + clang3.9|-clang3.9) + __ClangMajorVersion=3 + __ClangMinorVersion=9 + ;; + + clang4.0|-clang4.0) + __ClangMajorVersion=4 + __ClangMinorVersion=0 + ;; + + clang5.0|-clang5.0) + __ClangMajorVersion=5 + __ClangMinorVersion=0 + ;; + + clang6.0|-clang6.0) + __ClangMajorVersion=6 + __ClangMinorVersion=0 + ;; + + clang7|-clang7) + __ClangMajorVersion=7 + __ClangMinorVersion= + ;; + + clang8|-clang8) + __ClangMajorVersion=8 + __ClangMinorVersion= + ;; + + clang9|-clang9) + __ClangMajorVersion=9 + __ClangMinorVersion= + ;; + + gcc5|-gcc5) + __GccMajorVersion=5 + __GccMinorVersion= + __GccBuild=1 + ;; + + gcc6|-gcc6) + __GccMajorVersion=6 + __GccMinorVersion= + __GccBuild=1 + ;; + + gcc7|-gcc7) + __GccMajorVersion=7 + __GccMinorVersion= + __GccBuild=1 + ;; + + gcc8|-gcc8) + __GccMajorVersion=8 + __GccMinorVersion= + __GccBuild=1 + ;; + + gcc9|-gcc9) + __GccMajorVersion=9 + __GccMinorVersion= + __GccBuild=1 + ;; + + gcc|-gcc) + __GccMajorVersion= + __GccMinorVersion= + __GccBuild=1 + ;; + + ninja|-ninja) + __UseNinja=1 + ;; + + pgoinstrument|-pgoinstrument) + __PgoInstrument=1 + ;; + + nopgooptimize|-nopgooptimize) + __PgoOptimize=0 + __SkipRestoreOptData=1 + ;; + + ibcinstrument|-ibcinstrument) + __IbcTuning="/Tuning" + ;; + + configureonly|-configureonly) + __ConfigureOnly=1 + __SkipMSCorLib=1 + __SkipNuget=1 + ;; + + skipconfigure|-skipconfigure) + __SkipConfigure=1 + ;; + + skipnative|-skipnative) + # Use "skipnative" to use the same option name as build.cmd. + __SkipCoreCLR=1 + ;; + + skipcoreclr|-skipcoreclr) + # Accept "skipcoreclr" for backwards-compatibility. + __SkipCoreCLR=1 + ;; + + skipcrossarchnative|-skipcrossarchnative) + __SkipCrossArchNative=1 + ;; + + skipmanaged|-skipmanaged) + __SkipManaged=1 + ;; + + skipmscorlib|-skipmscorlib) + __SkipMSCorLib=1 + ;; + + skipgenerateversion|-skipgenerateversion) + __SkipGenerateVersion=1 + ;; + + skiprestoreoptdata|-skiprestoreoptdata) + __SkipRestoreOptData=1 + ;; + + skipcrossgen|-skipcrossgen) + __SkipCrossgen=1 + ;; + + skipmanagedtools | -skipmanagedtools) + __BuildManagedTools=0 + ;; + + crossgenonly|-crossgenonly) + __SkipMSCorLib=1 + __SkipCoreCLR=1 + __CrossgenOnly=1 + ;; + partialngen|-partialngen) + __PartialNgen=1 + ;; + + skipnuget|-skipnuget|skipbuildpackages|-skipbuildpackages) + __SkipNuget=1 + ;; + + ignorewarnings|-ignorewarnings) + __IgnoreWarnings=1 + __cmakeargs="$__cmakeargs -DCLR_CMAKE_WARNINGS_ARE_ERRORS=OFF" + ;; + + cmakeargs|-cmakeargs) + if [ -n "$2" ]; then + __cmakeargs="$__cmakeargs $2" + shift + else + echo "ERROR: 'cmakeargs' requires a non-empty option argument" + exit 1 + fi + ;; + + bindir|-bindir) + if [ -n "$2" ]; then + __RootBinDir="$2" + if [ ! -d $__RootBinDir ]; then + mkdir $__RootBinDir + fi + __RootBinParent=$(dirname $__RootBinDir) + __RootBinName=${__RootBinDir##*/} + __RootBinDir="$(cd $__RootBinParent &>/dev/null && printf %s/%s $PWD $__RootBinName)" + shift + else + echo "ERROR: 'bindir' requires a non-empty option argument" + exit 1 + fi + ;; + msbuildonunsupportedplatform|-msbuildonunsupportedplatform) + __msbuildonunsupportedplatform=1 + ;; + numproc|-numproc) + if [ -n "$2" ]; then + __NumProc="$2" + shift + else + echo "ERROR: 'numproc' requires a non-empty option argument" + exit 1 + fi + ;; + osgroup|-osgroup) + if [ -n "$2" ]; then + __BuildOS="$2" + shift + else + echo "ERROR: 'osgroup' requires a non-empty option argument" + exit 1 + fi + ;; + rebuild|-rebuild) + echo "ERROR: 'Rebuild' is not supported. Please remove it." + exit 1 + ;; + + -skiprestore) + __SkipRestoreArg="/p:RestoreDuringBuild=false" + ;; + + -disableoss) + __SignTypeArg="/p:SignType=real" + ;; + + -officialbuildid=*) + __Id=$(echo $1| cut -d'=' -f 2) + __OfficialBuildIdArg="/p:OfficialBuildId=$__Id" + ;; + + -staticanalyzer) + __StaticAnalyzer=1 + ;; + + --) + # Skip -Option=Value style argument passing + ;; + + *) + __UnprocessedBuildArgs="$__UnprocessedBuildArgs $1" + ;; + esac + + shift +done + +__CommonMSBuildArgs="/p:__BuildArch=$__BuildArch /p:__BuildType=$__BuildType /p:__BuildOS=$__BuildOS /nodeReuse:false $__OfficialBuildIdArg $__SignTypeArg $__SkipRestoreArg" + +# Configure environment if we are doing a verbose build +if [ $__VerboseBuild == 1 ]; then + export VERBOSE=1 + __CommonMSBuildArgs="$__CommonMSBuildArgs /v:detailed" +fi + +# Set default clang version +if [[ $__ClangMajorVersion == 0 && $__ClangMinorVersion == 0 ]]; then + if [[ "$__BuildArch" == "arm" || "$__BuildArch" == "armel" ]]; then + __ClangMajorVersion=5 + __ClangMinorVersion=0 + else + __ClangMajorVersion=3 + __ClangMinorVersion=9 + fi +fi + +# Set dependent variables +__LogsDir="$__RootBinDir/Logs" +__MsbuildDebugLogsDir="$__LogsDir/MsbuildDebugLogs" + +# Set the remaining variables based upon the determined build configuration +__BinDir="$__RootBinDir/Product/$__BuildOS.$__BuildArch.$__BuildType" +__PackagesBinDir="$__BinDir/.nuget" +export __IntermediatesDir="$__RootBinDir/obj/$__BuildOS.$__BuildArch.$__BuildType" +export __ArtifactsIntermediatesDir="$__ProjectDir/artifacts/obj" +__isMSBuildOnNETCoreSupported=0 +__CrossComponentBinDir="$__BinDir" + +__CrossArch="$__HostArch" +if [ $__CrossBuild == 1 ]; then + __CrossComponentBinDir="$__CrossComponentBinDir/$__CrossArch" +fi +__CrossGenCoreLibLog="$__LogsDir/CrossgenCoreLib_$__BuildOS.$__BuildArch.$__BuildType.log" + +# Configure environment if we are doing a cross compile. +if [ $__CrossBuild == 1 ]; then + export CROSSCOMPILE=1 + if ! [[ -n "$ROOTFS_DIR" ]]; then + export ROOTFS_DIR="$__ProjectRoot/cross/rootfs/$__BuildArch" + fi +fi + +# init the target distro name +initTargetDistroRid + +if [ $__PortableBuild == 0 ]; then + __CommonMSBuildArgs="$__CommonMSBuildArgs /p:PortableBuild=false" +fi + +# Init if MSBuild for .NET Core is supported for this platform +isMSBuildOnNETCoreSupported + +# CI_SPECIFIC - On CI machines, $HOME may not be set. In such a case, create a subfolder and set the variable to set. +# This is needed by CLI to function. +if [ -z "$HOME" ]; then + if [ ! -d "$__ProjectDir/temp_home" ]; then + mkdir temp_home + fi + export HOME=$__ProjectDir/temp_home + echo "HOME not defined; setting it to $HOME" +fi + +# Specify path to be set for CMAKE_INSTALL_PREFIX. +# This is where all built CoreClr libraries will copied to. +export __CMakeBinDir="$__BinDir" + +# Make the directories necessary for build if they don't exist +setup_dirs + +# Set up the directory for MSBuild debug logs. +export MSBUILDDEBUGPATH="${__MsbuildDebugLogsDir}" + +# Check prereqs. +check_prereqs + +# Restore the package containing profile counts for profile-guided optimizations +restore_optdata + +# Generate event logging infrastructure sources +generate_event_logging + +# Build the coreclr (native) components. +__ExtraCmakeArgs="-DCLR_CMAKE_PGO_INSTRUMENT=$__PgoInstrument -DCLR_CMAKE_OPTDATA_PATH=$__PgoOptDataPath -DCLR_CMAKE_PGO_OPTIMIZE=$__PgoOptimize" + +build_native $__SkipCoreCLR "$__BuildArch" "$__IntermediatesDir" "$__ExtraCmakeArgs" "CoreCLR component" + +# Build cross-architecture components +if [ $__SkipCrossArchNative != 1 ]; then + if [[ $__CrossBuild == 1 ]]; then + build_cross_architecture_components + fi +fi + +# Build System.Private.CoreLib. + +build_CoreLib + +if [ $__CrossgenOnly == 1 ]; then + build_CoreLib_ni "$__BinDir/crossgen" +fi + +# Generate nuget packages +if [ $__SkipNuget != 1 ]; then + generate_NugetPackages +fi + + +# Build complete + +echo "Repo successfully built." +echo "Product binaries are available at $__BinDir" +exit 0 diff --git a/src/coreclr/dotnet.cmd b/src/coreclr/dotnet.cmd index 686432dce4dd5..2977a944b68f9 100644 --- a/src/coreclr/dotnet.cmd +++ b/src/coreclr/dotnet.cmd @@ -17,7 +17,6 @@ set DOTNET_MULTILEVEL_LOOKUP=0 :: Disable first run since we do not need all ASP.NET packages restored. set DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 -echo Installing dotnet using Arcade... set PS_DOTNET_INSTALL_SCRIPT=". %__RepoRootDir%eng\common\tools.ps1; InitializeDotNetCli($true)" set "PS_COMMAND=powershell -NoProfile -ExecutionPolicy unrestricted -Command %PS_DOTNET_INSTALL_SCRIPT%" diff --git a/src/coreclr/src/pal/tools/gen-buildsys.sh b/src/coreclr/src/pal/tools/gen-buildsys.sh index 5e34f3da6b08e..41c49f032b4f9 100755 --- a/src/coreclr/src/pal/tools/gen-buildsys.sh +++ b/src/coreclr/src/pal/tools/gen-buildsys.sh @@ -30,6 +30,15 @@ then exit 1 fi +__CoreClrDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )/../../.." +__RepoRootDir=${__CoreClrDir}/../.. + +# BEGIN SECTION to remove after repo consolidation +if [ ! -f "${__RepoRootDir}/.dotnet-runtime-placeholder" ]; then + __RepoRootDir=${__CoreClrDir} +fi +# END SECTION to remove after repo consolidation + build_arch="$3" buildtype=DEBUG code_coverage=OFF @@ -65,12 +74,9 @@ if [ "$CROSSCOMPILE" == "1" ]; then echo "ROOTFS_DIR not set for crosscompile" exit 1 fi - if [[ -z $CONFIG_DIR ]]; then - CONFIG_DIR="$1/eng/common/cross" - fi export TARGET_BUILD_ARCH=$build_arch - cmake_extra_defines="$cmake_extra_defines -C $scriptroot/tryrun.cmake" - cmake_extra_defines="$cmake_extra_defines -DCMAKE_TOOLCHAIN_FILE=$CONFIG_DIR/toolchain.cmake" + cmake_extra_defines="$cmake_extra_defines -C ${__CoreClrDir}/tryrun.cmake" + cmake_extra_defines="$cmake_extra_defines -DCMAKE_TOOLCHAIN_FILE=${__RepoRootDir}/eng/common/cross/toolchain.cmake" fi cmake_command=$(command -v cmake) diff --git a/src/coreclr/tests/setup-stress-dependencies.sh b/src/coreclr/tests/setup-stress-dependencies.sh index b556ed27f33dd..1db0cc97894bb 100755 --- a/src/coreclr/tests/setup-stress-dependencies.sh +++ b/src/coreclr/tests/setup-stress-dependencies.sh @@ -90,7 +90,7 @@ fi # This script must be located in coreclr/tests. scriptDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -dotnet=$"${scriptDir}"/../.dotnet/dotnet +dotnet=$"${scriptDir}"/../dotnet.sh csprojPath="${scriptDir}"/stress_dependencies/stress_dependencies.csproj if [ ! -e $dotnetCmd ]; then diff --git a/src/coreclr/tests/src/runtest.proj b/src/coreclr/tests/src/runtest.proj index 9f2c2a054687c..c7b3483f293a6 100644 --- a/src/coreclr/tests/src/runtest.proj +++ b/src/coreclr/tests/src/runtest.proj @@ -26,7 +26,8 @@ $([System.IO.Path]::GetFullPath(%(Identity))) - + + diff --git a/src/coreclr/src/pal/tools/tryrun.cmake b/src/coreclr/tryrun.cmake similarity index 100% rename from src/coreclr/src/pal/tools/tryrun.cmake rename to src/coreclr/tryrun.cmake