This feature is still experimental; some aspects may not work fully or at all just yet. Proceed with caution!

From v12.2 onwards, Please has limited cross-compiling support. This allows you to instruct it to build outputs for other architectures alongside the host architecture.
This is triggered by passing the --arch flag when invoking plz.

The outputs from a cross-compiled build will be in a directory under plz-out prefixed with the architecture - e.g. plz-out/bin/linux_x86, plz-out/gen/darwin_amd64 etc.

Technical notes

When compiling a target for a different binary, the BUILD file will be re-parsed for it. The CONFIG.ARCH and CONFIG.OS properties will update appropriately, which is necessary for some rules to work correctly. Similarly, when the rule builds, the OS and ARCH environment variables will be set to the target architecture for that build target.

The distinction between srcs, tools and deps is extremely important when cross-compiling. srcs always match the architecture of the target, as do deps unless explicitly requested (e.g. by prefixing with the required arch, as in @linux_x86//package:target).
Conversely, tools always use the host architecture since they are executed on the host during the build.

The config file for any target architecture is read (if present) and applied for targets compiling for that architecture - i.e. .plzconfig_linux_x86 etc. Typically you will need to create this file and modify appropriate settings for compiler flags etc.

Architectures are currently always two-part tags in a similar format to Go's - i.e. linux_amd64 etc. These are passed in as a single flag but decomposed into separate OS and architecture parts for later operations. You can request whatever architecture you want, but obviously the build will probably not succeed unless you have tools set up etc.

Language status

The various builtin languages have differing levels of support. Currently they are as follows:

  • C & C++: Works at least for basic cases; there is an example in the Please repo which tests a simple amd64 -> x86 compilation.
    You will need to alter the config file to make this work - see the example for x86 for some examples of the settings to change.
    So far this has not been tested in anger on a more complex setup.
  • Go: Generally works, but you currently have to have a copy of the standard library available for the target architecture. Go can produce that via something like GOOS="linux" GOARCH="386" go install -i std.
  • Python: Currently has very limited support. Theoretically it will mostly work for pure Python; for binary modules built locally they'll need a similar approach to C.
    For third-party binary modules pip_library is unlikely to work since pip can't be instructed to use a different architecture; python_wheel should be fine but requires something else to have built & hosted the .whl file.
  • Java: This is not terribly relevant to Java since it effectively always targets the same JVM architecture. maven_jar rules that specify native = True will download for the target architecture.