Name Date Size #Lines LOC

..--

BUILD.bazelH A D25-Apr-20252.9 KiB144126

README.rstH A D25-Apr-20252.3 KiB6344

asm.sH A D25-Apr-2025294 1611

cross_test.goH A D25-Apr-20252 KiB9269

def.bzlH A D25-Apr-2025860 2521

ios_select_test.goH A D25-Apr-20251.7 KiB6743

lib_darwin.goH A D25-Apr-202548 42

lib_linux.goH A D25-Apr-202547 42

lib_windows.goH A D25-Apr-202549 42

main.goH A D25-Apr-2025736 278

non_executable_test.goH A D25-Apr-20252.8 KiB10778

proto_test.goH A D25-Apr-20253.2 KiB12791

sdk_version_test.goH A D25-Apr-20252.9 KiB136108

README.rst

1Cross compilation
2=================
3
4.. _go_binary: /docs/go/core/rules.md#go_binary
5.. _go_library: /docs/go/core/rules.md#go_library
6.. _go_cross_binary: /docs/go/core/rules.md#go_cross_binary
7.. _#2523: https://github.com/bazelbuild/rules_go/issues/2523
8
9Tests to ensure that cross compilation is working as expected.
10
11.. contents::
12
13cross_test
14----------
15
16
17Tests that cross compilation controlled by the ``goos`` and ``goarch``
18attributes on a `go_binary`_ produces executables for the correct platform.
19
20This builds binaries using `main.go <main.go>`_ in multiple configurations, and
21then passes them as data to a test `written in go <cross_test.go>`_.
22
23The test executes the unix command "file" on the binaries to determine their
24type, and checks they were built for the expected architecture.
25
26The test also checks that `go_library`_ packages imoprted by `go_binary`_ with
27``goos`` set are built in the correct configuration, and ``select`` is applied
28in that configuration. Each binary depends on ``platform_lib``, which has a
29different source file (determined by ``select``) for each platform. The source
30files have a ``goos`` suffix, so they will only be built on the right platform.
31If the wrong source file is used or if all files are filtered out, the
32`go_binary`_ will not build.
33
34go_cross_test
35-------------
36
37Indentical test to ``cross_test`` except tests using a `go_cross_binary`_ rule wrapping a `go_binary`_ instead of the ``goos`` and ``goarch`` attributes on a `go_binary`_.
38
39sdk_version_test
40----------------
41Tests that a `go_binary`_ wrapped in a `go_cross_binary`_ rule, with the ``sdk_version`` attribute set, produces an executable built with the correct Go SDK version.
42
43ios_select_test
44---------------
45
46Tests that we can cross-compile a library for iOS. We should be able to select
47a dependency using ``@io_bazel_rules_go//go/platform:darwin``, which is true
48when building for iOS (tested by ``ios_select_test``) and macOS
49(tested by ``use_ios_lib``).
50
51proto_test
52----------
53
54Tests that a ``go_proto_library`` can be cross-compiled, both with
55``--platforms`` and with mode attributes.
56
57no_context_info
58---------------
59
60Tests that a rule that uses ``@io_bazel_rules_go//go:toolchain`` but does not
61depend on any other target can call ``go_context`` without error. Verifies
62`#2523`_.
63