forked from HarbourMasters/Shipwright
-
Notifications
You must be signed in to change notification settings - Fork 0
Cross compilation for performance
fpasteau edited this page Jun 4, 2024
·
4 revisions
use Ubuntu 22.04 in WSL 2.
Build a working chroot using https://github.com/JeodC/PortMaster-ShipOfHarkinian/blob/main/BUILDING.md
In wsl2 Ubuntu :
sudo apt -y install wget gcc g++ git cmake ninja-build lsb-release libsdl2-dev libpng-dev libsdl2-net-dev libzip-dev zipcmp zipmerge ziptool nlohmann-json3-dev libtinyxml2-dev libspdlog-dev libboost-dev libopengl-dev libglew-dev gcc-12-aarch64-linux-gnu g++-12-aarch64-linux-gnu
All of those are necessary on the host machine to create the 2s2h.o2r file
mkdir ~/crosscompile
cd crosscompile
copy your sysroot into a new directory using
sudo cp -a /mnt/data/arm64 sysroot
Correct symlinks
wget https://raw.githubusercontent.com/riscv/riscv-poky/master/scripts/sysroot-relativelinks.py
chmod +x sysroot-relativelinks.py
sudo python3 sysroot-relativelinks.py sysroot
create a crosscompilation CMake File
nano crosscompile.cmake
with the following content
# the name of the target operating system
set(CMAKE_SYSTEM_NAME Linux)
# set(CMAKE_SYSTEM_PROCESSOR aarch64)
# which compilers to use for C and C++
set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc-12)
set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++-12)
# set(CMAKE_LIBRARY_ARCHITECTURE aarch64-linux-gnu)
# where is the target environment located
set(CMAKE_FIND_ROOT_PATH ~/crosscompile/sysroot)
# adjust the default behavior of the FIND_XXX() commands:
# search programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# search headers and libraries in the target environment
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_SYSROOT ~/crosscompile/sysroot)
clone Repository
git clone https://github.com/HarbourMasters/2ship2harkinian
cd 2ship2harkinian
git submodule update --init
Quick ugly patch to compile OTR in case it fails because of a missing header
cd OTRExporter/OTRExporter
ln -s ~/crosscompile/sysroot/usr/local/include/tinyxml2.h tinyxml2.h
cd ../..
Generate MakeFiles using crosscompilation
cmake -H. -B build-cmake -GNinja -DUSE_OPENGLES=1 -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_TOOLCHAIN_FILE=~/crosscompile/crosscompile.cmake
Build 2s2h.elf file
cmake --build build-cmake --config Release -j$(nproc)
Strip it
cd build-cmake/mm
aarch64-linux-gnu-strip 2s2h.elf
copy 2s2h.elf
To get 2s2h.o2r file Generate MakeFiles without crosscompilation
cd ~/crosscompile/2ship2harkinian
cmake -H. -B build-cmake_host -GNinja -DUSE_OPENGLES=1 -DCMAKE_BUILD_TYPE:STRING=Release
cmake --build build-cmake_host --config Release --target Generate2ShipOtr -j$(nproc)
cd build-cmake_host/mm
copy 2s2h.o2r