| 1 |
= Building iOS framework |
| 2 |
|
| 3 |
You can build Gauche as an iOS framework, so that you can evaluate |
| 4 |
Gauche code within iPhone and iPad app. This is still an experimental |
| 5 |
feature, so cross your fingers to proceed. |
| 6 |
|
| 7 |
Note: It doesn't mean you can build iPhone app with Gauche -- the |
| 8 |
created framework doesn't know anything about ObjC or other |
| 9 |
runtime on iOS, so although you can use most of Gauche functionalities |
| 10 |
including system functions, you can't create, say, `UIViewController` |
| 11 |
from Gauche code. We're working on that part and it would be a |
| 12 |
separate framework. |
| 13 |
|
| 14 |
1. Build and install Gauche on your macOS machine as usual. |
| 15 |
The build script for iOS needs the HEAD version of Gauche which |
| 16 |
is running on macOS. |
| 17 |
|
| 18 |
2. In `$(top_srcdir)`, run `src/cross-compile-ios.scm`: |
| 19 |
+ |
| 20 |
[source,console] |
| 21 |
---- |
| 22 |
$ gosh src/cross-compile-ios.scm |
| 23 |
---- |
| 24 |
+ |
| 25 |
This runs cross compiler for various arm architectures and |
| 26 |
x86 (for the emulator), link them together and put the resulting |
| 27 |
framework under `build-ios/Gauche-iOS-core.framework`. |
| 28 |
|
| 29 |
3. You can just copy `Gauche-iOS-core.framework` to wherever |
| 30 |
suits you. |
| 31 |
|
| 32 |
Now, the following steps are to use Gauche inside iOS app: |
| 33 |
|
| 34 |
1. In your App, add `Gauche-iOS-core.framework` in the framework |
| 35 |
section. You also need to add libraries Gauche depends on -- |
| 36 |
typically it's `libz` and `libiconv`. |
| 37 |
|
| 38 |
2. You have to call initialization routine before any other |
| 39 |
Gauche functions. We'd suggest to call it in ``AppDelegate``'s |
| 40 |
`application:didFinishLaunchingWithOptions`. You need these |
| 41 |
two imports near the beginning of `AppDelegate.m`. |
| 42 |
+ |
| 43 |
[source,objc] |
| 44 |
---- |
| 45 |
#import <Gauche-iOS-core/gauche.h> |
| 46 |
#import <Gauche-iOS-core/gauche/static.h> |
| 47 |
---- |
| 48 |
+ |
| 49 |
And in `application:didFinishLaunchingWithOptions` method, |
| 50 |
call: |
| 51 |
+ |
| 52 |
[source,objc] |
| 53 |
---- |
| 54 |
SCM_INIT_STATIC(); |
| 55 |
---- |
| 56 |
+ |
| 57 |
This sets up Gauche runtime. |
| 58 |
|
| 59 |
3. For other files, you only need to include `gauche.h`: |
| 60 |
+ |
| 61 |
[source,objc] |
| 62 |
---- |
| 63 |
#import <Gauche-iOS-core/gauche.h> |
| 64 |
---- |
| 65 |
+ |
| 66 |
And you can call Gauche API. |
| 67 |
+ |
| 68 |
NB: Gauche requires Gauche VM to be attached to the thread |
| 69 |
the Gauche API is called. If you're in a thread that iOS created, |
| 70 |
it's likely that there's no Gauche VM. You should call |
| 71 |
`Scm_AttachVM()` within the thread (but that feature is way less |
| 72 |
tested; expect some rough road.) |