github.com/sercand/please@v13.4.0+incompatible/docs/cross_compiling.html (about)

     1  <h1>Cross-compiling</h1>
     2  
     3  <p class="experimental">This feature is still experimental; some aspects may not work fully
     4    or at all just yet. Proceed with caution!</p>
     5  
     6  <p>From v12.2 onwards, Please has limited cross-compiling support. This allows you to
     7    instruct it to build outputs for other architectures alongside the host architecture.<br/>
     8    This is triggered by passing the <code>--arch</code> flag when invoking plz.</p>
     9  
    10  <p>The outputs from a cross-compiled build will be in a directory under plz-out prefixed
    11    with the architecture - e.g. <code>plz-out/bin/linux_x86</code>,
    12    <code>plz-out/gen/darwin_amd64</code> etc.</p>
    13  
    14  <h3>Technical notes</h3>
    15  
    16  <p>When compiling a target for a different binary, the BUILD file will be re-parsed for it.
    17    The <code>CONFIG.ARCH</code> and <code>CONFIG.OS</code> properties will update appropriately,
    18    which is necessary for some rules to work correctly. Similarly, when the rule builds, the
    19    <code>OS</code> and <code>ARCH</code> environment variables will be set to the target architecture
    20    for that build target.</p>
    21  
    22  <p>The distinction between <code>srcs</code>, <code>tools</code> and <code>deps</code> is
    23    <b>extremely</b> important when cross-compiling. <code>srcs</code> always match the architecture
    24    of the target, as do <code>deps</code> unless explicitly requested (e.g. by prefixing with
    25    the required arch, as in <code>@linux_x86//package:target</code>).<br/>
    26    Conversely, <code>tools</code> always use the host architecture since they are executed on
    27    the host during the build.</p>
    28  
    29  <p>The <a href="config.html">config file</a> for any target architecture is read
    30    (if present) and applied for targets compiling for that architecture - i.e.
    31    <code>.plzconfig_linux_x86</code> etc. Typically you will need to create this file and
    32    modify appropriate settings for compiler flags etc.</p>
    33  
    34  <p>Architectures are currently always two-part tags in a similar format to Go's - i.e.
    35    <code>linux_amd64</code> etc. These are passed in as a single flag but decomposed into
    36    separate OS and architecture parts for later operations. You can request whatever architecture
    37    you want, but obviously the build will probably not succeed unless you have tools set up etc.</p>
    38  
    39  <h3>Language status</h3>
    40  
    41  <p>The various builtin languages have differing levels of support. Currently they are as follows:
    42    <ul>
    43      <li><b>C</b> & <b>C++</b>: Works at least for basic cases; there is an example in the
    44        <a href="https://github.com/thought-machine/please/tree/master/test/cross_compile">Please repo</a>
    45        which tests a simple amd64 -> x86 compilation.<br/>
    46        You will need to alter the config file to make this work - see the
    47        <a href="https://github.com/thought-machine/please/blob/master/.plzconfig_linux_x86">example for x86</a>
    48        for some examples of the settings to change.<br/>
    49        So far this has not been tested in anger on a more complex setup.</li>
    50      <li><b>Go</b>: Generally works, but you currently have to have a copy of the standard
    51        library available for the target architecture. Go can produce that via something like
    52        <code>GOOS="linux" GOARCH="386" go install -i std</code>.</li>
    53      <li><b>Python</b>: Currently has very limited support. Theoretically it will mostly work
    54        for pure Python; for binary modules built locally they'll need a similar approach to C.<br/>
    55        For third-party binary modules <a href="lexicon.html#pip_library">pip_library</a> is unlikely
    56        to work since pip can't be instructed to use a different architecture;
    57        <a href="lexicon.html#python_wheel">python_wheel</a> should be fine but requires something else
    58        to have built & hosted the .whl file.</li>
    59      <li><b>Java</b>: This is not terribly relevant to Java since it effectively always targets
    60        the same JVM architecture. <a href="lexicon.html#maven_jar">maven_jar</a> rules that
    61        specify <code>native = True</code> will download for the target architecture.</li>
    62    </ul>
    63  </p>