Skip to content

Add iOS support#1084

Closed
whitequark wants to merge 14 commits intoocaml:trunkfrom
whitequark:trunk+ios
Closed

Add iOS support#1084
whitequark wants to merge 14 commits intoocaml:trunkfrom
whitequark:trunk+ios

Conversation

@whitequark
Copy link
Member

This is a cleaned-up Psellos patchset that I've rebased on top of 4.04 and now trunk (there weren't any conflicts when moving between 4.04 and trunk). It's been used in production for quite some time.

The PR is not as clean as it perhaps should be, commit messages and all, but I would like to get some initial feedback before spending more time on this.

iOS Porting Team and others added 13 commits March 6, 2017 08:19
EABI_APPLE, ARMv7s, configurable support for PIE.
PIC is now on if supported for the model.
This also includes:
 - workaround for the generation of jump tables in thumb mode
 - workaround for the generation of frametables
 - basic changes in arm.S
 - introduction of ldgaddr and ldladdr macros in arm.S which will
   be exploited later in the PIE patch
 - a little EABI fixup in arm.S: saving all FP regs where needed
   (EABI_APPLE is an EABI_HF variant)
  - on ARMv7s there are machine instructions
  - IOS defines __divsi3 and __modsi3 instead of __aeabi_idiv and
    __aeabi_imod, resp
The apple assembler does not understand some of pre-UAL mnemonics
This is a little bit tricky, as these conventions do not directly fit
to the framework (which doesn't support register pairs).
The workaround is that we pretend that the first two float args are
passed via d0 and d1, and that the single float result comes back in
d0. This is not the truth, but fits into the framework. In reality,
the float args go into r0/r1, r1/r2 or r2/r3, and are mixed with any
int or pointer args. The float result is in r0/r1. When we emit
the call instruction, we also emit additional code that moves
the floats from d0 and d1 to the register pairs (and potentially
also moves the integers away that are already there). After
returning from the call, the float, if any, is loaded into d0.
The price of this workaround: up to three additional moves per
extcall.
This only affects symbol literals. Jumps can be resolved by ld
(that's where PIE is simpler than PIC).
Only for add/sub we can handle negative immediates by inverting
the operation. (This is for all platforms, not only iOS.)
 - index immediates need a hash mark according to ARM
 - avoiding multi-statement C macros and using assembler macros
   instead
These instructions do not support  an immediate arg of #0 in
thumb mode. Replacing by a simple mov.
@shindere
Copy link
Contributor

shindere commented Mar 6, 2017 via email

@whitequark
Copy link
Member Author

GPR #182 is what I referred to as "Psellos patchset".

@shindere
Copy link
Contributor

shindere commented Mar 6, 2017 via email

@shindere
Copy link
Contributor

shindere commented Mar 6, 2017 via email

@whitequark
Copy link
Member Author

whitequark commented Mar 6, 2017

At first glance, it seems to me this PR does not include everything that
was included in PR#182, e.g. am I correct that commit
a755f51 has not been included in this
PR?

Yes. I did not alter the build system in any way because my method for producing cross-compilers is more robust, more flexible and doesn't need any build system hacks anyway. It is only my goal here to make OCaml mainline compatible with opam-cross-ios, just like the existing Android support is compatible with opam-cross-android; in neither case the configure script is helpful.

@mshinwell
Copy link
Contributor

One random remark: there are some changes relating to assembler directives which have to differ on various platforms. We should merge such changes into #756 , which is designed to abstract away from such things.

@whitequark
Copy link
Member Author

@mshinwell I'm fine with waiting until #756 lands.

@wokalski
Copy link

wokalski commented Mar 7, 2017

In your opam installation, you apply this patch. Should it be included in this PR?

@whitequark
Copy link
Member Author

@wokalski No. I've originally submitted it as #994, and then it was rejected in favor of #1022.

This was originally done in 5d02ca6, but subsequently clobbered
while adding the iOS port.
@damiendoligez damiendoligez modified the milestones: 4.06.0, 4.07-or-later Sep 29, 2017
@damiendoligez damiendoligez removed this from the consider-for-4.07 milestone Jun 5, 2018
@rauanmayemir
Copy link

Can this PR be re-rebased against trunk and if changes are not too significant maybe I could help with that in some way?
(Ideally, I want to be able to cross-compile for iOS using OCaml 4.07 and would appreciate any guidance. I'd be fine temporarily using a patch set on top of the release tag)

It looks like improved native debugger support is taking longer than originally planned, so maybe this could be merged in?

@rauanmayemir
Copy link

I managed to cherry-pick these commits on top of 4.07 branch and resolve the conflicts: https://github.com/esy-cross/ocaml/tree/4.07+ios.

Whether it's correct is entirely different matter, but my question is where do I go from there? ocaml-cross had extra configs to inject the correct toolchain and vars, this one doesn't.

@shindere
Copy link
Contributor

shindere commented Jan 21, 2019 via email

@shindere
Copy link
Contributor

shindere commented Jan 21, 2019 via email

@markghayden
Copy link

I had funded whitequark's effort to create opam-cross-ios. Last year, I brought opam-cross-ios up to 4.07.0 last year. It can be found here:

https://github.com/markghayden/ocaml/tree/4.07.0%2Bios

This is currently be used in large production software running 64-bit on IOS. I believe the 32-bit fixes were complete as well, but I don't think 32-bit is no longer relevant on IOS. If you have any questions about the patch, please feel free to contact me.

@rauanmayemir
Copy link

@markghayden This is wonderful! How did you make the config scripts for building to work? I.e Makefile.in files from opam-cross.package.

@whitequark
Copy link
Member Author

How did you make the config scripts for building to work? I.e Makefile.in files from opam-cross.package.

I looked at every #define, etc that OCaml needs and manually filled it in with the correct value for iOS.

@rauanmayemir
Copy link

Hey @whitequark, thanks for popping in!

I meant for 4.07 to work. I tried to follow your steps and make it work for version 4.07, but kept having '../boot/ocamlc is not a bytecode executable file'. I now suspect that I may have messed something up resolving git conflicts in mlp files.

I'll try this again with Mark's fork.

@shindere
Copy link
Contributor

shindere commented May 17, 2019 via email

@markghayden
Copy link

Mark Hayden (2019/05/05 19:35 -0700):
I had funded whitequark's effort to create opam-cross-ios. Last year, I brought opam-cross-ios up to 4.07.0 last year. It can be found here: https://github.com/markghayden/ocaml/tree/4.07.0%2Bios
Thanks a lot. Does it use the -with-target-bindir configure option? Do you have the project ot make it work with 4.08, too?

I'm not sure about -with-target-bindir. Please note that my work was based on Whitequark's patch who deserves 100% credit and upgrading to 4.07 was done as minimum change to his work.

I'd be very interested in learning more about this: the kind of applications this makes possible, how they are actually deployed on iOS devices and whether they have a graphical interface or not.

Sure; please see http://seaiq.com. This is marine navigation software used by pilot to bring ships in/out of ports. Like google maps for large ships. It has a graphical interface (OpenGL/ES). There is a free evaluation download and screenshots/videos on the web site. The apps are deployed to IOS devices via the Apple app store, similar to other apps. The Ocaml code is wrappered in a C API and then accessed on IOS via Objective C code (no Swift, which the software predated).

@shindere
Copy link
Contributor

shindere commented May 21, 2019 via email

@markghayden
Copy link

markghayden commented May 21, 2019 via email

@shindere
Copy link
Contributor

shindere commented May 21, 2019 via email

@markghayden
Copy link

markghayden commented May 21, 2019 via email

@XVilka
Copy link
Contributor

XVilka commented May 21, 2019

As a lighter (and faster) alternative would be to use OCaml-Vulkan + MoltenVK.

@markghayden
Copy link

markghayden commented May 21, 2019 via email

@dboris
Copy link

dboris commented Jun 23, 2019

@markghayden Does your 4.07.0+ios branch integrate with opam-cross-ios? How do you configure the build for a cross compiler?

@markghayden
Copy link

markghayden commented Jun 23, 2019 via email

@dboris
Copy link

dboris commented Jun 23, 2019

@markghayden Great. Thanks.
How do you deal with the following issue? Which version of Xcode works for you?

#=== ERROR while compiling ocaml-ios64.4.07.0 =================================#
# context     2.0.4 | macos/x86_64 | ocaml-base-compiler.4.07.0 | git+file:///Volumes/Mojave/Users/boris/src/ocaml/cross/opam-cross-ios
# path        ~/.opam/4.07.0/.opam-switch/build/ocaml-ios64.4.07.0
# command     ~/.opam/opam-init/hooks/sandbox.sh build make -j4 world
# exit-code   2
# env-file    ~/.opam/log/ocaml-ios64-24995-90b366.env
# output-file ~/.opam/log/ocaml-ios64-24995-90b366.out
### output ###
# [...]
# #define CAML_SYS_SYSTEM(command) system_os(command)
#                                  ^
# ./caml/misc.h:215:19: note: expanded from macro 'system_os'
# #define system_os system
#                   ^
# /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.4.sdk/usr/include/stdlib.h:195:6: note: 'system' has been explicitly marked unavailable here
# int      system(const char *) __DARWIN_ALIAS_C(system);
#          ^
# 1 error generated.
# make[1]: *** [sys.o] Error 1
# make[1]: *** Waiting for unfinished jobs....
# make: *** [coldstart] Error 2

@markghayden
Copy link

markghayden commented Jun 23, 2019 via email

@XVilka
Copy link
Contributor

XVilka commented Sep 20, 2019

Would be nice to rebase and reevaluate against 4.09 to target 4.10 if possible.

@shindere
Copy link
Contributor

shindere commented Sep 20, 2019 via email

@XVilka XVilka mentioned this pull request Oct 31, 2019
@EduardoRFS
Copy link
Contributor

EduardoRFS commented Apr 30, 2020

I would like to push this PR forward or open a new one if needed, perhaps it's possible to even get it for the next version, also it's possible to try to run the test suite on a jailbroken iPhone or on the iOS ARM emulator.

I rebased it to 4.08 and did some changes, so it's mostly this commit, there is also some unrelated changes on this branch and it still has some cleanup, but it's working.

Removed support to arm32

Even Apple seems to not support it anymore, and the last iPhone running 32bits is the iPhone 5c which is stuck on iOS 10

Use C macros

To clean up the patch, instead of using apple as it is using clang -c.

@wokalski
Copy link

This can be closed I suppose.

@nojb nojb closed this Jul 28, 2020
stedolan pushed a commit to stedolan/ocaml that referenced this pull request Mar 21, 2023
stedolan pushed a commit to stedolan/ocaml that referenced this pull request Mar 21, 2023
EmileTrotignon pushed a commit to EmileTrotignon/ocaml that referenced this pull request Jan 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.