github.com/0xKiwi/rules_go@v0.24.3/tests/core/stdlib/stdlib_files.bzl (about)

     1  # Copyright 2018 The Bazel Authors. All rights reserved.
     2  #
     3  # Licensed under the Apache License, Version 2.0 (the "License");
     4  # you may not use this file except in compliance with the License.
     5  # You may obtain a copy of the License at
     6  #
     7  #    http://www.apache.org/licenses/LICENSE-2.0
     8  #
     9  # Unless required by applicable law or agreed to in writing, software
    10  # distributed under the License is distributed on an "AS IS" BASIS,
    11  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  # See the License for the specific language governing permissions and
    13  # limitations under the License.
    14  
    15  load("@io_bazel_rules_go//go:def.bzl", "go_context", "go_rule")
    16  load("@io_bazel_rules_go//go/private:providers.bzl", "GoStdLib")
    17  
    18  def _pure_transition_impl(settings, attr):
    19      return {"//go/config:pure": True}
    20  
    21  pure_transition = transition(
    22      implementation = _pure_transition_impl,
    23      inputs = ["//go/config:pure"],
    24      outputs = ["//go/config:pure"],
    25  )
    26  
    27  def _stdlib_files_impl(ctx):
    28      # When a transition is used, ctx.attr._stdlib is a list of Target instead
    29      # of a Target. Possibly a bug?
    30      libs = ctx.attr._stdlib[0][GoStdLib].libs
    31      runfiles = ctx.runfiles(files = libs)
    32      return [DefaultInfo(
    33          files = depset(libs),
    34          runfiles = runfiles,
    35      )]
    36  
    37  stdlib_files = rule(
    38      implementation = _stdlib_files_impl,
    39      attrs = {
    40          "_stdlib": attr.label(
    41              default = "@io_bazel_rules_go//:stdlib",
    42              providers = [GoStdLib],
    43              cfg = pure_transition,  # force recompilation
    44          ),
    45          "_whitelist_function_transition": attr.label(
    46              default = "@bazel_tools//tools/whitelists/function_transition_whitelist",
    47          ),
    48      },
    49  )