Debian Codegraph @

bazel/platform/BUILD.bazel

raw
1 package(
2 default_applicable_licenses = ["//:license"],
3 )
4
5 licenses(["notice"])
6
7 # https://bazel.build/concepts/platforms-intro
8 # https://bazel.build/docs/platforms
9 platform(
10 name = "linux_x64_hermetic",
11 constraint_values = [
12 "@platforms//os:linux", # https://github.com/bazelbuild/platforms/blob/main/os/BUILD
13 "@platforms//cpu:x86_64", # https://github.com/bazelbuild/platforms/blob/main/cpu/BUILD
14 ":cgo_off", # Necessary to build on RBE.
15 ":use_hermetic_toolchain",
16 ],
17 # We specify exec_properties because we have an RBE instance that matches this platform.
18 # exec_properties specify some information that is passed along the Remote Execution API
19 # (REAPI) to the dispatcher which will use it to direct the request to the appropriate
20 # machine/worker, using the Remote Worker API (RWAPI).
21 # http://go/skolo-rbe
22 # These properties will be ignored when running locally, but we must specify them if we want
23 # the action cache to treat things built on a local Linux machine to be the same as built on
24 # a Linux RBE worker (which they should, assuming our hermetic toolchain *is* hermetic).
25 # See https://github.com/bazelbuild/bazel/blob/f28209df2b0ebeff1de0b8b7f6b9e215d890e753/src/main/java/com/google/devtools/build/lib/actions/ActionKeyCacher.java#L67-L73
26 # for how the exec_properties and execution platform impact the action cache.
27 # See this file for a list of the keys:
28 # https://github.com/bazelbuild/bazel-toolchains/blob/master/rules/exec_properties/exec_properties.bzl
29 exec_properties = {
30 "container-image": "docker://gcr.io/skia-public/rbe_linux@sha256:82e8a4c7d06c8f47bbc08ee899c4c03069af0f7f4d8c0d958a50a23d814405e6",
31 "OSFamily": "Linux",
32 "Pool": "gce_linux",
33 },
34 )
35
36 platform(
37 name = "mac_x64_hermetic",
38 constraint_values = [
39 "@platforms//os:macos",
40 "@platforms//cpu:x86_64",
41 ":cgo_off",
42 ":use_hermetic_toolchain",
43 ],
44 )
45
46 platform(
47 name = "mac_arm64_hermetic",
48 constraint_values = [
49 "@platforms//os:macos",
50 "@platforms//cpu:arm64",
51 ":cgo_off",
52 ":use_hermetic_toolchain",
53 ],
54 )
55
56 platform(
57 name = "windows_x64_hermetic",
58 constraint_values = [
59 "@platforms//os:windows",
60 "@platforms//cpu:x86_64",
61 ":cgo_off",
62 ":use_hermetic_toolchain",
63 ],
64 )
65
66 platform(
67 name = "host_with_hermetic_toolchain",
68 constraint_values = [
69 ":cgo_off", # Necessary to build locally (i.e. non-RBE builds).
70 ":use_hermetic_toolchain",
71 ],
72 parents = ["@local_config_platform//:host"],
73 )
74
75 platform(
76 name = "android_arm32",
77 constraint_values = [
78 "@platforms//os:android",
79 "@platforms//cpu:armv7",
80 ],
81 )
82
83 platform(
84 name = "android_arm64",
85 constraint_values = [
86 "@platforms//os:android",
87 "@platforms//cpu:arm64",
88 ],
89 )
90
91 # This platform covers only the ios hardware which is arm64.
92 # Simulator support if any will be a separate platform.
93 platform(
94 name = "ios",
95 constraint_values = [
96 "@platforms//os:ios",
97 "@platforms//cpu:arm64",
98 ],
99 )
100
101 # This constraint allows us to force Bazel to resolve our hermetic toolchain to build
102 # the target and not a default one (e.g. on the Linux RBE instance). We do this by
103 # adding the constraint to our platforms that describe the target we want Bazel to build for.
104 # https://bazel.build/reference/be/platform#constraint_setting
105 constraint_setting(name = "skia_hermetic_toolchain")
106
107 constraint_value(
108 name = "use_hermetic_toolchain",
109 constraint_setting = ":skia_hermetic_toolchain",
110 visibility = ["//visibility:public"],
111 )
112
113 # When added to a Bazel platform, this constraint has the effect of disabling cgo, meaning that
114 # the C++ compiler will never be invoked when building Go binaries.
115 #
116 # For context, when cgo is enabled, the C++ compiler will be involved when building Go binaries,
117 # even for pure builds (e.g. "bazel build //some:target --@rules_go//go/config:pure").
118 # Presumably this is because some parts of the Go stdlib are written in C. It is unclear to
119 # lovisolo@ whether disabling cgo means some parts of the Go stdlib become unavailable.
120 #
121 # We want to disable cgo because, for some unknown reason, the directory structure under which
122 # clang_trampoline_linux.sh is executed is slightly different when building Go-related C/C++ code.
123 # We previously worked around this issue by adding a special case to clang_trampoline_linux.sh
124 # where clang is invoked using a different path (see
125 # https://skia-review.googlesource.com/c/skia/+/791499/11/toolchain/linux_trampolines/clang_trampoline_linux.sh).
126 # Unfortunately this does not work under macOS because clang is not found anywhere in the directory
127 # tree under which clang_trampoline_mac.sh is invoked. By disabling cgo, we get rid of this problem
128 # altogether. Fortunately all our Go code still compiles without cgo.
129 #
130 # It is unclear whether this is a rules_go bug, or if there's something specific about our hermetic
131 # C++ toolchains (Linux and macOS) that is causing the build to fail when cgo is enabled.
132 #
133 # Note that the @rules_go//go/toolchain:cgo_off constraint is not well documented.
134 # lovisolo@ discovered this constraint because it was mentioned on some issues and PRs in the
135 # rules_go repository and some other places, namely:
136 #
137 # - https://github.com/bazelbuild/rules_go/issues/2115#issuecomment-507467744
138 # - https://github.com/bazelbuild/rules_go/issues/2591#issuecomment-670527288
139 # - https://github.com/aspect-build/bazel-lib/pull/289/files#diff-963e4331fa8afa39ffa09be04587bc2a66f8cbab3416842e1554a6825ee532ecR27
140 #
141 # Note also that there is an ongoing effort to make C++ toolchains optional in rules_go:
142 # https://github.com/bazelbuild/rules_go/pull/3390.
143 alias(
144 name = "cgo_off",
145 actual = "@rules_go//go/toolchain:cgo_off",
146 )