Skip to content

Commit

Permalink
Sync eng/native from runtime (#3318)
Browse files Browse the repository at this point in the history
  • Loading branch information
am11 committed Aug 30, 2022
1 parent d2632f9 commit 81f76f3
Show file tree
Hide file tree
Showing 20 changed files with 396 additions and 176 deletions.
4 changes: 2 additions & 2 deletions diagnostics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ stages:
condition: succeeded()
pool:
name: NetCore1ESPool-Internal
demands: ImageOverride -equals Build.Windows.10.Amd64.VS2019
demands: ImageOverride -equals windows.vs2022.amd64
enablePublishUsingPipelines: true
enableMicrobuild: true
artifacts:
Expand Down Expand Up @@ -376,7 +376,7 @@ stages:
publishUsingPipelines: true
pool:
name: NetCore1ESPool-Internal
demands: ImageOverride -equals Build.windows.10.amd64.vs2019
demands: ImageOverride -equals windows.vs2022.amd64

- ${{ if and(ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest')) }}:
- template: /eng/common/templates/post-build/post-build.yml
Expand Down
4 changes: 2 additions & 2 deletions eng/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ jobs:
# Official Build Windows Pool
${{ if and(eq(parameters.osGroup, 'Windows_NT'), ne(variables['System.TeamProject'], 'public')) }}:
name: NetCore1ESPool-Internal
demands: ImageOverride -equals Build.Windows.10.Amd64.VS2019
demands: ImageOverride -equals windows.vs2022.amd64

# Public Windows Build Pool
${{ if and(eq(parameters.osGroup, 'Windows_NT'), eq(variables['System.TeamProject'], 'public')) }}:
name: NetCore1ESPool-Public
demands: ImageOverride -equals Build.Windows.10.Amd64.VS2019.Open
demands: ImageOverride -equals windows.vs2022.amd64.open

${{ if and(ne(parameters.dockerImage, ''), ne(parameters.requiresCapPtraceContainer, 'true')) }}:
container: ${{ parameters.dockerImage }}
Expand Down
103 changes: 60 additions & 43 deletions eng/native/build-commons.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ initTargetDistroRid()
passedRootfsDir="$ROOTFS_DIR"
fi

initDistroRidGlobal "$__TargetOS" "$__BuildArch" "$__PortableBuild" "$passedRootfsDir"
initDistroRidGlobal "$__TargetOS" "$__TargetArch" "$__PortableBuild" "$passedRootfsDir"
}

setup_dirs()
Expand All @@ -35,7 +35,7 @@ check_prereqs()
if ! pkg-config openssl ; then
# We export the proper PKG_CONFIG_PATH where openssl was installed by Homebrew
# It's important to _export_ it since build-commons.sh is sourced by other scripts such as build-native.sh
export PKG_CONFIG_PATH=$(brew --prefix)/opt/[email protected]/lib/pkgconfig:$(brew --prefix)/opt/openssl/lib/pkgconfig
export PKG_CONFIG_PATH=$(brew --prefix)/opt/openssl@3/lib/pkgconfig:$(brew --prefix)/opt/openssl@1.1/lib/pkgconfig:$(brew --prefix)/opt/openssl/lib/pkgconfig
# We try again with the PKG_CONFIG_PATH in place, if pkg-config still can't find OpenSSL, exit with an error, cmake won't find OpenSSL either
pkg-config openssl || { echo >&2 "Please install openssl before running this script, see https://github.com/dotnet/runtime/blob/main/docs/workflow/requirements/macos-requirements.md"; exit 1; }
fi
Expand All @@ -53,23 +53,23 @@ build_native()
fi

targetOS="$1"
platformArch="$2"
hostArch="$2"
cmakeDir="$3"
intermediatesDir="$4"
target="$5"
cmakeArgs="$6"
message="$7"

# All set to commence the build
echo "Commencing build of \"$target\" target in \"$message\" for $__TargetOS.$__BuildArch.$__BuildType in $intermediatesDir"
echo "Commencing build of \"$target\" target in \"$message\" for $__TargetOS.$__TargetArch.$__BuildType in $intermediatesDir"

if [[ "$targetOS" == OSX || "$targetOS" == MacCatalyst ]]; then
if [[ "$platformArch" == x64 ]]; then
if [[ "$hostArch" == x64 ]]; then
cmakeArgs="-DCMAKE_OSX_ARCHITECTURES=\"x86_64\" $cmakeArgs"
elif [[ "$platformArch" == arm64 ]]; then
elif [[ "$hostArch" == arm64 ]]; then
cmakeArgs="-DCMAKE_OSX_ARCHITECTURES=\"arm64\" $cmakeArgs"
else
echo "Error: Unknown OSX architecture $platformArch."
echo "Error: Unknown OSX architecture $hostArch."
exit 1
fi
fi
Expand All @@ -78,28 +78,28 @@ build_native()
cmakeArgs="-DCMAKE_SYSTEM_VARIANT=MacCatalyst $cmakeArgs"
fi

if [[ "$targetOS" == Android && -z "$ROOTFS_DIR" ]]; then
if [[ ( "$targetOS" == Android || "$targetOS" == linux-bionic ) && -z "$ROOTFS_DIR" ]]; then
if [[ -z "$ANDROID_NDK_ROOT" ]]; then
echo "Error: You need to set the ANDROID_NDK_ROOT environment variable pointing to the Android NDK root."
exit 1
fi

# keep ANDROID_NATIVE_API_LEVEL in sync with src/mono/Directory.Build.props
cmakeArgs="-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_ROOT/build/cmake/android.toolchain.cmake -DANDROID_NATIVE_API_LEVEL=21 $cmakeArgs"
# keep ANDROID_PLATFORM in sync with src/mono/Directory.Build.props
cmakeArgs="-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_ROOT/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=android-21 $cmakeArgs"

# Don't try to set CC/CXX in init-compiler.sh - it's handled in android.toolchain.cmake already
__Compiler="default"

if [[ "$platformArch" == x64 ]]; then
if [[ "$hostArch" == x64 ]]; then
cmakeArgs="-DANDROID_ABI=x86_64 $cmakeArgs"
elif [[ "$platformArch" == x86 ]]; then
elif [[ "$hostArch" == x86 ]]; then
cmakeArgs="-DANDROID_ABI=x86 $cmakeArgs"
elif [[ "$platformArch" == arm64 ]]; then
elif [[ "$hostArch" == arm64 ]]; then
cmakeArgs="-DANDROID_ABI=arm64-v8a $cmakeArgs"
elif [[ "$platformArch" == arm ]]; then
elif [[ "$hostArch" == arm ]]; then
cmakeArgs="-DANDROID_ABI=armeabi-v7a $cmakeArgs"
else
echo "Error: Unknown Android architecture $platformArch."
echo "Error: Unknown Android architecture $hostArch."
exit 1
fi
fi
Expand All @@ -117,7 +117,7 @@ build_native()
scan_build=scan-build
fi

nextCommand="\"$__RepoRootDir/eng/native/gen-buildsys.sh\" \"$cmakeDir\" \"$intermediatesDir\" $platformArch $__Compiler $__BuildType \"$generator\" $scan_build $cmakeArgs"
nextCommand="\"$__RepoRootDir/eng/native/gen-buildsys.sh\" \"$cmakeDir\" \"$intermediatesDir\" $hostArch $__Compiler $__BuildType \"$generator\" $scan_build $cmakeArgs"
echo "Invoking $nextCommand"
eval $nextCommand

Expand Down Expand Up @@ -197,7 +197,7 @@ usage()
echo ""
echo "Common Options:"
echo ""
echo "BuildArch can be: -arm, -armv6, -armel, -arm64, -loongarch64, -s390x, x64, x86, -wasm"
echo "BuildArch can be: -arm, -armv6, -armel, -arm64, -loongarch64, -riscv64, -s390x, -ppc64le, x64, x86, -wasm"
echo "BuildType can be: -debug, -checked, -release"
echo "-os: target OS (defaults to running OS)"
echo "-bindir: output directory (defaults to $__ProjectRoot/artifacts)"
Expand Down Expand Up @@ -228,30 +228,25 @@ usage()

source "$__RepoRootDir/eng/native/init-os-and-arch.sh"

__BuildArch=$arch
__HostArch=$arch
__TargetArch=$arch
__TargetOS=$os
__HostOS=$os
__BuildOS=$os

# 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 -n hw.ncpu)+1))
__NumProc="$(($(sysctl -n hw.ncpu)+1))"
elif [[ "$platform" == "NetBSD" || "$platform" == "SunOS" ]]; then
__NumProc=$(($(getconf NPROCESSORS_ONLN)+1))
__NumProc="$(($(getconf NPROCESSORS_ONLN)+1))"
elif [[ "$platform" == "Darwin" ]]; then
__NumProc=$(($(getconf _NPROCESSORS_ONLN)+1))
__NumProc="$(($(getconf _NPROCESSORS_ONLN)+1))"
elif command -v nproc > /dev/null 2>&1; then
__NumProc="$(nproc)"
elif (NAME=""; . /etc/os-release; test "$NAME" = "Tizen"); then
__NumProc="$(getconf _NPROCESSORS_ONLN)"
else
if command -v nproc > /dev/null 2>&1; then
__NumProc=$(nproc --all)
elif (NAME=""; . /etc/os-release; test "$NAME" = "Tizen"); then
__NumProc=$(getconf _NPROCESSORS_ONLN)
else
__NumProc=1
fi
__NumProc=1
fi

while :; do
Expand All @@ -267,19 +262,19 @@ while :; do
;;

arm|-arm)
__BuildArch=arm
__TargetArch=arm
;;

armv6|-armv6)
__BuildArch=armv6
__TargetArch=armv6
;;

arm64|-arm64)
__BuildArch=arm64
__TargetArch=arm64
;;

armel|-armel)
__BuildArch=armel
__TargetArch=armel
;;

bindir|-bindir)
Expand Down Expand Up @@ -374,23 +369,31 @@ while :; do
;;

x86|-x86)
__BuildArch=x86
__TargetArch=x86
;;

x64|-x64)
__BuildArch=x64
__TargetArch=x64
;;

loongarch64|-loongarch64)
__BuildArch=loongarch64
__TargetArch=loongarch64
;;

riscv64|-riscv64)
__TargetArch=riscv64
;;

s390x|-s390x)
__BuildArch=s390x
__TargetArch=s390x
;;

wasm|-wasm)
__BuildArch=wasm
__TargetArch=wasm
;;

ppc64le|-ppc64le)
__TargetArch=ppc64le
;;

os|-os)
Expand All @@ -403,6 +406,16 @@ while :; do
fi
;;

hostarch|-hostarch)
if [[ -n "$2" ]]; then
__HostArch="$2"
shift
else
echo "ERROR: 'hostarch' requires a non-empty option argument"
exit 1
fi
;;

*)
handle_arguments "$1" "$2"
if [[ "$__ShiftArgs" == 1 ]]; then
Expand All @@ -415,7 +428,11 @@ while :; do
shift
done

__CommonMSBuildArgs="/p:TargetArchitecture=$__BuildArch /p:Configuration=$__BuildType /p:TargetOS=$__TargetOS /nodeReuse:false $__OfficialBuildIdArg $__SignTypeArg $__SkipRestoreArg"
if [[ -z "$__HostArch" ]]; then
__HostArch=$__TargetArch
fi

__CommonMSBuildArgs="/p:TargetArchitecture=$__TargetArch /p:Configuration=$__BuildType /p:TargetOS=$__TargetOS /nodeReuse:false $__OfficialBuildIdArg $__SignTypeArg $__SkipRestoreArg"

# Configure environment if we are doing a verbose build
if [[ "$__VerboseBuild" == 1 ]]; then
Expand All @@ -428,7 +445,7 @@ if [[ "$__PortableBuild" == 0 ]]; then
__CommonMSBuildArgs="$__CommonMSBuildArgs /p:PortableBuild=false"
fi

if [[ "$__BuildArch" == wasm ]]; then
if [[ "$__TargetArch" == wasm ]]; then
# nothing to do here
true
elif [[ "$__TargetOS" == iOS || "$__TargetOS" == iOSSimulator ]]; then
Expand All @@ -450,7 +467,7 @@ if [[ "$__CrossBuild" == 1 ]]; then
export CROSSCOMPILE
# Darwin that doesn't use rootfs
if [[ -z "$ROOTFS_DIR" && "$platform" != "Darwin" ]]; then
ROOTFS_DIR="$__RepoRootDir/.tools/rootfs/$__BuildArch"
ROOTFS_DIR="$__RepoRootDir/.tools/rootfs/$__TargetArch"
export ROOTFS_DIR
fi
fi
Expand Down
Loading

0 comments on commit 81f76f3

Please sign in to comment.