diff --git a/.github/workflows/xbox_nxdk.yml b/.github/workflows/xbox_nxdk.yml new file mode 100644 index 000000000000..87e8dcae341d --- /dev/null +++ b/.github/workflows/xbox_nxdk.yml @@ -0,0 +1,61 @@ +name: Xbox + +on: + push: + branches: + - master + pull_request: + types: [ opened, synchronize ] + +jobs: + xbox: + runs-on: ubuntu-latest + env: + NXDK_DIR: /opt/nxdk + steps: + - name: Install APT packages + run: sudo apt-get update && sudo apt-get install -y clang llvm lld bison flex cmake git gettext smpq + + - name: Clone NXDK Repo + shell: bash + run: git clone --recursive --depth 1 --branch devilutionx https://github.com/glebm/nxdk.git "$NXDK_DIR" + + - name: Build NXDK + shell: bash + run: PATH="${NXDK_DIR}/bin:$PATH" make -j $(nproc) -C "$NXDK_DIR" NXDK_ONLY=1 + + - name: Work around https://github.com/XboxDev/nxdk/issues/467 + run: > + mkdir -p "${NXDK_DIR}/lib/xboxrt/libc_extensions/sys" && + echo "#pragma once // Generated" > "${NXDK_DIR}/lib/xboxrt/libc_extensions/sys/types.h" && + echo "typedef long off_t;" >> "${NXDK_DIR}/lib/xboxrt/libc_extensions/sys/types.h" + + - name: Work around https://github.com/XboxDev/nxdk/issues/464 + run: > + mkdir -p "${NXDK_DIR}/lib/xboxrt/libc_extensions/sys" && + echo "#pragma once // Generated" > "${NXDK_DIR}/lib/xboxrt/libc_extensions/sys/stat.h" && + echo "#include " >> "${NXDK_DIR}/lib/xboxrt/libc_extensions/sys/stat.h" && + echo "struct _stat { size_t st_size; int st_mode; int st_mtime; int st_atime; int st_nlink; };" >> "${NXDK_DIR}/lib/xboxrt/libc_extensions/sys/stat.h" && + echo "struct _stati64 { size_t st_size; int st_mode; int st_mtime; int st_atime; int st_nlink; };" >> "${NXDK_DIR}/lib/xboxrt/libc_extensions/sys/stat.h" && + echo "static int _stati64(const char* x, ...) { return 0; };" >> "${NXDK_DIR}/lib/xboxrt/libc_extensions/sys/stat.h" + + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Configure CMake + working-directory: ${{github.workspace}} + run: cmake -S. -Bbuild-xbox -DCMAKE_TOOLCHAIN_FILE=/opt/nxdk/share/toolchain-nxdk.cmake + + - name: Build + working-directory: ${{github.workspace}} + shell: bash + run: cmake --build build-xbox -j $(nproc) --target package + + - name: Upload-Package + if: ${{ !env.ACT }} + uses: actions/upload-artifact@v2 + with: + name: devilutionx + path: build-xbox/devilutionx diff --git a/CMake/Platforms.cmake b/CMake/Platforms.cmake index 24a6e67fbb78..4fe4f20e1e61 100644 --- a/CMake/Platforms.cmake +++ b/CMake/Platforms.cmake @@ -67,3 +67,7 @@ endif() if(UWP_LIB) include(platforms/uwp_lib) endif() + +if(NXDK) + include(platforms/xbox_nxdk) +endif() diff --git a/CMake/platforms/xbox_nxdk.cmake b/CMake/platforms/xbox_nxdk.cmake new file mode 100644 index 000000000000..078e9964cf54 --- /dev/null +++ b/CMake/platforms/xbox_nxdk.cmake @@ -0,0 +1,12 @@ +set(NONET ON) +set(ASAN OFF) +set(UBSAN OFF) + +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/xbox_nxdk/finders") + +set(DEVILUTIONX_SYSTEM_BZIP2 OFF) + +set(CMAKE_THREAD_LIBS_INIT "-lpthread") +set(CMAKE_HAVE_THREADS_LIBRARY 1) +set(CMAKE_USE_WIN32_THREADS_INIT 0) +set(CMAKE_USE_PTHREADS_INIT 1) diff --git a/CMake/platforms/xbox_nxdk/finders/FindPNG.cmake b/CMake/platforms/xbox_nxdk/finders/FindPNG.cmake new file mode 100644 index 000000000000..20f8193a69cd --- /dev/null +++ b/CMake/platforms/xbox_nxdk/finders/FindPNG.cmake @@ -0,0 +1,5 @@ +if(NOT TARGET PNG::PNG) + find_package(PkgConfig REQUIRED) + pkg_check_modules(PNG REQUIRED IMPORTED_TARGET libpng) + add_library(PNG::PNG ALIAS PkgConfig::PNG) +endif() diff --git a/CMake/platforms/xbox_nxdk/finders/FindSDL2.cmake b/CMake/platforms/xbox_nxdk/finders/FindSDL2.cmake new file mode 100644 index 000000000000..37ffe10abdb2 --- /dev/null +++ b/CMake/platforms/xbox_nxdk/finders/FindSDL2.cmake @@ -0,0 +1,7 @@ +if(NOT TARGET SDL2::SDL2) + find_package(PkgConfig REQUIRED) + pkg_check_modules(SDL2 REQUIRED IMPORTED_TARGET sdl2) + add_library(SDL2::SDL2 ALIAS PkgConfig::SDL2) + add_library(SDL2_nomain INTERFACE) + add_library(SDL2::SDL2main ALIAS SDL2_nomain) +endif() diff --git a/CMake/platforms/xbox_nxdk/finders/FindZLIB.cmake b/CMake/platforms/xbox_nxdk/finders/FindZLIB.cmake new file mode 100644 index 000000000000..e1f055cba026 --- /dev/null +++ b/CMake/platforms/xbox_nxdk/finders/FindZLIB.cmake @@ -0,0 +1,5 @@ +if(NOT TARGET ZLIB::ZLIB) + find_package(PkgConfig REQUIRED) + pkg_check_modules(ZLIB REQUIRED IMPORTED_TARGET zlib) + add_library(ZLIB::ZLIB ALIAS PkgConfig::ZLIB) +endif()