Docs / BuckleScript / BuildAdvanced

Build System: Advanced

Customize Rules (Generators Support)

You might use some pre-processor to generate boilerplate code during development.

Note: pre-processors can be classified as two categories:

  • System-dependent, which should be delayed until running on user machines.

  • System-independent: lex, yacc, m4, re2c, etc, which can be executed any time.

BS has built in support for conditional compilation, which satisfies the first point. This section is about the second point.

An example, where bsb uses ocamlyacc:

JSON
{ "generators" : [ { "name" : "ocamlyacc", "command": "ocamlyacc $in" } ], "sources" : { "dir" : "src", "generators" : [ { "name" : "ocamlyacc", "edge" : ["test.ml", "test.mli", ":", "test.mly"] } ] } }

ocamlyacc will generate the artifacts test.ml and test.mli in the same directory than test.mly.

Note: we highly recommend you to check in the generated files, since this cuts out dependencies like ocamlyacc for the end-users.

When developing a project, bsb will track the dependencies between test.ml and test.mly properly. When released as a package, bsb will cut such dependency, so that users will only need the generated test.ml. To help test such behavior in development mode, users could set it manually:

JSON
{ "cut-generators" : true }

This prevents bsb from regenerating test.ml whenever test.mly changes.