From 3b966bc0ec30ff1ec4e6937969442ffcfe8e33ba Mon Sep 17 00:00:00 2001 From: Adeel <3840695+am11@users.noreply.github.com> Date: Tue, 20 Dec 2022 23:27:40 +0200 Subject: [PATCH 1/3] Sync eng/native from dotnet/runtime --- eng/native/build-commons.sh | 20 +++++++++++++++-- eng/native/configurecompiler.cmake | 15 ++++++++++--- eng/native/configureplatform.cmake | 19 ++++++++++------ eng/native/gen-buildsys.cmd | 35 ++++++++++++++++++++---------- eng/native/gen-buildsys.sh | 18 ++++++++++----- eng/native/init-distro-rid.sh | 11 ++++++++-- eng/native/init-vs-env.cmd | 2 +- eng/native/tryrun.cmake | 8 +++++-- 8 files changed, 94 insertions(+), 34 deletions(-) diff --git a/eng/native/build-commons.sh b/eng/native/build-commons.sh index dd0dea81cd..c9160b1e4b 100755 --- a/eng/native/build-commons.sh +++ b/eng/native/build-commons.sh @@ -117,7 +117,7 @@ build_native() scan_build=scan-build fi - nextCommand="\"$__RepoRootDir/eng/native/gen-buildsys.sh\" \"$cmakeDir\" \"$intermediatesDir\" $hostArch $__Compiler $__BuildType \"$generator\" $scan_build $cmakeArgs" + nextCommand="\"$__RepoRootDir/eng/native/gen-buildsys.sh\" \"$cmakeDir\" \"$intermediatesDir\" $hostArch $targetOS $__Compiler $__BuildType \"$generator\" $scan_build $cmakeArgs" echo "Invoking $nextCommand" eval $nextCommand @@ -163,7 +163,7 @@ build_native() popd else cmake_command=cmake - if [[ "$build_arch" == "wasm" ]]; then + if [[ "$build_arch" == "wasm" && "$__TargetOS" == "Browser" ]]; then cmake_command="emcmake cmake" echo "Executing $cmake_command --build \"$intermediatesDir\" --target $target -- -j $__NumProc" $cmake_command --build "$intermediatesDir" --target $target -- -j "$__NumProc" @@ -212,6 +212,7 @@ usage() echo "-gccx.y: optional argument to build using gcc version x.y." echo "-ninja: target ninja instead of GNU make" echo "-numproc: set the number of build processes." + echo "-outputrid: optional argument that overrides the target rid name." echo "-portablebuild: pass -portablebuild=false to force a non-portable build." echo "-skipconfigure: skip build configuration." echo "-keepnativesymbols: keep native/unmanaged debug symbols." @@ -232,6 +233,7 @@ __TargetArch=$arch __TargetOS=$os __HostOS=$os __BuildOS=$os +__OutputRid='' # Get the number of processors available to the scheduler platform="$(uname)" @@ -392,6 +394,16 @@ while :; do __TargetArch=wasm ;; + outputrid|-outputrid) + if [[ -n "$2" ]]; then + __OutputRid="$2" + shift + else + echo "ERROR: 'outputrid' requires a non-empty option argument" + exit 1 + fi + ;; + ppc64le|-ppc64le) __TargetArch=ppc64le ;; @@ -474,3 +486,7 @@ fi # init the target distro name initTargetDistroRid + +if [ -z "$__OutputRid" ]; then + __OutputRid="$(echo $__DistroRid | tr '[:upper:]' '[:lower:]')" +fi diff --git a/eng/native/configurecompiler.cmake b/eng/native/configurecompiler.cmake index a0163845e6..d9443ce6dd 100644 --- a/eng/native/configurecompiler.cmake +++ b/eng/native/configurecompiler.cmake @@ -160,9 +160,8 @@ elseif (CLR_CMAKE_HOST_UNIX) list(JOIN CLR_LINK_SANITIZERS "," CLR_LINK_SANITIZERS_OPTIONS) list(APPEND CLR_SANITIZE_LINK_OPTIONS "-fsanitize=${CLR_LINK_SANITIZERS_OPTIONS}") - # -fdata-sections -ffunction-sections: each function has own section instead of one per .o file (needed for --gc-sections) # -O1: optimization level used instead of -O0 to avoid compile error "invalid operand for inline asm constraint" - add_compile_options("$<$,$>:${CLR_SANITIZE_CXX_OPTIONS};-fdata-sections;--ffunction-sections;-O1>") + add_compile_options("$<$,$>:${CLR_SANITIZE_CXX_OPTIONS};-fdata-sections;-O1>") add_linker_flag("${CLR_SANITIZE_LINK_OPTIONS}" DEBUG CHECKED) # -Wl and --gc-sections: drop unused sections\functions (similar to Windows /Gy function-level-linking) add_linker_flag("-Wl,--gc-sections" DEBUG CHECKED) @@ -220,6 +219,7 @@ elseif (CLR_CMAKE_HOST_ARCH_ARM) add_definitions(-DHOST_ARM) elseif (CLR_CMAKE_HOST_ARCH_ARMV6) set(ARCH_HOST_NAME armv6) + add_definitions(-DHOST_ARM) add_definitions(-DHOST_ARMV6) elseif (CLR_CMAKE_HOST_ARCH_ARM64) set(ARCH_HOST_NAME arm64) @@ -461,6 +461,8 @@ if (CLR_CMAKE_HOST_UNIX) # 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>) + + add_compile_options($<$:-Wno-class-memaccess>) endif() if (CMAKE_CXX_COMPILER_ID) @@ -477,6 +479,9 @@ if (CLR_CMAKE_HOST_UNIX) # We mark the function which needs exporting with DLLEXPORT add_compile_options(-fvisibility=hidden) + + # Separate functions so linker can remove them. + add_compile_options(-ffunction-sections) # Specify the minimum supported version of macOS # Mac Catalyst needs a special CFLAG, exclusive with mmacosx-version-min @@ -508,7 +513,7 @@ if (CLR_CMAKE_HOST_UNIX) set(CMAKE_OSX_DEPLOYMENT_TARGET "11.0") add_compile_options(-arch arm64) elseif(CLR_CMAKE_HOST_ARCH_AMD64) - set(CMAKE_OSX_DEPLOYMENT_TARGET "10.14") + set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15") add_compile_options(-arch x86_64) else() clr_unknown_arch() @@ -540,6 +545,10 @@ if(CLR_CMAKE_TARGET_UNIX) add_compile_definitions($<$>>:TARGET_ILLUMOS>) endif() endif() +elseif(CLR_CMAKE_TARGET_WASI) + add_compile_definitions($<$>>:TARGET_WASI>) +elseif(CLR_CMAKE_TARGET_BROWSER) + add_compile_definitions($<$>>:TARGET_BROWSER>) else(CLR_CMAKE_TARGET_UNIX) add_compile_definitions($<$>>:TARGET_WINDOWS>) endif(CLR_CMAKE_TARGET_UNIX) diff --git a/eng/native/configureplatform.cmake b/eng/native/configureplatform.cmake index c7a38c3eee..c849c59217 100644 --- a/eng/native/configureplatform.cmake +++ b/eng/native/configureplatform.cmake @@ -214,6 +214,10 @@ if(CLR_CMAKE_HOST_OS STREQUAL Emscripten) set(CLR_CMAKE_HOST_BROWSER 1) endif(CLR_CMAKE_HOST_OS STREQUAL Emscripten) +if(CLR_CMAKE_TARGET_OS STREQUAL Wasi) + set(CLR_CMAKE_HOST_WASI 1) +endif(CLR_CMAKE_TARGET_OS STREQUAL Wasi) + #-------------------------------------------- # This repo builds two set of binaries # 1. binaries which execute on target arch machine @@ -263,6 +267,9 @@ elseif(CLR_CMAKE_HOST_UNIX_POWERPC64) elseif(CLR_CMAKE_HOST_BROWSER) set(CLR_CMAKE_HOST_ARCH_WASM 1) set(CLR_CMAKE_HOST_ARCH "wasm") +elseif(CLR_CMAKE_HOST_WASI) + set(CLR_CMAKE_HOST_ARCH_WASM 1) + set(CLR_CMAKE_HOST_ARCH "wasm") elseif(CLR_CMAKE_HOST_UNIX_MIPS64) set(CLR_CMAKE_HOST_ARCH_MIPS64 1) set(CLR_CMAKE_HOST_ARCH "mips64") @@ -410,6 +417,10 @@ if(CLR_CMAKE_TARGET_OS STREQUAL Emscripten) set(CLR_CMAKE_TARGET_BROWSER 1) endif(CLR_CMAKE_TARGET_OS STREQUAL Emscripten) +if(CLR_CMAKE_TARGET_OS STREQUAL Wasi) + set(CLR_CMAKE_TARGET_WASI 1) +endif(CLR_CMAKE_TARGET_OS STREQUAL Wasi) + if(CLR_CMAKE_TARGET_UNIX) if(CLR_CMAKE_TARGET_ARCH STREQUAL x64) set(CLR_CMAKE_TARGET_UNIX_AMD64 1) @@ -443,13 +454,7 @@ else() endif(CLR_CMAKE_TARGET_UNIX) # check if host & target os/arch combination are valid -if (CLR_CMAKE_TARGET_OS STREQUAL CLR_CMAKE_HOST_OS) - if(NOT(CLR_CMAKE_TARGET_ARCH STREQUAL CLR_CMAKE_HOST_ARCH)) - if(NOT((CLR_CMAKE_HOST_ARCH_AMD64 AND CLR_CMAKE_TARGET_ARCH_ARM64) OR (CLR_CMAKE_HOST_ARCH_I386 AND CLR_CMAKE_TARGET_ARCH_ARM) OR (CLR_CMAKE_HOST_ARCH_AMD64 AND CLR_CMAKE_TARGET_ARCH_ARM) OR (CLR_CMAKE_HOST_ARCH_AMD64 AND CLR_CMAKE_TARGET_ARCH_I386))) - message(FATAL_ERROR "Invalid platform and target arch combination TARGET_ARCH=${CLR_CMAKE_TARGET_ARCH} HOST_ARCH=${CLR_CMAKE_HOST_ARCH}") - endif() - endif() -else() +if (NOT (CLR_CMAKE_TARGET_OS STREQUAL CLR_CMAKE_HOST_OS)) if(NOT (CLR_CMAKE_HOST_OS STREQUAL windows)) message(FATAL_ERROR "Invalid host and target os/arch combination. Host OS: ${CLR_CMAKE_HOST_OS}") endif() diff --git a/eng/native/gen-buildsys.cmd b/eng/native/gen-buildsys.cmd index 3701e639ce..b97b8125e0 100644 --- a/eng/native/gen-buildsys.cmd +++ b/eng/native/gen-buildsys.cmd @@ -22,6 +22,7 @@ set __SourceDir=%1 set __IntermediatesDir=%2 set __VSVersion=%3 set __Arch=%4 +set __Os=%5 set __CmakeGenerator=Visual Studio set __UseEmcmake=0 if /i "%__Ninja%" == "1" ( @@ -41,25 +42,35 @@ if /i "%__Ninja%" == "1" ( if /i "%__Arch%" == "wasm" ( - if "%EMSDK_PATH%" == "" ( - if not exist "%__repoRoot%src\mono\wasm\emsdk" ( - echo Error: Should set EMSDK_PATH environment variable pointing to emsdk root. - exit /B 1 + if "%__Os%" == "" ( + echo Error: Please add target OS parameter + exit /B 1 + ) + if /i "%__Os%" == "Browser" ( + if "%EMSDK_PATH%" == "" ( + if not exist "%__repoRoot%src\mono\wasm\emsdk" ( + echo Error: Should set EMSDK_PATH environment variable pointing to emsdk root. + exit /B 1 + ) + + set EMSDK_PATH=%__repoRoot%src\mono\wasm\emsdk + set EMSDK_PATH=!EMSDK_PATH:\=/! ) - set EMSDK_PATH=%__repoRoot%src\mono\wasm\emsdk - set EMSDK_PATH=!EMSDK_PATH:\=/! + set __ExtraCmakeParams=%__ExtraCmakeParams% "-DCMAKE_TOOLCHAIN_FILE=!EMSDK_PATH!/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake" + set __UseEmcmake=1 + ) + if /i "%__Os%" == "wasi" ( + echo Error: WASI build not implemented on Windows yet + exit /B 1 ) - - set __ExtraCmakeParams=%__ExtraCmakeParams% "-DCMAKE_TOOLCHAIN_FILE=!EMSDK_PATH!/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake" - set __UseEmcmake=1 ) else ( set __ExtraCmakeParams=%__ExtraCmakeParams% "-DCMAKE_SYSTEM_VERSION=10.0" ) :loop -if [%5] == [] goto end_loop -set __ExtraCmakeParams=%__ExtraCmakeParams% %5 +if [%6] == [] goto end_loop +set __ExtraCmakeParams=%__ExtraCmakeParams% %6 shift goto loop :end_loop @@ -98,7 +109,7 @@ exit /B %errorlevel% :USAGE echo "Usage..." - echo "gen-buildsys.cmd " + echo "gen-buildsys.cmd " echo "Specify the path to the top level CMake file - /src/NDP" echo "Specify the VSVersion to be used - VS2017 or VS2019" EXIT /B 1 diff --git a/eng/native/gen-buildsys.sh b/eng/native/gen-buildsys.sh index c3bf9adbbe..72f90cdf15 100755 --- a/eng/native/gen-buildsys.sh +++ b/eng/native/gen-buildsys.sh @@ -7,7 +7,7 @@ scriptroot="$( cd -P "$( dirname "$0" )" && pwd )" if [[ "$#" -lt 4 ]]; then echo "Usage..." - echo "gen-buildsys.sh [build flavor] [ninja] [scan-build] [cmakeargs]" + 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 host architecture (the architecture the built tools should run on)." @@ -20,11 +20,12 @@ if [[ "$#" -lt 4 ]]; then fi host_arch="$3" -compiler="$4" +target_os="$4" +compiler="$5" if [[ "$compiler" != "default" ]]; then nativescriptroot="$( cd -P "$scriptroot/../common/native" && pwd )" - source "$nativescriptroot/init-compiler.sh" "$nativescriptroot" "$host_arch" "$compiler" + build_arch="$host_arch" compiler="$compiler" . "$nativescriptroot/init-compiler.sh" CCC_CC="$CC" CCC_CXX="$CXX" @@ -39,7 +40,7 @@ scan_build=OFF generator="Unix Makefiles" __UnprocessedCMakeArgs="" -for i in "${@:5}"; do +for i in "${@:6}"; do upperI="$(echo "$i" | tr "[:lower:]" "[:upper:]")" case "$upperI" in # Possible build types are DEBUG, CHECKED, RELEASE, RELWITHDEBINFO. @@ -93,7 +94,14 @@ if [[ "$scan_build" == "ON" && -n "$SCAN_BUILD_COMMAND" ]]; then fi if [[ "$host_arch" == "wasm" ]]; then - cmake_command="emcmake $cmake_command" + if [[ "$target_os" == "Browser" ]]; then + cmake_command="emcmake $cmake_command" + elif [[ "$target_os" == "wasi" ]]; then + true + else + echo "target_os was not specified" + exit 1 + fi fi # We have to be able to build with CMake 3.6.2, so we can't use the -S or -B options diff --git a/eng/native/init-distro-rid.sh b/eng/native/init-distro-rid.sh index 7501224063..309f6970a0 100644 --- a/eng/native/init-distro-rid.sh +++ b/eng/native/init-distro-rid.sh @@ -148,8 +148,13 @@ initDistroRidGlobal() initNonPortableDistroRid "${targetOs}" "${buildArch}" "${isPortable}" "${rootfsDir}" if [ "$buildArch" = "wasm" ]; then - __DistroRid=browser-wasm - export __DistroRid + if [ "$targetOs" = "Browser" ]; then + __DistroRid=browser-wasm + export __DistroRid + elif [ "$targetOs" = "wasi" ]; then + __DistroRid=wasi-wasm + export __DistroRid + fi fi if [ -z "${__DistroRid}" ]; then @@ -186,6 +191,8 @@ initDistroRidGlobal() distroRid="android-$buildArch" elif [ "$targetOs" = "Browser" ]; then distroRid="browser-$buildArch" + elif [ "$targetOs" = "wasi" ]; then + distroRid="wasi-$buildArch" elif [ "$targetOs" = "FreeBSD" ]; then distroRid="freebsd-$buildArch" elif [ "$targetOs" = "illumos" ]; then diff --git a/eng/native/init-vs-env.cmd b/eng/native/init-vs-env.cmd index 5f450d0636..403f355eca 100644 --- a/eng/native/init-vs-env.cmd +++ b/eng/native/init-vs-env.cmd @@ -52,7 +52,7 @@ if "%VisualStudioVersion%"=="17.0" ( ) :VSMissing -echo %__MsgPrefix%Error: Visual Studio 2019 or 2022 with C++ tools required. ^ +echo %__MsgPrefix%Error: Visual Studio 2022 with C++ tools required. ^ Please see https://github.com/dotnet/runtime/blob/main/docs/workflow/requirements/windows-requirements.md for build requirements. exit /b 1 diff --git a/eng/native/tryrun.cmake b/eng/native/tryrun.cmake index 5c5344bd80..dc7bffb741 100644 --- a/eng/native/tryrun.cmake +++ b/eng/native/tryrun.cmake @@ -20,6 +20,8 @@ elseif(EXISTS ${CROSS_ROOTFS}/usr/platform/i86pc) set(CLR_CMAKE_TARGET_OS SunOS) elseif(EXISTS /System/Library/CoreServices) set(DARWIN 1) +elseif(EXISTS ${CROSS_ROOTFS}/etc/tizen-release) + set(TIZEN 1) endif() if(DARWIN) @@ -64,11 +66,11 @@ if(DARWIN) set_cache_value(SSCANF_CANNOT_HANDLE_MISSING_EXPONENT_EXITCODE 1) set_cache_value(SSCANF_SUPPORT_ll_EXITCODE 0) set_cache_value(UNGETC_NOT_RETURN_EOF_EXITCODE 1) - set_cache_value(HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP_EXITCODE 0) + set_cache_value(HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP_EXITCODE 1) 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|riscv64|s390x|ppc64le|x86)$" OR FREEBSD OR ILLUMOS) +elseif(TARGET_ARCH_NAME MATCHES "^(armel|arm|armv6|arm64|loongarch64|riscv64|s390x|ppc64le|x86)$" OR FREEBSD OR ILLUMOS OR TIZEN) 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) @@ -144,6 +146,8 @@ elseif(TARGET_ARCH_NAME MATCHES "^(armel|arm|armv6|arm64|loongarch64|riscv64|s39 set_cache_value(HAVE_SET_MAX_VARIABLE 1) set_cache_value(HAVE_FULLY_FEATURED_PTHREAD_MUTEXES 1) set_cache_value(HAVE_FUNCTIONAL_PTHREAD_ROBUST_MUTEXES_EXITCODE 0) + elseif (TIZEN) + 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, ppc64le and x86 are supported!") From fdac5af1d9c887f9e1bfb18160b0d9efd6935321 Mon Sep 17 00:00:00 2001 From: Adeel <3840695+am11@users.noreply.github.com> Date: Wed, 21 Dec 2022 00:06:41 +0200 Subject: [PATCH 2/3] Sync eng/common/native/init-compiler.sh --- eng/common/native/init-compiler.sh | 81 ++++++++++++++---------------- 1 file changed, 37 insertions(+), 44 deletions(-) diff --git a/eng/common/native/init-compiler.sh b/eng/common/native/init-compiler.sh index 292ebb6535..c670cb7968 100644 --- a/eng/common/native/init-compiler.sh +++ b/eng/common/native/init-compiler.sh @@ -1,30 +1,25 @@ -#!/usr/bin/env bash +#!/bin/sh # # This file detects the C/C++ compiler and exports it to the CC/CXX environment variables # # NOTE: some scripts source this file and rely on stdout being empty, make sure to not output anything here! -if [[ "$#" -lt 3 ]]; then +if [ -z "$build_arch" ] || [ -z "$compiler" ]; then echo "Usage..." - echo "init-compiler.sh