summaryrefslogtreecommitdiff
path: root/rules/CC/proto/RULES
blob: 2e4b1d31ac0f21c0f94379f04234893f42cd6bfe (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
{ "defaults":
  { "doc":
    [ "A rule to provide protoc/GRPC defaults."
    , "Used to implement [\"CC/proto\", \"defaults\"] for CC proto libraries"
    , "and [\"CC/proto\", \"service defaults\"] for CC proto service libraries"
    , "(GRPC)."
    ]
  , "target_fields": ["base", "toolchain", "deps"]
  , "string_fields":
    [ "PROTOC"
    , "PROTOCFLAGS"
    , "ADD_PROTOCFLAGS"
    , "LDFLAGS"
    , "ADD_LDFLAGS"
    , "GRPC_PLUGIN"
    , "PATH"
    ]
  , "config_vars": ["ARCH", "HOST_ARCH", "DEBUG"]
  , "field_doc":
    { "base":
      [ "Other targets (using the same rule) to inherit values from. If"
      , "multiple targets are specified, for values that are overwritten (see"
      , "documentation of other fields) the last specified value wins."
      ]
    , "toolchain":
      [ "Optional toolchain directory. A collection of artifacts that provide"
      , "the protobuf compiler and the GRPC plugin (if needed). Note that only"
      , "artifacts of the specified targets are considered (no runfiles etc.)."
      , "Specifying this field extends artifacts from \"base\"."
      ]
    , "deps":
      [ "Optional CC libraries the resulting CC proto libraries implicitly"
      , "depend on. Those are typically \"libprotobuf\" for CC proto libraries"
      , "and \"libgrpc++\" for CC proto service libraries. Specifying this"
      , "field extends dependencies from \"base\"."
      ]
    , "PROTOC":
      [ "The proto compiler. If \"toolchain\" is empty, this field's value is"
      , "considered the proto compiler name that is looked up in \"PATH\". If"
      , "\"toolchain\" is non-empty, this field's value is assumed to be the"
      , "relative path to the proto compiler in \"toolchain\". Specifying this"
      , "field overwrites values from \"base\"."
      ]
    , "GRPC_PLUGIN":
      [ "The GRPC plugin for the proto compiler. If \"toolchain\" is empty,"
      , "this field's value is considered to be the absolute system path to the"
      , "plugin. If \"toolchain\" is non-empty, this field's value is assumed"
      , "to be the relative path to the plugin in \"toolchain\". Specifying"
      , "this field overwrites values from \"base\"."
      ]
    , "PROTOCFLAGS":
      [ "Protobuf compiler flags. Specifying this field overwrites values from"
      , "\"base\"."
      ]
    , "ADD_PROTOCFLAGS":
      [ "Additional protobuf compiler flags. Specifying this field extends"
      , "values from \"base\"."
      ]
    , "LDFLAGS":
      [ "Linker flags for linking the final CC library. Specifying this field"
      , "overwrites values from \"base\"."
      ]
    , "ADD_LDFLAGS":
      [ "Additional linker flags for linking the final CC library. Specifying"
      , "this field extends values from \"base\"."
      ]
    , "PATH":
      [ "Path for looking up the proto compiler. Individual paths are joined"
      , "with \":\". Specifying this field extends values from \"base\"."
      ]
    }
  , "config_doc":
    { "ARCH":
      [ "The unqualified architecture. Is taken as a default for \"HOST_ARCH\""
      , "and \"TARGET_ARCH\" if not set."
      ]
    , "HOST_ARCH":
      ["The architecture on which the build actions are carried out."]
    , "DEBUG": ["Compute the debug-stage, needed for local debugging."]
    }
  , "imports":
    { "base-provides": ["./", "..", "defaults-base-provides"]
    , "base-provides-++": ["./", "..", "defaults-base-provides-++"]
    , "base-provides-list": ["./", "..", "defaults-base-provides-list"]
    , "artifacts_list": ["", "field_artifacts_list"]
    , "nub_left": ["", "nub_left"]
    , "compile-deps": ["CC", "compile-deps"]
    , "compile-args-deps": ["CC", "compile-args-deps"]
    , "link-deps": ["CC", "link-deps"]
    , "link-args-deps": ["CC", "link-args-deps"]
    , "cflags-files-deps": ["CC", "cflags-files-deps"]
    , "ldflags-files-deps": ["CC", "ldflags-files-deps"]
    , "for host": ["transitions", "for host"]
    , "debug-deps": ["CC", "debug-deps"]
    }
  , "config_transitions":
    {"toolchain": [{"type": "CALL_EXPRESSION", "name": "for host"}]}
  , "expression":
    { "type": "let*"
    , "bindings":
      [ ["PROTOC", {"type": "FIELD", "name": "PROTOC"}]
      , ["PROTOCFLAGS", {"type": "FIELD", "name": "PROTOCFLAGS"}]
      , ["LDFLAGS", {"type": "FIELD", "name": "LDFLAGS"}]
      , ["GRPC_PLUGIN", {"type": "FIELD", "name": "GRPC_PLUGIN"}]
      , ["PATH", {"type": "FIELD", "name": "PATH"}]
      , ["provider", "PROTOC"]
      , [ "PROTOC"
        , { "type": "if"
          , "cond": {"type": "var", "name": "PROTOC"}
          , "then": {"type": "var", "name": "PROTOC"}
          , "else": {"type": "CALL_EXPRESSION", "name": "base-provides"}
          }
        ]
      , ["provider", "PROTOCFLAGS"]
      , [ "PROTOCFLAGS"
        , { "type": "if"
          , "cond": {"type": "var", "name": "PROTOCFLAGS"}
          , "then": {"type": "var", "name": "PROTOCFLAGS"}
          , "else": {"type": "CALL_EXPRESSION", "name": "base-provides-++"}
          }
        ]
      , ["provider", "LDFLAGS"]
      , [ "LDFLAGS"
        , { "type": "if"
          , "cond": {"type": "var", "name": "LDFLAGS"}
          , "then": {"type": "var", "name": "LDFLAGS"}
          , "else": {"type": "CALL_EXPRESSION", "name": "base-provides-++"}
          }
        ]
      , ["provider", "GRPC_PLUGIN"]
      , [ "GRPC_PLUGIN"
        , { "type": "if"
          , "cond": {"type": "var", "name": "GRPC_PLUGIN"}
          , "then": {"type": "var", "name": "GRPC_PLUGIN"}
          , "else": {"type": "CALL_EXPRESSION", "name": "base-provides"}
          }
        ]
      , ["provider", "PATH"]
      , [ "PATH"
        , { "type": "++"
          , "$1":
            [ {"type": "var", "name": "PATH"}
            , {"type": "CALL_EXPRESSION", "name": "base-provides-++"}
            ]
          }
        ]
      , [ "PATH"
        , { "type": "let*"
          , "bindings": [["list", {"type": "var", "name": "PATH"}]]
          , "body": {"type": "CALL_EXPRESSION", "name": "nub_left"}
          }
        ]
      , ["provider", "ENV"]
      , ["default", {"type": "empty_map"}]
      , ["ENV", {"type": "CALL_EXPRESSION", "name": "base-provides"}]
      , ["provider", "NON_SYSTEM_TOOLS"]
      , ["default", {"type": "empty_map"}]
      , [ "NON_SYSTEM_TOOLS"
        , { "type": "map_union"
          , "$1":
            { "type": "++"
            , "$1":
              [ [{"type": "CALL_EXPRESSION", "name": "base-provides"}]
              , { "type": "if"
                , "cond": {"type": "FIELD", "name": "PROTOC"}
                , "then":
                  [ { "type": "singleton_map"
                    , "key": "PROTOC"
                    , "value":
                      { "type": "if"
                      , "cond": {"type": "FIELD", "name": "toolchain"}
                      , "then": true
                      , "else": false
                      }
                    }
                  ]
                }
              , { "type": "if"
                , "cond": {"type": "FIELD", "name": "GRPC_PLUGIN"}
                , "then":
                  [ { "type": "singleton_map"
                    , "key": "GRPC_PLUGIN"
                    , "value":
                      { "type": "if"
                      , "cond": {"type": "FIELD", "name": "toolchain"}
                      , "then": true
                      , "else": false
                      }
                    }
                  ]
                }
              ]
            }
          }
        ]
      , ["provider", "TOOLCHAIN"]
      , ["default", {"type": "empty_map"}]
      , [ "TOOLCHAIN"
        , { "type": "disjoint_map_union"
          , "msg": "toolchain artifacts may not overlap"
          , "$1":
            { "type": "++"
            , "$1":
              [ {"type": "CALL_EXPRESSION", "name": "base-provides-list"}
              , { "type": "if"
                , "cond": {"type": "FIELD", "name": "toolchain"}
                , "then":
                  { "type": "let*"
                  , "bindings":
                    [ ["fieldname", "toolchain"]
                    , [ "transition"
                      , {"type": "CALL_EXPRESSION", "name": "for host"}
                      ]
                    ]
                  , "body":
                    {"type": "CALL_EXPRESSION", "name": "artifacts_list"}
                  }
                }
              ]
            }
          }
        ]
      , [ "PROTOCFLAGS"
        , { "type": "++"
          , "$1":
            [ {"type": "var", "name": "PROTOCFLAGS"}
            , {"type": "FIELD", "name": "ADD_PROTOCFLAGS"}
            ]
          }
        ]
      , [ "LDFLAGS"
        , { "type": "++"
          , "$1":
            [ {"type": "var", "name": "LDFLAGS"}
            , {"type": "FIELD", "name": "ADD_LDFLAGS"}
            ]
          }
        ]
      , ["deps-fieldnames", ["base", "deps"]]
      , ["compile-deps", {"type": "CALL_EXPRESSION", "name": "compile-deps"}]
      , [ "compile-args"
        , {"type": "CALL_EXPRESSION", "name": "compile-args-deps"}
        ]
      , ["link-deps", {"type": "CALL_EXPRESSION", "name": "link-deps"}]
      , ["link-args", {"type": "CALL_EXPRESSION", "name": "link-args-deps"}]
      , [ "cflags-files"
        , {"type": "CALL_EXPRESSION", "name": "cflags-files-deps"}
        ]
      , [ "ldflags-files"
        , {"type": "CALL_EXPRESSION", "name": "ldflags-files-deps"}
        ]
      , ["package", {"type": "env", "vars": ["cflags-files", "ldflags-files"]}]
      , [ "debug-srcs"
        , { "type": "if"
          , "cond": {"type": "var", "name": "DEBUG"}
          , "then":
            { "type": "let*"
            , "bindings": [["deps-provider", "debug-srcs"]]
            , "body": {"type": "CALL_EXPRESSION", "name": "debug-deps"}
            }
          , "else": {"type": "empty_map"}
          }
        ]
      , [ "debug-hdrs"
        , { "type": "if"
          , "cond": {"type": "var", "name": "DEBUG"}
          , "then":
            { "type": "map_union"
            , "$1":
              [ { "type": "let*"
                , "bindings": [["deps-provider", "debug-hdrs"]]
                , "body": {"type": "CALL_EXPRESSION", "name": "debug-deps"}
                }
              , {"type": "var", "name": "compile-deps"}
              ]
            }
          , "else": {"type": "empty_map"}
          }
        ]
      ]
    , "body":
      { "type": "RESULT"
      , "provides":
        { "type": "env"
        , "vars":
          [ "PROTOC"
          , "PROTOCFLAGS"
          , "LDFLAGS"
          , "GRPC_PLUGIN"
          , "PATH"
          , "ENV"
          , "TOOLCHAIN"
          , "NON_SYSTEM_TOOLS"
          , "compile-deps"
          , "compile-args"
          , "link-deps"
          , "link-args"
          , "package"
          , "debug-srcs"
          , "debug-hdrs"
          ]
        }
      }
    }
  }
, "library":
  { "doc":
    [ "A C++ library, generated from proto files."
    , ""
    , "This rule usually is used to bind anonymous targets generated from"
    , "proto libraries."
    ]
  , "string_fields": ["name", "stage"]
  , "target_fields": ["srcs", "deps"]
  , "config_vars": ["CXX", "CXXFLAGS", "ADD_CXXFLAGS", "AR", "ENV", "DEBUG"]
  , "implicit":
    {"defaults": [["./", "..", "defaults"]], "proto-defaults": ["defaults"]}
  , "imports": {"protoc-compile": "protoc-compile"}
  , "expression":
    { "type": "let*"
    , "bindings":
      [ ["name", {"type": "join", "$1": {"type": "FIELD", "name": "name"}}]
      , [ "stage"
        , { "type": "join"
          , "separator": "/"
          , "$1": {"type": "FIELD", "name": "stage"}
          }
        ]
      , ["public-fieldnames", ["deps", "proto-defaults"]]
      , ["private-fieldnames", ["deps", "proto-defaults"]]
      ]
    , "body": {"type": "CALL_EXPRESSION", "name": "protoc-compile"}
    }
  }
, "service library":
  { "doc":
    [ "A service C++ library, generated from proto files."
    , ""
    , "Calls protoc with gRPC plugin to additionally generate gRPC services"
    , "from proto libraries."
    ]
  , "string_fields": ["name", "stage"]
  , "target_fields": ["srcs", "deps"]
  , "config_vars": ["CXX", "CXXFLAGS", "ADD_CXXFLAGS", "AR", "ENV", "DEBUG"]
  , "implicit":
    { "defaults": [["./", "..", "defaults"]]
    , "proto-defaults": ["service defaults"]
    }
  , "imports": {"protoc-compile": "protoc-compile"}
  , "expression":
    { "type": "let*"
    , "bindings":
      [ ["service support", true]
      , ["name", {"type": "join", "$1": {"type": "FIELD", "name": "name"}}]
      , [ "stage"
        , { "type": "join"
          , "separator": "/"
          , "$1": {"type": "FIELD", "name": "stage"}
          }
        ]
      , ["public-fieldnames", ["deps", "proto-defaults"]]
      , ["private-fieldnames", ["deps", "proto-defaults"]]
      ]
    , "body": {"type": "CALL_EXPRESSION", "name": "protoc-compile"}
    }
  }
}