aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: 420c0ba5a545a693e3645584d3d28d06185fab21 (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
# nimpb_build

**NOTE** nimpb_build is still experimental :-)

A tool for generating suitable Nim code for
[nimpb](https://github.com/oswjk/nimpb). It uses a prebuilt and bundled protoc
compiler. This tool supports the following platforms:

- Linux x86_32
- Linux x86_64
- Linux aarch_64
- OSX x86_64
- Windows

nimpb_build is modeled somewhat after [prost-build](https://github.com/danburkert/prost).

# Install with Nimble

    $ nimble install https://github.com/oswjk/nimpb_build

# Usage

## As a binary

Using the tool is simple:

    $ nimpb_build -I. --out=. my.proto

It's almost like using protoc directly. In fact, the arguments are basically
passed along to protoc.

You can specify nimpb_build as a dependency for your project in your .nimble
file and create a task for generating code:

    requires "nimpb_build"

    task proto, "Process .proto files":
        exec "nimpb_build -I. --out=. my.proto"

## As a library

It's also possible to use nimpb_build as a library:

```nim
import nimpb_build

let protos = @["my.proto"]
let incdirs = @["."]
let outdir = "."

compileProtos(protos, incdirs, outdir)
```

# How it works

nimpb_build invokes the protoc compiler with `--descriptor_set_out` parameter,
which makes protoc output a `FileDescriptorSet` (defined [here](src/nimpb_buildpkg/protobuf/include/google/protobuf/descriptor.proto)) into a file. nimpb_build then reads and parses the file,
and generates Nim code from the parsed definitions.