Add Switch to Github actions (#4514)

This commit is contained in:
Mary 2021-04-08 22:36:49 -04:00 committed by GitHub
parent 4f55f11000
commit 7f3de8ff5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 238 additions and 20 deletions

100
.github/workflows/switch.yml vendored Normal file
View File

@ -0,0 +1,100 @@
name: switch
on:
push:
branches:
- master
tags:
- '*'
pull_request: {}
workflow_dispatch:
jobs:
build_switch:
name: Build Switch
runs-on: ubuntu-latest
container:
image: 'devkitpro/devkita64'
steps:
- name: Checkout code
uses: actions/checkout@v2
with:
fetch-depth: 1
path: "./stk-code"
- name: Checkout OpenAL
uses: actions/checkout@v2
with:
fetch-depth: 1
path: "./stk-code/lib/openal"
repository: "kcat/openal-soft"
- name: Checkout Harfbuzz
uses: actions/checkout@v2
with:
fetch-depth: 1
path: "./stk-code/lib/harfbuzz"
repository: "harfbuzz/harfbuzz"
- name: Grab assets
run: |
sudo apt update
sudo apt install unzip zip -y
wget -q https://github.com/supertuxkart/stk-assets-mobile/releases/download/git/stk-assets-full.zip
unzip -q stk-assets-full.zip -d stk-assets
rm stk-assets-full.zip
# Env setup!
- name: Configure packaging name for git master branch
if: ${{ github.ref == 'refs/heads/master' }}
run: |
echo "release_tag=git`date +%Y%m%d`" >> $GITHUB_ENV
echo "release_name=preview" >> $GITHUB_ENV
- name: Configure packaging name for tag
if: ${{ startsWith(github.ref, 'refs/tags/') }}
run: |
echo "release_tag=`basename $GITHUB_REF`" >> $GITHUB_ENV
echo "release_name=`basename $GITHUB_REF`" >> $GITHUB_ENV
- name: Configure packaging name for non-releasing branch
if: ${{ (github.ref != 'refs/heads/master' && !startsWith(github.ref, 'refs/tags/')) || github.repository_owner != 'supertuxkart' }}
run: |
echo "release_tag=" >> $GITHUB_ENV
echo "release_name=" >> $GITHUB_ENV
- name: Check for prerelease
if: ${{ github.ref == 'refs/heads/master' || contains(github.ref, 'rc') || contains(github.ref, 'beta') }}
run: |
echo "release_pre=true" >> $GITHUB_ENV
- name: Check for non-prerelease
if: ${{ github.ref != 'refs/heads/master' && !contains(github.ref, 'rc') && !contains(github.ref, 'beta') }}
run: |
echo "release_pre=false" >> $GITHUB_ENV
- name: Show packaging name
run : |
echo "${{ env.release_tag }}"
echo "${{ env.release_name }}"
echo "${{ env.release_pre }}"
- name: Cache cmake_build
id: cache-switch-cmake
uses: actions/cache@v2
with:
path: |
stk-code/cmake_build
stk-code/lib/openal/cmake_build
stk-code/lib/harfbuzz/cmake_build
# Make sure PRs can't overwrite!
key: ${{ github.ref }}-switch-cmake-0
- name: Run build script
run: |
cp -v stk-code/switch/pkgbuild-scripts/* "$DEVKITPRO/"
cd stk-code/switch
PROJECT_VERSION="${{ env.release_tag }}" ./make.sh
- name: Create release
uses: ncipollo/release-action@v1
if: ${{ env.release_tag != '' }}
with:
token: ${{ secrets.GITHUB_TOKEN }}
artifacts: "stk-code/cmake_build/bin/SuperTuxKart-${{ env.release_tag }}-switch.zip"
tag: ${{ env.release_tag }}
omitBodyDuringUpdate: true
omitNameDuringUpdate: true
allowUpdates: true
prerelease: ${{ env.release_pre }}

View File

@ -384,7 +384,7 @@ if (NOT SERVER_ONLY)
# Freetype
if (USE_SWITCH)
SET(FREETYPE_INCLUDE_DIRS /opt/devkitpro/portlibs/switch/include/freetype2)
SET(FREETYPE_LIBRARY freetype)
find_library(FREETYPE_LIBRARIES freetype libfreetype REQUIRED)
SET(FREETYPE_FOUND YES)
else()
find_package(Freetype)
@ -627,17 +627,20 @@ if (USE_SWITCH)
find_library(NX_LIBRARY NAMES nx libnx REQUIRED)
find_library(DRM_LIBRARY NAMES drm_nouveau libdrm_nouveau REQUIRED)
find_library(GLAPI_LIBRARY NAMES glapi libglapi REQUIRED)
find_library(ZLIB_LIBRARY NAMES z libz REQUIRED)
find_library(PNG_LIBRARY NAMES png libpng REQUIRED)
find_library(BZ2_LIBRARY NAMES bz2 libbz2 REQUIRED)
target_link_libraries(supertuxkart
${NX_LIBRARY}
-lz
-lfreetype
-lSDL2
-lpng
-lbz2
-lharfbuzz
${ZLIB_LIBRARY}
${FREETYPE_LIBRARIES}
-logg
-lvorbis
-lopenal
${SDL2_LIBRARY}
${PNG_LIBRARY}
${BZ2_LIBRARY}
${HARFBUZZ_LIBRARY}
${OPENAL_LIBRARY}
${EGL_LIBRARY}
${DRM_LIBRARY}
${GLAPI_LIBRARY}

View File

@ -13,9 +13,22 @@ else
exit 1
fi
# GH Actions adds manually (hack!)
OPTIONAL=""
if [ ! -f "$DEVKITPRO/switch.cmake" ]; then
echo "pkgbuild-helpers not installed!"
ls "$DEVKITPRO/switch.cmake"
ls "$DEVKITPRO"
OPTIONAL="devkitpro-pkgbuild-helpers"
fi
# Install deps. --needed means don't reinstall if already installed
sudo $PACMAN -S --needed switch-dev \
devkitpro-pkgbuild-helpers \
sudo $PACMAN -S --needed \
devkit-env \
devkitA64 \
general-tools \
\
$OPTIONAL \
switch-curl switch-mbedtls \
switch-freetype switch-libfribidi \
switch-libogg switch-libvorbis \
@ -53,12 +66,12 @@ if [ ! -d "${STK_DIR}/lib/harfbuzz/cmake_build" ]; then
mkdir "${STK_DIR}/lib/harfbuzz/cmake_build"
cd "${STK_DIR}/lib/harfbuzz/cmake_build"
cmake -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE="${DEVKITPRO}/switch.cmake" \
-DUSE_SWITCH=ON -DCMAKE_INSTALL_PREFIX="${PORTLIBS_PREFIX}" \
-DUSE_SWITCH=ON -DCMAKE_INSTALL_PREFIX="$(pwd)/install" \
-DHB_HAVE_FREETYPE=ON \
../
make -j$(nproc)
sudo make install
make install
fi
if [ ! -d "${STK_DIR}/lib/openal/cmake_build" ]; then
@ -70,22 +83,32 @@ if [ ! -d "${STK_DIR}/lib/openal/cmake_build" ]; then
-DUSE_SWITCH=ON -DALSOFT_UTILS=OFF -DLIBTYPE=STATIC -DALSOFT_EXAMPLES=OFF \
-DALSOFT_REQUIRE_SDL2=ON -DALSOFT_BACKEND_SDL2=ON \
-DSDL2_INCLUDE_DIR="${PORTLIBS_PREFIX}/include" \
-DCMAKE_INSTALL_PREFIX="${PORTLIBS_PREFIX}" \
-DCMAKE_INSTALL_PREFIX="$(pwd)/install" \
../
make -j$(nproc)
sudo make install
make install
fi
echo "Compiling STK"
mkdir "${STK_DIR}/cmake_build"
if [[ ! -d "${STK_DIR}/cmake_dir" ]]; then
mkdir "${STK_DIR}/cmake_build"
else
ls "${STK_DIR}/cmake_build"
fi
cd "${STK_DIR}/cmake_build"
cmake -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE="${DEVKITPRO}/switch.cmake" \
-DUSE_SWITCH=ON \
-DCMAKE_INSTALL_PREFIX=/ \
../
if [[ ! -f "${STK_DIR}/cmake_build/CMakeCache.txt" ]]; then
cmake -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE="${DEVKITPRO}/switch.cmake" \
-DUSE_SWITCH=ON \
-DOPENAL_LIBRARY="${STK_DIR}/lib/openal/cmake_build/install/lib/libopenal.a" \
-DOPENAL_INCLUDE_DIR="${STK_DIR}/lib/openal/cmake_build/install/include" \
-DHARFBUZZ_LIBRARY="${STK_DIR}/lib/harfbuzz/cmake_build/install/lib/libharfbuzz.a" \
-DHARFBUZZ_INCLUDEDIR="${STK_DIR}/lib/harfbuzz/cmake_build/install/include" \
-DCMAKE_INSTALL_PREFIX=/ \
../
fi
make -j$(nproc)
make install DESTDIR=./install
@ -107,7 +130,7 @@ echo "Compressing"
# Zip up actual release:
cd sdcard
ZIP_PATH="${STK_DIR}/cmake_build/bin/SuperTuxKart-Switch-${PROJECT_VERSION}.zip"
ZIP_PATH="${STK_DIR}/cmake_build/bin/SuperTuxKart-${PROJECT_VERSION}-switch.zip"
zip -r "${ZIP_PATH}" .
# Recover old pwd

View File

@ -0,0 +1,25 @@
cmake_minimum_required(VERSION 3.2)
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_SYSTEM_PROCESSOR "aarch64")
set(CMAKE_CROSSCOMPILING 1)
set(DEVKITPRO /opt/devkitpro)
set(TOOL_PREFIX ${DEVKITPRO}/devkitA64/bin/aarch64-none-elf-)
set(CMAKE_ASM_COMPILER ${TOOL_PREFIX}gcc CACHE PATH "")
set(CMAKE_C_COMPILER ${TOOL_PREFIX}gcc CACHE PATH "")
set(CMAKE_CXX_COMPILER ${TOOL_PREFIX}g++ CACHE PATH "")
set(CMAKE_LINKER ${TOOL_PREFIX}g++ CACHE PATH "")
set(CMAKE_AR ${TOOL_PREFIX}ar CACHE PATH "")
set(CMAKE_STRIP ${TOOL_PREFIX}strip CACHE PATH "")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH)
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(BUILD_SHARED_LIBS OFF CACHE INTERNAL "Shared libs not available" )

View File

@ -0,0 +1,7 @@
#!/usr/bin/env bash
export DEVKITPRO=/opt/devkitpro
export PORTLIBS_ROOT=${DEVKITPRO}/portlibs
export PATH=${DEVKITPRO}/tools/bin:${DEVKITPRO}/devkitA64/bin:$PATH
export TOOL_PREFIX=aarch64-none-elf-
export AR=${TOOL_PREFIX}gcc-ar
export RANLIB=${TOOL_PREFIX}gcc-ranlib

View File

@ -0,0 +1,11 @@
#!/usr/bin/env bash
SCRIPTDIR="${BASH_SOURCE%/*}"
if [ -z "$1" ]; then
echo "No platform specified." 1>&2
exit 1
fi
PLATFORM="$1"
source ${SCRIPTDIR}/${PLATFORM}vars.sh
echo "${PORTLIBS_PREFIX}"

View File

@ -0,0 +1,38 @@
include(/opt/devkitpro/devkita64.cmake)
set (DKA_SWITCH_C_FLAGS "-D__SWITCH__ -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -ftls-model=local-exec -ffunction-sections -fdata-sections")
set(CMAKE_C_FLAGS "${DKA_SWITCH_C_FLAGS}" CACHE STRING "")
set(CMAKE_CXX_FLAGS "${DKA_SWITCH_C_FLAGS}" CACHE STRING "")
set(CMAKE_ASM_FLAGS "${DKA_SWITCH_C_FLAGS}" CACHE STRING "")
set(CMAKE_EXE_LINKER_FLAGS_INIT "-specs=${DEVKITPRO}/libnx/switch.specs")
set(CMAKE_FIND_ROOT_PATH
${DEVKITPRO}/devkitA64
${DEVKITPRO}/tools
${DEVKITPRO}/portlibs/switch
${DEVKITPRO}/libnx
)
# Set pkg-config for the same
find_program(PKG_CONFIG_EXECUTABLE NAMES aarch64-none-elf-pkg-config HINTS "${DEVKITPRO}/portlibs/switch/bin")
if (NOT PKG_CONFIG_EXECUTABLE)
message(WARNING "Could not find aarch64-none-elf-pkg-config: try installing switch-pkg-config")
endif()
set(NSWITCH TRUE)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(NX_ROOT ${DEVKITPRO}/libnx)
set(NX_STANDARD_LIBRARIES "${NX_ROOT}/lib/libnx.a")
set(CMAKE_C_STANDARD_LIBRARIES "${NX_STANDARD_LIBRARIES}" CACHE STRING "")
set(CMAKE_CXX_STANDARD_LIBRARIES "${NX_STANDARD_LIBRARIES}" CACHE STRING "")
set(CMAKE_ASM_STANDARD_LIBRARIES "${NX_STANDARD_LIBRARIES}" CACHE STRING "")
#for some reason cmake (3.14.3) doesn't appreciate having \" here
set(NX_STANDARD_INCLUDE_DIRECTORIES "${NX_ROOT}/include")
set(CMAKE_C_STANDARD_INCLUDE_DIRECTORIES "${NX_STANDARD_INCLUDE_DIRECTORIES}" CACHE STRING "")
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES "${NX_STANDARD_INCLUDE_DIRECTORIES}" CACHE STRING "")
set(CMAKE_ASM_STANDARD_INCLUDE_DIRECTORIES "${NX_STANDARD_INCLUDE_DIRECTORIES}" CACHE STRING "")

View File

@ -0,0 +1,11 @@
. "${BASH_SOURCE%/*}"/devkita64.sh
export PORTLIBS_PREFIX=${DEVKITPRO}/portlibs/switch
export PATH=$PORTLIBS_PREFIX/bin:$PATH
export ARCH="-march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIC -ftls-model=local-exec"
export CFLAGS="${ARCH} -O2 -ffunction-sections -fdata-sections"
export CXXFLAGS="${CFLAGS}"
export CPPFLAGS="-D__SWITCH__ -I ${PORTLIBS_PREFIX}/include -isystem ${DEVKITPRO}/libnx/include"
export LDFLAGS="${ARCH} -L${PORTLIBS_PREFIX}/lib -L${DEVKITPRO}/libnx/lib"
export LIBS="-lnx"