diff --git a/docs/workflow/building/libraries/freebsd-instructions.md b/docs/workflow/building/libraries/freebsd-instructions.md index 1ee100dfd62978..09008a4f49c49b 100644 --- a/docs/workflow/building/libraries/freebsd-instructions.md +++ b/docs/workflow/building/libraries/freebsd-instructions.md @@ -7,7 +7,7 @@ Tested on plain FreeBSD 11.3 Azure image ## Prerequisites This needs to be done once on fresh system. -```sudo pkg install cmake git icu libunwind bash python2 krb5 lttng-ust llvm60 libgit2``` +```sudo pkg install cmake git icu libunwind bash python2 krb5 lttng-ust llvm90 libgit2 libinotify openssl``` some scripts may still assume /bin/bash exists. To workaround it for now do of needed: ``` diff --git a/eng/native/build-commons.sh b/eng/native/build-commons.sh index 53be70562aaff0..9c93eb9bd81e55 100755 --- a/eng/native/build-commons.sh +++ b/eng/native/build-commons.sh @@ -204,6 +204,7 @@ __BuildArch=$arch __HostArch=$arch __TargetOS=$os __HostOS=$os +__BuildOS=$os __msbuildonunsupportedplatform=0 diff --git a/eng/native/configurecompiler.cmake b/eng/native/configurecompiler.cmake index a31b7b168c6163..a4c66676e3214f 100644 --- a/eng/native/configurecompiler.cmake +++ b/eng/native/configurecompiler.cmake @@ -182,7 +182,7 @@ if(CLR_CMAKE_HOST_LINUX) endif(CLR_CMAKE_HOST_LINUX) if(CLR_CMAKE_HOST_FREEBSD) add_compile_options($<$:-Wa,--noexecstack>) - add_link_options(-fuse-ld=lld LINKER:--build-id=sha1) + add_link_options(LINKER:--build-id=sha1) endif(CLR_CMAKE_HOST_FREEBSD) #------------------------------------ diff --git a/eng/native/init-distro-rid.sh b/eng/native/init-distro-rid.sh index 310e1c4f8ea64b..fdb332afc6e427 100644 --- a/eng/native/init-distro-rid.sh +++ b/eng/native/init-distro-rid.sh @@ -20,14 +20,6 @@ # If -portablebuild=false is passed a non-portable rid will be created for any # distro. # -# Below is the list of current non-portable platforms. -# -# Builds from the following *must* be non-portable: -# -# | OS | Expected RID | -# ------------------------------------------------- -# | freeBSD | freebsd.(version)-x64 | -# # It is important to note that the function does not return anything, but it # exports __DistroRid, if there is a non-portable distro rid to be used. # @@ -70,8 +62,11 @@ initNonPortableDistroRid() fi if [ "$targetOs" = "FreeBSD" ]; then - __freebsd_major_version=$(freebsd-version | { read v; echo "${v%%.*}"; }) - nonPortableBuildID="freebsd.$__freebsd_major_version-${buildArch}" + if (( isPortable == 0 )); then + # $rootfsDir can be empty. freebsd-version is shell script and it should always work. + __freebsd_major_version=$($rootfsDir/bin/freebsd-version | { read v; echo "${v%%.*}"; }) + nonPortableBuildID="freebsd.$__freebsd_major_version-${buildArch}" + fi elif getprop ro.product.system.model 2>&1 | grep -qi android; then __android_sdk_version=$(getprop ro.build.version.sdk) nonPortableBuildID="android.$__android_sdk_version-${buildArch}" diff --git a/src/coreclr/crossgen-corelib.proj b/src/coreclr/crossgen-corelib.proj index 08e7e52b1201d6..6551f5db6ba267 100644 --- a/src/coreclr/crossgen-corelib.proj +++ b/src/coreclr/crossgen-corelib.proj @@ -6,6 +6,7 @@ <_CoreClrBuildArg Condition="'$(TargetArchitecture)' != ''" Include="-$(TargetArchitecture)" /> <_CoreClrBuildArg Include="-$(Configuration.ToLower())" /> + <_CoreClrBuildArg Include="-os $(TargetOS)" /> diff --git a/src/coreclr/crossgen-corelib.sh b/src/coreclr/crossgen-corelib.sh index 570f22db10511e..73811315afefa0 100755 --- a/src/coreclr/crossgen-corelib.sh +++ b/src/coreclr/crossgen-corelib.sh @@ -94,7 +94,7 @@ __UnprocessedBuildArgs= source "$__ProjectRoot"/_build-commons.sh -if [[ "${__BuildArch}" != "${__HostArch}" ]]; then +if [[ "${__BuildArch}" != "${__HostArch}" ]] || [[ "$__BuildOS" != "$__TargetOS" ]]; then __CrossBuild=1 fi diff --git a/src/coreclr/runtime.proj b/src/coreclr/runtime.proj index c36ed54bc80cf3..344d76b2f28fef 100644 --- a/src/coreclr/runtime.proj +++ b/src/coreclr/runtime.proj @@ -10,6 +10,8 @@ <_CoreClrBuildArg Include="$(Compiler)" /> <_CoreClrBuildArg Condition="'$(ContinuousIntegrationBuild)' == 'true'" Include="-ci" /> <_CoreClrBuildArg Condition="'$(CrossBuild)' == 'true'" Include="-cross" /> + <_CoreClrBuildArg Include="-os $(TargetOS)" /> + <_CoreClrBuildArg Condition="$([MSBuild]::IsOsPlatform(Windows)) and ('$(TargetArchitecture)' == 'x86' or '$(TargetArchitecture)' == 'x64') and '$(Configuration)' == 'Release'" Include="-enforcepgo" /> <_CoreClrBuildArg Condition="$([MSBuild]::IsOsPlatform(Windows)) and '$(CrossDac)' != ''" Include="-$(CrossDac)dac" /> <_CoreClrBuildArg Condition="'$(OfficialBuildId)' != ''" Include="/p:OfficialBuildId=$(OfficialBuildId)" /> diff --git a/src/coreclr/src/pal/src/CMakeLists.txt b/src/coreclr/src/pal/src/CMakeLists.txt index 093d7d9b79df35..e7c1629d5b263f 100644 --- a/src/coreclr/src/pal/src/CMakeLists.txt +++ b/src/coreclr/src/pal/src/CMakeLists.txt @@ -5,6 +5,8 @@ endif(CLR_CMAKE_TARGET_OSX OR CLR_CMAKE_TARGET_FREEBSD) if(NOT DEFINED ENV{ROOTFS_DIR}) include_directories(SYSTEM /usr/local/include) +elseif (CLR_CMAKE_TARGET_FREEBSD) + include_directories(SYSTEM $ENV{ROOTFS_DIR}/usr/local/include) endif() if(NOT CLR_CMAKE_USE_SYSTEM_LIBUNWIND) diff --git a/src/coreclr/src/pal/src/configure.cmake b/src/coreclr/src/pal/src/configure.cmake index 048139971879df..62e5690af32037 100644 --- a/src/coreclr/src/pal/src/configure.cmake +++ b/src/coreclr/src/pal/src/configure.cmake @@ -8,7 +8,7 @@ include(CheckTypeSize) include(CheckLibraryExists) if(CLR_CMAKE_TARGET_FREEBSD) - set(CMAKE_REQUIRED_INCLUDES /usr/local/include) + set(CMAKE_REQUIRED_INCLUDES ${CROSS_ROOTFS}/usr/local/include) elseif(CLR_CMAKE_TARGET_SUNOS) set(CMAKE_REQUIRED_INCLUDES /opt/local/include) endif() diff --git a/src/coreclr/tryrun.cmake b/src/coreclr/tryrun.cmake index f841f56b83b49d..5fdc28a4f204e9 100644 --- a/src/coreclr/tryrun.cmake +++ b/src/coreclr/tryrun.cmake @@ -12,9 +12,16 @@ if(EXISTS ${CROSS_ROOTFS}/usr/lib/gcc/armv6-alpine-linux-musleabihf OR SET(ALPINE_LINUX 1) else() SET(ALPINE_LINUX 0) + if(EXISTS ${CROSS_ROOTFS}/bin/freebsd-version) + set(FREEBSD 1) + set(CMAKE_SYSTEM_NAME FreeBSD) + set(CLR_CMAKE_TARGET_OS FreeBSD) + else() + SET(FREEBSD 0) + endif() endif() -if(TARGET_ARCH_NAME MATCHES "^(armel|arm|arm64|x86)$") +if(TARGET_ARCH_NAME MATCHES "^(armel|arm|arm64|x86)$" OR FREEBSD) 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) @@ -57,6 +64,16 @@ if(TARGET_ARCH_NAME MATCHES "^(armel|arm|arm64|x86)$") set_cache_value(UNGETC_NOT_RETURN_EOF_EXITCODE 0) endif() + if (FREEBSD) + set_cache_value(HAVE_BROKEN_FIFO_KEVENT_EXITCODE 1) + set_cache_value(HAVE_PROCFS_MAPS 0) + set_cache_value(HAVE_PROCFS_STAT 0) + set_cache_value(HAVE_PROCFS_STATUS 0) + set_cache_value(GETPWUID_R_SETS_ERRNO 0) + set_cache_value(UNGETC_NOT_RETURN_EOF 0) + set_cache_value(HAVE_COMPATIBLE_ILOGBNAN 1) + set_cache_value(HAVE_FUNCTIONAL_PTHREAD_ROBUST_MUTEXES_EXITCODE 0) + endif() else() message(FATAL_ERROR "Arch is ${TARGET_ARCH_NAME}. Only armel, arm, arm64 and x86 are supported!") endif() diff --git a/src/installer/corehost/build.proj b/src/installer/corehost/build.proj index 583a24caa31eea..9de06c607f6460 100644 --- a/src/installer/corehost/build.proj +++ b/src/installer/corehost/build.proj @@ -27,7 +27,7 @@ $(IntermediateOutputRootPath)corehost\cmake\ - $(Configuration) $(TargetArchitecture) -apphostver "$(AppHostVersion)" -hostver "$(HostVersion)" -fxrver "$(HostResolverVersion)" -policyver "$(HostPolicyVersion)" -commithash "$(LatestCommit)" + $(Configuration) $(TargetArchitecture) -apphostver "$(AppHostVersion)" -hostver "$(HostVersion)" -fxrver "$(HostResolverVersion)" -policyver "$(HostPolicyVersion)" -commithash "$(LatestCommit)" -os $(TargetOS) $(BuildArgs) -portablebuild=false $(BuildArgs) -cross $(BuildArgs) $(Compiler) diff --git a/src/libraries/Native/Unix/CMakeLists.txt b/src/libraries/Native/Unix/CMakeLists.txt index bb4dbcbe05f2af..b3c9613a0e10b0 100644 --- a/src/libraries/Native/Unix/CMakeLists.txt +++ b/src/libraries/Native/Unix/CMakeLists.txt @@ -149,7 +149,6 @@ endif () if(CLR_CMAKE_TARGET_FREEBSD) add_definitions(-D_BSD_SOURCE) # required for getline - add_link_options(-fuse-ld=lld) endif(CLR_CMAKE_TARGET_FREEBSD) # CLR_ADDITIONAL_LINKER_FLAGS - used for passing additional arguments to linker diff --git a/src/libraries/Native/Unix/configure.cmake b/src/libraries/Native/Unix/configure.cmake index bba87eba0f125b..c97d318fee90a9 100644 --- a/src/libraries/Native/Unix/configure.cmake +++ b/src/libraries/Native/Unix/configure.cmake @@ -22,8 +22,8 @@ elseif (CLR_CMAKE_TARGET_IOS) set(PAL_UNIX_NAME \"IOS\") elseif (CLR_CMAKE_TARGET_FREEBSD) set(PAL_UNIX_NAME \"FREEBSD\") - include_directories(SYSTEM /usr/local/include) - set(CMAKE_REQUIRED_INCLUDES /usr/local/include) + include_directories(SYSTEM ${CROSS_ROOTFS}/usr/local/include) + set(CMAKE_REQUIRED_INCLUDES ${CROSS_ROOTFS}/usr/local/include) elseif (CLR_CMAKE_TARGET_NETBSD) set(PAL_UNIX_NAME \"NETBSD\") elseif (CLR_CMAKE_TARGET_ARCH_WASM) @@ -728,12 +728,11 @@ check_symbol_exists( if(CLR_CMAKE_TARGET_IOS) set(HAVE_IOS_NET_ROUTE_H 1) - set(NET_ROUTE_H_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/System.Native/ios/net/route.h") + set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h "${CMAKE_CURRENT_SOURCE_DIR}/System.Native/ios/net/route.h") else() - set(NET_ROUTE_H_INCLUDE net/route.h) + set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h net/if.h net/route.h) endif() -set(CMAKE_EXTRA_INCLUDE_FILES sys/types.h ${NET_ROUTE_H_INCLUDE}) check_type_size( "struct rt_msghdr" HAVE_RT_MSGHDR diff --git a/src/libraries/Native/Unix/tryrun.cmake b/src/libraries/Native/Unix/tryrun.cmake index 9c027966532498..a1d7384f5a9557 100644 --- a/src/libraries/Native/Unix/tryrun.cmake +++ b/src/libraries/Native/Unix/tryrun.cmake @@ -1,4 +1,5 @@ set(TARGET_ARCH_NAME $ENV{TARGET_BUILD_ARCH}) +set(CROSS_ROOTFS $ENV{ROOTFS_DIR}) macro(set_cache_value) set(${ARGV0} ${ARGV1} CACHE STRING "Result from TRY_RUN" FORCE) @@ -9,11 +10,19 @@ if(EXISTS ${CROSS_ROOTFS}/usr/lib/gcc/armv6-alpine-linux-musleabihf OR EXISTS ${CROSS_ROOTFS}/usr/lib/gcc/aarch64-alpine-linux-musl) SET(ALPINE_LINUX 1) + SET(FREEBSD 0) else() SET(ALPINE_LINUX 0) + if(EXISTS ${CROSS_ROOTFS}/bin/freebsd-version) + set(FREEBSD 1) + set(CMAKE_SYSTEM_NAME FreeBSD) + set(CLR_CMAKE_TARGET_OS FreeBSD) + else() + SET(FREEBSD 0) + endif() endif() -if(TARGET_ARCH_NAME MATCHES "^(armel|arm|arm64|x86)$") +if(TARGET_ARCH_NAME MATCHES "^(armel|arm|arm64|x86)$" OR FREEBSD) set_cache_value(HAVE_CLOCK_MONOTONIC_EXITCODE 0) set_cache_value(HAVE_CLOCK_REALTIME_EXITCODE 0) @@ -22,6 +31,11 @@ if(TARGET_ARCH_NAME MATCHES "^(armel|arm|arm64|x86)$") else() set_cache_value(HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP_EXITCODE 0) endif() + if (FREEBSD) + set_cache_value(HAVE_SHM_OPEN_THAT_WORKS_WELL_ENOUGH_WITH_MMAP 1) + set_cache_value(HAVE_CLOCK_MONOTONIC 1) + set_cache_value(HAVE_CLOCK_REALTIME 1) + endif() else() message(FATAL_ERROR "Arch is ${TARGET_ARCH_NAME}. Only armel, arm, arm64 and x86 are supported!") endif()