Packages

rebar3 plugin wrapping the thrift_generator IDL compiler

Current section

Files

Jump to
rebar3_thrift README.md
Raw

README.md

# rebar3_thrift

A rebar3 plugin that runs the
[`thrift_generator`](https://hex.pm/packages/thrift_generator) IDL
compiler over the Thrift IDL files declared in your `rebar.config` and
keeps the generated Erlang sources fresh. The generated code depends
on [`thrift_runtime`](https://hex.pm/packages/thrift_runtime) — add it
to your deps.

## Install

```erlang
%% rebar.config
{plugins, [rebar3_thrift]},
{deps, [thrift_runtime]},
{thrift, [
    {files, ["src/my_api.thrift"]},  %% required, one or more IDL files
    {out_dir, "src"}                 %% optional, default "src"
]}.
```

## Commands

- **`rebar3 thrift`** — (re)generate the Erlang sources for every
  declared IDL file. Files whose content is already up to date are
  left untouched, so regenerating an unchanged IDL does not churn
  mtimes. To generate before every compilation, hook it in your
  `rebar.config`:
  `{provider_hooks, [{pre, [{compile, {default, thrift}}]}]}`.
- **`rebar3 thrift --check`** — verify instead of write: fails when
  any generated artifact is missing or stale relative to its IDL — a
  freshness gate for CI.
- **`rebar3 thrift clean`** — delete generated files from the out
  dir: every `.erl`/`.hrl` carrying the generator's autogenerated
  banner, so files orphaned by a removed service or a deleted IDL go
  too. Hook into cleanup with
  `{provider_hooks, [{post, [{clean, {thrift, clean}}]}]}`.

Four optional option axes in `{thrift, [...]}` mirror the generator's
CLI flags and apply only where the IDL carries no explicit annotation
of its own: `{repr, record | map | native}`,
`{union_type, record | sum}`, `{set, list | sets | ordset}`,
`{typedef_type, alias | nominal}`.

See the [repository README](https://github.com/kpy3/thrift-erl) for
the full story.

## License

Apache-2.0 — see
[LICENSE.md](https://github.com/kpy3/thrift-erl/blob/master/LICENSE.md).