diff --git a/diagnostics.yml b/diagnostics.yml index 9a1019438f..9127a5f407 100644 --- a/diagnostics.yml +++ b/diagnostics.yml @@ -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: @@ -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 diff --git a/eng/build.yml b/eng/build.yml index fb790587d5..8076c8fdd4 100644 --- a/eng/build.yml +++ b/eng/build.yml @@ -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 }} diff --git a/eng/native/build-commons.sh b/eng/native/build-commons.sh index 294e9832ad..dd0dea81cd 100755 --- a/eng/native/build-commons.sh +++ b/eng/native/build-commons.sh @@ -11,7 +11,7 @@ initTargetDistroRid() passedRootfsDir="$ROOTFS_DIR" fi - initDistroRidGlobal "$__TargetOS" "$__BuildArch" "$__PortableBuild" "$passedRootfsDir" + initDistroRidGlobal "$__TargetOS" "$__TargetArch" "$__PortableBuild" "$passedRootfsDir" } setup_dirs() @@ -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/openssl@1.1/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 @@ -53,7 +53,7 @@ build_native() fi targetOS="$1" - platformArch="$2" + hostArch="$2" cmakeDir="$3" intermediatesDir="$4" target="$5" @@ -61,15 +61,15 @@ build_native() 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 @@ -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 @@ -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 @@ -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)" @@ -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 @@ -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) @@ -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) @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/eng/native/configurecompiler.cmake b/eng/native/configurecompiler.cmake index c3e757ccde..a0163845e6 100644 --- a/eng/native/configurecompiler.cmake +++ b/eng/native/configurecompiler.cmake @@ -133,7 +133,7 @@ elseif (CLR_CMAKE_HOST_UNIX) message("Address Sanitizer (asan) enabled") endif () if (${__UBSAN_POS} GREATER -1) - # all sanitizier flags are enabled except alignment (due to heavy use of __unaligned modifier) + # all sanitizer flags are enabled except alignment (due to heavy use of __unaligned modifier) list(APPEND CLR_CXX_SANITIZERS "bool" bounds @@ -227,6 +227,9 @@ elseif (CLR_CMAKE_HOST_ARCH_ARM64) elseif (CLR_CMAKE_HOST_ARCH_LOONGARCH64) set(ARCH_HOST_NAME loongarch64) add_definitions(-DHOST_LOONGARCH64 -DHOST_64BIT) +elseif (CLR_CMAKE_HOST_ARCH_RISCV64) + set(ARCH_HOST_NAME riscv64) + add_definitions(-DHOST_RISCV64 -DHOST_64BIT) elseif (CLR_CMAKE_HOST_ARCH_S390X) set(ARCH_HOST_NAME s390x) add_definitions(-DHOST_S390X -DHOST_64BIT -DBIGENDIAN) @@ -236,6 +239,9 @@ elseif (CLR_CMAKE_HOST_ARCH_WASM) elseif (CLR_CMAKE_HOST_ARCH_MIPS64) set(ARCH_HOST_NAME mips64) add_definitions(-DHOST_MIPS64 -DHOST_64BIT=1) +elseif (CLR_CMAKE_HOST_ARCH_POWERPC64) + set(ARCH_HOST_NAME ppc64le) + add_definitions(-DHOST_POWERPC64 -DHOST_64BIT) else () clr_unknown_arch() endif () @@ -245,17 +251,21 @@ if (CLR_CMAKE_HOST_UNIX) if(CLR_CMAKE_HOST_UNIX_AMD64) message("Detected Linux x86_64") elseif(CLR_CMAKE_HOST_UNIX_ARM) - message("Detected Linux ARM") + message("Detected Linux arm") elseif(CLR_CMAKE_HOST_UNIX_ARMV6) - message("Detected Linux ARMv6") + message("Detected Linux armv6") elseif(CLR_CMAKE_HOST_UNIX_ARM64) - message("Detected Linux ARM64") + message("Detected Linux arm64") elseif(CLR_CMAKE_HOST_UNIX_LOONGARCH64) - message("Detected Linux LOONGARCH64") + message("Detected Linux loongarch64") + elseif(CLR_CMAKE_HOST_UNIX_RISCV64) + message("Detected Linux riscv64") elseif(CLR_CMAKE_HOST_UNIX_X86) message("Detected Linux i686") elseif(CLR_CMAKE_HOST_UNIX_S390X) message("Detected Linux s390x") + elseif(CLR_CMAKE_HOST_UNIX_POWERPC64) + message("Detected Linux ppc64le") else() clr_unknown_arch() endif() @@ -327,11 +337,21 @@ elseif (CLR_CMAKE_TARGET_ARCH_LOONGARCH64) set(ARCH_SOURCES_DIR loongarch64) add_compile_definitions($<$>>:TARGET_LOONGARCH64>) add_compile_definitions($<$>>:TARGET_64BIT>) +elseif (CLR_CMAKE_TARGET_ARCH_RISCV64) + set(ARCH_TARGET_NAME riscv64) + set(ARCH_SOURCES_DIR riscv64) + add_compile_definitions($<$>>:TARGET_RISCV64>) + add_compile_definitions($<$>>:TARGET_64BIT>) elseif (CLR_CMAKE_TARGET_ARCH_S390X) set(ARCH_TARGET_NAME s390x) set(ARCH_SOURCES_DIR s390x) add_compile_definitions($<$>>:TARGET_S390X>) add_compile_definitions($<$>>:TARGET_64BIT>) +elseif (CLR_CMAKE_TARGET_ARCH_POWERPC64) + set(ARCH_TARGET_NAME ppc64le) + set(ARCH_SOURCES_DIR ppc64le) + add_compile_definitions($<$>>:TARGET_POWERPC64>) + add_compile_definitions($<$>>:TARGET_64BIT>) elseif (CLR_CMAKE_TARGET_ARCH_WASM) set(ARCH_TARGET_NAME wasm) set(ARCH_SOURCES_DIR wasm) @@ -365,6 +385,11 @@ if (CLR_CMAKE_HOST_UNIX) if(CLR_CMAKE_HOST_OSX OR CLR_CMAKE_HOST_MACCATALYST) # We cannot enable "stack-protector-strong" on OS X due to a bug in clang compiler (current version 7.0.2) add_compile_options(-fstack-protector) + if(CLR_CMAKE_HOST_UNIX_ARM64) + # For OSX-Arm64, LSE instructions are enabled by default + add_definitions(-DLSE_INSTRUCTIONS_ENABLED_BY_DEFAULT) + add_compile_options(-mcpu=apple-m1) + endif(CLR_CMAKE_HOST_UNIX_ARM64) elseif(NOT CLR_CMAKE_HOST_BROWSER) check_c_compiler_flag(-fstack-protector-strong COMPILER_SUPPORTS_F_STACK_PROTECTOR_STRONG) if (COMPILER_SUPPORTS_F_STACK_PROTECTOR_STRONG) @@ -426,11 +451,17 @@ if (CLR_CMAKE_HOST_UNIX) add_compile_options(-Wno-uninitialized) add_compile_options(-Wno-strict-aliasing) add_compile_options(-Wno-array-bounds) - add_compile_options($<$:-Wno-class-memaccess>) add_compile_options($<$:-Wno-misleading-indentation>) add_compile_options($<$:-Wno-stringop-overflow>) + add_compile_options($<$:-Wno-restrict>) add_compile_options($<$:-Wno-stringop-truncation>) - add_compile_options($<$:-Wno-placement-new>) + + if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12.0) + # this warning is only reported by g++ 11 in debug mode when building + # src/coreclr/vm/stackingallocator.h. It is a false-positive, fixed in g++ 12. + # see: https://github.com/dotnet/runtime/pull/69188#issuecomment-1136764770 + add_compile_options($<$:-Wno-placement-new>) + endif() if (CMAKE_CXX_COMPILER_ID) check_cxx_compiler_flag(-faligned-new COMPILER_SUPPORTS_F_ALIGNED_NEW) @@ -586,48 +617,42 @@ if (MSVC) add_compile_options($<$:/wd4065>) # switch statement contains 'default' but no 'case' labels add_compile_options($<$:/wd4100>) # 'identifier' : unreferenced formal parameter add_compile_options($<$:/wd4127>) # conditional expression is constant + add_compile_options($<$:/wd4131>) # 'function' : uses old-style declarator add_compile_options($<$:/wd4189>) # local variable is initialized but not referenced add_compile_options($<$:/wd4200>) # nonstandard extension used : zero-sized array in struct/union add_compile_options($<$:/wd4201>) # nonstandard extension used : nameless struct/union + add_compile_options($<$:/wd4206>) # nonstandard extension used : translation unit is empty + add_compile_options($<$:/wd4239>) # nonstandard extension used : 'token' : conversion from 'type' to 'type' add_compile_options($<$:/wd4245>) # conversion from 'type1' to 'type2', signed/unsigned mismatch add_compile_options($<$:/wd4291>) # no matching operator delete found; memory will not be freed if initialization throws an exception + add_compile_options($<$:/wd4310>) # cast truncates constant value + add_compile_options($<$:/wd4324>) # 'struct_name' : structure was padded due to __declspec(align()) + add_compile_options($<$:/wd4366>) # The result of the unary 'operator' operator may be unaligned add_compile_options($<$:/wd4456>) # declaration of 'identifier' hides previous local declaration add_compile_options($<$:/wd4457>) # declaration of 'identifier' hides function parameter add_compile_options($<$:/wd4458>) # declaration of 'identifier' hides class member + add_compile_options($<$:/wd4459>) # declaration of 'identifier' hides global declaration + add_compile_options($<$:/wd4463>) # overflow; assigning value to bit-field that can only hold values from low_value to high_value + add_compile_options($<$:/wd4505>) # unreferenced function with internal linkage has been removed add_compile_options($<$:/wd4702>) # unreachable code + add_compile_options($<$:/wd4706>) # assignment within conditional expression add_compile_options($<$:/wd4733>) # Inline asm assigning to 'FS:0' : handler not registered as safe handler + add_compile_options($<$:/wd4815>) # 'var': zero-sized array in stack object will have no elements (unless the object is an aggregate that has been aggregate initialized) add_compile_options($<$:/wd4838>) # conversion from 'type_1' to 'type_2' requires a narrowing conversion + add_compile_options($<$:/wd4918>) # 'character' : invalid character in pragma optimization list add_compile_options($<$:/wd4960>) # 'function' is too big to be profiled add_compile_options($<$:/wd4961>) # No profile data was merged into '.pgd file', profile-guided optimizations disabled add_compile_options($<$:/wd5105>) # macro expansion producing 'defined' has undefined behavior + add_compile_options($<$:/wd5205>) # delete of an abstract class 'type-name' that has a non-virtual destructor results in undefined behavior # Treat Warnings as Errors: add_compile_options($<$:/we4007>) # 'main' : must be __cdecl. add_compile_options($<$:/we4013>) # 'function' undefined - assuming extern returning int. - add_compile_options($<$:/we4018>) # 'expression' : signed/unsigned mismatch - add_compile_options($<$:/we4055>) # 'conversion' : from data pointer 'type1' to function pointer 'type2' add_compile_options($<$:/we4102>) # "'%$S' : unreferenced label". - add_compile_options($<$:/we4146>) # unary minus operator applied to unsigned type, result still unsigned - add_compile_options($<$:/we4242>) # 'identifier' : conversion from 'type1' to 'type2', possible loss of data - add_compile_options($<$:/we4244>) # 'conversion' conversion from 'type1' to 'type2', possible loss of data - add_compile_options($<$:/we4267>) # 'var' : conversion from 'size_t' to 'type', possible loss of data - add_compile_options($<$:/we4302>) # 'conversion' : truncation from 'type 1' to 'type 2' - add_compile_options($<$:/we4308>) # negative integral constant converted to unsigned type - add_compile_options($<$:/we4509>) # nonstandard extension used: 'function' uses SEH and 'object' has destructor - add_compile_options($<$:/we4510>) # 'class' : default constructor could not be generated - add_compile_options($<$:/we4532>) # 'continue' : jump out of __finally/finally block has undefined behavior during termination handling - add_compile_options($<$:/we4533>) # initialization of 'variable' is skipped by 'instruction' add_compile_options($<$:/we4551>) # Function call missing argument list. - add_compile_options($<$:/we4610>) # object 'class' can never be instantiated - user-defined constructor required - add_compile_options($<$:/we4611>) # interaction between 'function' and C++ object destruction is non-portable - add_compile_options($<$:/we4640>) # 'instance' : construction of local static object is not thread-safe add_compile_options($<$:/we4700>) # Local used w/o being initialized. - add_compile_options($<$:/we4701>) # Potentially uninitialized local variable 'name' used - add_compile_options($<$:/we4703>) # Potentially uninitialized local pointer variable 'name' used - add_compile_options($<$:/we4789>) # destination of memory copy is too small + add_compile_options($<$:/we4640>) # 'instance' : construction of local static object is not thread-safe add_compile_options($<$:/we4806>) # Unsafe operation involving type 'bool'. - add_compile_options($<$:/we4995>) # 'function': name was marked as #pragma deprecated - add_compile_options($<$:/we4996>) # 'function': was declared deprecated also 'std::': Function call with parameters that are potentially unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators' # Set Warning Level 3: add_compile_options($<$:/w34092>) # Sizeof returns 'unsigned long'. @@ -762,6 +787,13 @@ if (CLR_CMAKE_HOST_WIN32) endif() elseif (NOT CLR_CMAKE_HOST_BROWSER) + # This is a workaround for upstream issue: https://gitlab.kitware.com/cmake/cmake/-/issues/22995. + # + # In Clang.cmake, the decision to use single or double hyphen for target and gcc-toolchain + # is made based on CMAKE_${LANG}_COMPILER_VERSION, but CMAKE_ASM_COMPILER_VERSION is empty + # so it picks up single hyphen options, which new clang versions don't recognize. + set (CMAKE_ASM_COMPILER_VERSION "${CMAKE_C_COMPILER_VERSION}") + enable_language(ASM) -endif(CLR_CMAKE_HOST_WIN32) \ No newline at end of file +endif(CLR_CMAKE_HOST_WIN32) diff --git a/eng/native/configureoptimization.cmake b/eng/native/configureoptimization.cmake index 50c7b1cfa8..f6b5da696f 100644 --- a/eng/native/configureoptimization.cmake +++ b/eng/native/configureoptimization.cmake @@ -12,6 +12,11 @@ if(CLR_CMAKE_HOST_WIN32) elseif(CLR_CMAKE_HOST_UNIX) add_compile_options($<$:-O0>) add_compile_options($<$:-O2>) - add_compile_options($<$:-O3>) + if(CLR_CMAKE_TARGET_ANDROID) + # -O2 optimization generates faster/smaller code on Android + add_compile_options($<$:-O2>) + else() + add_compile_options($<$:-O3>) + endif() add_compile_options($<$:-O2>) endif() diff --git a/eng/native/configurepaths.cmake b/eng/native/configurepaths.cmake index 3f41026eee..7d6851d1cf 100644 --- a/eng/native/configurepaths.cmake +++ b/eng/native/configurepaths.cmake @@ -2,6 +2,7 @@ get_filename_component(CLR_REPO_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../.. ABSOLUT set(CLR_ENG_NATIVE_DIR ${CMAKE_CURRENT_LIST_DIR}) get_filename_component(CLR_SRC_NATIVE_DIR ${CMAKE_CURRENT_LIST_DIR}/../../src/native ABSOLUTE) set (CLR_ARTIFACTS_OBJ_DIR "${CLR_REPO_ROOT_DIR}/artifacts/obj") +set (CLR_SOURCELINK_FILE_PATH "${CLR_ARTIFACTS_OBJ_DIR}/native.sourcelink.json") set(VERSION_HEADER_PATH "${CLR_ARTIFACTS_OBJ_DIR}/_version.h") set(VERSION_FILE_PATH "${CLR_ARTIFACTS_OBJ_DIR}/_version.c") set(VERSION_FILE_RC_PATH "${CLR_ARTIFACTS_OBJ_DIR}/NativeVersion.rc") diff --git a/eng/native/configureplatform.cmake b/eng/native/configureplatform.cmake index ecf10a8d4c..c7a38c3eee 100644 --- a/eng/native/configureplatform.cmake +++ b/eng/native/configureplatform.cmake @@ -1,7 +1,7 @@ include(${CMAKE_CURRENT_LIST_DIR}/functions.cmake) -# If set, indicates that this is not an officially supported release -# Keep in sync with IsPrerelease in Directory.Build.props +# If set, indicates that this is not an officially supported release. +# Release branches should set this to false. set(PRERELEASE 1) #---------------------------------------- @@ -36,7 +36,7 @@ if(CLR_CMAKE_HOST_OS STREQUAL Linux) # "amd64" string. Accept either of the two here. if(CMAKE_SYSTEM_PROCESSOR STREQUAL x86_64 OR CMAKE_SYSTEM_PROCESSOR STREQUAL amd64) set(CLR_CMAKE_HOST_UNIX_AMD64 1) - elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL armv7l) + elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL armv7l OR CMAKE_SYSTEM_PROCESSOR STREQUAL armv8l) set(CLR_CMAKE_HOST_UNIX_ARM 1) set(CLR_CMAKE_HOST_UNIX_ARMV7L 1) elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL arm OR CMAKE_SYSTEM_PROCESSOR STREQUAL armv7-a) @@ -45,12 +45,16 @@ if(CLR_CMAKE_HOST_OS STREQUAL Linux) set(CLR_CMAKE_HOST_UNIX_ARMV6 1) elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64 OR CMAKE_SYSTEM_PROCESSOR STREQUAL arm64) set(CLR_CMAKE_HOST_UNIX_ARM64 1) - elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL loongarch64 OR CMAKE_SYSTEM_PROCESSOR STREQUAL loongarch64) + elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL loongarch64) set(CLR_CMAKE_HOST_UNIX_LOONGARCH64 1) + elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL riscv64) + set(CLR_CMAKE_HOST_UNIX_RISCV64 1) elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL i686 OR CMAKE_SYSTEM_PROCESSOR STREQUAL x86) set(CLR_CMAKE_HOST_UNIX_X86 1) elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL s390x) set(CLR_CMAKE_HOST_UNIX_S390X 1) + elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL ppc64le) + set(CLR_CMAKE_HOST_UNIX_POWERPC64 1) elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL mips64) set(CLR_CMAKE_HOST_UNIX_MIPS64 1) else() @@ -70,6 +74,11 @@ if(CLR_CMAKE_HOST_OS STREQUAL Linux) COMMAND bash -c "source ${LINUX_ID_FILE} && echo \$ID" OUTPUT_VARIABLE CLR_CMAKE_LINUX_ID OUTPUT_STRIP_TRAILING_WHITESPACE) + + execute_process( + COMMAND bash -c "if strings \"${CMAKE_SYSROOT}/usr/bin/ldd\" 2>&1 | grep -q musl; then echo musl; fi" + OUTPUT_VARIABLE CLR_CMAKE_LINUX_MUSL + OUTPUT_STRIP_TRAILING_WHITESPACE) endif() if(DEFINED CLR_CMAKE_LINUX_ID) @@ -80,6 +89,10 @@ if(CLR_CMAKE_HOST_OS STREQUAL Linux) set(CLR_CMAKE_HOST_ALPINE_LINUX 1) set(CLR_CMAKE_HOST_OS ${CLR_CMAKE_LINUX_ID}) endif() + + if(CLR_CMAKE_LINUX_MUSL STREQUAL musl) + set(CLR_CMAKE_HOST_LINUX_MUSL 1) + endif() endif(DEFINED CLR_CMAKE_LINUX_ID) endif(CLR_CMAKE_HOST_OS STREQUAL Linux) @@ -232,6 +245,9 @@ elseif(CLR_CMAKE_HOST_UNIX_ARM64) elseif(CLR_CMAKE_HOST_UNIX_LOONGARCH64) set(CLR_CMAKE_HOST_ARCH_LOONGARCH64 1) set(CLR_CMAKE_HOST_ARCH "loongarch64") +elseif(CLR_CMAKE_HOST_UNIX_RISCV64) + set(CLR_CMAKE_HOST_ARCH_RISCV64 1) + set(CLR_CMAKE_HOST_ARCH "riscv64") elseif(CLR_CMAKE_HOST_UNIX_AMD64) set(CLR_CMAKE_HOST_ARCH_AMD64 1) set(CLR_CMAKE_HOST_ARCH "x64") @@ -241,6 +257,9 @@ elseif(CLR_CMAKE_HOST_UNIX_X86) elseif(CLR_CMAKE_HOST_UNIX_S390X) set(CLR_CMAKE_HOST_ARCH_S390X 1) set(CLR_CMAKE_HOST_ARCH "s390x") +elseif(CLR_CMAKE_HOST_UNIX_POWERPC64) + set(CLR_CMAKE_HOST_ARCH_POWERPC64 1) + set(CLR_CMAKE_HOST_ARCH "ppc64le") elseif(CLR_CMAKE_HOST_BROWSER) set(CLR_CMAKE_HOST_ARCH_WASM 1) set(CLR_CMAKE_HOST_ARCH "wasm") @@ -278,27 +297,31 @@ endif() # Set target architecture variables if (CLR_CMAKE_TARGET_ARCH STREQUAL x64) set(CLR_CMAKE_TARGET_ARCH_AMD64 1) - elseif(CLR_CMAKE_TARGET_ARCH STREQUAL x86) +elseif(CLR_CMAKE_TARGET_ARCH STREQUAL x86) set(CLR_CMAKE_TARGET_ARCH_I386 1) - elseif(CLR_CMAKE_TARGET_ARCH STREQUAL arm64) +elseif(CLR_CMAKE_TARGET_ARCH STREQUAL arm64) set(CLR_CMAKE_TARGET_ARCH_ARM64 1) - elseif(CLR_CMAKE_TARGET_ARCH STREQUAL loongarch64) +elseif(CLR_CMAKE_TARGET_ARCH STREQUAL loongarch64) set(CLR_CMAKE_TARGET_ARCH_LOONGARCH64 1) - elseif(CLR_CMAKE_TARGET_ARCH STREQUAL arm) +elseif(CLR_CMAKE_TARGET_ARCH STREQUAL riscv64) + set(CLR_CMAKE_TARGET_ARCH_RISCV64 1) +elseif(CLR_CMAKE_TARGET_ARCH STREQUAL arm) set(CLR_CMAKE_TARGET_ARCH_ARM 1) - elseif(CLR_CMAKE_TARGET_ARCH STREQUAL armv6) +elseif(CLR_CMAKE_TARGET_ARCH STREQUAL armv6) set(CLR_CMAKE_TARGET_ARCH_ARMV6 1) - elseif(CLR_CMAKE_TARGET_ARCH STREQUAL armel) +elseif(CLR_CMAKE_TARGET_ARCH STREQUAL armel) set(CLR_CMAKE_TARGET_ARCH_ARM 1) set(CLR_CMAKE_TARGET_ARCH_ARMV7L 1) set(ARM_SOFTFP 1) - elseif(CLR_CMAKE_TARGET_ARCH STREQUAL s390x) +elseif(CLR_CMAKE_TARGET_ARCH STREQUAL s390x) set(CLR_CMAKE_TARGET_ARCH_S390X 1) - elseif(CLR_CMAKE_TARGET_ARCH STREQUAL wasm) +elseif(CLR_CMAKE_TARGET_ARCH STREQUAL ppc64le) + set(CLR_CMAKE_TARGET_ARCH_POWERPC64 1) +elseif(CLR_CMAKE_TARGET_ARCH STREQUAL wasm) set(CLR_CMAKE_TARGET_ARCH_WASM 1) - elseif(CLR_CMAKE_TARGET_ARCH STREQUAL mips64) +elseif(CLR_CMAKE_TARGET_ARCH STREQUAL mips64) set(CLR_CMAKE_TARGET_ARCH_MIPS64 1) - else() +else() clr_unknown_arch() endif() @@ -314,6 +337,10 @@ if(CLR_CMAKE_TARGET_OS STREQUAL Linux) set(CLR_CMAKE_TARGET_LINUX 1) endif(CLR_CMAKE_TARGET_OS STREQUAL Linux) +if(CLR_CMAKE_HOST_LINUX_MUSL) + set(CLR_CMAKE_TARGET_LINUX_MUSL 1) +endif(CLR_CMAKE_HOST_LINUX_MUSL) + if(CLR_CMAKE_TARGET_OS STREQUAL tizen) set(CLR_CMAKE_TARGET_UNIX 1) set(CLR_CMAKE_TARGET_LINUX 1) @@ -396,10 +423,14 @@ if(CLR_CMAKE_TARGET_UNIX) set(CLR_CMAKE_TARGET_UNIX_ARM64 1) elseif(CLR_CMAKE_TARGET_ARCH STREQUAL loongarch64) set(CLR_CMAKE_TARGET_UNIX_LOONGARCH64 1) + elseif(CLR_CMAKE_TARGET_ARCH STREQUAL riscv64) + set(CLR_CMAKE_TARGET_UNIX_RISCV64 1) elseif(CLR_CMAKE_TARGET_ARCH STREQUAL x86) set(CLR_CMAKE_TARGET_UNIX_X86 1) elseif(CLR_CMAKE_TARGET_ARCH STREQUAL s390x) set(CLR_CMAKE_TARGET_UNIX_S390X 1) + elseif(CLR_CMAKE_TARGET_ARCH STREQUAL ppc64le) + set(CLR_CMAKE_TARGET_UNIX_POWERPC64 1) elseif(CLR_CMAKE_TARGET_ARCH STREQUAL wasm) set(CLR_CMAKE_TARGET_UNIX_WASM 1) elseif(CLR_CMAKE_TARGET_ARCH STREQUAL mips64) diff --git a/eng/native/configuretools.cmake b/eng/native/configuretools.cmake index ad5dc38107..07a3bbfafe 100644 --- a/eng/native/configuretools.cmake +++ b/eng/native/configuretools.cmake @@ -7,59 +7,69 @@ if (CMAKE_C_COMPILER MATCHES "-?[0-9]+(\.[0-9]+)?$") endif() if(NOT WIN32 AND NOT CLR_CMAKE_TARGET_BROWSER) - if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + if(CMAKE_C_COMPILER_ID MATCHES "Clang") if(APPLE) set(TOOLSET_PREFIX "") else() set(TOOLSET_PREFIX "llvm-") endif() - elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU") + elseif(CMAKE_C_COMPILER_ID MATCHES "GNU") if(CMAKE_CROSSCOMPILING) - set(TOOLSET_PREFIX "${CMAKE_CXX_COMPILER_TARGET}-") + set(TOOLSET_PREFIX "${CMAKE_C_COMPILER_TARGET}-") else() set(TOOLSET_PREFIX "") endif() endif() - function(locate_toolchain_exec exec var) + function(locate_toolchain_exec exec var required) string(TOUPPER ${exec} EXEC_UPPERCASE) if(NOT "$ENV{CLR_${EXEC_UPPERCASE}}" STREQUAL "") set(${var} "$ENV{CLR_${EXEC_UPPERCASE}}" PARENT_SCOPE) return() endif() + unset(EXEC_LOCATION_${exec} CACHE) find_program(EXEC_LOCATION_${exec} NAMES "${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 toolchain executable. Name: ${exec}, Prefix: ${TOOLSET_PREFIX}.") + if (required AND EXEC_LOCATION_${exec} STREQUAL "EXEC_LOCATION_${exec}-NOTFOUND") + message(FATAL_ERROR "Unable to find toolchain executable. Name: '${exec}', Prefix: '${TOOLSET_PREFIX}'") + endif() + + if (NOT EXEC_LOCATION_${exec} STREQUAL "EXEC_LOCATION_${exec}-NOTFOUND") + set(${var} ${EXEC_LOCATION_${exec}} PARENT_SCOPE) endif() - set(${var} ${EXEC_LOCATION_${exec}} PARENT_SCOPE) endfunction() - locate_toolchain_exec(ar CMAKE_AR) - locate_toolchain_exec(nm CMAKE_NM) - locate_toolchain_exec(ranlib CMAKE_RANLIB) + locate_toolchain_exec(ar CMAKE_AR YES) + locate_toolchain_exec(nm CMAKE_NM YES) + locate_toolchain_exec(ranlib CMAKE_RANLIB YES) if(CMAKE_C_COMPILER_ID MATCHES "Clang") - locate_toolchain_exec(link CMAKE_LINKER) + locate_toolchain_exec(link CMAKE_LINKER YES) endif() if(NOT CLR_CMAKE_TARGET_OSX AND NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS AND (NOT CLR_CMAKE_TARGET_ANDROID OR CROSS_ROOTFS)) - locate_toolchain_exec(objdump CMAKE_OBJDUMP) + locate_toolchain_exec(objdump CMAKE_OBJDUMP YES) - if(CLR_CMAKE_TARGET_ANDROID) - set(TOOLSET_PREFIX ${ANDROID_TOOLCHAIN_PREFIX}) - elseif(CMAKE_CROSSCOMPILING AND NOT DEFINED CLR_CROSS_COMPONENTS_BUILD AND - CMAKE_SYSTEM_PROCESSOR MATCHES "^(armv7l|armv6l|aarch64|arm|s390x)$") - set(TOOLSET_PREFIX "${TOOLCHAIN}-") - else() - set(TOOLSET_PREFIX "") + unset(CMAKE_OBJCOPY CACHE) + locate_toolchain_exec(objcopy CMAKE_OBJCOPY NO) + + if (CMAKE_OBJCOPY) + execute_process( + COMMAND ${CMAKE_OBJCOPY} --help + OUTPUT_VARIABLE OBJCOPY_HELP_OUTPUT + ) endif() - locate_toolchain_exec(objcopy CMAKE_OBJCOPY) + # if llvm-objcopy does not support --only-keep-debug argument, try to locate binutils' objcopy + if (NOT CMAKE_OBJCOPY OR (CMAKE_C_COMPILER_ID MATCHES "Clang" AND NOT "${OBJCOPY_HELP_OUTPUT}" MATCHES "--only-keep-debug")) + set(TOOLSET_PREFIX "") + locate_toolchain_exec(objcopy CMAKE_OBJCOPY YES) + endif () + endif() endif() diff --git a/eng/native/functions.cmake b/eng/native/functions.cmake index bc5e3c879d..efb36de6e4 100644 --- a/eng/native/functions.cmake +++ b/eng/native/functions.cmake @@ -4,7 +4,7 @@ function(clr_unknown_arch) elseif(CLR_CROSS_COMPONENTS_BUILD) message(FATAL_ERROR "Only AMD64, I386 host are supported for linux cross-architecture component. Found: ${CMAKE_SYSTEM_PROCESSOR}") else() - message(FATAL_ERROR "Only AMD64, ARMV6, ARM64, LOONGARCH64 and ARM are supported. Found: ${CMAKE_SYSTEM_PROCESSOR}") + message(FATAL_ERROR "'${CMAKE_SYSTEM_PROCESSOR}' is an unsupported architecture.") endif() endfunction() @@ -15,7 +15,7 @@ function(h2inc filename output) get_filename_component(path "${filename}" DIRECTORY) file(RELATIVE_PATH relative_filename "${CLR_REPO_ROOT_DIR}" "${filename}") - file(APPEND "${output}" "// File start: ${relative_filename}\n") + file(WRITE "${output}" "// File start: ${relative_filename}\n") # Use of NEWLINE_CONSUME is needed for lines with trailing backslash file(STRINGS ${filename} contents NEWLINE_CONSUME) @@ -167,6 +167,10 @@ function(find_unwind_libs UnwindLibs) find_library(UNWIND_ARCH NAMES unwind-loongarch64) endif() + if(CLR_CMAKE_HOST_ARCH_RISCV64) + find_library(UNWIND_ARCH NAMES unwind-riscv64) + endif() + if(CLR_CMAKE_HOST_ARCH_AMD64) find_library(UNWIND_ARCH NAMES unwind-x86_64) endif() @@ -175,6 +179,10 @@ function(find_unwind_libs UnwindLibs) find_library(UNWIND_ARCH NAMES unwind-s390x) endif() + if(CLR_CMAKE_HOST_ARCH_POWERPC64) + find_library(UNWIND_ARCH NAMES unwind-ppc64le) + endif() + if(NOT UNWIND_ARCH STREQUAL UNWIND_ARCH-NOTFOUND) set(UNWIND_LIBS ${UNWIND_ARCH}) endif() @@ -200,7 +208,8 @@ endfunction(find_unwind_libs) function(convert_to_absolute_path RetSources) set(Sources ${ARGN}) foreach(Source IN LISTS Sources) - list(APPEND AbsolutePathSources ${CMAKE_CURRENT_SOURCE_DIR}/${Source}) + get_filename_component(AbsolutePathSource ${Source} ABSOLUTE BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) + list(APPEND AbsolutePathSources ${AbsolutePathSource}) endforeach() set(${RetSources} ${AbsolutePathSources} PARENT_SCOPE) endfunction(convert_to_absolute_path) @@ -390,18 +399,29 @@ function(strip_symbols targetName outputFilename) message(FATAL_ERROR "strip not found") endif() + set(strip_command ${STRIP} -no_code_signature_warning -S ${strip_source_file}) + + # codesign release build string(TOLOWER "${CMAKE_BUILD_TYPE}" LOWERCASE_CMAKE_BUILD_TYPE) if (LOWERCASE_CMAKE_BUILD_TYPE STREQUAL release) - set(strip_command ${STRIP} -no_code_signature_warning -S ${strip_source_file} && codesign -f -s - ${strip_source_file}) - else () - set(strip_command) + set(strip_command ${strip_command} && codesign -f -s - ${strip_source_file}) + endif () + + execute_process( + COMMAND ${DSYMUTIL} --help + OUTPUT_VARIABLE DSYMUTIL_HELP_OUTPUT + ) + + set(DSYMUTIL_OPTS "--flat") + if ("${DSYMUTIL_HELP_OUTPUT}" MATCHES "--minimize") + list(APPEND DSYMUTIL_OPTS "--minimize") endif () add_custom_command( TARGET ${targetName} POST_BUILD VERBATIM - COMMAND ${DSYMUTIL} --flat ${strip_source_file} + COMMAND ${DSYMUTIL} ${DSYMUTIL_OPTS} ${strip_source_file} COMMAND ${strip_command} COMMENT "Stripping symbols from ${strip_source_file} into file ${strip_destination_file}" ) @@ -412,7 +432,7 @@ function(strip_symbols targetName outputFilename) POST_BUILD VERBATIM COMMAND ${CMAKE_OBJCOPY} --only-keep-debug ${strip_source_file} ${strip_destination_file} - COMMAND ${CMAKE_OBJCOPY} --strip-unneeded ${strip_source_file} + COMMAND ${CMAKE_OBJCOPY} --strip-debug --strip-unneeded ${strip_source_file} COMMAND ${CMAKE_OBJCOPY} --add-gnu-debuglink=${strip_destination_file} ${strip_source_file} COMMENT "Stripping symbols from ${strip_source_file} into file ${strip_destination_file}" ) diff --git a/eng/native/gen-buildsys.cmd b/eng/native/gen-buildsys.cmd index 243921d93d..3701e639ce 100644 --- a/eng/native/gen-buildsys.cmd +++ b/eng/native/gen-buildsys.cmd @@ -29,8 +29,6 @@ if /i "%__Ninja%" == "1" ( ) else ( if /i NOT "%__Arch%" == "wasm" ( if /i "%__VSVersion%" == "vs2022" (set __CmakeGenerator=%__CmakeGenerator% 17 2022) - if /i "%__VSVersion%" == "vs2019" (set __CmakeGenerator=%__CmakeGenerator% 16 2019) - if /i "%__VSVersion%" == "vs2017" (set __CmakeGenerator=%__CmakeGenerator% 15 2017) if /i "%__Arch%" == "x64" (set __ExtraCmakeParams=%__ExtraCmakeParams% -A x64) if /i "%__Arch%" == "arm" (set __ExtraCmakeParams=%__ExtraCmakeParams% -A ARM) diff --git a/eng/native/gen-buildsys.sh b/eng/native/gen-buildsys.sh index 550613b163..c3bf9adbbe 100755 --- a/eng/native/gen-buildsys.sh +++ b/eng/native/gen-buildsys.sh @@ -10,7 +10,7 @@ if [[ "$#" -lt 4 ]]; then echo "gen-buildsys.sh [build flavor] [ninja] [scan-build] [cmakeargs]" echo "Specify the path to the top level CMake file." echo "Specify the path that the build system files are generated in." - echo "Specify the target architecture." + echo "Specify the host architecture (the architecture the built tools should run on)." echo "Specify the name of compiler (clang or gcc)." echo "Optionally specify the build configuration (flavor.) Defaults to DEBUG." echo "Optionally specify 'scan-build' to enable build with clang static analyzer." @@ -19,12 +19,12 @@ if [[ "$#" -lt 4 ]]; then exit 1 fi -build_arch="$3" +host_arch="$3" compiler="$4" if [[ "$compiler" != "default" ]]; then nativescriptroot="$( cd -P "$scriptroot/../common/native" && pwd )" - source "$nativescriptroot/init-compiler.sh" "$nativescriptroot" "$build_arch" "$compiler" + source "$nativescriptroot/init-compiler.sh" "$nativescriptroot" "$host_arch" "$compiler" CCC_CC="$CC" CCC_CXX="$CXX" @@ -67,7 +67,7 @@ if [[ "$CROSSCOMPILE" == "1" ]]; then exit 1 fi - TARGET_BUILD_ARCH="$build_arch" + TARGET_BUILD_ARCH="$host_arch" export TARGET_BUILD_ARCH cmake_extra_defines="$cmake_extra_defines -C $scriptroot/tryrun.cmake" @@ -79,7 +79,7 @@ if [[ "$CROSSCOMPILE" == "1" ]]; then fi fi -if [[ "$build_arch" == "armel" ]]; then +if [[ "$host_arch" == "armel" ]]; then cmake_extra_defines="$cmake_extra_defines -DARM_SOFTFP=1" fi @@ -92,23 +92,10 @@ if [[ "$scan_build" == "ON" && -n "$SCAN_BUILD_COMMAND" ]]; then cmake_command="$SCAN_BUILD_COMMAND $cmake_command" fi -if [[ "$build_arch" == "wasm" ]]; then +if [[ "$host_arch" == "wasm" ]]; then cmake_command="emcmake $cmake_command" fi -cmake_args_to_cache="$scan_build\n$SCAN_BUILD_COMMAND\n$generator\n$__UnprocessedCMakeArgs" -cmake_args_cache_file="$2/cmake_cmd_line.txt" -if [[ -z "$__ConfigureOnly" ]]; then - if [[ -e "$cmake_args_cache_file" ]]; then - cmake_args_cache=$(<"$cmake_args_cache_file") - if [[ "$cmake_args_cache" == "$cmake_args_to_cache" ]]; then - echo "CMake command line is unchanged. Reusing previous cache instead of regenerating." - exit 0 - fi - fi - echo $cmake_args_to_cache > $cmake_args_cache_file -fi - # We have to be able to build with CMake 3.6.2, so we can't use the -S or -B options pushd "$2" diff --git a/eng/native/ijw/IJW.cmake b/eng/native/ijw/IJW.cmake new file mode 100644 index 0000000000..9a38a18dc0 --- /dev/null +++ b/eng/native/ijw/IJW.cmake @@ -0,0 +1,82 @@ +if (CLR_CMAKE_HOST_WIN32) + + function(remove_ijw_incompatible_options options updatedOptions) + + # IJW isn't compatible with Ehsc, which CMake enables by default, + if(options MATCHES "/EHsc") + string(REPLACE "/EHsc" "" options "${options}") + endif() + + # IJW isn't compatible with CFG + if(options MATCHES "/guard:cf") + string(REPLACE "/guard:cf" "" options "${options}") + endif() + + # IJW isn't compatible with EHCONT, which requires CFG + if(options MATCHES "/guard:ehcont") + string(REPLACE "/guard:ehcont" "" options "${options}") + endif() + + # IJW isn't compatible with GR- + if(options MATCHES "/GR-") + string(REPLACE "/GR-" "" options "${options}") + endif() + + SET(${updatedOptions} "${options}" PARENT_SCOPE) + endfunction() + + function(remove_ijw_incompatible_target_options targetName) + get_target_property(compileOptions ${targetName} COMPILE_OPTIONS) + remove_ijw_incompatible_options("${compileOptions}" compileOptions) + set_target_properties(${targetName} PROPERTIES COMPILE_OPTIONS "${compileOptions}") + endfunction() + + # 4365 - signed/unsigned mismatch + # 4679 - Could not import member. This is an issue with IJW and static abstract methods in interfaces. + add_compile_options(/wd4365 /wd4679) + + # IJW + add_compile_options(/clr:netcore) + + # IJW requires the CRT as a dll, not linked in + set(CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded$<$,$>:Debug>DLL) + + # CMake enables /RTC1 and /EHsc by default, but they're not compatible with /clr, so remove them + if(CMAKE_CXX_FLAGS_DEBUG MATCHES "/RTC1") + string(REPLACE "/RTC1" " " CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}") + endif() + + remove_ijw_incompatible_options("${CMAKE_CXX_FLAGS}" CMAKE_CXX_FLAGS) + + set(CLR_SDK_REF_PACK_OUTPUT "") + set(CLR_SDK_REF_PACK_DISCOVERY_ERROR "") + set(CLR_SDK_REF_PACK_DISCOVERY_RESULT 0) + + if (CPP_CLI_LIVE_REF_ASSEMBLIES) + message("Using live-built ref assemblies for C++/CLI runtime tests.") + execute_process( + COMMAND powershell -ExecutionPolicy ByPass -NoProfile "${CMAKE_CURRENT_LIST_DIR}/getRefPackFolderFromArtifacts.ps1" + OUTPUT_VARIABLE CLR_SDK_REF_PACK_OUTPUT + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_VARIABLE CLR_SDK_REF_PACK_DISCOVERY_ERROR + RESULT_VARIABLE CLR_SDK_REF_PACK_DISCOVERY_RESULT) + else() + execute_process( + COMMAND powershell -ExecutionPolicy ByPass -NoProfile "${CMAKE_CURRENT_LIST_DIR}/getRefPackFolderFromSdk.ps1" + OUTPUT_VARIABLE CLR_SDK_REF_PACK_OUTPUT + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_VARIABLE CLR_SDK_REF_PACK_DISCOVERY_ERROR + RESULT_VARIABLE CLR_SDK_REF_PACK_DISCOVERY_RESULT) + endif() + + if (NOT CLR_SDK_REF_PACK_DISCOVERY_RESULT EQUAL 0) + message(FATAL_ERROR "Unable to find reference assemblies: ${CLR_SDK_REF_PACK_DISCOVERY_ERROR}") + endif() + + string(REGEX REPLACE ".*refPackPath=(.*)" "\\1" CLR_SDK_REF_PACK ${CLR_SDK_REF_PACK_OUTPUT}) + + add_compile_options(/AI${CLR_SDK_REF_PACK}) + + list(APPEND LINK_LIBRARIES_ADDITIONAL ijwhost) + +endif() diff --git a/eng/native/ijw/getRefPackFolderFromArtifacts.ps1 b/eng/native/ijw/getRefPackFolderFromArtifacts.ps1 new file mode 100644 index 0000000000..f9b53286c2 --- /dev/null +++ b/eng/native/ijw/getRefPackFolderFromArtifacts.ps1 @@ -0,0 +1,21 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. + +$engNativeFolder = Split-Path $PSScriptRoot -Parent +$engFolder = Split-Path $engNativeFolder -Parent +$repoRoot = Split-Path $engFolder -Parent + +$versionPropsFile = "$repoRoot/eng/Versions.props" + +$majorVersion = Select-Xml -Path $versionPropsFile -XPath "/Project/PropertyGroup/MajorVersion" | %{$_.Node.InnerText} +$minorVersion = Select-Xml -Path $versionPropsFile -XPath "/Project/PropertyGroup/MinorVersion" | %{$_.Node.InnerText} + +$refPackPath = "$repoRoot/artifacts/bin/ref/net$majorVersion.$minorVersion" + +if (-not (Test-Path $refPackPath)) +{ + Write-Error "Reference assemblies not found in the artifacts folder at '$refPackPath'. Did you invoke 'build.cmd libs.sfx+libs.oob /p:RefOnly=true' to make sure that refs are built? Did the repo layout change?" + exit 1 +} + +Write-Output "refPackPath=$refPackPath" diff --git a/eng/native/ijw/getRefPackFolderFromSdk.ps1 b/eng/native/ijw/getRefPackFolderFromSdk.ps1 new file mode 100644 index 0000000000..1b59248cb4 --- /dev/null +++ b/eng/native/ijw/getRefPackFolderFromSdk.ps1 @@ -0,0 +1,27 @@ +# Licensed to the .NET Foundation under one or more agreements. +# The .NET Foundation licenses this file to you under the MIT license. + +$engNativeFolder = Split-Path $PSScriptRoot -Parent +$engFolder = Split-Path $engNativeFolder -Parent +$repoRoot = Split-Path $engFolder -Parent + +. "$repoRoot/eng/common/tools.ps1" + +$dotnetRoot = InitializeDotNetCli $true $false + +$dotnetSdkVersion = $GlobalJson.tools.dotnet + +$sdkBundledVersionsFile = "$dotnetRoot/sdk/$dotnetSdkVersion/Microsoft.NETCoreSdk.BundledVersions.props" + +$refPackVersion = Select-Xml -Path $sdkBundledVersionsFile -XPath "/Project/PropertyGroup/BundledNETCoreAppPackageVersion" | %{$_.Node.InnerText} +$refPackTfmVersion = Select-Xml -Path $sdkBundledVersionsFile -XPath "/Project/PropertyGroup/BundledNETCoreAppTargetFrameworkVersion" | %{$_.Node.InnerText} + +$refPackPath = "$dotnetRoot/packs/Microsoft.NETCore.App.Ref/$refPackVersion/ref/net$refPackTfmVersion" + +if (-not (Test-Path $refPackPath)) +{ + Write-Error "Reference assemblies not found in the SDK folder. Did the SDK layout change? Did the SDK change how it describes the bundled runtime version?" + exit 1 +} + +Write-Output "refPackPath=$refPackPath" diff --git a/eng/native/init-distro-rid.sh b/eng/native/init-distro-rid.sh index 97fd647081..7501224063 100644 --- a/eng/native/init-distro-rid.sh +++ b/eng/native/init-distro-rid.sh @@ -41,7 +41,7 @@ initNonPortableDistroRid() # We have forced __PortableBuild=0. This is because -portablebuld # has been passed as false. if (( isPortable == 0 )); then - if [[ "${ID}" == "rhel" || "${ID}" == "rocky" ]]; then + if [[ "${ID}" == "rhel" || "${ID}" == "rocky" || "${ID}" == "alpine" ]]; then # remove the last version digit VERSION_ID="${VERSION_ID%.*}" fi @@ -138,7 +138,7 @@ initDistroRidGlobal() fi if [ -n "${rootfsDir}" ]; then - # We may have a cross build. Check for the existance of the rootfsDir + # We may have a cross build. Check for the existence of the rootfsDir if [ ! -e "${rootfsDir}" ]; then echo "Error rootfsDir has been passed, but the location is not valid." exit 1 @@ -168,6 +168,8 @@ initDistroRidGlobal() if [ -z "${distroRid}" ]; then if [ "$targetOs" = "Linux" ]; then distroRid="linux-$buildArch" + elif [ "$targetOs" = "linux-bionic" ]; then + distroRid="linux-bionic-$buildArch" elif [ "$targetOs" = "OSX" ]; then distroRid="osx-$buildArch" elif [ "$targetOs" = "MacCatalyst" ]; then diff --git a/eng/native/init-os-and-arch.sh b/eng/native/init-os-and-arch.sh index eda07a5fee..9f8b78984d 100644 --- a/eng/native/init-os-and-arch.sh +++ b/eng/native/init-os-and-arch.sh @@ -13,8 +13,8 @@ FreeBSD|Linux|NetBSD|OpenBSD|SunOS|Android) Darwin) os=OSX ;; *) - echo "Unsupported OS $OSName detected, configuring as if for Linux" - os=Linux ;; + echo "Unsupported OS $OSName detected!" + exit 1 ;; esac # On Solaris, `uname -m` is discouraged, see https://docs.oracle.com/cd/E36784_01/html/E36870/uname-1.html @@ -41,11 +41,15 @@ case "$CPUName" in arch=loongarch64 ;; + riscv64) + arch=riscv64 + ;; + amd64|x86_64) arch=x64 ;; - armv7l) + armv7l|armv8l) if (NAME=""; . /etc/os-release; test "$NAME" = "Tizen"); then arch=armel else @@ -64,10 +68,13 @@ case "$CPUName" in s390x) arch=s390x - ;; + ;; + ppc64le) + arch=ppc64le + ;; *) - echo "Unknown CPU $CPUName detected, configuring as if for x64" - arch=x64 + echo "Unknown CPU $CPUName detected!" + exit 1 ;; esac diff --git a/eng/native/init-vs-env.cmd b/eng/native/init-vs-env.cmd index 7eefeea127..5f450d0636 100644 --- a/eng/native/init-vs-env.cmd +++ b/eng/native/init-vs-env.cmd @@ -16,7 +16,7 @@ if /i "%~1" == "wasm" (set __VCBuildArch=x86_amd64) :: is no longer set as a global environment variable and is instead only set if the user :: has launched the Visual Studio Developer Command Prompt. :: -:: Following this logic, we will default to the Visual Studio toolset assocated with the active +:: Following this logic, we will default to the Visual Studio toolset associated with the active :: Developer Command Prompt. Otherwise, we will query VSWhere to locate the later version of :: Visual Studio available on the machine. Finally, we will fail the script if no supported :: instance can be found. @@ -45,14 +45,9 @@ set "__VSCOMNTOOLS=" set "VSCMD_START_DIR=" :VSDetected -if "%VisualStudioVersion%"=="16.0" ( - set __VSVersion=vs2019 - set __PlatformToolset=v142 - goto :SetVCEnvironment -) if "%VisualStudioVersion%"=="17.0" ( set __VSVersion=vs2022 - set __PlatformToolset=v142 + set __PlatformToolset=v143 goto :SetVCEnvironment ) diff --git a/eng/native/naming.props b/eng/native/naming.props index 2f39564569..b50c0c131c 100644 --- a/eng/native/naming.props +++ b/eng/native/naming.props @@ -21,15 +21,6 @@ .dwarf - - - lib - .so - .a - - .debug - - lib @@ -45,10 +36,4 @@ - - - $(SymbolsSuffix) - - diff --git a/eng/native/tryrun.cmake b/eng/native/tryrun.cmake index fca410fcb4..5c5344bd80 100644 --- a/eng/native/tryrun.cmake +++ b/eng/native/tryrun.cmake @@ -68,7 +68,7 @@ if(DARWIN) else() message(FATAL_ERROR "Arch is ${TARGET_ARCH_NAME}. Only arm64 or x64 is supported for OSX cross build!") endif() -elseif(TARGET_ARCH_NAME MATCHES "^(armel|arm|armv6|arm64|loongarch64|s390x|x86)$" OR FREEBSD OR ILLUMOS) +elseif(TARGET_ARCH_NAME MATCHES "^(armel|arm|armv6|arm64|loongarch64|riscv64|s390x|ppc64le|x86)$" OR FREEBSD OR ILLUMOS) set_cache_value(FILE_OPS_CHECK_FERROR_OF_PREVIOUS_CALL_EXITCODE 1) set_cache_value(GETPWUID_R_SETS_ERRNO_EXITCODE 0) set_cache_value(HAS_POSIX_SEMAPHORES_EXITCODE 0) @@ -146,9 +146,9 @@ elseif(TARGET_ARCH_NAME MATCHES "^(armel|arm|armv6|arm64|loongarch64|s390x|x86)$ set_cache_value(HAVE_FUNCTIONAL_PTHREAD_ROBUST_MUTEXES_EXITCODE 0) endif() else() - message(FATAL_ERROR "Arch is ${TARGET_ARCH_NAME}. Only armel, arm, armv6, arm64, loongarch64, s390x and x86 are supported!") + message(FATAL_ERROR "Arch is ${TARGET_ARCH_NAME}. Only armel, arm, armv6, arm64, loongarch64, s390x, ppc64le and x86 are supported!") endif() -if(TARGET_ARCH_NAME STREQUAL "x86" OR TARGET_ARCH_NAME STREQUAL "s390x" OR TARGET_ARCH_NAME STREQUAL "armv6" OR TARGET_ARCH_NAME STREQUAL "loongarch64") +if(TARGET_ARCH_NAME MATCHES "^(x86|s390x|armv6|loongarch64|riscv64|ppc64le)$") set_cache_value(HAVE_FUNCTIONAL_PTHREAD_ROBUST_MUTEXES_EXITCODE 0) endif() diff --git a/eng/prepare-release.yml b/eng/prepare-release.yml index f1246e2ec5..2f7dbf8d91 100644 --- a/eng/prepare-release.yml +++ b/eng/prepare-release.yml @@ -7,13 +7,13 @@ stages: jobs: - job: PrepareReleaseJob displayName: Prepare release with Darc - pool: + pool: ${{ if 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 eq(variables['System.TeamProject'], 'internal') }}: name: NetCore1ESPool-Internal - demands: ImageOverride -equals build.windows.10.amd64.vs2019 + demands: ImageOverride -equals windows.vs2022.amd64 variables: - ${{ if and(ne(variables['System.TeamProject'], 'public'), notin(variables['Build.Reason'], 'PullRequest'), startsWith(variables['Build.SourceBranch'], 'refs/heads/release/')) }}: - group: DotNet-Diagnostics-Storage @@ -70,4 +70,4 @@ stages: inputs: targetPath: '$(System.ArtifactsDirectory)\ReleaseStaging' publishLocation: 'pipeline' - artifact: 'DiagnosticsRelease' \ No newline at end of file + artifact: 'DiagnosticsRelease'