Skip to content

Commit

Permalink
haiku: initial platform support
Browse files Browse the repository at this point in the history
Tracking in dotnet#55803.
  • Loading branch information
jessicah committed Jul 19, 2021
1 parent 1749deb commit 5b0e008
Show file tree
Hide file tree
Showing 27 changed files with 303 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Build.proj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<!-- Upfront restore hooks -->
<Import Project="$(RepositoryEngineeringDir)restore\docs.targets" Condition="'$(DotNetBuildFromSource)' != 'true'" />
<Import Project="$(RepositoryEngineeringDir)restore\optimizationData.targets" Condition="'$(DotNetBuildFromSource)' != 'true'" />
<!--<Import Project="$(RepositoryEngineeringDir)restore\optimizationData.targets" Condition="'$(DotNetBuildFromSource)' != 'true'" />-->

<Target Name="BuildLocalTasks"
BeforeTargets="Build">
Expand Down
4 changes: 3 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
<_portableOS Condition="'$(_runtimeOS)' == 'tvos'">tvos</_portableOS>
<_portableOS Condition="'$(_runtimeOS)' == 'tvOSSimulator'">tvossimulator</_portableOS>
<_portableOS Condition="'$(_runtimeOS)' == 'android'">android</_portableOS>
<_portableOS Condition="'$(_runtimeOS)' == 'Haiku'">haiku</_portableOS>

<_runtimeOS Condition="$(_runtimeOS.StartsWith('tizen'))">linux</_runtimeOS>
<_runtimeOS Condition="'$(PortableBuild)' == 'true'">$(_portableOS)</_runtimeOS>
Expand Down Expand Up @@ -182,7 +183,8 @@
<TargetsAndroid Condition="'$(TargetOS)' == 'Android'">true</TargetsAndroid>
<TargetsBrowser Condition="'$(TargetOS)' == 'Browser'">true</TargetsBrowser>
<TargetsWindows Condition="'$(TargetOS)' == 'windows'">true</TargetsWindows>
<TargetsUnix Condition="'$(TargetsFreeBSD)' == 'true' or '$(Targetsillumos)' == 'true' or '$(TargetsSolaris)' == 'true' or '$(TargetsLinux)' == 'true' or '$(TargetsNetBSD)' == 'true' or '$(TargetsOSX)' == 'true' or '$(TargetsMacCatalyst)' == 'true' or '$(TargetstvOS)' == 'true' or '$(TargetsiOS)' == 'true' or '$(TargetsAndroid)' == 'true'">true</TargetsUnix>
<TargetsHaiku Condition="'$(TargetOS)' == 'Haiku'">true</TargetsHaiku>
<TargetsUnix Condition="'$(TargetsHaiku)' == 'true' or '$(TargetsFreeBSD)' == 'true' or '$(Targetsillumos)' == 'true' or '$(TargetsSolaris)' == 'true' or '$(TargetsLinux)' == 'true' or '$(TargetsNetBSD)' == 'true' or '$(TargetsOSX)' == 'true' or '$(TargetsMacCatalyst)' == 'true' or '$(TargetstvOS)' == 'true' or '$(TargetsiOS)' == 'true' or '$(TargetsAndroid)' == 'true'">true</TargetsUnix>
</PropertyGroup>

<PropertyGroup>
Expand Down
5 changes: 4 additions & 1 deletion eng/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ usage()
echo " --librariesConfiguration (-lc) Libraries build configuration: Debug or Release."
echo " [Default: Debug]"
echo " --os Target operating system: windows, Linux, FreeBSD, OSX, MacCatalyst, tvOS,"
echo " tvOSSimulator, iOS, iOSSimulator, Android, Browser, NetBSD, illumos or Solaris."
echo " tvOSSimulator, iOS, iOSSimulator, Android, Browser, NetBSD, illumos, Solaris,"
echo " or Haiku."
echo " [Default: Your machine's OS.]"
echo " --projects <value> Project or solution file(s) to build."
echo " --runtimeConfiguration (-rc) Runtime build configuration: Debug, Release or Checked."
Expand Down Expand Up @@ -281,6 +282,8 @@ while [[ $# > 0 ]]; do
os="illumos" ;;
solaris)
os="Solaris" ;;
haiku)
os="Haiku" ;;
*)
echo "Unsupported target OS '$2'."
echo "The allowed values are windows, Linux, FreeBSD, OSX, MacCatalyst, tvOS, tvOSSimulator, iOS, iOSSimulator, Android, Browser, illumos and Solaris."
Expand Down
1 change: 1 addition & 0 deletions eng/codeOptimization.targets
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
See issue https://github.com/dotnet/runtime/issues/33303
-->
<IsEligibleForNgenOptimization Condition="'$(TargetOS)' == 'OSX' or '$(TargetsMobile)' == 'true'">false</IsEligibleForNgenOptimization>
<IsEligibleForNgenOptimization Condition="'$(TargetOS)' == 'Haiku'">false</IsEligibleForNgenOptimization>
</PropertyGroup>

<Target Name="SetApplyNgenOptimization"
Expand Down
31 changes: 30 additions & 1 deletion eng/common/cross/build-rootfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ while :; do
__BuildArch=x64
__SkipUnmount=1
;;
haiku)
__CodeName=haiku
__BuildArch=x64
__SkipUnmount=1
;;
--skipunmount)
__SkipUnmount=1
;;
Expand Down Expand Up @@ -250,7 +255,7 @@ if [ -d "$__RootfsDir" ]; then
if [ $__SkipUnmount == 0 ]; then
umount $__RootfsDir/* || true
fi
rm -rf $__RootfsDir
#rm -rf $__RootfsDir
fi

mkdir -p $__RootfsDir
Expand Down Expand Up @@ -347,6 +352,30 @@ elif [[ "$__CodeName" == "illumos" ]]; then
wget -P "$__RootfsDir"/usr/include/net https://raw.githubusercontent.com/illumos/illumos-gate/master/usr/src/uts/common/io/bpf/net/dlt.h
wget -P "$__RootfsDir"/usr/include/netpacket https://raw.githubusercontent.com/illumos/illumos-gate/master/usr/src/uts/common/inet/sockmods/netpacket/packet.h
wget -P "$__RootfsDir"/usr/include/sys https://raw.githubusercontent.com/illumos/illumos-gate/master/usr/src/uts/common/sys/sdt.h
elif [[ "$__CodeName" == "haiku" ]]; then
# For now, assume we're building for x86_64
mkdir "$__RootfsDir/tmp"
pushd "$__RootfsDir/tmp"
git clone --depth=1 https://review.haiku-os.org/haiku
git clone --depth=1 https://github.com/haiku/buildtools
# Build jam
pushd buildtools/jam
make
popd
# Configure cross tools
mkdir "$__RootfsDir/generated"
pushd "$__RootfsDir/generated"
"$__RootfsDir/tmp/haiku/configure" --cross-tools-source "$__RootfsDir/tmp/buildtools" --build-cross-tools x86_64
"$__RootfsDir/tmp/buildtools/jam/jam0" -q haiku.hpkg haiku_devel.hpkg '<build>package'
popd
# Setup the sysroot
mkdir -p "$__RootfsDir/boot/system"
for file in "$__RootfsDir/generated/objects/haiku/x86_64/packaging/packages/"*.hpkg; do
"$__RootfsDir/generated/objects/linux/x86_64/release/tools/package/package" extract -C "$__RootfsDir/boot/system" "$file"
done
for file in "$__RootfsDir/generated/download/"*.hpkg; do
"$__RootfsDir/generated/objects/linux/x86_64/release/tools/package/package" extract -C "$__RootfsDir/boot/system" "$file"
done
elif [[ -n $__CodeName ]]; then
qemu-debootstrap --arch $__UbuntuArch $__CodeName $__RootfsDir $__UbuntuRepo
cp $__CrossDir/$__BuildArch/sources.list.$__CodeName $__RootfsDir/etc/apt/sources.list
Expand Down
18 changes: 17 additions & 1 deletion eng/common/cross/toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ if(EXISTS ${CROSS_ROOTFS}/bin/freebsd-version)
elseif(EXISTS ${CROSS_ROOTFS}/usr/platform/i86pc)
set(CMAKE_SYSTEM_NAME SunOS)
set(ILLUMOS 1)
elseif(EXISTS ${CROSS_ROOTFS}/boot/system/develop/headers/config/HaikuConfig.h)
set(CMAKE_SYSTEM_NAME Haiku)
set(HAIKU 1)
message(STATUS "found haiku cross install")
message(STATUS Haiku)
message(STATUS Linux)
else()
set(CMAKE_SYSTEM_NAME Linux)
endif()
Expand Down Expand Up @@ -48,6 +54,9 @@ elseif (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
elseif (ILLUMOS)
set(CMAKE_SYSTEM_PROCESSOR "x86_64")
set(TOOLCHAIN "x86_64-illumos")
elseif (CMAKE_SYSTEM_NAME STREQUAL "Haiku")
set(CMAKE_SYSTEM_PROCESSOR "x86_64")
set(TOOLCHAIN "x86_64-unknown-haiku")
else()
message(FATAL_ERROR "Arch is ${TARGET_ARCH_NAME}. Only armel, arm, arm64, s390x and x86 are supported!")
endif()
Expand Down Expand Up @@ -122,6 +131,8 @@ elseif(ILLUMOS)

set(CMAKE_C_STANDARD_LIBRARIES "${CMAKE_C_STANDARD_LIBRARIES} -lssp")
set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES} -lssp")
elseif(CMAKE_SYSTEM_NAME STREQUAL "Haiku")
set(CMAKE_SYSROOT "${CROSS_ROOTFS}")
else()
set(CMAKE_SYSROOT "${CROSS_ROOTFS}")

Expand Down Expand Up @@ -170,11 +181,13 @@ elseif(TARGET_ARCH_NAME STREQUAL "x86")
elseif(ILLUMOS)
add_toolchain_linker_flag("-L${CROSS_ROOTFS}/lib/amd64")
add_toolchain_linker_flag("-L${CROSS_ROOTFS}/usr/amd64/lib")
elseif(HAIKU)
add_toolchain_linker_flag("-lnetwork")
endif()

# Specify compile options

if((TARGET_ARCH_NAME MATCHES "^(arm|armel|arm64|s390x)$" AND NOT "$ENV{__DistroRid}" MATCHES "android.*") OR ILLUMOS)
if((TARGET_ARCH_NAME MATCHES "^(arm|armel|arm64|s390x)$" AND NOT "$ENV{__DistroRid}" MATCHES "android.*") OR ILLUMOS OR HAIKU)
set(CMAKE_C_COMPILER_TARGET ${TOOLCHAIN})
set(CMAKE_CXX_COMPILER_TARGET ${TOOLCHAIN})
set(CMAKE_ASM_COMPILER_TARGET ${TOOLCHAIN})
Expand All @@ -199,6 +212,9 @@ if(TARGET_ARCH_NAME MATCHES "^(arm|armel)$")
elseif(TARGET_ARCH_NAME STREQUAL "x86")
add_compile_options(-m32)
add_compile_options(-Wno-error=unused-command-line-argument)
elseif(HAIKU)
add_compile_options(-fPIC)
add_definitions(-D_GNU_SOURCE)
endif()

if(DEFINED TIZEN_TOOLCHAIN)
Expand Down
3 changes: 3 additions & 0 deletions eng/native/build-commons.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ build_native()
generator="ninja"
buildTool="$(command -v ninja || command -v ninja-build)"
else
echo "Using make"
buildTool="make"
fi

Expand Down Expand Up @@ -206,6 +207,8 @@ EOF
# multiple targets. Instead, directly invoke the build tool to build multiple targets in one invocation.
pushd "$intermediatesDir"

echo "native/build-commons.sh in $(pwd)"

echo "Executing $buildTool $target -j $__NumProc"
"$buildTool" $target -j "$__NumProc"
exit_code="$?"
Expand Down
2 changes: 2 additions & 0 deletions eng/native/configurecompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,8 @@ if(CLR_CMAKE_TARGET_UNIX)
add_compile_definitions($<$<NOT:$<BOOL:$<TARGET_PROPERTY:IGNORE_DEFAULT_TARGET_OS>>>:TARGET_SUNOS>)
elseif(CLR_CMAKE_TARGET_ANDROID)
add_compile_definitions($<$<NOT:$<BOOL:$<TARGET_PROPERTY:IGNORE_DEFAULT_TARGET_OS>>>:TARGET_ANDROID>)
elseif(CLR_CMAKE_TARGET_HAIKU)
add_compile_definitions($<$<NOT:$<BOOL:$<TARGET_PROPERTY:IGNORE_DEFAULT_TARGET_OS>>>:TARGET_HAIKU>)
endif()
else(CLR_CMAKE_TARGET_UNIX)
add_compile_definitions($<$<NOT:$<BOOL:$<TARGET_PROPERTY:IGNORE_DEFAULT_TARGET_OS>>>:TARGET_WINDOWS>)
Expand Down
11 changes: 11 additions & 0 deletions eng/native/configureplatform.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ if(CLR_CMAKE_HOST_OS STREQUAL Emscripten)
set(CLR_CMAKE_HOST_BROWSER 1)
endif(CLR_CMAKE_HOST_OS STREQUAL Emscripten)

if(CLR_CMAKE_HOST_OS STREQUAL Haiku)
set(CLR_CMAKE_HOST_UNIX 1)
set(CLR_CMAKE_HOST_UNIX_AMD64 1)
set(CLAR_CMAKE_HOST_HAIKU 1)
endif(CLR_CMAKE_HOST_OS STREQUAL Haiku)

#--------------------------------------------
# This repo builds two set of binaries
# 1. binaries which execute on target arch machine
Expand Down Expand Up @@ -359,6 +365,11 @@ 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 Haiku)
set(CLR_CMAKE_TARGET_UNIX 1)
set(CLR_CMAKE_TARGET_HAIKU 1)
endif(CLR_CMAKE_TARGET_OS STREQUAL Haiku)

if(CLR_CMAKE_TARGET_UNIX)
if(CLR_CMAKE_TARGET_ARCH STREQUAL x64)
set(CLR_CMAKE_TARGET_UNIX_AMD64 1)
Expand Down
4 changes: 4 additions & 0 deletions eng/native/init-distro-rid.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ initNonPortableDistroRid()
__uname_version=$(uname -v)
__solaris_major_version=$(echo "${__uname_version%.*}")
nonPortableBuildID=solaris."$__solaris_major_version"-"$buildArch"
elif [ "$targetOs" = "Haiku" ]; then
nonPortableBuildID="haiku.r1-$buildArch"
fi

if [ -n "${nonPortableBuildID}" ]; then
Expand Down Expand Up @@ -190,6 +192,8 @@ initDistroRidGlobal()
distroRid="illumos-$buildArch"
elif [ "$targetOs" = "Solaris" ]; then
distroRid="solaris-$buildArch"
elif [ "$targetOs" = "Haiku" ]; then
distroRid="haiku-$buildArch"
fi
fi

Expand Down
9 changes: 9 additions & 0 deletions eng/native/tryrun.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ 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}/boot/system/develop/headers/config/HaikuConfig.h)
set(HAIKU 1)
set(CMAKE_SYSTEM_NAME Haiku)
set(CLR_CMAKE_TARGET_OS Haiku)
message(WARNING "Haiku cache values for HAVE_xyz definitions need to be added")
else()
message(FATAL_ERROR "Cross build not configured")
endif()

if(DARWIN)
Expand Down Expand Up @@ -145,6 +152,8 @@ elseif(TARGET_ARCH_NAME MATCHES "^(armel|arm|arm64|s390x|x86)$" OR FREEBSD OR IL
set_cache_value(HAVE_FULLY_FEATURED_PTHREAD_MUTEXES 1)
set_cache_value(HAVE_FUNCTIONAL_PTHREAD_ROBUST_MUTEXES_EXITCODE 0)
endif()
elseif(HAIKU)
message(WARNING "set configure values for native")
else()
message(FATAL_ERROR "Arch is ${TARGET_ARCH_NAME}. Only armel, arm, arm64, s390x and x86 are supported!")
endif()
Expand Down
7 changes: 7 additions & 0 deletions eng/targetframeworksuffix.props
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@
<PackageTargetRuntime>browser</PackageTargetRuntime>
</PropertyGroup>
</When>
<When Condition="'$(TargetFrameworkSuffix)' == 'Haiku'">
<PropertyGroup>
<TargetsUnix>true</TargetsUnix>
<TargetsHaiku>true</TargetsHaiku>
<PackageTargetRuntime>haiku</PackageTargetRuntime>
</PropertyGroup>
</When>
<When Condition="'$(TargetFrameworkSuffix)' == ''">
<PropertyGroup>
<TargetsAnyOS>true</TargetsAnyOS>
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/build-runtime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ build_cross_architecture_components()
__SkipCrossArchBuild=0
else
# not supported
return
#return
echo "build_cross_architecture_components"
fi

__CMakeBinDir="$crossArchBinDir"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Runtime.InteropServices;

#pragma warning disable CA1823 // analyzer incorrectly flags fixed buffer length const (https://github.com/dotnet/roslyn/issues/37593)

internal static partial class Interop
{
internal static partial class Process
{
private const int B_OS_NAME_LENGTH = 32;

[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_TeamInfo", SetLastError = false)]
private static extern unsafe int TeamInfo(int id, team_info *info, ulong size);

[DllImport(Libraries.SystemNative, EntryPoint = "SystemNative_NextAreaInfo", SetLastError = false)]
private static extern unsafe int NextAreaInfo(int id, long *cookie, area_info *areaInfo, ulong size);

[StructLayout(LayoutKind.Sequential)]
public unsafe struct area_info
{
public int area;
public fixed byte name[B_OS_NAME_LENGTH];
public uint size;
public uint @lock;
public uint protection;
public int team;
public uint ram_size;
public uint copy_count;
public uint in_count;
public uint out_count;
public void* address;
}

[StructLayout(LayoutKind.Sequential)]
public unsafe struct team_info
{
public int team;
public int thread_count;
public int image_count;
public int debugger_nub_thread;
public int debugger_nub_port;
public int argc;
public fixed byte args[64];
public uint uid;
public uint gid;
}

/// <summary>
/// Gets information about a team (aka process)
/// </summary>
/// <param name="id">The team id.</param>
public static unsafe team_info* GetTeamInfo(int id)
{
IntPtr handle = Marshal.AllocHGlobal(sizeof(team_info));
team_info* teamInfo = (team_info*)handle;

int status = TeamInfo(id, teamInfo, (ulong)sizeof(team_info));

if (status != 0)
{
teamInfo = null;
Marshal.FreeHGlobal(handle);
}

return teamInfo;
}

/// <summary>
/// Gets information about an area
/// </summary>
/// <param name="team">The team id.</param>
/// <param name="cookie">A pointer for iterating over areas.</param>
/// <param name="info">The area_info to store retrieved info.</param>
/// <returns>0 if successful.</returns>
public static unsafe int GetNextAreaInfo(int team, long* cookie, area_info* info)
{
return NextAreaInfo(team, cookie, info, (ulong)sizeof(area_info));
}

public static unsafe area_info* AllocAreaInfo()
{
IntPtr handle = Marshal.AllocHGlobal(sizeof(area_info));

return (area_info*)handle;
}
}
}
2 changes: 1 addition & 1 deletion src/libraries/Native/Unix/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ else ()
add_compile_options(-fstack-protector-strong)
endif ()

if (CLR_CMAKE_TARGET_LINUX)
if (CLR_CMAKE_TARGET_LINUX OR CLR_CMAKE_TARGET_HAIKU)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GNU_SOURCE")
endif ()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ macro(append_extra_compression_libs NativeLibsExtra)
set(ZLIB_LIBRARIES z)
elseif (CLR_CMAKE_TARGET_SUNOS)
set(ZLIB_LIBRARIES z m)
elseif (CLR_CMAKE_TARGET_HAIKU)
set(ZLIB_LIBRARIES z)
else ()
find_package(ZLIB REQUIRED)
endif ()
Expand Down
5 changes: 5 additions & 0 deletions src/libraries/Native/Unix/System.Native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ if (NOT CLR_CMAKE_TARGET_BROWSER)
list (APPEND NATIVE_SOURCES pal_networkchange.c)
endif ()

if (CLR_CMAKE_TARGET_HAIKU)
list (APPEND NATIVE_SOURCES
pal_teaminfo.c)
endif ()

include(${CMAKE_CURRENT_LIST_DIR}/extra_libs.cmake)

set(NATIVE_LIBS_EXTRA)
Expand Down
Loading

0 comments on commit 5b0e008

Please sign in to comment.