Fix multiple iOS issues and add iOS compilation (#10426)

This commit is contained in:
Ihar Hubchyk
2025-12-10 11:49:38 +08:00
committed by GitHub
parent 8366478700
commit 783b99f3e7
11 changed files with 151 additions and 21 deletions
+36
View File
@@ -0,0 +1,36 @@
name: iOS
on:
workflow_call:
permissions:
contents: write
jobs:
ios:
name: iOS
runs-on: macos-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v6
- name: check Xcode version
run: |
/usr/bin/xcodebuild -version
- name: Install dependencies
run: |
./script/ios/install_packages.sh
# TODO: remove this step once we figure out how to build without the need of resources.
- name: Prepare build
run: |
mkdir anim
mkdir data
mkdir music
- name: Build
# TODO: compile for a proper target, not for simulator.
run: |
cd ios
xcodebuild -project fheroes2.xcodeproj \
-scheme fheroes2 \
-destination 'platform=iOS Simulator,name=iPhone 16' \
build
# TODO: add signing stage.
+5
View File
@@ -98,3 +98,8 @@ jobs:
needs:
- msvc
uses: ./.github/workflows/make.yml
ios:
name: iOS
needs:
- msvc
uses: ./.github/workflows/ios.yml
+4
View File
@@ -98,6 +98,10 @@ android/app/src/main/assets/
ios/*/xcuserdata
ios/**/xcuserdata
# Third-party packages for XCode
ios/SDL2/
ios/SDL2_mixer/
# Mac magic folders
.DS_Store
+1 -8
View File
@@ -39,15 +39,8 @@ Please follow the instructions below to be able to build the project from source
* To build this build you need to have the necessary Data, Anim, Maps and Music folders for the engine present in the fheroes2 project's folder.
* Download and install Xcode on your macos device. Download the iOS SDK during installation.
* Go to the directory `script/ios` and run the file `install_packages.sh`. This script will install all the required packages to build the project using Xcode.
* Open `fheroes2.xcodeproj` in the "iOS" folder".
* Download SDL2 and SDL_mixer source codes from their GitHub repositories's release pages. Make sure you get SDL2 and not SDL3.
* Paste the SDL2 and SDL_mixer folders in the same parent directory as your fheroes2 source folder. This means that next to the folder containing
your fheroes2 local clone, you will have the two SDL folders.
* Remove any version number from the name of the SDL2 and SDL_mixer folder so that their names are respectively `SDL` and `SDL_mixer`.
* In Xcode SDL and SDL_mixer should now be recognized in the Navigator area, recognized by them not having read names. Open on `SDL_mixer` in the Navigator on the left side.
* Click "fheroes2" in the Navigator area on the left side of Xcode.
* In the right side Editor area select "fheroes2" under "Project". Open the `Build Settings` tab. Make sure to set `All` options and scroll down to `Search Paths`.
* Open up the `User Header Search Paths` and add `$(SRCROOT)/../../SDL/include` to the list of paths.
* In the Editor area select "fheroes2" under the "Targets" menu instead of "Projects". Open the "Signing & Capabilities" tab. Under "Signing", add your AppleID in
the "Team" field.
* Connect your iOS device to your mac device with the necessary cable. Select the device in the devices in Xcode's upper Toolbar.
@@ -1,9 +1,10 @@
{
"images" : [
{
"filename" : "icon.jpg",
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
"size" : "256x256"
}
],
"info" : {
Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

+6 -6
View File
@@ -157,9 +157,9 @@
EA54669E29FE02FF00A9D8B2 /* Shaders.metal */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.metal; path = Shaders.metal; sourceTree = "<group>"; };
EA5466A329FE02FF00A9D8B2 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
EA5466A629FE02FF00A9D8B2 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
EA67D2A229FE04380004F40F /* SDL.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = SDL.xcodeproj; path = ../../SDL/Xcode/SDL/SDL.xcodeproj; sourceTree = "<group>"; };
EA67D2A229FE04380004F40F /* SDL.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = SDL.xcodeproj; path = SDL2/Xcode/SDL/SDL.xcodeproj; sourceTree = "<group>"; };
EA67D2CB29FE05030004F40F /* SDL_uikit_main.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_uikit_main.c; sourceTree = "<group>"; };
EA67D5DE29FE0B350004F40F /* SDL_mixer.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = SDL_mixer.xcodeproj; path = ../../SDL_mixer/Xcode/SDL_mixer.xcodeproj; sourceTree = "<group>"; };
EA67D5DE29FE0B350004F40F /* SDL_mixer.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = SDL_mixer.xcodeproj; path = SDL2_mixer/Xcode/SDL_mixer.xcodeproj; sourceTree = "<group>"; };
EA67D5F229FE0C8C0004F40F /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; };
EA67D60129FE186F0004F40F /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = System/Library/Frameworks/CoreFoundation.framework; sourceTree = SDKROOT; };
/* End PBXFileReference section */
@@ -669,9 +669,9 @@
SWIFT_OBJC_BRIDGING_HEADER = ShaderTypes.h;
SWIFT_VERSION = 5.0;
SYSTEM_HEADER_SEARCH_PATHS = (
"\"$(SRCROOT)/../../SDL/include\"",
"\"$(SRCROOT)/SDL2/include\"",
"\"$(SRCROOT)/../src\"/**",
"\"$(SRCROOT)/../../SDL_mixer/include\"/**",
"\"$(SRCROOT)/SDL2_mixer/include\"/**",
);
TARGETED_DEVICE_FAMILY = "1,2";
};
@@ -705,9 +705,9 @@
SWIFT_OBJC_BRIDGING_HEADER = ShaderTypes.h;
SWIFT_VERSION = 5.0;
SYSTEM_HEADER_SEARCH_PATHS = (
"\"$(SRCROOT)/../../SDL/include\"",
"\"$(SRCROOT)/SDL2/include\"",
"\"$(SRCROOT)/../src\"/**",
"\"$(SRCROOT)/../../SDL_mixer/include\"/**",
"\"$(SRCROOT)/SDL2_mixer/include\"/**",
);
TARGETED_DEVICE_FAMILY = "1,2";
};
+3
View File
@@ -0,0 +1,3 @@
# Package installation for XCode
Run the `install_packages.sh` and it will try to install everything at once.
+82
View File
@@ -0,0 +1,82 @@
#!/usr/bin/env bash
###########################################################################
# fheroes2: https://github.com/ihhub/fheroes2 #
# Copyright (C) 2025 #
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program; if not, write to the #
# Free Software Foundation, Inc., #
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
###########################################################################
set -e -o pipefail
# We might need to move packages into https://github.com/fheroes2/fheroes2-prebuilt-deps
# repository as we did for other packages.
PKG_NAME="release-2.32.10"
PKG_FILE="$PKG_NAME.zip"
PKG_FILE_SHA256="7a3c207b8509edc487d658df357ad764cd852d68fe248d307b25c0741d52fdf0"
PKG_URL="https://github.com/libsdl-org/SDL/archive/refs/tags/$PKG_FILE"
TMP_DIR="$(mktemp -d)"
if [[ -n "$(command -v wget)" ]]; then
wget -O "$TMP_DIR/$PKG_FILE" "$PKG_URL"
elif [[ -n "$(command -v curl)" ]]; then
curl -o "$TMP_DIR/$PKG_FILE" -L "$PKG_URL"
else
echo "Neither wget nor curl were found in your system. Unable to download the package archive. Installation aborted."
exit 1
fi
echo "$PKG_FILE_SHA256 *$PKG_FILE" > "$TMP_DIR/checksums"
if [[ -n "$(command -v shasum)" ]]; then
(cd "$TMP_DIR" && shasum --check --algorithm 256 checksums)
elif [[ -n "$(command -v sha256sum)" ]]; then
(cd "$TMP_DIR" && sha256sum --check --strict checksums)
else
echo "Neither shasum nor sha256sum were found in your system. Unable to verify the downloaded file. Installation aborted."
exit 1
fi
unzip -d "$(dirname "$0")/../../ios" "$TMP_DIR/$PKG_FILE"
mv "$(dirname "$0")/../../ios/SDL-$PKG_NAME" "$(dirname "$0")/../../ios/SDL2"
PKG_NAME="release-2.8.1"
PKG_FILE="$PKG_NAME.zip"
PKG_FILE_SHA256="3738827df73c86268dfa52898780769d1a796316d73b535e2ab5ff2d8d0ff44f"
PKG_URL="https://github.com/libsdl-org/SDL_mixer/archive/refs/tags/$PKG_FILE"
if [[ -n "$(command -v wget)" ]]; then
wget -O "$TMP_DIR/$PKG_FILE" "$PKG_URL"
elif [[ -n "$(command -v curl)" ]]; then
curl -o "$TMP_DIR/$PKG_FILE" -L "$PKG_URL"
else
echo "Neither wget nor curl were found in your system. Unable to download the package archive. Installation aborted."
exit 1
fi
echo "$PKG_FILE_SHA256 *$PKG_FILE" > "$TMP_DIR/checksums"
unzip -d "$(dirname "$0")/../../ios" "$TMP_DIR/$PKG_FILE"
mv "$(dirname "$0")/../../ios/SDL_Mixer-$PKG_NAME" "$(dirname "$0")/../../ios/SDL2_Mixer"
# Patch SDL_Mixer project.
# It is needed since we are trying to build SDL Mixer using the latest SDL2 version.
# Also, SDL Mixer doesn't support iPhone Simulator so we have to change this code or another one.
sed -i '' 's#$(SRCROOT)/$(PLATFORM)/SDL2.framework/Headers#$(SRCROOT)/../../SDL2/include#' \
ios/SDL2_Mixer/Xcode/SDL_mixer.xcodeproj/project.pbxproj
+5 -5
View File
@@ -1,6 +1,6 @@
/***************************************************************************
* fheroes2: https://github.com/ihhub/fheroes2 *
* Copyright (C) 2019 - 2024 *
* Copyright (C) 2019 - 2025 *
* *
* Free Heroes2 Engine: http://sourceforge.net/projects/fheroes2 *
* Copyright (C) 2009 by Andrey Afletdinov <[email protected]> *
@@ -95,7 +95,7 @@ namespace
{
const char * homeEnvPath = getenv( "HOME" );
#if defined( MACOS_APP_BUNDLE )
#if defined( MACOS_APP_BUNDLE ) || defined( __IPHONEOS__ )
if ( homeEnvPath != nullptr ) {
return System::concatPath( System::concatPath( homeEnvPath, "Library/Preferences" ), appName );
}
@@ -267,7 +267,7 @@ namespace
bool System::isHandheldDevice()
{
#if defined( ANDROID )
#if defined( ANDROID ) || defined( __IPHONEOS__ )
return true;
#else
return false;
@@ -281,7 +281,7 @@ bool System::isTouchInputAvailable()
bool System::isVirtualKeyboardSupported()
{
#if defined( ANDROID ) || defined( TARGET_PS_VITA ) || defined( TARGET_NINTENDO_SWITCH )
#if defined( ANDROID ) || defined( TARGET_PS_VITA ) || defined( TARGET_NINTENDO_SWITCH ) || defined( __IPHONEOS__ )
return true;
#else
return false;
@@ -382,7 +382,7 @@ std::string System::GetDataDirectory( const std::string_view appName )
}
return {};
#elif defined( MACOS_APP_BUNDLE )
#elif defined( MACOS_APP_BUNDLE ) || defined( __IPHONEOS__ )
if ( const char * homeEnv = getenv( "HOME" ); homeEnv != nullptr ) {
return concatPath( concatPath( homeEnv, "Library/Application Support" ), appName );
}
+7 -1
View File
@@ -301,8 +301,14 @@ void Interface::AdventureMap::EventSystemDialog() const
fheroes2::GameMode Interface::BaseInterface::EventExit()
{
if ( Dialog::YES & fheroes2::showStandardTextMessage( _( "Quit" ), _( "Are you sure you want to quit?" ), Dialog::YES | Dialog::NO ) )
#if defined( __IPHONEOS__ )
// iOS discourages to exit a running application.
fheroes2::showStandardTextMessage( _( "Quit" ), _( "To exit fheroes2, press the Home button or swipe up." ), Dialog::OK );
#else
if ( Dialog::YES & fheroes2::showStandardTextMessage( _( "Quit" ), _( "Are you sure you want to quit?" ), Dialog::YES | Dialog::NO ) ) {
return fheroes2::GameMode::QUIT_GAME;
}
#endif
return fheroes2::GameMode::CANCEL;
}