github.com/ajguerrer/rules_go@v0.20.3/go/extras.rst (about)

     1  Extra rules
     2  ===========
     3  
     4  .. _`core go rules`: core.rst
     5  .. _go_repository: https://github.com/bazelbuild/bazel-gazelle/blob/master/repository.rst#go_repository
     6  .. _`gazelle documentation`: https://github.com/bazelbuild/bazel-gazelle/blob/master/README.rst
     7  .. _gazelle rule: https://github.com/bazelbuild/bazel-gazelle#bazel-rule
     8  .. _gomock_rule: https://github.com/jmhodges/bazel_gomock
     9  .. _golang/mock: github.com/golang/mock
    10  
    11  .. role:: param(kbd)
    12  .. role:: type(emphasis)
    13  .. role:: value(code)
    14  .. |mandatory| replace:: **mandatory value**
    15  
    16  This is a collection of helper rules. These are not core to building a go binary, but are supplied
    17  to make life a little easier.
    18  
    19  .. contents::
    20  
    21  -----
    22  
    23  gazelle
    24  -------
    25  
    26  This rule has moved. See `gazelle rule`_ in the Gazelle repository.
    27  
    28  gomock
    29  ------
    30  
    31  This rule allows you to generate mock interfaces with mockgen (from `golang/mock`_) which can be useful for certain testing scenarios. See  `gomock_rule`_ in the gomock repository.
    32  
    33  go_embed_data
    34  -------------
    35  
    36  ``go_embed_data`` generates a .go file that contains data from a file or a
    37  list of files. It should be consumed in the srcs list of one of the
    38  `core go rules`_.
    39  
    40  Before using ``go_embed_data``, you must add the following snippet to your
    41  WORKSPACE:
    42  
    43  .. code:: bzl
    44  
    45      load("@io_bazel_rules_go//extras:embed_data_deps.bzl", "go_embed_data_dependencies")
    46  
    47      go_embed_data_dependencies()
    48  
    49  
    50  ``go_embed_data`` accepts the attributes listed below.
    51  
    52  +----------------------------+-----------------------------+---------------------------------------+
    53  | **Name**                   | **Type**                    | **Default value**                     |
    54  +----------------------------+-----------------------------+---------------------------------------+
    55  | :param:`name`              | :type:`string`              | |mandatory|                           |
    56  +----------------------------+-----------------------------+---------------------------------------+
    57  | A unique name for this rule.                                                                     |
    58  +----------------------------+-----------------------------+---------------------------------------+
    59  | :param:`package`           | :type:`string`              | :value:`""`                           |
    60  +----------------------------+-----------------------------+---------------------------------------+
    61  | Go package name for the generated .go file.                                                      |
    62  +----------------------------+-----------------------------+---------------------------------------+
    63  | :param:`var`               | :type:`string`              | :value:`"Data"`                       |
    64  +----------------------------+-----------------------------+---------------------------------------+
    65  | Name of the variable that will contain the embedded data.                                        |
    66  +----------------------------+-----------------------------+---------------------------------------+
    67  | :param:`src`               | :type:`string`              | :value:`""`                           |
    68  +----------------------------+-----------------------------+---------------------------------------+
    69  | A single file to embed. This cannot be used at the same time as :param:`srcs`.                   |
    70  | The generated file will have a variable of type :type:`[]byte` or :type:`string` with the        |
    71  | contents of this file.                                                                           |
    72  +----------------------------+-----------------------------+---------------------------------------+
    73  | :param:`srcs`              | :type:`string`              | :value:`None`                         |
    74  +----------------------------+-----------------------------+---------------------------------------+
    75  | A list of files to embed. This cannot be used at the same time as :param:`src`.                  |
    76  | The generated file will have a variable of type :type:`map[string][]byte` or                     |
    77  | :type:`map[string]string` with the contents of each file.                                        |
    78  | The map keys are relative paths the files from the repository root.                              |
    79  | Keys for files in external repositories will be prefixed with :value:`"external/repo/"` where    |
    80  | "repo" is the name of the external repository.                                                   |
    81  +----------------------------+-----------------------------+---------------------------------------+
    82  | :param:`flatten`           | :type:`boolean`             | :value:`False`                        |
    83  +----------------------------+-----------------------------+---------------------------------------+
    84  | If :value:`True` and :param:`srcs` is used, map keys are file base names instead of relative     |
    85  | paths.                                                                                           |
    86  +----------------------------+-----------------------------+---------------------------------------+
    87  | :param:`unpack`            | :type:`boolean`             | :value:`False`                        |
    88  +----------------------------+-----------------------------+---------------------------------------+
    89  | If :value:`True`, sources are treated as archives and their contents will be stored. Supported   |
    90  | formats are `.zip` and `.tar`.                                                                   |
    91  +----------------------------+-----------------------------+---------------------------------------+
    92  | :param:`string`            | :type:`boolean`             | :value:`False`                        |
    93  +----------------------------+-----------------------------+---------------------------------------+
    94  | If :value:`True`, the embedded data will be stored as :type:`string` instead of :type:`[]byte`.  |
    95  +----------------------------+-----------------------------+---------------------------------------+