Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
20 changes: 18 additions & 2 deletions eng/native/build-commons.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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."
Expand All @@ -232,6 +233,7 @@ __TargetArch=$arch
__TargetOS=$os
__HostOS=$os
__BuildOS=$os
__OutputRid=''

# Get the number of processors available to the scheduler
platform="$(uname)"
Expand Down Expand Up @@ -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
;;
Expand Down Expand Up @@ -474,3 +486,7 @@ fi

# init the target distro name
initTargetDistroRid

if [ -z "$__OutputRid" ]; then
__OutputRid="$(echo $__DistroRid | tr '[:upper:]' '[:lower:]')"
fi
15 changes: 12 additions & 3 deletions eng/native/configurecompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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("$<$<OR:$<CONFIG:DEBUG>,$<CONFIG:CHECKED>>:${CLR_SANITIZE_CXX_OPTIONS};-fdata-sections;--ffunction-sections;-O1>")
add_compile_options("$<$<OR:$<CONFIG:DEBUG>,$<CONFIG:CHECKED>>:${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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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($<$<COMPILE_LANGUAGE:CXX>:-Wno-placement-new>)

add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Wno-class-memaccess>)
endif()

if (CMAKE_CXX_COMPILER_ID)
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -540,6 +545,10 @@ if(CLR_CMAKE_TARGET_UNIX)
add_compile_definitions($<$<NOT:$<BOOL:$<TARGET_PROPERTY:IGNORE_DEFAULT_TARGET_OS>>>:TARGET_ILLUMOS>)
endif()
endif()
elseif(CLR_CMAKE_TARGET_WASI)
add_compile_definitions($<$<NOT:$<BOOL:$<TARGET_PROPERTY:IGNORE_DEFAULT_TARGET_OS>>>:TARGET_WASI>)
elseif(CLR_CMAKE_TARGET_BROWSER)
add_compile_definitions($<$<NOT:$<BOOL:$<TARGET_PROPERTY:IGNORE_DEFAULT_TARGET_OS>>>:TARGET_BROWSER>)
else(CLR_CMAKE_TARGET_UNIX)
add_compile_definitions($<$<NOT:$<BOOL:$<TARGET_PROPERTY:IGNORE_DEFAULT_TARGET_OS>>>:TARGET_WINDOWS>)
endif(CLR_CMAKE_TARGET_UNIX)
Expand Down
19 changes: 12 additions & 7 deletions eng/native/configureplatform.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
35 changes: 23 additions & 12 deletions eng/native/gen-buildsys.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -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" (
Expand All @@ -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
Expand Down Expand Up @@ -98,7 +109,7 @@ exit /B %errorlevel%

:USAGE
echo "Usage..."
echo "gen-buildsys.cmd <path to top level CMakeLists.txt> <path to location for intermediate files> <VSVersion> <arch>"
echo "gen-buildsys.cmd <path to top level CMakeLists.txt> <path to location for intermediate files> <VSVersion> <arch> <os>"
echo "Specify the path to the top level CMake file - <ProjectK>/src/NDP"
echo "Specify the VSVersion to be used - VS2017 or VS2019"
EXIT /B 1
18 changes: 13 additions & 5 deletions eng/native/gen-buildsys.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ scriptroot="$( cd -P "$( dirname "$0" )" && pwd )"

if [[ "$#" -lt 4 ]]; then
echo "Usage..."
echo "gen-buildsys.sh <path to top level CMakeLists.txt> <path to intermediate directory> <Architecture> <compiler> [build flavor] [ninja] [scan-build] [cmakeargs]"
echo "gen-buildsys.sh <path to top level CMakeLists.txt> <path to intermediate directory> <Architecture> <Os> <compiler> [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)."
Expand All @@ -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"
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions eng/native/init-distro-rid.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion eng/native/init-vs-env.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 6 additions & 2 deletions eng/native/tryrun.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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!")
Expand Down