Skip to content

Files

Latest commit

d343457 · Apr 10, 2024

History

History
48 lines (36 loc) · 1.53 KB

build-advanced.mdx

File metadata and controls

48 lines (36 loc) · 1.53 KB

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:

{
  "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:

{
  "cut-generators": true
}

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