aboutsummaryrefslogtreecommitdiff
path: root/third_party/emboss/docs.rst
blob: 1cabc8aaeb4ef4e7f7f5d7dc96071471feb45339 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
.. _module-pw_third_party_emboss:

======
Emboss
======
`Emboss <https://github.com/google/emboss>`_ is a tool for generating code to
safely read and write binary data structures.

The ``$dir_pw_third_party/emboss`` module provides an ``emboss_cc_library`` GN
template, defined in build_defs.gni, which generates C++ bindings for the given
Emboss source file. The Emboss source code needs to be provided by the user.

------------------
Configuring Emboss
------------------
The recommended way to include the Emboss source code is to add it as a
Git submodule:

.. code-block:: sh

   git submodule add https://github.com/google/emboss.git third_party/emboss/src

Next, set the GN variable ``dir_pw_third_party_emboss`` to the path of your Emboss
installation. If using the submodule path from above, add the following to the
``default_args`` of your project's ``.gn`` file:

.. code-block::

   dir_pw_third_party_emboss = "//third_party/emboss/src"

..
   inclusive-language: disable

Optionally, configure the Emboss defines documented at
`dir_pw_third_party_emboss/runtime/cpp/emboss_defines.h
<https://github.com/google/emboss/blob/master/runtime/cpp/emboss_defines.h>`_
by setting the ``pw_third_party_emboss_CONFIG`` variable to a config that
overrides the defines. By default, checks will use PW_DCHECK.

..
   inclusive-language: enable

------------
Using Emboss
------------
Let's say you've authored an Emboss source file at ``//some/path/to/my-protocol.emb``.
To generate its bindings, you can add the following to ``//some/path/to/BUILD.gn``:

.. code-block::

  import("$dir_pw_third_party/emboss/build_defs.gni")

  emboss_cc_library("protocol") {
    source = "my-protocol.emb"
  }

This generates a source set of the same name as the target, in this case "protocol".
To use the bindings, list this target as a dependency in GN and include the generated
header by adding ``.h`` to the path of your Emboss source file:

.. code-block::

  #include <some/path/to/protocol.emb.h>