From 255f3845ca103a5ae370798d6362d1e12e07d9d1 Mon Sep 17 00:00:00 2001 From: Adeel Mujahid Date: Mon, 11 Nov 2019 16:36:16 +0200 Subject: [PATCH] Deduplicate some build configuration code (dotnet/coreclr#27636) * Deduplicate some build configuration code While working on another PR, noticed that currently it requires updating two places to add a new platform/compiler/architecture configuration. This PR tries to consolidate the code. Changes: * replace `read_array` custom function with a simple `grep -v` call. * remove `$__PortableLinux` from build-test.sh, as it is unused. * move argument parsing and few common functions in `build.sh` and `build-test.sh` in `_build-commons.sh` and sourced it. * combine the long case-esac block and sort cases alphabetically. * add missing `hyphen-less|hyphened)` variants. * sort `CPUName` and `OSName` list. * changed `__CommonMSBuildArgs` from array to string in `build-test.sh`, as it is in `build.sh`. * sort local argument names in build/build-test alphabetically at declaration site. * merge `locate_llvm_exec` and `locate_gcc_exec` into a single `locate_toolchain_exec` cmake function. * this enables overriding individual llvm tool via `CLR_` environment variable, as it was supported by `locate_gcc_exec` today. * Merge dotnet/master to fix/deduplicate-configs * Merge conflict * Move __CrossBuild check back to build.sh Commit migrated from https://github.com/dotnet/coreclr/commit/a15413fd520f7f25273b92d1087b5f7964801dba --- src/coreclr/_build-commons.sh | 425 +++++++++++++++++++++++++ src/coreclr/build-test.sh | 558 +++++---------------------------- src/coreclr/build.sh | 649 +++++++-------------------------------- src/coreclr/configuretools.cmake | 90 +++--- 4 files changed, 666 insertions(+), 1056 deletions(-) create mode 100755 src/coreclr/_build-commons.sh diff --git a/src/coreclr/_build-commons.sh b/src/coreclr/_build-commons.sh new file mode 100755 index 0000000..28f02ce --- /dev/null +++ b/src/coreclr/_build-commons.sh @@ -0,0 +1,425 @@ +#!/usr/bin/env bash + +initTargetDistroRid() +{ + source ${__ProjectDir}/init-distro-rid.sh + + local passedRootfsDir="" + + # Only pass ROOTFS_DIR if cross is specified. + if [ "$__CrossBuild" = 1 ]; then + passedRootfsDir=${ROOTFS_DIR} + fi + + initDistroRidGlobal "$__BuildOS" "$__BuildArch" "$__PortableBuild" "$passedRootfsDir" +} + +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 + elif [ "$__HostArch" = "x64" ] && { [ "$__HostOS" = "OSX" ] || [ "$__HostOS" = "FreeBSD" ]; }; then + __isMSBuildOnNETCoreSupported=1 + fi +} + +usage() +{ + echo "Usage: $0 " + echo "" + echo "Common Options:" + echo "" + echo "BuildArch can be: -x64, -x86, -arm, -armel, -arm64" + echo "BuildType can be: -debug, -checked, -release" + echo "-bindir - output directory (defaults to $__ProjectRoot/bin)" + echo "-clang - optional argument to build using clang in PATH (default)." + echo "-clangx.y - optional argument to build using clang version x.y." + echo "-cmakeargs - user-settable additional arguments passed to CMake." + echo "-configureonly - do not perform any builds; just configure the build." + echo "-coverage - optional argument to enable code coverage build (currently supported only for Linux and OSX)." + echo "-cross - optional argument to signify cross compilation," + echo " - will use ROOTFS_DIR environment variable if set." + echo "-gcc - optional argument to build using gcc in PATH." + echo "-gccx.y - optional argument to build using gcc version x.y." + echo "-msbuildonunsupportedplatform - build managed binaries even if distro is not officially supported." + echo "-ninja - target ninja instead of GNU make" + echo "-numproc - set the number of build processes." + echo "-portablebuild - pass -portablebuild=false to force a non-portable build." + echo "-skipconfigure - skip build configuration." + echo "-skipmanaged - do not build managed components." + echo "-skipnative - do not build native components." + echo "-skipgenerateversion - disable version generation even if MSBuild is supported." + echo "-verbose - optional argument to enable verbose build output." + echo "" + echo "Additional Options:" + echo "" + for i in ${!usage_list[@]}; do + echo "${usage_list[${i}]}" + done + echo "" + exit 1 +} + +# 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 + aarch64) + __BuildArch=arm64 + __HostArch=arm64 + ;; + + amd64) + __BuildArch=x64 + __HostArch=x64 + ;; + + armv7l) + echo "Unsupported CPU $CPUName detected, build might not succeed!" + __BuildArch=arm + __HostArch=arm + ;; + + i686) + echo "Unsupported CPU $CPUName detected, build might not succeed!" + __BuildArch=x86 + __HostArch=x86 + ;; + + x86_64) + __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 + Darwin) + __BuildOS=OSX + __HostOS=OSX + ;; + + FreeBSD) + __BuildOS=FreeBSD + __HostOS=FreeBSD + ;; + + Linux) + __BuildOS=Linux + __HostOS=Linux + ;; + + NetBSD) + __BuildOS=NetBSD + __HostOS=NetBSD + ;; + + OpenBSD) + __BuildOS=OpenBSD + __HostOS=OpenBSD + ;; + + SunOS) + __BuildOS=SunOS + __HostOS=SunOS + ;; + + *) + echo "Unsupported OS $OSName detected, configuring as if for Linux" + __BuildOS=Linux + __HostOS=Linux + ;; +esac + +while :; do + if [ $# -le 0 ]; then + break + fi + + lowerI="$(echo "$1" | awk '{print tolower($0)}')" + case $lowerI in + -\?|-h|--help) + usage + exit 1 + ;; + + arm|-arm) + __BuildArch=arm + ;; + + arm64|-arm64) + __BuildArch=arm64 + ;; + + armel|-armel) + __BuildArch=armel + ;; + + 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 + ;; + + checked|-checked) + __BuildType=Checked + ;; + + ci|-ci) + __ArcadeScriptArgs="--ci" + __ErrMsgPrefix="##vso[task.logissue type=error]" + ;; + + 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= + ;; + + cmakeargs|-cmakeargs) + if [ -n "$2" ]; then + __cmakeargs="$__cmakeargs $2" + shift + else + echo "ERROR: 'cmakeargs' requires a non-empty option argument" + exit 1 + fi + ;; + + configureonly|-configureonly) + __ConfigureOnly=1 + __SkipMSCorLib=1 + __SkipNuget=1 + ;; + + coverage|-coverage) + __CodeCoverage=Coverage + ;; + + cross|-cross) + __CrossBuild=1 + ;; + + debug|-debug) + __BuildType=Debug + ;; + + 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 + ;; + + msbuildonunsupportedplatform|-msbuildonunsupportedplatform) + __msbuildonunsupportedplatform=1 + ;; + + ninja|-ninja) + __UseNinja=1 + ;; + + numproc|-numproc) + if [ -n "$2" ]; then + __NumProc="$2" + shift + else + echo "ERROR: 'numproc' requires a non-empty option argument" + exit 1 + fi + ;; + + portablebuild=false|-portablebuild=false) + __PortableBuild=0 + ;; + + rebuild|-rebuild) + __RebuildTests=1 + ;; + + release|-release) + __BuildType=Release + ;; + + skipconfigure|-skipconfigure) + __SkipConfigure=1 + ;; + + skipgenerateversion|-skipgenerateversion) + __SkipGenerateVersion=1 + ;; + + skipmanaged|-skipmanaged) + __SkipManaged=1 + __BuildTestWrappers=0 + ;; + + skipnative|-skipnative) + __SkipNative=1 + __SkipCoreCLR=1 + __CopyNativeProjectsAfterCombinedTestBuild=false + ;; + + verbose|-verbose) + __VerboseBuild=1 + ;; + + x86|-x86) + __BuildArch=x86 + ;; + + x64|-x64) + __BuildArch=x64 + ;; + + *) + handle_arguments "$1" + ;; + esac + + shift +done + +# 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. +platform=$(uname) +if [ "$platform" = "FreeBSD" ]; then + __NumProc=$(sysctl hw.ncpu | awk '{ print $2+1 }') +elif [ "$platform" = "NetBSD" ]; then + __NumProc=$(($(getconf NPROCESSORS_ONLN)+1)) +elif [ "$platform" = "Darwin" ]; then + __NumProc=$(($(getconf _NPROCESSORS_ONLN)+1)) +else + __NumProc=$(nproc --all) +fi + +__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 diff --git a/src/coreclr/build-test.sh b/src/coreclr/build-test.sh index 9c1ea07..7d6db0d 100755 --- a/src/coreclr/build-test.sh +++ b/src/coreclr/build-test.sh @@ -1,44 +1,5 @@ #!/usr/bin/env bash -__PortableBuild=1 - -initTargetDistroRid() -{ - source ${__ProjectDir}/init-distro-rid.sh - - # Only pass ROOTFS_DIR if cross is specified. - if (( ${__CrossBuild} == 1 )); then - passedRootfsDir=${ROOTFS_DIR} - fi - - initDistroRidGlobal ${__BuildOS} ${__BuildArch} ${__PortableBuild} ${passedRootfsDir} -} - -isMSBuildOnNETCoreSupported() -{ - __isMSBuildOnNETCoreSupported=$__msbuildonunsupportedplatform - - if [ $__isMSBuildOnNETCoreSupported == 1 ]; then - return - fi - - if [ "$__HostArch" == "x64" ]; then - if [ "$__HostOS" == "Linux" ]; then - __isMSBuildOnNETCoreSupported=1 - UNSUPPORTED_RIDS=("debian.9-x64" "ubuntu.17.04-x64") - for UNSUPPORTED_RID in "${UNSUPPORTED_RIDS[@]}" - do - if [ "${__DistroRid}" == "$UNSUPPORTED_RID" ]; then - __isMSBuildOnNETCoreSupported=0 - break - fi - done - elif [ "$__HostOS" == "OSX" ]; then - __isMSBuildOnNETCoreSupported=1 - fi - fi -} - build_test_wrappers() { if [ $__BuildTestWrappers -ne -0 ]; then @@ -175,9 +136,9 @@ precompile_coreroot_fx() { local overlayDir=$CORE_ROOT local compilerName=Crossgen - + # Read the exclusion file for this platform - skipCrossGenFiles=($(read_array "$(dirname "$0")/tests/skipCrossGenFiles.${__BuildArch}.txt")) + skipCrossGenFiles=($(grep -v '^#' "$(dirname "$0")/tests/skipCrossGenFiles.${__BuildArch}.txt" 2> /dev/null)) skipCrossGenFiles+=('System.Runtime.WindowsRuntime.dll') # Temporary output folder for Crossgen2-compiled assemblies @@ -212,7 +173,7 @@ precompile_coreroot_fx() filesToPrecompile=$(find -L $overlayDir -maxdepth 1 -iname \*.dll -not -iname \*.ni.dll -not -iname \*-ms-win-\* -not -iname xunit.\* -type f) for fileToPrecompile in ${filesToPrecompile} do - local filename=${fileToPrecompile} + local filename=${fileToPrecompile} if is_skip_crossgen_test "$(basename $filename)"; then continue fi @@ -260,25 +221,6 @@ function is_skip_crossgen_test { return 1 } -# Get an array of items by reading the specified file line by line. -function read_array { - local theArray=() - - if [ ! -f "$1" ]; then - return - fi - - # bash in Mac OS X doesn't support 'readarray', so using alternate way instead. - # readarray -t theArray < "$1" - # Any line that starts with '#' is ignored. - while IFS='' read -r line || [ -n "$line" ]; do - if [[ $line != "#"* ]]; then - theArray[${#theArray[@]}]=$line - fi - done < "$1" - echo ${theArray[@]} -} - generate_testhost() { echo "${__MsgPrefix}Generating test host..." @@ -468,7 +410,7 @@ build_MSBuild_projects() buildArgs+=("${__msbuildLog}" "${__msbuildWrn}" "${__msbuildErr}") buildArgs+=("${extraBuildParameters[@]}") - buildArgs+=("${__CommonMSBuildArgs[@]}") + buildArgs+=("${__CommonMSBuildArgs}") buildArgs+=("${__UnprocessedBuildArgs[@]}") buildArgs+=("\"/p:CopyNativeProjectBinaries=${__CopyNativeProjectsAfterCombinedTestBuild}\""); buildArgs+=("/p:__SkipPackageRestore=true"); @@ -502,7 +444,7 @@ build_MSBuild_projects() buildArgs+=("${__msbuildLog}" "${__msbuildWrn}" "${__msbuildErr}") buildArgs+=("${extraBuildParameters[@]}") - buildArgs+=("${__CommonMSBuildArgs[@]}") + buildArgs+=("${__CommonMSBuildArgs}") buildArgs+=("${__UnprocessedBuildArgs[@]}") # Disable warnAsError - coreclr issue 19922 @@ -583,7 +525,7 @@ build_native_projects() nextCommand="\"$scriptDir/gen-buildsys.sh\" \"$__TestDir\" \"$intermediatesForBuild\" $platformArch $__BuildType $generator $extraCmakeArguments $__cmakeargs" echo "Invoking $nextCommand" eval $nextCommand - + if [ $? != 0 ]; then echo "${__ErrMsgPrefix}Failed to generate $message build project!" exit 1 @@ -604,7 +546,7 @@ build_native_projects() echo "Executing cmake --build \"$intermediatesForBuild\" --target install -j $__NumProc" cmake --build "$intermediatesForBuild" --target install -j $__NumProc - + local exit_code=$? if [ $exit_code != 0 ]; then echo "${__ErrMsgPrefix}Failed to build $message." @@ -614,37 +556,15 @@ build_native_projects() echo "Native tests build success!" } -usage() -{ - echo "Usage: $0 [BuildArch] [BuildType] [verbose] [coverage] [cross] [clangx.y] [ninja] [runtests] [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 "clangx.y - optional argument to build using clang version x.y - supported version 3.5 - 6.0" - echo "gccx.y - optional argument to build using gcc version x.y." - echo "cross - optional argument to signify cross compilation," - echo " - will use ROOTFS_DIR environment variable if set." - echo "portableLinux - build for Portable Linux Distribution" - echo "portablebuild - Use portable build." - echo "verbose - optional argument to enable verbose build output." - echo "rebuild - if tests have already been built - rebuild them" - echo "skipnative: skip the native tests build" - echo "skipmanaged: skip the managed section of the test build" - echo "buildtestwrappersonly - only build the test wrappers" - echo "generatelayoutonly - only pull down dependencies and build coreroot" - echo "generatetesthostonly - only pull down dependencies and build coreroot and the CoreFX testhost" - echo "skiprestorepackages - skip package restore" - echo "crossgen - Precompiles the framework managed assemblies in coreroot" - echo "runtests - run tests after building them" - echo "bindir - output directory (defaults to $__ProjectRoot/bin)" - echo "msbuildonunsupportedplatform - build managed binaries even if distro is not officially supported." - echo "priority1 - include priority=1 tests in the build" - echo "copynativeonly: Only copy the native test binaries to the managed output. Do not build the native or managed tests." - echo "skipgeneratelayout: Do not generate the Core_Root layout or the CoreFX testhost." - exit 1 -} - +usage_list=("-buildtestwrappersonly - only build the test wrappers.") +usage_list+=("-copynativeonly: Only copy the native test binaries to the managed output. Do not build the native or managed tests.") +usage_list+=("-crossgen - Precompiles the framework managed assemblies in coreroot.") +usage_list+=("-generatelayoutonly - only pull down dependencies and build coreroot.") +usage_list+=("-generatetesthostonly - only pull down dependencies and build coreroot and the CoreFX testhost.") +usage_list+=("-priority1 - include priority=1 tests in the build.") +usage_list+=("-runtests - run tests after building them.") +usage_list+=("-skipgeneratelayout: Do not generate the Core_Root layout or the CoreFX testhost.") +usage_list+=("-skiprestorepackages - skip package restore.") # Obtain the location of the bash script to figure out where the root of the repo is. __ProjectRoot="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" @@ -656,374 +576,49 @@ if [ ! -f "${__RepoRootDir}/.dotnet-runtime-placeholder" ]; then 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 - ;; - - *) - 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= -__IncludeTests=INCLUDE_TESTS - -# Set the various build properties here so that CMake and MSBuild can pick them up -export __ProjectDir="$__ProjectRoot" -__SourceDir="$__ProjectDir/src" -__RootBinDir="$__ProjectDir/bin" -__DotNetCli="$__ProjectDir/dotnet.sh" -__UnprocessedBuildArgs= -__CommonMSBuildArgs= -__MSBCleanBuildArgs= -__UseNinja=0 -__VerboseBuild=0 -__SkipRestore="" -__SkipNative=0 -__SkipManaged=0 -__SkipConfigure=0 -__SkipGenerateVersion=0 -__ConfigureOnly=0 -__CrossBuild=0 -__ClangMajorVersion=0 -__ClangMinorVersion=0 -__GccBuild=0 -__GccMajorVersion=0 -__GccMinorVersion=0 -__SkipRestorePackages=0 -__DistroRid="" -__cmakeargs="" -__PortableLinux=0 -__msbuildonunsupportedplatform=0 -__NativeTestIntermediatesDir= -__RunTests=0 -__RebuildTests=0 -__BuildTestWrappers=1 -__GenerateLayoutOnly= -__GenerateTestHostOnly= -__priority1= -__BuildTestWrappersOnly= -__DoCrossgen=0 -__DoCrossgen2=0 -__CopyNativeTestBinaries=0 -__CopyNativeProjectsAfterCombinedTestBuild=true -__SkipGenerateLayout=0 -CORE_ROOT= - -while :; do - if [ $# -le 0 ]; then - break - fi - - lowerI="$(echo $1 | awk '{print tolower($0)}')" - case $lowerI in - -\?|-h|--help) - usage - exit 1 - ;; - - x86) - __BuildArch=x86 - ;; - - x64) - __BuildArch=x64 - ;; - - arm) - __BuildArch=arm - ;; - - armel) - __BuildArch=armel - ;; - - arm64) - __BuildArch=arm64 - ;; - - debug) - __BuildType=Debug - ;; - - checked) - __BuildType=Checked - ;; - - release) - __BuildType=Release - ;; - - ci|-ci) - __ArcadeScriptArgs="--ci" - __ErrMsgPrefix="##vso[task.logissue type=error]" - ;; - - coverage) - __CodeCoverage=Coverage - ;; - - cross) - __CrossBuild=1 - ;; - - portablebuild=false) - __PortableBuild=0 - ;; - - portablelinux) - if [ "$__BuildOS" == "Linux" ]; then - __PortableLinux=1 - else - echo "ERROR: portableLinux not supported for non-Linux platforms." - exit 1 - fi - ;; - - verbose) - __VerboseBuild=1 - ;; - - 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) - __UseNinja=1 - ;; - - runtests) - __RunTests=1 - ;; - - rebuild) - __RebuildTests=1 +handle_arguments() { + case $1 in + buildtestwrappersonly|-buildtestwrappersonly) + __BuildTestWrappersOnly=1 ;; - skipnative|-skipnative) + copynativeonly|-copynativeonly) __SkipNative=1 - __CopyNativeProjectsAfterCombinedTestBuild=false - ;; - - skipmanaged|-skipmanaged) __SkipManaged=1 - __BuildTestWrappers=0 - ;; - - buildtestwrappersonly) - __BuildTestWrappersOnly=1 - ;; - - generatelayoutonly) - __GenerateLayoutOnly=1 - ;; - - generatetesthostonly) - __GenerateTestHostOnly=1 - ;; - - skiprestorepackages) - __SkipRestorePackages=1 + __CopyNativeTestBinaries=1 + __CopyNativeProjectsAfterCombinedTestBuild=true ;; - crossgen) + crossgen|-crossgen) __DoCrossgen=1 ;; - crossgen2) + crossgen2|-crossgen2) __DoCrossgen2=1 ;; - 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 + generatetesthostonly|-generatetesthostonly) + __GenerateTestHostOnly=1 ;; - msbuildonunsupportedplatform) - __msbuildonunsupportedplatform=1 + generatelayoutonly|-generatelayoutonly) + __GenerateLayoutOnly=1 ;; - priority1) + priority1|-priority1) __priority1=1 __UnprocessedBuildArgs+=("/p:CLRTestPriorityToBuild=1") ;; - copynativeonly) - __SkipNative=1 - __SkipManaged=1 - __CopyNativeTestBinaries=1 - __CopyNativeProjectsAfterCombinedTestBuild=true + runtests|-runtests) + __RunTests=1 + ;; + + skiprestorepackages|-skiprestorepackages) + __SkipRestorePackages=1 ;; - skipgeneratelayout) + skipgeneratelayout|-skipgeneratelayout) __SkipGenerateLayout=1 ;; @@ -1031,41 +626,56 @@ while :; do __UnprocessedBuildArgs+=("$1") ;; esac +} - shift -done - -# 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 - -__CommonMSBuildArgs=("/p:__BuildArch=$__BuildArch" "/p:__BuildType=$__BuildType" "/p:__BuildOS=$__BuildOS" "/nodeReuse:false") +__BuildArch= +__BuildType=Debug +__CodeCoverage= +__IncludeTests=INCLUDE_TESTS -# Configure environment if we are doing a verbose build -if [ $__VerboseBuild == 1 ]; then - export VERBOSE=1 - __CommonMSBuildArgs+=("/v:detailed") -fi +# Set the various build properties here so that CMake and MSBuild can pick them up +export __ProjectDir="$__ProjectRoot" +__BuildTestWrappers=1 +__BuildTestWrappersOnly= +__ClangMajorVersion=0 +__ClangMinorVersion=0 +__CommonMSBuildArgs= +__ConfigureOnly=0 +__CopyNativeProjectsAfterCombinedTestBuild=true +__CopyNativeTestBinaries=0 +__CrossBuild=0 +__DistroRid="" +__DoCrossgen=0 +__DoCrossgen2=0 +__DotNetCli="$__ProjectDir/dotnet.sh" +__GccBuild=0 +__GccMajorVersion=0 +__GccMinorVersion=0 +__GenerateLayoutOnly= +__GenerateTestHostOnly= +__MSBCleanBuildArgs= +__NativeTestIntermediatesDir= +__PortableBuild=1 +__RebuildTests=0 +__RootBinDir="$__ProjectDir/bin" +__RunTests=0 +__SkipConfigure=0 +__SkipGenerateLayout=0 +__SkipGenerateVersion=0 +__SkipManaged=0 +__SkipNative=0 +__SkipRestore="" +__SkipRestorePackages=0 +__SourceDir="$__ProjectDir/src" +__UnprocessedBuildArgs= +__UseNinja=0 +__VerboseBuild=0 +__cmakeargs="" +__msbuildonunsupportedplatform=0 +__priority1= +CORE_ROOT= -# 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 +source "$__ProjectRoot"/_build-commons.sh # Set dependent variables __LogsDir="$__RootBinDir/Logs" diff --git a/src/coreclr/build.sh b/src/coreclr/build.sh index b4235dd..85c35d6 100755 --- a/src/coreclr/build.sh +++ b/src/coreclr/build.sh @@ -23,61 +23,22 @@ 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} - fi - - initDistroRidGlobal ${__BuildOS} ${__BuildArch} ${__PortableBuild} ${passedRootfsDir} -} +usage_list=("-crossgenonly: only run native image generation.") +usage_list+=("-disableoss: Disable Open Source Signing for System.Private.CoreLib.") +usage_list+=("-ibcinstrument: generate IBC-tuning-enabled native images when invoking crossgen.") +usage_list+=("-nopgooptimize: do not use profile guided optimizations.") +usage_list+=("-officialbuildid=^: specify the official build ID to be used by this build.") +usage_list+=("-partialngen: build CoreLib as PartialNGen.") +usage_list+=("-pgoinstrument: generate instrumented code for profile guided optimization enabled binaries.") +usage_list+=("-skipcrossgen: skip native image generation.") +usage_list+=("-skipcrossarchnative: Disable Open Source Signing for System.Private.CoreLib.") +usage_list+=("-skipmanagedtools: generate instrumented code for profile guided optimization enabled binaries.") +usage_list+=("-skipmscorlib: generate IBC-tuning-enabled native images when invoking crossgen.") +usage_list+=("-skipnuget: do not use profile guided optimizations.") +usage_list+=("-skiprestore: specify the official build ID to be used by this build.") +usage_list+=("-skiprestoreoptdata: build CoreLib as PartialNGen.") +usage_list+=("-staticanalyzer: skip native image generation.") +usage_list+=("-stripSymbols: skip native image generation.") setup_dirs() { @@ -103,7 +64,7 @@ check_prereqs() # 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); }'; } + 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]+") @@ -265,7 +226,7 @@ build_native() 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 @@ -273,7 +234,7 @@ build_native() nextCommand="\"$scriptDir/gen-buildsys.sh\" \"$__ProjectRoot\" \"$intermediatesForBuild\" $platformArch $__BuildType $generator $scan_build $extraCmakeArguments $__cmakeargs" echo "Invoking $nextCommand" eval $nextCommand - + if [ $? != 0 ]; then echo "${__ErrMsgPrefix}Failed to generate $message build project!" exit 1 @@ -306,7 +267,7 @@ build_native() cmake --build "$intermediatesForBuild" --target install -j $__NumProc fi - + local exit_code=$? if [ $exit_code != 0 ]; then echo "${__ErrMsgPrefix}Failed to build $message." @@ -345,32 +306,6 @@ build_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 @@ -549,334 +484,25 @@ generate_NugetPackages() 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 +handle_arguments() { + case $1 in + crossgenonly|-crossgenonly) + __SkipMSCorLib=1 + __SkipCoreCLR=1 + __CrossgenOnly=1 ;; - gcc|-gcc) - __GccMajorVersion= - __GccMinorVersion= - __GccBuild=1 + disableoss|-disableoss) + __SignTypeArg="/p:SignType=real" ;; - ninja|-ninja) - __UseNinja=1 + ibcinstrument|-ibcinstrument) + __IbcTuning="/Tuning" ;; - pgoinstrument|-pgoinstrument) - __PgoInstrument=1 + ignorewarnings|-ignorewarnings) + __IgnoreWarnings=1 + __cmakeargs="$__cmakeargs -DCLR_CMAKE_WARNINGS_ARE_ERRORS=OFF" ;; nopgooptimize|-nopgooptimize) @@ -884,23 +510,17 @@ while :; do __SkipRestoreOptData=1 ;; - ibcinstrument|-ibcinstrument) - __IbcTuning="/Tuning" - ;; - - configureonly|-configureonly) - __ConfigureOnly=1 - __SkipMSCorLib=1 - __SkipNuget=1 + officialbuildid=*|-officialbuildid=*) + __Id=$(echo "$1" | cut -d'=' -f 2) + __OfficialBuildIdArg="/p:OfficialBuildId=$__Id" ;; - skipconfigure|-skipconfigure) - __SkipConfigure=1 + partialngen|-partialngen) + __PartialNgen=1 ;; - skipnative|-skipnative) - # Use "skipnative" to use the same option name as build.cmd. - __SkipCoreCLR=1 + pgoinstrument|-pgoinstrument) + __PgoInstrument=1 ;; skipcoreclr|-skipcoreclr) @@ -912,149 +532,114 @@ while :; do __SkipCrossArchNative=1 ;; - skipmanaged|-skipmanaged) - __SkipManaged=1 - ;; - - skipmscorlib|-skipmscorlib) - __SkipMSCorLib=1 - ;; - - skipgenerateversion|-skipgenerateversion) - __SkipGenerateVersion=1 - ;; - - skiprestoreoptdata|-skiprestoreoptdata) - __SkipRestoreOptData=1 - ;; - skipcrossgen|-skipcrossgen) __SkipCrossgen=1 ;; - skipmanagedtools | -skipmanagedtools) + skipmanagedtools|-skipmanagedtools) __BuildManagedTools=0 ;; - crossgenonly|-crossgenonly) + skipmscorlib|-skipmscorlib) __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) + skiprestore|-skiprestore) __SkipRestoreArg="/p:RestoreDuringBuild=false" ;; - -disableoss) - __SignTypeArg="/p:SignType=real" - ;; - - -officialbuildid=*) - __Id=$(echo $1| cut -d'=' -f 2) - __OfficialBuildIdArg="/p:OfficialBuildId=$__Id" - ;; - - -staticanalyzer) + staticanalyzer|-staticanalyzer) __StaticAnalyzer=1 ;; - --) - # Skip -Option=Value style argument passing + stripsymbols|-stripsymbols) + __cmakeargs="$__cmakeargs -DSTRIP_SYMBOLS=true" ;; *) - __UnprocessedBuildArgs="$__UnprocessedBuildArgs $1" + __UnprocessedBuildArgs+=("$1") ;; esac +} - shift -done +echo "Commencing CoreCLR Repo build" -if [ "${__BuildArch}" != "${__HostArch}" ]; then - __CrossBuild=1 -fi +# 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 -__CommonMSBuildArgs="/p:__BuildArch=$__BuildArch /p:__BuildType=$__BuildType /p:__BuildOS=$__BuildOS /nodeReuse:false $__OfficialBuildIdArg $__SignTypeArg $__SkipRestoreArg" +# 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}/../.." -# Configure environment if we are doing a verbose build -if [ $__VerboseBuild == 1 ]; then - export VERBOSE=1 - __CommonMSBuildArgs="$__CommonMSBuildArgs /v:detailed" +# BEGIN SECTION to remove after repo consolidation +if [ ! -f "${__RepoRootDir}/.dotnet-runtime-placeholder" ]; then + __RepoRootDir=${__ProjectRoot} fi +# END SECTION to remove after repo consolidation -# 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 +__BuildArch= +__BuildType=Debug +__CodeCoverage= +__IgnoreWarnings=0 + +# Set the various build properties here so that CMake and MSBuild can pick them up +__BuildManagedTools=1 +__ClangMajorVersion=0 +__ClangMinorVersion=0 +__CommonMSBuildArgs= +__ConfigureOnly=0 +__CrossBuild=0 +__CrossgenOnly=0 +__DistroRid="" +__GccBuild=0 +__GccMajorVersion=0 +__GccMinorVersion=0 +__IbcOptDataPath="" +__IbcTuning="" +__MSBCleanBuildArgs= +__OfficialBuildIdArg="" +__PartialNgen=0 +__PgoInstrument=0 +__PgoOptDataPath="" +__PgoOptimize=1 +__PortableBuild=1 +__ProjectDir="$__ProjectRoot" +__RootBinDir="$__ProjectDir/bin" +__SignTypeArg="" +__SkipConfigure=0 +__SkipCoreCLR=0 +__SkipCrossArchNative=0 +__SkipCrossgen=0 +__SkipGenerateVersion=0 +__SkipMSCorLib=0 +__SkipManaged=0 +__SkipNuget=0 +__SkipRestore="" +__SkipRestoreArg="/p:RestoreDuringBuild=true" +__SkipRestoreOptData=0 +__SourceDir="$__ProjectDir/src" +__StaticAnalyzer=0 +__UnprocessedBuildArgs= +__UseNinja=0 +__VerboseBuild=0 +__ValidateCrossArg=1 +__cmakeargs="" +__msbuildonunsupportedplatform=0 + +source "$__ProjectRoot"/_build-commons.sh + +if [ "${__BuildArch}" != "${__HostArch}" ]; then + __CrossBuild=1 fi # Set dependent variables diff --git a/src/coreclr/configuretools.cmake b/src/coreclr/configuretools.cmake index 9b56220..df32fb2 100644 --- a/src/coreclr/configuretools.cmake +++ b/src/coreclr/configuretools.cmake @@ -4,37 +4,22 @@ if (CMAKE_C_COMPILER MATCHES "-?[0-9]+(\.[0-9]+)?$") set(CLR_CMAKE_COMPILER_FILE_NAME_VERSION "${CMAKE_MATCH_0}") endif() -if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") - if(APPLE) - set(LLVM_PREFIX "") - else() - set(LLVM_PREFIX "llvm-") - endif() - - function(locate_llvm_exec exec var) - find_program(EXEC_LOCATION_${exec} - NAMES - "${LLVM_PREFIX}${exec}${CLR_CMAKE_COMPILER_FILE_NAME_VERSION}" - "${LLVM_PREFIX}${exec}") - if (EXEC_LOCATION_${exec} STREQUAL "EXEC_LOCATION_${exec}-NOTFOUND") - message(FATAL_ERROR "Unable to find llvm tool for: ${exec}.") +if(NOT WIN32) + if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + if(APPLE) + set(TOOLSET_PREFIX "") + else() + set(TOOLSET_PREFIX "llvm-") + endif() + elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU") + if(CMAKE_CROSSCOMPILING) + set(TOOLSET_PREFIX "${CMAKE_CXX_COMPILER_TARGET}-") + else() + set(TOOLSET_PREFIX "") endif() - set(${var} ${EXEC_LOCATION_${exec}} PARENT_SCOPE) - endfunction() - locate_llvm_exec(ar CMAKE_AR) - locate_llvm_exec(link CMAKE_LINKER) - locate_llvm_exec(nm CMAKE_NM) - if(NOT APPLE) - locate_llvm_exec(objdump CMAKE_OBJDUMP) - endif() -elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU") - if(CMAKE_CROSSCOMPILING) - set(GCC_PREFIX "${CMAKE_CXX_COMPILER_TARGET}-") - else() - set(GCC_PREFIX "") endif() - function(locate_gcc_exec exec var) + function(locate_toolchain_exec exec var) string(TOUPPER ${exec} EXEC_UPPERCASE) if(NOT "$ENV{CLR_${EXEC_UPPERCASE}}" STREQUAL "") set(${var} "$ENV{CLR_${EXEC_UPPERCASE}}" PARENT_SCOPE) @@ -43,37 +28,42 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU") find_program(EXEC_LOCATION_${exec} NAMES - "${GCC_PREFIX}${exec}${CLR_CMAKE_COMPILER_FILE_NAME_VERSION}" - "${GCC_PREFIX}${exec}") + "${TOOLSET_PREFIX}${exec}${CLR_CMAKE_COMPILER_FILE_NAME_VERSION}" + "${TOOLSET_PREFIX}${exec}") if (EXEC_LOCATION_${exec} STREQUAL "EXEC_LOCATION_${exec}-NOTFOUND") - message(FATAL_ERROR "Unable to find gcc tool for: ${exec}.") + message(FATAL_ERROR "Unable to find toolchain executable for: ${exec}.") endif() set(${var} ${EXEC_LOCATION_${exec}} PARENT_SCOPE) endfunction() - locate_gcc_exec(ar CMAKE_AR) - locate_gcc_exec(link CMAKE_LINKER) - locate_gcc_exec(nm CMAKE_NM) + + locate_toolchain_exec(ar CMAKE_AR) + locate_toolchain_exec(link CMAKE_LINKER) + locate_toolchain_exec(nm CMAKE_NM) + if(NOT APPLE) - locate_gcc_exec(objdump CMAKE_OBJDUMP) + locate_toolchain_exec(objdump CMAKE_OBJDUMP) endif() - locate_gcc_exec(objcopy CMAKE_OBJCOPY) - locate_gcc_exec(ranlib CMAKE_RANLIB) -endif() -if (NOT WIN32 AND NOT CMAKE_SYSTEM_NAME STREQUAL Darwin) - if (CMAKE_CROSSCOMPILING AND NOT DEFINED CLR_CROSS_COMPONENTS_BUILD) - if (CMAKE_SYSTEM_PROCESSOR STREQUAL armv7l OR CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64 OR CMAKE_SYSTEM_PROCESSOR STREQUAL arm) - find_program(OBJCOPY ${TOOLCHAIN}-objcopy) - elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL i686) - find_program(OBJCOPY objcopy) + if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") + locate_toolchain_exec(objcopy CMAKE_OBJCOPY) + locate_toolchain_exec(ranlib CMAKE_RANLIB) + endif() + + if (NOT CMAKE_SYSTEM_NAME STREQUAL Darwin) + if (CMAKE_CROSSCOMPILING AND NOT DEFINED CLR_CROSS_COMPONENTS_BUILD) + if (CMAKE_SYSTEM_PROCESSOR STREQUAL armv7l OR CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64 OR CMAKE_SYSTEM_PROCESSOR STREQUAL arm) + find_program(OBJCOPY ${TOOLCHAIN}-objcopy) + elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL i686) + find_program(OBJCOPY objcopy) + else() + clr_unknown_arch() + endif() else() - clr_unknown_arch() + find_program(OBJCOPY objcopy) endif() - else() - find_program(OBJCOPY objcopy) - endif() - if (OBJCOPY STREQUAL "OBJCOPY-NOTFOUND") - message(FATAL_ERROR "objcopy not found") + if (OBJCOPY STREQUAL "OBJCOPY-NOTFOUND") + message(FATAL_ERROR "objcopy not found") + endif() endif() endif() -- 2.7.4