xref: /aosp_15_r20/external/bazelbuild-rules_go/BUILD.bazel (revision 9bb1b549b6a84214c53be0924760be030e66b93a)
1load(
2    "//go/private/tools:lines_sorted_test.bzl",
3    "lines_sorted_test",
4)
5load(
6    "//go/private/rules:nogo.bzl",
7    "nogo",
8)
9load(
10    "//go/private/rules:info.bzl",
11    "go_info",
12)
13load(
14    "//go:def.bzl",
15    "TOOLS_NOGO",
16)
17load(
18    "//go/private:context.bzl",
19    "cgo_context_data",
20    "cgo_context_data_proxy",
21    "go_config",
22    "go_context_data",
23)
24load(
25    "//go/private/rules:stdlib.bzl",
26    "stdlib",
27)
28
29# gazelle:prefix github.com/bazelbuild/rules_go
30# gazelle:exclude tests
31# gazelle:exclude third_party
32# gazelle:exclude go/tools/builders
33# gazelle:exclude go/tools/coverdata
34# gazelle:exclude go/tools/fetch_repo
35# gazelle:exclude go/tools/windows-testrunner
36# gazelle:go_naming_convention import_alias
37
38# TODO(jayconrod): add a gazelle rule so gazelle can be run automatically.
39# It can't go here though, because it would break anything that depends on
40# rules_go but not Gazelle, including our own go_bazel_tests.
41
42stdlib(
43    name = "stdlib",
44    cgo_context_data = select({
45        "//go/platform:internal_cgo_off": None,
46        "//conditions:default": ":cgo_context_data",
47    }),
48    visibility = ["//visibility:public"],
49)
50
51# default_nogo is the nogo target that nogo references by default. It
52# does not analyze anything, which means no binary is built or run
53# at compile time.
54filegroup(
55    name = "default_nogo",
56    visibility = ["//visibility:public"],
57)
58
59# tools_nogo includes all of the analysis passes in
60# golang.org/x/tools/go/analysis/passes.
61# This is not backward compatible, so use caution when depending on this --
62# new analyses may discover issues in existing builds.
63nogo(
64    name = "tools_nogo",
65    visibility = ["//visibility:public"],
66    deps = TOOLS_NOGO,
67)
68
69# go_context_data collects build options and is depended on by all Go targets.
70# It may depend on cgo_context_data if CGo isn't disabled.
71go_context_data(
72    name = "go_context_data",
73    cgo_context_data = select({
74        "//go/platform:internal_cgo_off": None,
75        "//conditions:default": ":cgo_context_data",
76    }),
77    coverdata = "//go/tools/coverdata",
78    go_config = ":go_config",
79    nogo = "@io_bazel_rules_nogo//:nogo",
80    stdlib = ":stdlib",
81    visibility = ["//visibility:public"],
82)
83
84# cgo_context_data collects information about the C/C++ toolchain.
85# go_context_data depends if cgo is enabled in the target configuration.
86cgo_context_data(
87    name = "cgo_context_data",
88    visibility = ["//visibility:private"],
89)
90
91# cgo_context_data_proxy depends on cgo_context_data if cgo is enabled and
92# forwards its provider. Rule attributes may depend on this, since they cannot
93# use select.
94cgo_context_data_proxy(
95    name = "cgo_context_data_proxy",
96    actual = select({
97        "//go/platform:internal_cgo_off": None,
98        "//conditions:default": ":cgo_context_data",
99    }),
100    visibility = ["//visibility:public"],
101)
102
103# go_config collects information about build settings in the current
104# configuration. go_context_data depends on this so that rules don't need
105# to depend on all build settings directly.
106go_config(
107    name = "go_config",
108    amd64 = select({
109        "//go/constraints/amd64:v2": "v2",
110        "//go/constraints/amd64:v3": "v3",
111        "//go/constraints/amd64:v4": "v4",
112        # The default is v1.
113        "//conditions:default": None,
114    }),
115    cover_format = "//go/config:cover_format",
116    # Always include debug symbols with -c dbg.
117    debug = select({
118        "//go/private:is_compilation_mode_dbg": "//go/private:always_true",
119        "//conditions:default": "//go/config:debug",
120    }),
121    gc_goopts = "//go/config:gc_goopts",
122    gc_linkopts = "//go/config:gc_linkopts",
123    gotags = "//go/config:tags",
124    linkmode = "//go/config:linkmode",
125    msan = "//go/config:msan",
126    pure = "//go/config:pure",
127    race = "//go/config:race",
128    stamp = select({
129        "//go/private:stamp": True,
130        "//conditions:default": False,
131    }),
132    static = "//go/config:static",
133    strip = select({
134        "//go/private:is_strip_always": True,
135        "//go/private:is_strip_sometimes_fastbuild": True,
136        "//conditions:default": False,
137    }),
138    visibility = ["//visibility:public"],
139)
140
141lines_sorted_test(
142    name = "contributors_sorted_test",
143    size = "small",
144    cmd = "grep -v '^#' $< | grep -v '^$$' >$@",
145    error_message = "Contributors must be sorted by first name",
146    file = "CONTRIBUTORS",
147)
148
149lines_sorted_test(
150    name = "authors_sorted_test",
151    size = "small",
152    cmd = "grep -v '^#' $< | grep -v '^$$' >$@",
153    error_message = "Authors must be sorted by first name",
154    file = "AUTHORS",
155)
156
157# AUTHORS is used as an anchor point for the directory in tests and the
158# license can be consumed by depending projects.
159exports_files([
160    "AUTHORS",
161    "LICENSE.txt",
162])
163
164go_info()
165
166filegroup(
167    name = "all_files",
168    testonly = True,
169    srcs = [
170        "BUILD.bazel",
171        "WORKSPACE",
172        "//extras:all_files",
173        "//go:all_files",
174        "//proto:all_files",
175        "//third_party:all_files",
176    ],
177    visibility = ["//visibility:public"],
178)
179