Merge pull request #642 from Lgt2x/arm64-cross

Introduce cross-compiled ARM64 build
This commit is contained in:
Azamat H. Hackimov 2024-11-29 16:15:01 +03:00 committed by GitHub
commit 7fe52ecb97
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 87 additions and 33 deletions

View File

@ -5,9 +5,7 @@ on:
push:
branches: [ "main" ]
paths-ignore:
- '**/README.md'
- '**/LICENSE'
- '**/.github/**'
- '**/*.md'
pull_request:
branches: [ "main" ]
paths-ignore:
@ -46,6 +44,11 @@ jobs:
cc: clang
cxx: clang++
name: Linux-x64-clang
- runner: ubuntu-latest
preset: linux-cross-arm64
cc: gcc
cxx: g++++
name: Linux-cross-arm64
build_type:
- Debug
- Release
@ -64,12 +67,18 @@ jobs:
brew bundle install
- name: Install Linux dependencies
if: ${{ matrix.os.preset == 'linux' }}
if: ${{ matrix.os.runner == 'ubuntu-latest' }}
run: |
sudo apt update
sudo apt install -y --no-install-recommends \
ninja-build cmake g++ curl pkg-config autoconf automake libtool libltdl-dev make python3-jinja2 libx11-dev libxft-dev libxext-dev libwayland-dev libxkbcommon-dev libegl1-mesa-dev libibus-1.0-dev libasound2-dev libpulse-dev libaudio-dev libjack-dev libsndio-dev
- name: Install Linux Cross-compilation dependencies
if: ${{ matrix.os.preset == 'linux-cross-arm64' }}
run: |
sudo apt install -y --no-install-recommends \
gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu g++-aarch64-linux-gnu
- name: Install Windows dependencies
if: ${{ matrix.os.runner == 'windows-latest' }}
run: choco install ninja
@ -83,7 +92,15 @@ jobs:
with:
vcpkgJsonGlob: vcpkg.json
- name: Configure cross-compiled build
if: ${{ matrix.os.preset == 'linux-cross-arm64' }}
run: |
cmake --preset linux
ninja -f build-${{ matrix.build_type }}.ninja -C builds/linux/ HogMaker
cmake --preset linux-cross-arm64 -DHogMaker_DIR=$PWD/builds/linux/ -DBUILD_TESTING=OFF -DENABLE_LOGGER=ON -DFORCE_PORTABLE_INSTALL=ON -DBUILD_EDITOR=OFF -DUSE_EXTERNAL_PLOG=ON
- name: Configure CMake
if: ${{ matrix.os.preset != 'linux-cross-arm64' }}
env:
CC: ${{ matrix.os.cc }}
CXX: ${{ matrix.os.cxx }}
@ -93,6 +110,7 @@ jobs:
run: cmake --build --preset ${{ matrix.os.preset }} --config ${{ matrix.build_type }} --verbose
- name: Run ${{ matrix.build_type }} Unittests
if: ${{ matrix.os.preset != 'linux-cross-arm64' }}
run: ctest --preset ${{ matrix.os.preset }} -C ${{ matrix.build_type }}
- name: Local install

View File

@ -152,24 +152,22 @@ Once CMake finishes, the built files will be put in `builds/linux/build/Debug` o
## Cross-compilation
In order to cross-compile Descent3 to another platform (for example, Linux ARM64), you'll need to build auxiliary
tools which needed to build data files. First create build-native directory and configure project in it:
tools natively which are needed to build data files. First create build-native directory and configure project in it:
```shell
mkdir build-native
cd build-native
cmake ..
make HogMaker
cmake --build . --target HogMaker
```
Now you ready for cross-compilation. Create cross-compile directory and configure project in it, but this time add
`-DCMAKE_TOOLCHAIN_FILE=MyToolchain.cmake` and `-DHogMaker_DIR=<path-to-Descent3/build-native/` options. This enables
cross-compilation environment.
Now, you are ready for cross-compilation. Create a new cross-compilation build directory and configure the project in it, but this time specify the location of the HogMaker native executable just built, as well as the [toolchain file](https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#id14) location. This enables the cross-compilation environment. An example toolchain file is provided for a Linux ARM64 build at `cmake/toolchains/linux-aarch64-gcc-toolchain.cmake`. The custom toolchain system can be used in combination with VCPKG to build all dependencies for the target system.
```shell
mkdir build-cross
cd build-cross
cmake -DCMAKE_TOOLCHAIN_FILE=MyToolchain.cmake -DHogMaker_DIR=~/src/build-native/ ..
make
cmake -DCMAKE_TOOLCHAIN_FILE=cmake/toolchains/MyToolChain.cmake -DHogMaker_DIR=../build-native/ ..
cmake --build .
```
## Build Options

View File

@ -275,7 +275,12 @@ endif()
add_subdirectory(Descent3)
add_subdirectory(tools)
if (CMAKE_CROSSCOMPILING)
find_package(HogMaker REQUIRED)
else()
add_subdirectory(tools)
endif()
add_subdirectory(netcon)
add_subdirectory(netgames)
add_subdirectory(scripts)

View File

@ -42,6 +42,20 @@
"lhs": "${hostSystemName}",
"rhs": "Linux"
}
},
{
"name": "linux-cross-arm64",
"inherits": "defaults",
"generator": "Ninja Multi-Config",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Linux"
},
"cacheVariables": {
"VCPKG_TARGET_TRIPLET": "arm64-linux",
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/cmake/toolchains/linux-aarch64-gcc-toolchain.cmake"
}
}
],
"buildPresets": [
@ -56,6 +70,10 @@
{
"name": "linux",
"configurePreset": "linux"
},
{
"name": "linux-cross-arm64",
"configurePreset": "linux-cross-arm64"
}
],
"testPresets": [
@ -85,4 +103,4 @@
"configurePreset": "linux"
}
]
}
}

View File

@ -46,9 +46,9 @@ context menu.
builds [here](https://github.com/DescentDevelopers/Descent3/actions/workflows/build.yml?query=branch%3Amain+event%3Apush).
- If you want to build the engine files yourself, the follow the
instructions in [BUILD.md](BUILD.md). Once you build the engine files,
theyll be put in `builds/<platform>/<build-type>/`. For example, if
theyll be put in `builds/<platform>/build/<build-type>/`. For example, if
youre using Linux and you create a “Release” build, then the files will
be located at `builds/linux/Release`.
be located at `builds/linux/build/Release`.
9. Copy all the new engine files into `D3-open-source` and overwrite any
conflicts.

View File

@ -0,0 +1,12 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++)
set(CMAKE_CROSSCOMPILING ON)

View File

@ -1,11 +1,7 @@
if(CMAKE_CROSSCOMPILING)
find_package(HogMaker)
else()
add_executable(
HogMaker
HogMaker/HogFormat.cpp
HogMaker/HogMaker.cpp
)
target_include_directories(HogMaker PRIVATE ${PROJECT_BINARY_DIR}/lib)
export(TARGETS HogMaker FILE "${CMAKE_BINARY_DIR}/HogMakerConfig.cmake")
endif()
add_executable(
HogMaker
HogMaker/HogFormat.cpp
HogMaker/HogMaker.cpp
)
target_include_directories(HogMaker PRIVATE ${PROJECT_BINARY_DIR}/lib)
export(TARGETS HogMaker FILE "${CMAKE_BINARY_DIR}/HogMakerConfig.cmake")

View File

@ -1,5 +1,5 @@
{
"builtin-baseline": "198d68dbcc6c907cb3d0b9b1d93c3df6ecf93c62",
"builtin-baseline": "e60236ee051183f1122066bee8c54a0b47c43a60",
"dependencies": [
"glm",
"gtest",
@ -7,20 +7,27 @@
"zlib",
{
"name": "sdl2",
"version>=": "2.30.3",
"features": ["x11","wayland", "alsa"],
"platform": "linux"
"version>=": "2.30.8",
"features": ["x11", "wayland", "alsa"],
"default-features": false,
"platform": "linux & !native"
},
{
"name": "sdl2",
"version>=": "2.30.3",
"version>=": "2.30.8",
"features": ["x11","wayland", "alsa"],
"platform": "linux & native"
},
{
"name": "sdl2",
"version>=": "2.30.8",
"platform": "!linux"
}
],
"overrides": [
{
"name": "sdl2",
"version": "2.30.3"
"version": "2.30.8"
}
]
}
}