...

Text file src/github.com/bazelbuild/rules_go/docs/go/core/cross_compilation.md

Documentation: github.com/bazelbuild/rules_go/docs/go/core

     1
     2## Cross compilation
     3
     4rules_go can cross-compile Go projects to any platform the Go toolchain
     5supports. The simplest way to do this is by setting the `--platforms` flag on
     6the command line.
     7
     8``` bash
     9$ bazel build --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 //my/project
    10```
    11
    12You can replace `linux_amd64` in the example above with any valid
    13GOOS / GOARCH pair. To list all platforms, run this command:
    14
    15``` bash
    16$ bazel query 'kind(platform, @io_bazel_rules_go//go/toolchain:all)'
    17```
    18
    19By default, cross-compilation will cause Go targets to be built in "pure mode",
    20which disables cgo; cgo files will not be compiled, and C/C++ dependencies will
    21not be compiled or linked.
    22
    23Cross-compiling cgo code is possible, but not fully supported. You will need to
    24[write a CROSSTOOL file] that describes your C/C++ toolchain. You'll need to
    25ensure it works by building `cc_binary` and `cc_library` targets with the
    26`--cpu` command line flag set. Then, to build a mixed Go / C / C++ project,
    27add `pure = "off"` to your `go_binary` target and run Bazel with `--cpu`
    28and `--platforms`.
    29

View as plain text