Changes between Version 18 and Version 19 of Building/CrossCompiling/iOS


Ignore:
Timestamp:
Aug 28, 2013 11:20:55 PM (2 years ago)
Author:
StephenBlackheath
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Building/CrossCompiling/iOS

    v18 v19  
    1515=== 2. Scripts ===
    1616
    17 The following scripts are maintained at [https://github.com/ghc-ios/ghc-ios-scripts]
    18 
    19 Place these scripts somewhere in your path:
    20 
    21 '''arm-apple-darwin10-gcc'''
    22 {{{
    23 #!/bin/sh
    24 
    25 TARGET_PLATFORM=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk
    26 TARGET_BIN="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin"
    27 
    28 TARGET_GCC=$TARGET_BIN/arm-apple-darwin10-llvm-gcc-4.2
    29 TARGET_CFLAGS="-isysroot $TARGET_PLATFORM -mcpu=cortex-a8 -mfpu=neon"
    30 
    31 allArgs=$@
    32 
    33 # Only need lipo when we're building object files
    34 if [[ "$allArgs" == *.o* ]]
    35 then
    36 # Find the filename
    37 fileName=$(echo "$allArgs" | sed 's|.*-o \([^.]*\)\.o.*|\1|')
    38 
    39 # Create filename variants for armV7 and armV7s
    40 fileNameForArmv7=$fileName-armv7
    41 fileNameForArmv7s=$fileName-armv7s
    42 
    43 # Call gcc twice, once for each architecture, outputting to our filename variants
    44 $TARGET_GCC $TARGET_CFLAGS "-march=armv7" ${allArgs//$fileName.o/$fileNameForArmv7.o}
    45 $TARGET_GCC $TARGET_CFLAGS "-march=armv7s" ${allArgs//$fileName.o/$fileNameForArmv7s.o}
    46 
    47 # Lipo the two filename variants together
    48 lipo $fileNameForArmv7.o $fileNameForArmv7s.o -create -output $fileName.o
    49 else
    50 # If not building object files, call regularly.
    51 exec $TARGET_GCC $TARGET_CFLAGS "$@"
    52 fi
    53 }}}
    54 
    55 '''arm-apple-darwin10-ld'''
    56 {{{
    57 #!/bin/sh
    58 
    59 TARGET_PLATFORM=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk
    60 TARGET_BIN="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin"
    61 
    62 TARGET_LD=$TARGET_BIN/ld
    63 TARGET_LDFLAGS="-L$TARGET_PLATFORM/usr/lib/"
    64 }}}
    65 
    66 '''arm-apple-darwin10-nm'''
    67 {{{
    68 #!/bin/sh
    69 
    70 TARGET_BIN="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin"
    71 
    72 TARGET_NM=$TARGET_BIN/nm
    73 exec $TARGET_NM "$@"
    74 }}}
    75 
    76 '''arm-apple-darwin10-cabal''' (not needed during the build, but useful afterwards)
    77 {{{
    78 #!/bin/sh
    79 exec cabal --with-ghc=arm-apple-darwin10-ghc --with-ghc-pkg=arm-apple-darwin10-ghc-pkg --with-ld=arm-apple-darwin10-ld \
    80 --configure-option=--host=arm-apple-darwin10 --host-arch=arm --host-os=ios \
    81 "$@"
    82 }}}
    83 
    84 '''i386-apple-darwin11-gcc'''
    85 {{{
    86 #!/bin/sh
    87 
    88 TARGET_PLATFORM=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/
    89 TARGET_BIN="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin"
    90 
    91 TARGET_GCC=$TARGET_BIN/i686-apple-darwin11-llvm-gcc-4.2
    92 TARGET_CFLAGS="-isysroot $TARGET_PLATFORM -march=i386"
    93 
    94 exec $TARGET_GCC $TARGET_CFLAGS "$@"
    95 }}}
    96 
    97 '''i386-apple-darwin11-ld'''
    98 {{{
    99 #!/bin/sh
    100 
    101 TARGET_PLATFORM=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk/
    102 TARGET_BIN="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin"
    103 
    104 TARGET_LD=$TARGET_BIN/ld
    105 TARGET_LDFLAGS="-L$TARGET_PLATFORM/usr/lib/ -arch i386"
    106 
    107 exec $TARGET_LD $TARGET_LDFLAGS "$@"
    108 }}}
    109 
    110 '''i386-apple-darwin11-nm'''
    111 {{{
    112 #!/bin/sh
    113 
    114 TARGET_BIN="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin"
    115 
    116 TARGET_NM=$TARGET_BIN/nm
    117 exec $TARGET_NM "$@"
    118 }}}
    119 
    120 '''i386-apple-darwin11-cabal''' (not needed during the build, but useful afterwards)
    121 {{{
    122 #!/bin/sh
    123 exec cabal --with-ghc=i386-apple-darwin11-ghc --with-ghc-pkg=i386-apple-darwin11-ghc-pkg --with-ld=i386-apple-darwin11-ld \
    124 --configure-option=--host=i386-apple-darwin11 \
    125 "$@"
    126 }}}
    127 
    128 Edit these scripts to ensure the platform version matches what you are compiling to in Xcode
     17You will need to check out the scripts at [https://github.com/ghc-ios/ghc-ios-scripts] and add the checked out directory to your PATH. You may need to edit these scripts if you are using a different iOS / iOS simulator platform version than the one the scripts are pointed at.
    12918
    13019=== 3. Check out GHC ===
     
    17362}}}
    17463
    175 === 6. Create an Xcode project ===
     64=== 6. Make sure your Cabal and cabal-install are new enough ===
     65
     66Some recent changes are needed for the cross-compiling stuff to work right. Type {{{cabal --version}}} to find out what you have. Cabal-1.17.0 is new enough.
     67
     68The easiest way to install the right version is to do this inside your ghc build directory:
     69
     70{{{
     71cd libraries/Cabal/Cabal/
     72cabal install
     73cd -
     74cd libraries/Cabal/cabal-install/
     75cabal install
     76}}}
     77
     78The ghc-ios-scripts directory you checked out earlier contains two wrappers called {{{arm-apple-darwin10-cabal}}} and {{{i386-apple-darwin11-cabal}}}. These will pass the right arguments to cabal, so you can do, for example:
     79
     80{{{
     81arm-apple-darwin10-cabal install network
     82}}}
     83
     84=== 7. Create an Xcode project ===
    17685
    17786Create a new skeleton Xcode project using the wizard, and make sure it runs on your device.
    17887
    179 === 7. Compile your Haskell code ===
     88=== 8. Compile your Haskell code ===
    18089
    18190Open a terminal and add {{{/usr/local/ghc-ios/bin:/usr/local/ghc-ios-sim/bin}}} to your {{{PATH}}} environment variable.
     
    222131This will create (in this example) '''haskell.a'''.
    223132
    224 === 8. Set up your Xcode project for Haskell ===
     133=== 9. Set up your Xcode project for Haskell ===
    225134
    226135Now configure it as follows:
     
    232141 * When you've compiled your Haskell code to a .a (e.g. '''haskell.a''') file, add it to the project anywhere in the hierarchy with '''Add files to (project)''' in the right-mouse button menu.
    233142
    234 === 9. Build and run ===
     143=== 10. Build and run ===
    235144
    236145Run the project again as usual, and Xcode will pick up the haskell.a file and your Haskell code should now run on your iOS device. Anything printed with putStrLn will appear in the Xcode runtime console.
     
    247156 * Packaging with the wrapper scripts and perhaps release of binaries of official ghc releases
    248157 * Would be nice to not have to disable dead-code removal. (Simon Marlow says "we have special hacks so that you don't have to disable dead-code removal on OS X, in the native code generator and (I presume) in the LLVM backend. Perhaps this just needs to be adapted to work on iOS too?")
    249  * Test cabal more, as there are likely to be some areas where cross-compiling isn't quite right yet
    250158 * Fix the copious link warnings
    251159 * Stop llvm generating an unnecessary 'bx lr' (return) instruction after the GHC calling convention (which is actually a goto)