Changes between Version 23 and Version 24 of CrossCompilation


Ignore:
Timestamp:
Jan 18, 2013 9:17:36 AM (3 years ago)
Author:
simonmar
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • CrossCompilation

    v23 v24  
    11= Cross Compiling GHC =
    22
    3 As of this moment (GHC 7.0) GHC does not support cross-compilation. This page is to gather information and plans it.  See also [wiki:Building/Porting].
     3This page contains the design notes for cross compilation.  For instructions on how to actually do it, see [wiki:Building/CrossCompiling].
     4
     5Support for cross-compilation works reasonably well in 7.8.1.  Previous versions had various issues which are usually work-aroundable.
    46
    57== General Problem ==
     
    1618   * Other porting tasks might be easier, given a suitable cross-compilation toolchain.
    1719
    18 From the developer's perspective, these can be categorized as:
    19  * '''Cross-compiler''': B = H, and H ≠ T.
    20  * '''Cross-building''': B ≠ H, and H = T.
    21 
    2220It seems reasonable to limit ourselves to these two cases.
    2321
     
    3331 * '''Stage 2''': the final GHC built, compiled by the Stage 1 GHC, and linked with only the install libs
    3432
    35 In summary:
     33One way we could have done this is:
    3634
    3735||               ||'''Stage 0''' || '''libs boot''' || '''Stage 1''' || '''libs install''' || '''Stage 2''' ||
     
    4038||'''targets'''  ||''build''     || ---             || ''host''      || ---                || ''target''    ||
    4139
    42 Because of the way the compiler is configured (same configuration for Stage 1 and Stage 2), and the way the install libraries are built (built with Stage 1, but shipped with Stage 2), you can see that both Stage 1 and Stage 2 compilers must target the same architecture. Furthermore, the build only allows for probing for the properties (word size, library function availability, etc...) of one platform. This means that the build isn't as general as one might expect, and what we really have is:
     40But that isn't terribly useful, because if ''host'' /= ''target'', then libs-install can't be used with the stage 2 compiler.  Furthermore, the build only allows for probing for the properties (word size, library function availability, etc...) of one platform.  So this setup would not support ''host'' /= ''target''.  To cross-compile you would set ''host'' to something different from ''build''.
     41
     42An alternative way to set it up is:
    4343
    4444||               ||'''Stage 0''' || '''libs boot''' || '''Stage 1''' || '''libs install''' || '''Stage 2''' ||
    4545||'''built on''' || ---          || ''build''       || ''build''     || ''build''          || ''build''     ||
    46 ||'''runs on'''  ||''build''     || ''build''       || ''build''     || ''target''         || ''target''    ||
     46||'''runs on'''  ||''build''     || ''build''       || ''host''      || ''target''         || ''target''    ||
    4747||'''targets'''  ||''build''     || ---             || ''target''    || ---                || ''target''    ||
    4848
    49 But this works out just fine for the two use cases we've identified:
     49Which is actually equivalent, but it makes ''target'' the platform you set (which is more natural, we expect to set ''target'' when configuring a cross-compiler).  In this setup, ''build'' must equal ''host'', because we must be able to run the stage 1 compiler to compile libs-install.
     50
     51This works out just fine for the two use cases we've identified:
    5052
    5153 * '''Cross-compiler''': a Stage 1 compiler & libs install
    5254 * '''Cross-building''': a Stage 2 compiler & libs install
    5355
    54 The build plan becomes:
    55 
    56  * '''Cross-compiler'''
    57    * Developer configures with B = H, and H ≠ T:[[BR]]`$ ./configure --target=`''other-platform''
    58    * Build though Stage 1 and libs install
    59    * Package Stage 1 GHC and libs install as the desired cross-compiler
    60  * '''Cross-build'''
    61    * Developer configures with B ≠ H, and H = T:[[BR]]`$ ./configure --host=`''other-platform''` --target=`''other-platform''
    62    * Internally, set H to B, so that we have B = H, and H ≠ T as required
    63    * Build through libs install and Stage 2
    64    * Package Stage 2 GHC and libs install as the desired cross-compiler
    65 
    66 Thus, as far as the mechanics of the build are concerned, the two use cases are actually handled the same once the B/H/T variables are normalized. The only real difference is when to stop (before or after Stage 2), and which compiler gets bundled as the installed compiler (Stage 1 or Stage 2).
    67 
    68 From here on out, this page assumes that the B/H/T variables have been normalized. That is B = H, and H ≠ T.
     56And both setups start by configuring with ''target'' set to the target platform.
    6957
    7058== Tool-chains ==
     
    7563
    7664== Autoconf ==
     65
     66(this is slightly out of date now --SDM 18 Jan 2013)
    7767
    7868Autoconf offers only limited support for cross compiling. While it professes to know about three platforms, base, host, and target; it knows only about one tool-chain. It uses that tool-chain to determine two classes of information: Information about how to use the tool-chain itself, and information about the target of that tool-chain. Hence, in the cross-compilation case, it makes sense for ./configure to be told about XT.
     
    112102
    113103
    114 == Things that probably need fixing ==
    115 
    116  * We can't build anything with stage2 when cross-compiling, e.g. Haddock and DPH must be disabled.
    117 
    118 
    119 -----
    120104== Status ==
    121105
     
    138122Cross-compiling is almost working in HEAD for 7.7.  Check the mailing list for patches that make it work (at least for some platforms).
    139123
     124=== Jan 2013: Simon Marlow ===
     125I've done some cleanup of the build system, fixed some problems, and created the user instructions [wiki:Building/CrossCompiling].
     126
     127Cross-compiling is working smoothly in at least one setup (Linux/x86_64 to Linux/armv6 unregisterised (Raspberry Pi))
     128
    140129-----
    141130== Questions ==