Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ project(diagnostics)
include(eng/native/configurepaths.cmake)
include(${CLR_ENG_NATIVE_DIR}/configurecompiler.cmake)

# Platform specific compiler options
set(CLR_SHARED_DIR ${CLR_REPO_ROOT_DIR}/src/shared)
get_filename_component(CLR_SRC_NATIVE_DIR ${CLR_SHARED_DIR}/native ABSOLUTE)

if(CLR_CMAKE_HOST_UNIX)
# The -fms-extensions enable the stuff like __if_exists, __declspec(uuid()), etc.
add_compile_options(-fms-extensions)
Expand Down
81 changes: 53 additions & 28 deletions eng/native/build-commons.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,20 @@ build_native()
# All set to commence the build
echo "Commencing build of \"$target\" target in \"$message\" for $__TargetOS.$__TargetArch.$__BuildType in $intermediatesDir"

SAVED_CFLAGS="${CFLAGS}"
SAVED_CXXFLAGS="${CXXFLAGS}"
SAVED_LDFLAGS="${LDFLAGS}"

# Let users provide additional compiler/linker flags via EXTRA_CFLAGS/EXTRA_CXXFLAGS/EXTRA_LDFLAGS.
# If users directly override CFLAG/CXXFLAGS/LDFLAGS, that may lead to some configure tests working incorrectly.
# See https://github.com/dotnet/runtime/issues/35727 for more information.
#
# These flags MUST be exported before gen-buildsys.sh runs or cmake will ignore them
#
export CFLAGS="${CFLAGS} ${EXTRA_CFLAGS}"
export CXXFLAGS="${CXXFLAGS} ${EXTRA_CXXFLAGS}"
export LDFLAGS="${LDFLAGS} ${EXTRA_LDFLAGS}"

if [[ "$targetOS" == osx || "$targetOS" == maccatalyst ]]; then
if [[ "$hostArch" == x64 ]]; then
cmakeArgs="-DCMAKE_OSX_ARCHITECTURES=\"x86_64\" $cmakeArgs"
Expand All @@ -75,19 +89,26 @@ build_native()
fi

if [[ "$targetOS" == maccatalyst ]]; then
cmakeArgs="-DCMAKE_SYSTEM_VARIANT=maccatalyst $cmakeArgs"
cmakeArgs="-C $__RepoRootDir/eng/native/tryrun_ios_tvos.cmake $cmakeArgs"

# Intentionally do not set CMAKE_OSX_DEPLOYMENT_TARGET for maccatalyst here:
# - CMake interprets CMAKE_OSX_DEPLOYMENT_TARGET as a macOS minimum version
# instead of MacCatalyst, causing newer clang to reject it as invalid.
# - The effective Catalyst minimum version is enforced via the
# -target *-apple-ios<version>-macabi flag in eng/native/configurecompiler.cmake
cmakeArgs="-DCMAKE_SYSTEM_NAME=Darwin -DCMAKE_OSX_SYSROOT=macosx -DCMAKE_SYSTEM_VARIANT=maccatalyst $cmakeArgs"
fi

if [[ "$targetOS" == android || "$targetOS" == linux-bionic ]]; then
# Keep in sync with $(AndroidApiLevelMin) in Directory.Build.props in the repository rooot
local ANDROID_API_LEVEL=24
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

cmakeArgs="-C $__RepoRootDir/eng/native/tryrun.cmake $cmakeArgs"

# keep ANDROID_PLATFORM in sync with SetOSTargetMinVersions in the root Directory.Build.props
cmakeArgs="-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_ROOT/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=android-21 $cmakeArgs"
cmakeArgs="-DANDROID_BUILD=1 -C $__RepoRootDir/eng/native/tryrun.cmake $cmakeArgs"
cmakeArgs="-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_ROOT/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=android-${ANDROID_API_LEVEL} -DANDROID_NATIVE_API_LEVEL=${ANDROID_API_LEVEL} $cmakeArgs"

# Don't try to set CC/CXX in init-compiler.sh - it's handled in android.toolchain.cmake already
__Compiler="default"
Expand All @@ -109,7 +130,7 @@ build_native()

# set default iOS simulator deployment target
# keep in sync with SetOSTargetMinVersions in the root Directory.Build.props
cmakeArgs="-DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphonesimulator -DCMAKE_OSX_DEPLOYMENT_TARGET=12.2 $cmakeArgs"
cmakeArgs="-DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphonesimulator -DCMAKE_OSX_DEPLOYMENT_TARGET=13.0 $cmakeArgs"
if [[ "$__TargetArch" == x64 ]]; then
cmakeArgs="-DCMAKE_OSX_ARCHITECTURES=\"x86_64\" $cmakeArgs"
elif [[ "$__TargetArch" == arm64 ]]; then
Expand All @@ -123,7 +144,7 @@ build_native()

# set default iOS device deployment target
# keep in sync with SetOSTargetMinVersions in the root Directory.Build.props
cmakeArgs="-DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphoneos -DCMAKE_OSX_DEPLOYMENT_TARGET=12.2 $cmakeArgs"
cmakeArgs="-DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphoneos -DCMAKE_OSX_DEPLOYMENT_TARGET=13.0 $cmakeArgs"
if [[ "$__TargetArch" == arm64 ]]; then
cmakeArgs="-DCMAKE_OSX_ARCHITECTURES=\"arm64\" $cmakeArgs"
else
Expand All @@ -135,7 +156,7 @@ build_native()

# set default tvOS simulator deployment target
# keep in sync with SetOSTargetMinVersions in the root Directory.Build.props
cmakeArgs="-DCMAKE_SYSTEM_NAME=tvOS -DCMAKE_OSX_SYSROOT=appletvsimulator -DCMAKE_OSX_DEPLOYMENT_TARGET=12.2 $cmakeArgs"
cmakeArgs="-DCMAKE_SYSTEM_NAME=tvOS -DCMAKE_OSX_SYSROOT=appletvsimulator -DCMAKE_OSX_DEPLOYMENT_TARGET=13.0 $cmakeArgs"
if [[ "$__TargetArch" == x64 ]]; then
cmakeArgs="-DCMAKE_OSX_ARCHITECTURES=\"x86_64\" $cmakeArgs"
elif [[ "$__TargetArch" == arm64 ]]; then
Expand All @@ -149,7 +170,7 @@ build_native()

# set default tvOS device deployment target
# keep in sync with SetOSTargetMinVersions in the root Directory.Build.props
cmakeArgs="-DCMAKE_SYSTEM_NAME=tvOS -DCMAKE_OSX_SYSROOT=appletvos -DCMAKE_OSX_DEPLOYMENT_TARGET=12.2 $cmakeArgs"
cmakeArgs="-DCMAKE_SYSTEM_NAME=tvOS -DCMAKE_OSX_SYSROOT=appletvos -DCMAKE_OSX_DEPLOYMENT_TARGET=13.0 $cmakeArgs"
if [[ "$__TargetArch" == arm64 ]]; then
cmakeArgs="-DCMAKE_OSX_ARCHITECTURES=\"arm64\" $cmakeArgs"
else
Expand Down Expand Up @@ -194,24 +215,13 @@ build_native()
return
fi

SAVED_CFLAGS="${CFLAGS}"
SAVED_CXXFLAGS="${CXXFLAGS}"
SAVED_LDFLAGS="${LDFLAGS}"

# Let users provide additional compiler/linker flags via EXTRA_CFLAGS/EXTRA_CXXFLAGS/EXTRA_LDFLAGS.
# If users directly override CFLAG/CXXFLAGS/LDFLAGS, that may lead to some configure tests working incorrectly.
# See https://github.com/dotnet/runtime/issues/35727 for more information.
export CFLAGS="${CFLAGS} ${EXTRA_CFLAGS}"
export CXXFLAGS="${CXXFLAGS} ${EXTRA_CXXFLAGS}"
export LDFLAGS="${LDFLAGS} ${EXTRA_LDFLAGS}"

local exit_code
if [[ "$__StaticAnalyzer" == 1 ]]; then
pushd "$intermediatesDir"

buildTool="$SCAN_BUILD_COMMAND -o $__BinDir/scan-build-log $buildTool"
echo "Executing $buildTool $target -j $__NumProc"
"$buildTool" $target -j "$__NumProc"
echo "Executing $buildTool -j $__NumProc $target"
"$buildTool" -j "$__NumProc" $target
exit_code="$?"

popd
Expand All @@ -227,8 +237,8 @@ build_native()
# multiple targets. Instead, directly invoke the build tool to build multiple targets in one invocation.
pushd "$intermediatesDir"

echo "Executing $buildTool $target -j $__NumProc"
"$buildTool" $target -j "$__NumProc"
echo "Executing $buildTool -j $__NumProc $target"
"$buildTool" -j "$__NumProc" $target
exit_code="$?"

popd
Expand Down Expand Up @@ -264,7 +274,7 @@ usage()
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 "-ninja: target ninja instead of GNU make"
echo "-ninja: target ninja instead of GNU make (default: true, use -ninja false to disable)"
echo "-numproc: set the number of build processes."
echo "-targetrid: optional argument that overrides the target rid name."
echo "-portablebuild: pass -portablebuild=false to force a non-portable build."
Expand All @@ -290,7 +300,7 @@ __TargetRid=''

# Get the number of processors available to the scheduler
platform="$(uname -s | tr '[:upper:]' '[:lower:]')"
if [[ "$platform" == "freebsd" ]]; then
if [[ "$platform" == "freebsd" || "$platform" == "openbsd" ]]; then
__NumProc="$(($(sysctl -n hw.ncpu)+1))"
elif [[ "$platform" == "netbsd" || "$platform" == "sunos" ]]; then
__NumProc="$(($(getconf NPROCESSORS_ONLN)+1))"
Expand All @@ -304,6 +314,9 @@ else
__NumProc=1
fi

# Default to using Ninja for faster builds
__UseNinja=1

while :; do
if [[ "$#" -le 0 ]]; then
break
Expand Down Expand Up @@ -405,7 +418,17 @@ while :; do
;;

ninja|-ninja)
__UseNinja=1
if [[ -z "${2+x}" ]] || [[ "$2" == -* ]]; then
__UseNinja=1
else
ninja_arg="$(echo "$2" | tr "[:upper:]" "[:lower:]")"
if [[ "$ninja_arg" == "false" ]]; then
__UseNinja=0
else
__UseNinja=1
fi
shift
fi
;;

numproc|-numproc)
Expand Down Expand Up @@ -485,7 +508,6 @@ while :; do
hostarch|-hostarch)
if [[ -n "$2" ]]; then
__HostArch="$2"
__ExplicitHostArch=1
shift
else
echo "ERROR: 'hostarch' requires a non-empty option argument"
Expand Down Expand Up @@ -545,6 +567,9 @@ elif [[ "$__TargetOS" == ios || "$__TargetOS" == iossimulator ]]; then
elif [[ "$__TargetOS" == tvos || "$__TargetOS" == tvossimulator ]]; then
# nothing to do here
true
elif [[ "$__TargetOS" == osx || "$__TargetOS" == maccatalyst ]]; then
# nothing to do here
true
elif [[ "$__TargetOS" == android ]]; then
# nothing to do here
true
Expand Down
Loading
Loading