Merge pull request #22783 from hrydgard/ios-simulator-build

iOS: Build and run on the simulator
This commit is contained in:
Henrik Rydgård authored and GitHub committed 2026-10-25 23:15:37 +01:00
commit 888abaa97e
6 files changed
+93 -16

No files matched your search

+9 -5
View File
@@ -1575,9 +1575,13 @@ if(IOS AND NOT LIBRETRO)
#endif()
# Can't figure out properly using .xcframework from CMake, so just linking directly to the .a file.
target_link_libraries(${TargetBin}
"${CMAKE_CURRENT_SOURCE_DIR}/ios/MoltenVK/MoltenVK.xcframework/${MOLTENVK_SLICE}/libMoltenVK.a"
)
# The simulator renders with Metal only, and loads no Vulkan (see PPSSPP_VK_STATIC).
if(IOS_PLATFORM STREQUAL "SIMULATOR")
set(MOLTENVK_LIB "")
else()
set(MOLTENVK_LIB "${CMAKE_CURRENT_SOURCE_DIR}/ios/MoltenVK/MoltenVK.xcframework/${MOLTENVK_SLICE}/libMoltenVK.a")
endif()
target_link_libraries(${TargetBin} ${MOLTENVK_LIB})
set(MACOSX_DEPLOYMENT_TARGET ${DEPLOYMENT_TARGET})
set(PRODUCT_NAME "PPSSPP")
@@ -1663,7 +1667,7 @@ if(IOS AND NOT LIBRETRO)
if(IOS_APP_STORE)
# https://stackoverflow.com/questions/40664125/cmake-and-code-signing-in-xcode-8-for-ios-projects
set_target_properties(${TargetBin} PROPERTIES
XCODE_ATTRIBUTE_DEVELOPMENT_TEAM ${DEVELOPMENT_TEAM_ID}
XCODE_ATTRIBUTE_DEVELOPMENT_TEAM "${DEVELOPMENT_TEAM_ID}"
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "Apple Development"
XCODE_ATTRIBUTE_CODE_SIGN_STYLE "Automatic"
)
@@ -1682,7 +1686,7 @@ if(IOS AND NOT LIBRETRO)
# PPSSPPHeadless as an app of its own (org.ppsspp.headless), for running frame dumps on a
# device. Signed for development, so devicectl can copy files in and out of its container.
target_link_libraries(PPSSPPHeadless
"${CMAKE_CURRENT_SOURCE_DIR}/ios/MoltenVK/MoltenVK.xcframework/${MOLTENVK_SLICE}/libMoltenVK.a"
${MOLTENVK_LIB}
"-framework Foundation -framework UIKit -framework CoreGraphics -framework CoreText -framework QuartzCore -framework Metal -framework IOSurface -framework AudioToolbox -framework AVFoundation -framework CoreMedia -framework CoreVideo -framework UniformTypeIdentifiers"
)
if(NOT ICONV_LIBRARY)
+2 -2
View File
@@ -339,7 +339,7 @@ static constexpr DriverBlackListEntry g_gpuNameBlacklist[] = {
#if !defined(_WIN32) && !PPSSPP_VK_STATIC
static const char * const so_names[] = {
#if PPSSPP_PLATFORM(IOS)
// Only reached by the libretro core, the app links MoltenVK statically.
// Only reached by the libretro core and the simulator (which has none). The app links MoltenVK statically.
"@executable_path/Frameworks/libMoltenVK.dylib",
"MoltenVK",
#elif PPSSPP_PLATFORM(MAC)
@@ -443,7 +443,7 @@ void VulkanSetNativeLibDir(std::string_view nativeLibDir) {
}
bool VulkanMayBeAvailable() {
#if PPSSPP_PLATFORM(IOS)
#if PPSSPP_PLATFORM(IOS) && !PPSSPP_PLATFORM(IOS_SIMULATOR)
// The deployment target (15.0) is above anything MoltenVK doesn't support.
g_vulkanAvailabilityChecked = true;
g_vulkanMayBeAvailable = true;
+3 -2
View File
@@ -32,8 +32,9 @@
#endif
// The iOS app links MoltenVK statically and calls Vulkan directly. Everywhere else (including the
// iOS libretro core), we load the functions at runtime into the pointers below.
#if PPSSPP_PLATFORM(IOS) && !defined(__LIBRETRO__)
// iOS libretro core), we load the functions at runtime into the pointers below. The simulator build
// has no MoltenVK at all (it uses Metal), so it takes the runtime path, which finds no library.
#if PPSSPP_PLATFORM(IOS) && !PPSSPP_PLATFORM(IOS_SIMULATOR) && !defined(__LIBRETRO__)
#define PPSSPP_VK_STATIC 1
#else
#define VK_NO_PROTOTYPES
+57
View File
@@ -0,0 +1,57 @@
#!/bin/bash
# Builds the App Store variant for the iOS simulator (Apple Silicon Macs), and runs it in the
# simulator. Useful for App Store screenshots of devices we don't have.
#
# Usage: ./b-ios-simulator.sh ["Device name"]
#
# With a device name ("iPhone Duo", "iPad Pro 13-inch (M5)" - see xcrun simctl list devicetypes),
# runs on a simulator of that type, creating and booting one if needed. Without one, runs on the
# booted simulator, or boots the newest iPhone if none is booted.
set -e
FOLDER_NAME="build-ios-sim"
CONFIGURATION="${CONFIGURATION:-Debug}"
BUNDLE_ID="org.ppsspp.ppsspp-free"
DEVICE_NAME="$1"
if [[ ! -d $FOLDER_NAME ]]; then
cmake -S . -B $FOLDER_NAME -GXcode -DCMAKE_TOOLCHAIN_FILE=cmake/Toolchains/ios.cmake -DIOS_PLATFORM=SIMULATOR -DIOS_APP_STORE=ON
# Xcode looks for git-version.cpp before any script phase gets to generate it.
cmake -DSOURCE_DIR=. -DOUTPUT_DIR=$FOLDER_NAME -P git-version.cmake
fi
xcodebuild -project $FOLDER_NAME/PPSSPP.xcodeproj -scheme PPSSPP -configuration $CONFIGURATION -destination 'generic/platform=iOS Simulator' -quiet build
APP="$FOLDER_NAME/$CONFIGURATION-iphonesimulator/PPSSPP.app"
echo "Built $APP"
# Finds an existing simulator with the given name, on any runtime.
find_device() {
xcrun simctl list devices available | grep -F " $1 (" | head -1 | sed -E 's/.*\(([0-9A-F-]{36})\).*/\1/'
}
if [[ -z $DEVICE_NAME ]]; then
UDID=$(xcrun simctl list devices booted | grep -E -o '[0-9A-F-]{36}' | head -1)
if [[ -z $UDID ]]; then
# Newest device type the installed runtimes support. The newest type overall may have none.
DEVICE_NAME=$(xcrun simctl list devices available | sed -n '/^-- iOS/,/^-- [^i]/p' | grep -E '^ iPhone [0-9]+ Pro \(' | tail -1 | sed -E 's/^ (.*) \([0-9A-F-]{36}\).*/\1/')
fi
fi
if [[ -n $DEVICE_NAME ]]; then
UDID=$(find_device "$DEVICE_NAME")
if [[ -z $UDID ]]; then
echo "Creating a simulator: $DEVICE_NAME"
# Picks the newest runtime the device type supports.
UDID=$(xcrun simctl create "$DEVICE_NAME" "$DEVICE_NAME")
fi
fi
xcrun simctl boot "$UDID" 2>/dev/null || true
# The simulator UI: DeviceHub from Xcode 27, Simulator before that.
open -b com.apple.dt.Devices 2>/dev/null || open -a Simulator
xcrun simctl bootstatus "$UDID" -b > /dev/null
xcrun simctl install "$UDID" "$APP"
xcrun simctl launch --terminate-running-process "$UDID" $BUNDLE_ID
+7 -7
View File
@@ -2,6 +2,7 @@
#
# IOS_PLATFORM = OS (default)
# OS - the default, used to build for iPhone and iPad physical devices, which have an arm arch.
# SIMULATOR - the iOS simulator on Apple Silicon Macs (arm64).
#
# CMAKE_IOS_SDK_ROOT = automatic(default) or /path/to/platform/Developer/SDKs/SDK folder
# By default this location is automatcially chosen based on the CMAKE_IOS_DEVELOPER_ROOT value.
@@ -10,8 +11,8 @@
# PPSSPP platform flags
set(MOBILE_DEVICE ON)
# The compiler checks re-read this file without the cache, so pass IOS_APP_STORE on.
list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES IOS_APP_STORE)
# The compiler checks re-read this file without the cache, so pass these on.
list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES IOS_APP_STORE IOS_PLATFORM)
# The static MoltenVK in ios/MoltenVK needs 15.0.
set(IPHONEOS_DEPLOYMENT_TARGET 15.0)
add_definitions(-U__STRICT_ANSI__)
@@ -25,6 +26,9 @@ endif()
if(IOS_PLATFORM STREQUAL "TVOS")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mappletvos-version-min=${IPHONEOS_DEPLOYMENT_TARGET}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mappletvos-version-min=${IPHONEOS_DEPLOYMENT_TARGET}")
elseif(IOS_PLATFORM STREQUAL "SIMULATOR")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mios-simulator-version-min=${IPHONEOS_DEPLOYMENT_TARGET}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mios-simulator-version-min=${IPHONEOS_DEPLOYMENT_TARGET}")
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mios-version-min=${IPHONEOS_DEPLOYMENT_TARGET}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mios-version-min=${IPHONEOS_DEPLOYMENT_TARGET}")
@@ -80,11 +84,7 @@ set(CMAKE_IOS_SDK_ROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Location of the selecte
set(CMAKE_OSX_SYSROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Sysroot used for iOS support")
# set the architecture for iOS
if(IOS_PLATFORM STREQUAL "OS" OR IOS_PLATFORM STREQUAL "TVOS")
set(IOS_ARCH "arm64")
else()
set(IOS_ARCH "i386;x86_64")
endif()
set(IOS_ARCH "arm64")
set(CMAKE_OSX_ARCHITECTURES "${IOS_ARCH}" CACHE STRING "Build architecture for iOS")
set(CMAKE_ASM_FLAGS "" CACHE STRING "" FORCE)
+15
View File
@@ -95,6 +95,21 @@ library such as `/t:CoreUWP`), same MSBuild setup as above:
& $msbuild "UWP\PPSSPP_UWP.sln" /t:PPSSPP_UWP /p:Configuration=Debug /p:Platform=<platform> /m
```
## iOS simulator build
On an Apple Silicon Mac, `./b-ios-simulator.sh` builds the App Store variant for the iOS simulator
into `build-ios-sim/`, then installs and launches it. `./b-ios-simulator.sh "iPhone Duo"` runs it on a
simulator of that type (names from `xcrun simctl list devicetypes`), creating and booting one if
needed. Without a name it uses the booted simulator, or boots the newest iPhone. The script also
opens the simulator UI, which Xcode 27 calls DeviceHub (it replaced Simulator.app). Set
`CONFIGURATION=Release` for a release build.
`xcrun simctl io booted screenshot shot.png` saves a screenshot at the device's full resolution,
as App Store Connect wants it. To work in Xcode instead, `open build-ios-sim/PPSSPP.xcodeproj` and
pick a simulator as the run destination.
The simulator build renders with Metal only and doesn't link MoltenVK.
## Android assets
The APK's `assets/` directory is the repo-root `assets/` directory, wired up by