github.com/bazelbuild/rules_go@v0.47.2-0.20240515105122-e7ddb9ea474e/BUILD.bazel (about)

     1  load(
     2      "//go:def.bzl",
     3      "TOOLS_NOGO",
     4  )
     5  load(
     6      "//go/private:context.bzl",
     7      "cgo_context_data",
     8      "cgo_context_data_proxy",
     9      "go_config",
    10      "go_context_data",
    11  )
    12  load(
    13      "//go/private/rules:info.bzl",
    14      "go_info",
    15  )
    16  load(
    17      "//go/private/rules:nogo.bzl",
    18      "nogo",
    19  )
    20  load(
    21      "//go/private/rules:stdlib.bzl",
    22      "stdlib",
    23  )
    24  load(
    25      "//go/private/tools:lines_sorted_test.bzl",
    26      "lines_sorted_test",
    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  
    42  stdlib(
    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.
    54  filegroup(
    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.
    63  nogo(
    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.
    71  go_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.
    86  cgo_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.
    94  cgo_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.
   106  go_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      arm = select({
   116          "//go/constraints/arm:5": "5",
   117          "//go/constraints/arm:6": "6",
   118          "//go/constraints/arm:7": "7",
   119          "//conditions:default": None,
   120      }),
   121      cover_format = "//go/config:cover_format",
   122      # Always include debug symbols with -c dbg.
   123      debug = select({
   124          "//go/private:is_compilation_mode_dbg": "//go/private:always_true",
   125          "//conditions:default": "//go/config:debug",
   126      }),
   127      gc_goopts = "//go/config:gc_goopts",
   128      gc_linkopts = "//go/config:gc_linkopts",
   129      gotags = "//go/config:tags",
   130      linkmode = "//go/config:linkmode",
   131      msan = "//go/config:msan",
   132      pgoprofile = "//go/config:pgoprofile",
   133      pure = "//go/config:pure",
   134      race = "//go/config:race",
   135      stamp = select({
   136          "//go/private:stamp": True,
   137          "//conditions:default": False,
   138      }),
   139      static = "//go/config:static",
   140      strip = select({
   141          "//go/private:is_strip_always": True,
   142          "//go/private:is_strip_sometimes_fastbuild": True,
   143          "//conditions:default": False,
   144      }),
   145      visibility = ["//visibility:public"],
   146  )
   147  
   148  lines_sorted_test(
   149      name = "contributors_sorted_test",
   150      size = "small",
   151      cmd = "grep -v '^#' $< | grep -v '^$$' >$@",
   152      error_message = "Contributors must be sorted by first name",
   153      file = "CONTRIBUTORS",
   154  )
   155  
   156  lines_sorted_test(
   157      name = "authors_sorted_test",
   158      size = "small",
   159      cmd = "grep -v '^#' $< | grep -v '^$$' >$@",
   160      error_message = "Authors must be sorted by first name",
   161      file = "AUTHORS",
   162  )
   163  
   164  # AUTHORS is used as an anchor point for the directory in tests and the
   165  # license can be consumed by depending projects.
   166  exports_files([
   167      "AUTHORS",
   168      "LICENSE.txt",
   169  ])
   170  
   171  go_info()
   172  
   173  filegroup(
   174      name = "all_files",
   175      testonly = True,
   176      srcs = [
   177          "BUILD.bazel",
   178          "MODULE.bazel",
   179          "WORKSPACE",
   180          "go.mod",
   181          "go.sum",
   182          "//extras:all_files",
   183          "//go:all_files",
   184          "//proto:all_files",
   185          "//third_party:all_files",
   186      ],
   187      visibility = ["//visibility:public"],
   188  )