Skip to content

Commit

Permalink
build: Initial support for arm64
Browse files Browse the repository at this point in the history
- Detects the current architecture based on the current machine
(`uname -m` or `CMAKE_SYSETM_PROCESSOR`) instead of assuming `x86_64`.
- When appropriate, distinguish between the "Unix architecture" (the one
reported by `uname -m` and GCC target triples, such as `aarch64`) and
the "Haiku architecture" (the one used by Haiku's toolchains, like
`arm64`).
  • Loading branch information
trungnt2910 committed Mar 5, 2024
1 parent 0f1fedb commit f265b90
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ add_custom_target(CopyHaikuObjects
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/copy_objects.sh)

if(NOT DEFINED HYCLONE_ARCH)
set(HYCLONE_ARCH "x86_64")
set(HYCLONE_ARCH "${CMAKE_SYSTEM_PROCESSOR}")
if(HYCLONE_ARCH MATCHES "aarch64")
set(HYCLONE_ARCH "arm64")
endif()
endif()

add_compile_definitions(HYCLONE_ARCH=${HYCLONE_ARCH})
Expand Down
14 changes: 12 additions & 2 deletions build_hprefix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,17 @@ done

SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

HAIKU_ARCH=${HAIKU_ARCH:-"x86_64"}
HAIKU_UNIX_ARCH=${HAIKU_UNIX_ARCH:-"$(uname -m)"}

case $HAIKU_UNIX_ARCH in
"aarch64")
HAIKU_ARCH="arm64"
;;
*)
HAIKU_ARCH=$HAIKU_UNIX_ARCH
;;
esac

HAIKU_BUILD_ENVIRONMENT_ROOT=${HAIKU_BUILD_ENVIRONMENT_ROOT:-"$SCRIPT_DIR/.."}
HAIKU_BUILD_SOURCE_DIRECTORY=${HAIKU_BUILD_SOURCE_DIRECTORY:-"$HAIKU_BUILD_ENVIRONMENT_ROOT/haiku"}
HPREFIX=${HPREFIX:-"$HOME/.hprefix"}
Expand Down Expand Up @@ -162,4 +172,4 @@ if [ ! -L "$HPREFIX/system" ]; then
ln -s boot/system $HPREFIX/system
fi

echo "Done"
echo "Done"
16 changes: 13 additions & 3 deletions copy_objects.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
#!/bin/bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

HAIKU_ARCH=${HAIKU_ARCH:-"x86_64"}
HAIKU_UNIX_ARCH=${HAIKU_UNIX_ARCH:-"$(uname -m)"}

case $HAIKU_UNIX_ARCH in
"aarch64")
HAIKU_ARCH="arm64"
;;
*)
HAIKU_ARCH=$HAIKU_UNIX_ARCH
;;
esac

# TODO: This is personalized for my local environment, but making this a subdirectory of the HyClone
# tree (such as "haiku-build") seems to be a better idea.
HAIKU_BUILD_ENVIRONMENT_ROOT=${HAIKU_BUILD_ENVIRONMENT_ROOT:-"$SCRIPT_DIR/.."}
Expand All @@ -17,9 +27,9 @@ HAIKU_GLUE="$HAIKU_BUILD_OUTPUT_ROOT/objects/haiku/$HAIKU_ARCH/release/system/gl
HAIKU_GLUE_ARCH="$HAIKU_GLUE/arch/$HAIKU_ARCH"

# Some distros store the GCC glue objects in lib64, others in lib.
HAIKU_GLUE_GCC=$(echo $HAIKU_BUILD_OUTPUT_ROOT/cross-tools-$HAIKU_ARCH/lib64/gcc/$HAIKU_ARCH-unknown-haiku/**)
HAIKU_GLUE_GCC=$(echo $HAIKU_BUILD_OUTPUT_ROOT/cross-tools-$HAIKU_ARCH/lib64/gcc/$HAIKU_UNIX_ARCH-unknown-haiku/**)
if [ ! -f "$HAIKU_GLUE_GCC/crtbeginS.o" ]; then
HAIKU_GLUE_GCC=$(echo $HAIKU_BUILD_OUTPUT_ROOT/cross-tools-$HAIKU_ARCH/lib/gcc/$HAIKU_ARCH-unknown-haiku/**)
HAIKU_GLUE_GCC=$(echo $HAIKU_BUILD_OUTPUT_ROOT/cross-tools-$HAIKU_ARCH/lib/gcc/$HAIKU_UNIX_ARCH-unknown-haiku/**)
fi

# If Haiku is not built, build it!
Expand Down
6 changes: 3 additions & 3 deletions runtime_loader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ add_custom_target(RemoveHaikuSyscalls
COMMAND ar d ${CMAKE_CURRENT_SOURCE_DIR}/libruntime_loader_nosyscalls.a syscalls.o tls.o)

add_library(runtime_loader SHARED blank.c)
target_link_options(runtime_loader PRIVATE
target_link_options(runtime_loader PRIVATE
-nodefaultlibs
-nostartfiles
-Wl,--no-undefined,-shared,-Bsymbolic,-soname=runtime_loader,-entry=runtime_loader
Expand All @@ -42,7 +42,7 @@ target_link_libraries(runtime_loader PRIVATE monika)
target_link_libraries(runtime_loader PRIVATE root_os_tls)
target_link_libraries(runtime_loader PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/libgcc_eh-kernel.a)
target_link_libraries(runtime_loader PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/libgcc-kernel.a)
target_link_libraries(runtime_loader PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/libruntime_loader_x86_64.a)
target_link_libraries(runtime_loader PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/libruntime_loader_${HYCLONE_ARCH}.a)
target_link_libraries(runtime_loader PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/libruntime_loader_nosyscalls.a)

install(TARGETS runtime_loader DESTINATION bin)
install(TARGETS runtime_loader DESTINATION bin)

0 comments on commit f265b90

Please sign in to comment.