Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New host platform: iOS/iPadOS #74

Open
Spidy123222 opened this issue Mar 6, 2023 · 31 comments
Open

New host platform: iOS/iPadOS #74

Spidy123222 opened this issue Mar 6, 2023 · 31 comments
Labels
new platform support A problem when building or running on a platform we don't claim to support yet (see README)

Comments

@Spidy123222
Copy link

Spidy123222 commented Mar 6, 2023

It would be ideal and make sense to have a port for apple devices. iOS doesn't support 32bit apps and some apps that were great back then just no longer able to be ran. Games I wanted to play like minibash (toribash mobile) and geodefence no longer possible. You can sideload apps via things like AltStore and sidestore to install ipa's. If needed you can allow jit ability using a debugger which both these programs can use. There is automatic activation for those too called altkit and sidekit. It is early on project just wanted to mention, Has it been attempted to build this rust program to "aarch64-apple-ios"?

@hikari-no-yume
Copy link
Collaborator

hikari-no-yume commented Mar 6, 2023

iOS is still a very closed and locked-down platform, so even though I am an iOS user and I totally understand the appeal, I'm not very enthusiastic about the idea of trying to port to it, it would probably be a pain and not useful to many people in practice.

There's a bunch of practical hurdles right now… JIT might be possible via hacky setups, but I doubt dynarmic supports it, and I don't want to try to implement that myself. Then there would be some pain relating to getting OpenGL ES working, though that'll be solved when I eventually try to port this to Android, I guess.

@hikari-no-yume hikari-no-yume added the new platform support A problem when building or running on a platform we don't claim to support yet (see README) label Mar 6, 2023
@hikari-no-yume
Copy link
Collaborator

With that said, if the changes aren't too intrusive, I'm not going to stop someone if they want to try to port it and contribute the changes upstream. (Please don't fork the project though…)

@upintheairsheep
Copy link
Contributor

I thought you were saying to add support for emulating latest iOS apps, needs a title change.

@hikari-no-yume hikari-no-yume changed the title [Feature Request] Latest iOS/iPadOS support New host platform: iOS/iPadOS Mar 6, 2023
@Spidy123222
Copy link
Author

iOS is still a very closed and locked-down platform, so even though I am an iOS user and I totally understand the appeal, I'm not very enthusiastic about the idea of trying to port to it, it would probably be a pain and not useful to many people in practice.

There's a bunch of practical hurdles right now… JIT might be possible via hacky setups, but I doubt dynarmic supports it, and I don't want to try to implement that myself. Then there would be some pain relating to getting OpenGL ES working, though that'll be solved when I eventually try to port this to Android, I guess.

There is also stuff about iOS 17 having offical sideloading support. About arm64 jit, It requires swapping between w^x and r^x using a seperate thread to sync properly. You can look at how dolphiniOS and pojavlauncher does this. Currently helping (with info I don't develop apps but modify them usually) with getting citra to build on iOS which also uses dynarmic. From seeing their progress it's not fully done but seemed like person making emuthreeDS got jit portion working fast and is mostly just working on moltenvk stuff. This is great work btw and I bet other people will also try help out including maybe porting to iOS.

@hikari-no-yume
Copy link
Collaborator

Yeah I'm hoping the rumours of iOS opening up a bit, perhaps in response to EU pressure, are true. If that happens for real then of course I'll try to port to iOS.

@duckfromdiscord
Copy link

duckfromdiscord commented Sep 1, 2023

Has it been attempted to build this rust program to "aarch64-apple-ios"?

I am trying to do this right now, or at least to find out what the build issues are. Apologies for bumping an old issue but I would like to help if I can

@Spidy123222
Copy link
Author

Spidy123222 commented Sep 1, 2023

Has it been attempted to build this rust program to "aarch64-apple-ios"?

I am trying to do this right now, or at least to find out what the build issues are. Apologies for bumping an old issue but I would like to help if I can

It's completely fine. Infact I'm still interested as it essentially would start restoring 32bit app support for games. From my experience building with Linux and hearing others on iOS development on other emulators. You will have a bit of struggle using sdl2. Sdl2 does say it supports iOS so maybe just needs a bit of a touch up idk.

@hikari-no-yume
Copy link
Collaborator

I am trying to do this right now, or at least to find out what the build issues are. Apologies for bumping an old issue but I would like to help if I can

touchHLE tries to be platform-independent as much as possible. There's very little platform-specific code in touchHLE itself, and all the libraries used should work on multiple platforms. In theory, if you build it for iOS, the build should succeed with minimal tinkering.

The problem is just that iOS is a very locked-down target:

  • touchHLE relies on Dynarmic for the CPU emulation, and Dynarmic is a JIT compiler, but iOS doesn't allow normal apps to use JIT.
  • touchHLE currently uses 4GiB of virtual address space for the guest app's memory. iOS won't let you allocate that much. (It could be relatively easily changed to use, say, 1GiB, which might be small enough?)
  • iOS sandboxes file access, but in fairness so does Android, and the way iOS does it is much nicer for emulators, so this may be no big deal.

Also, touchHLE requires OpenGL ES 1.1 support. That's deprecated on modern iOS, but is it removed? Are new apps allowed to link to it?

@hikari-no-yume
Copy link
Collaborator

From my experience building with Linux and hearing others on iOS development on other emulators. You will have a bit of struggle using sdl2. Sdl2 does say it supports iOS so maybe just needs a bit of a touch up idk.

I don't know what SDL2 is like on iOS, but using it on Android has been a huge pain in certain ways, so I might know what you mean. iOS is a bit more normal of an OS compared to Android though, so I'd expect less issues overall with SDL2. SDL2 has to do some horrible things to work on Android that aren't necessary on iOS, I think.

@duckfromdiscord
Copy link

touchHLE relies on Dynarmic for the CPU emulation, and Dynarmic is a JIT compiler, but iOS doesn't allow normal apps to use JIT.

Yes. This is true and there isn't much we can do about this. We can enable JIT for certain apps for a limited amount of time using AltJIT/SideJIT/DirtyJIT. I'm personally hoping JIT is officially allowed by Apple within the next few years but who knows.

Also, touchHLE requires OpenGL ES 1.1 support. That's deprecated on modern iOS, but is it removed? Are new apps allowed to link to it?

I'm fairly certain OpenGL ES 1.1 is just fine. I was able to get 2.3 contexts thru SDL_GL_CreateContext just fine about a year ago.


Has it been attempted to build this rust program to "aarch64-apple-ios"?

I was able to compile most of the dependencies immediately, except for some issues with Rust-SDL2. See Rust-SDL2/rust-sdl2#1331 . I also got some issues with the OpenAL, STB and Dynarmic wrappers. The STB wrapper issue was fixed by changing the minimum iOS version from 7(?!?!) to 16 but I can't figure out how to trick the compiler and CMake into doing this automatically.

@Spidy123222
Copy link
Author

Spidy123222 commented Sep 1, 2023

I am trying to do this right now, or at least to find out what the build issues are. Apologies for bumping an old issue but I would like to help if I can

touchHLE tries to be platform-independent as much as possible. There's very little platform-specific code in touchHLE itself, and all the libraries used should work on multiple platforms. In theory, if you build it for iOS, the build should succeed with minimal tinkering.

The problem is just that iOS is a very locked-down target:

  • touchHLE relies on Dynarmic for the CPU emulation, and Dynarmic is a JIT compiler, but iOS doesn't allow normal apps to use JIT.

  • touchHLE currently uses 4GiB of virtual address space for the guest app's memory. iOS won't let you allocate that much. (It could be relatively easily changed to use, say, 1GiB, which might be small enough?)

  • iOS sandboxes file access, but in fairness so does Android, and the way iOS does it is much nicer for emulators, so this may be no big deal.

Also, touchHLE requires OpenGL ES 1.1 support. That's deprecated on modern iOS, but is it removed? Are new apps allowed to link to it?

iOS has not been limited to 1gb of addressing space in a long time. You could get 4gb of address space using a 4g ram device. There is also entitlements for people that can get a lot more via paid developer accounts on lower end devices (10+ on a iPhone 8 Plus for example which is 3gb ram). Dolphinios is a port of dolphin for example as it uses 8gb of address space. There was that limit so some developer halfed the needed address space as a hacky fastmem (no longer needed since softmmu exists now) which allowed 4gb ram devices to run it without jailbreak or added entitlements that needs a paid developer account.

Dynarmic has been ported to iOS a few times already via things like emuthreeds and other arm device based emulators. Even qemu has been ported via utm.

@Spidy123222
Copy link
Author

Spidy123222 commented Sep 1, 2023

touchHLE relies on Dynarmic for the CPU emulation, and Dynarmic is a JIT compiler, but iOS doesn't allow normal apps to use JIT.

Yes. This is true and there isn't much we can do about this. We can enable JIT for certain apps for a limited amount of time using AltJIT/SideJIT/DirtyJIT. I'm personally hoping JIT is officially allowed by Apple within the next few years but who knows.

Also, touchHLE requires OpenGL ES 1.1 support. That's deprecated on modern iOS, but is it removed? Are new apps allowed to link to it?

I'm fairly certain OpenGL ES 1.1 is just fine. I was able to get 2.3 contexts thru SDL_GL_CreateContext just fine about a year ago.


Has it been attempted to build this rust program to "aarch64-apple-ios"?

I was able to compile most of the dependencies immediately, except for some issues with Rust-SDL2. See Rust-SDL2/rust-sdl2#1331 . I also got some issues with the OpenAL, STB and Dynarmic wrappers. The STB wrapper issue was fixed by changing the minimum iOS version from 7(?!?!) to 16 but I can't figure out how to trick the compiler and CMake into doing this automatically.

The jit methods are enabled via debugger. Wasn't sure if you didn't know because of the libraries you mentioned like sidejit,altjit,dirtyjit. I am one of the people that helps develop sidestore (currently working on sidekit for auto debugging apps) and helped on jitstreamer.

Have you though of doing the tricks you mention in a shell script. Have you tried lower minimum iOS version like 15 or 14?

For dynarmic I might have to refer to somone for that but there is available info for it to work on iOS. You could join the discord us in sidestore hangout in to ask antique using dynarmic for emuthreeds. You can also directly contact me in sidestore discord with same name.

@duckfromdiscord
Copy link

Have you though of doing the tricks you mention in a shell script. Have you tried lower minimum iOS version like 15 or 14?

The issue is that I don't know how to set the minimum iOS version. The fix for the STB wrapper issue I was talking about came from me copy-pasting one of the commands CMake gave me and changing it. I don't know how to actually apply it to everything, and when I did run the command, Cargo & CMake didn't use that compiled result.

For dynarmic I might have to refer to somone for that but there is available info for it to work on iOS.

Yeah.

@Spidy123222
Copy link
Author

The issue is that I don't know how to set the minimum iOS version. The fix for the STB wrapper issue I was talking about came from me copy-pasting one of the commands CMake gave me and changing it. I don't know how to actually apply it to everything, and when I did run the command, Cargo & CMake didn't use that compiled result.

Did you manage to get around these issues? Also it's very likely you will need to modify those wrappers if you cannot get them working without touching them.

@duckfromdiscord
Copy link

Did you manage to get around these issues?

Sadly, no. Help would be appreciated 😅 CMake is a mystery to me

Also it's very likely you will need to modify those wrappers if you cannot get them working without touching them.

Probably true. Not quite sure how to go about this.

@Spidy123222
Copy link
Author

Did you manage to get around these issues?

Sadly, no. Help would be appreciated 😅 CMake is a mystery to me

Also it's very likely you will need to modify those wrappers if you cannot get them working without touching them.

Probably true. Not quite sure how to go about this.

I should be able to get you some help in discord. Since your username has discord in name I'm guessing you might have one. Join our hangout server as we have some emulator devs for iOS that could help out. This link expires in 1 day. I go by the same name. https://discord.gg/m6SDtvrG

@ciciplusplus
Copy link
Collaborator

ciciplusplus commented Jan 20, 2024

I have a working proof of concept on my branch here https://github.com/ciciplusplus/touchHLE/tree/tmp-ios
Demo video https://www.youtube.com/watch?v=f_wfLFaKgoE (orientation bug was fixed later)

I tested with Super Monkey Ball and Wolf3d
I can confirm that you need to have an attached debugger from Xcode to work.
(and also an Apple's dev account for running on a device)

GEUlCrAWkAAJQk4
GEUkq6OXkAEXGrK

P.S. rough explanation of how i get it working https://x.com/ciciplusplus/status/1748732428116517263?s=20

@Spidy123222
Copy link
Author

Spidy123222 commented Jan 21, 2024

I have a working proof of concept on my branch here https://github.com/ciciplusplus/touchHLE/tree/tmp-ios

Demo video https://www.youtube.com/watch?v=f_wfLFaKgoE (orientation bug was fixed later)

I tested with Super Monkey Ball and Wolf3d

I can confirm that you need to have an attached debugger from Xcode to work.

(and also an Apple's dev account for running on a device)

GEUlCrAWkAAJQk4

GEUkq6OXkAEXGrK

P.S. rough explanation of how i get it working https://x.com/ciciplusplus/status/1748732428116517263?s=20

Is there a reason you need paid developer account. It doesn't feel like such low end apps would use up more than what is needed for them to run with jit. Is this not related to extended virtual addressing? Also is there any special build instructions you need to build it? Also I'm sure you can get the app size smaller. I believe one time I saw somone built it and it had debug symbols with it.

What idevice is it. It could be possible your device just has low ammount of unified memory.

@duckfromdiscord
Copy link

I believe one time I saw somone built it and it had debug symbols with it.

Yeah, make sure to build the Rust project with --release.

@ciciplusplus
Copy link
Collaborator

I have a working proof of concept on my branch here https://github.com/ciciplusplus/touchHLE/tree/tmp-ios
Demo video https://www.youtube.com/watch?v=f_wfLFaKgoE (orientation bug was fixed later)
I tested with Super Monkey Ball and Wolf3d
I can confirm that you need to have an attached debugger from Xcode to work.
(and also an Apple's dev account for running on a device)
GEUlCrAWkAAJQk4
GEUkq6OXkAEXGrK
P.S. rough explanation of how i get it working https://x.com/ciciplusplus/status/1748732428116517263?s=20

Is there a reason you need paid developer account. It doesn't feel like such low end apps would use up more than what is needed for them to run with jit. Is this not related to extended virtual addressing? Also is there any special build instructions you need to build it? Also I'm sure you can get the app size smaller. I believe one time I saw somone built it and it had debug symbols with it.

What idevice is it. It could be possible your device just has low ammount of unified memory.


Is there a reason you need paid developer account.

I'm not aware of any other way to install a custom app on non-jailbroken device.

Also is there any special build instructions you need to build it?

There is a XCode project inside ios-host folder on my branch, it should be straightforward to build

Also I'm sure you can get the app size smaller.

Not my goal here. I need debug symbols anyway to debug crashes.

What idevice is it.

iPhone SE 1st gen, iOS 15.8

@Spidy123222
Copy link
Author

I'm not aware of any other way to install a custom app on non-jailbroken device.

People usually use AltStore, SideStore (I work on this project with others), sideloady.

Even then, Xcode can install apps without paid developer accounts. Just matters if you need certain entitlements. Extended virtual addressing is one of the entitlements that need paid developer accounts. Dynarmic on other iOS apps like limon which is a port of citra doesn't need it for example.

This was referenced Feb 25, 2024
@Spidy123222
Copy link
Author

Spidy123222 commented Apr 11, 2024

I have a working proof of concept on my branch here https://github.com/ciciplusplus/touchHLE/tree/tmp-ios Demo video https://www.youtube.com/watch?v=f_wfLFaKgoE (orientation bug was fixed later)

I tested with Super Monkey Ball and Wolf3d I can confirm that you need to have an attached debugger from Xcode to work. (and also an Apple's dev account for running on a device)

GEUlCrAWkAAJQk4 GEUkq6OXkAEXGrK

P.S. rough explanation of how i get it working https://x.com/ciciplusplus/status/1748732428116517263?s=20

so I managed to get a proper device as my last one has lots of troubles but seems to be fixed using a newer device to compile. so I am having an issue compiling your repo. essentially its missing a SDL2.Framework file and few other sdl files. trying to git recurse submodules as I notice dynarmic isn't getting pulled properly and doesn't seem to work anymore. any ideas?

Edit: I found I needed to manually download the dependencies as it wasn't being installed. It now gets stuck at compiling via rust.

fatal error: 'dynarmic/interface/A32/context.h' file not found
Edit2: I managed to find the file and just moved them and got past it. Compiling in cargo gives an error about not able to compile the app as it panicked at build.rs:92:74. I did update the branch to latest if that matters after a bit to see if it helped but no different outcome.

It's probably messed up, I can't get the exact commits for the dependancies which is likely the problem but not sure completely.

@hikari-no-yume
Copy link
Collaborator

The original repo for dynarmic no longer exists. There is a fork that we are using now. You may need to check out the fork.

@Spidy123222
Copy link
Author

The original repo for dynarmic no longer exists. There is a fork that we are using now. You may need to check out the fork.

Yeah I added that one in place since the latest touchHLE used it. I pretty much just did the default branch for all of them but did sdl2 branch for sdl.

@Spidy123222
Copy link
Author

Seems like iOS can have emulators on AppStore now. It's possible that it could get on AppStore if it was using an interpreter also. Their review stuff does mention providing files so would need to be homebrew. Retro console emulation is kinda broad in a way and idk if Apple considers old iOS games as retro console?

@hikari-no-yume
Copy link
Collaborator

Having a commercial relationship with Apple could be troublesome for a project like this. I don't think touchHLE will ever be on the App Store.

@Raypuia
Copy link

Raypuia commented May 9, 2024

Having a commercial relationship with Apple could be troublesome for a project like this. I don't think touchHLE will ever be on the App Store.

Would AltStore be an alternative?
It obviously doesn't need to be a paid app (which would make it a easy target for DMCA)

@Spidy123222
Copy link
Author

Having a commercial relationship with Apple could be troublesome for a project like this.

I could understand not wanting a relationship with Apple as the emulator emulates old iOS programs. I'm not sure exactly sure how it would be troublesome as they don't have any right to the touchHLE code unless I'm missing something here.

As mentioned above, there is using third party app marketplaces (eu only) like altstore pal but you will have to find a way to get around core technology fee (paid fee or like ads for getting around it). There's using sideloading stores like altstore global and SideStore's stores (connect is in beta rn) or just provide an ipa and people can deal with it themselves.

If it was planned to go any route, I would atleast try AppStore/testflight and if not being accepted for being an iOS 4 emulator or not a console emulator then go to any suggested stuff above.

@hikari-no-yume
Copy link
Collaborator

hikari-no-yume commented May 9, 2024

The EU version of AltStore is not really an alternative, for the same reason. That also requires me to have a commercial relationship with Apple due to the notarisation process.

@omagadsamsa
Copy link

The EU version of AltStore is not really an alternative, for the same reason. That also requires me to have a commercial relationship with Apple due to the notarisation process.

It’s not necessary to throw them into stores, just make a build with it. you can install sherry certificates install for 7 days

@Raypuia
Copy link

Raypuia commented May 10, 2024

If the fear of confronting Apple is a concern.
I think the only reasonable approach would be just giving a build and let the userbase figure out by themselves.
I mean, emulators and game source ports on iOS have existed for quite a while by "jailbreaking" devices.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new platform support A problem when building or running on a platform we don't claim to support yet (see README)
Projects
None yet
Development

No branches or pull requests

7 participants