OCaml Rules Last updated June 2, 2022

WARNING Beta version - subject to change

Configurable defaults

These options and flags apply to all ocaml_* rules. They can be overridden on the command line; for example, to enable verbosity (-verbose) for all ocaml_* build targets, pass --@ocaml//verbose. See Configurable Defaults for more information.

In addition to the options and flags listed here, which apply to all ocaml_* rule instances, each rule may have its own set of configurable defaults.

Options

May be enums, strings, labels, etc.

Label Default x

@rules_ocaml//build/mode

@ocaml//build/mode:native

Enum: :bytecode, :native

@rules_ocaml//build/cc/mode

@ocaml//build/cc/mode:fastbuild

Enum: :dbg, :fastbuild, :opt

@rules_ocaml//build/profile

@ocaml//build/profile:fastbuild

Enum: :dbg, :fastbuild, :opt

CC build mode is set by passing --compilation_mode (equivalently -c) on the command line, e.g. -c opt. This sets the value of @rules_ocaml//build/cc/mode.

Flags

Each boolean flag foo may be enabled by --@ocaml//foo or --@ocaml//foo:enable, and disabled with --no@ocaml//foo or --@ocaml//foo:disable. Each flag has a corresponding OCaml option and an OBazl (not an OCaml) negation; see Configurable_Defaults: Disabling for information on how to use negated options to override defaults.

Label Default opts attrib

@rules_ocaml//cfg/debug

disabled

-g, -no-g

@rules_ocaml//cfg/cmt

disabled

-bin-annot, -no-bin-annot

@rules_ocaml//cfg/keep-locs

enabled

-keep-locs, -no-keep-locs

@rules_ocaml//cfg/noassert

enabled

-noassert, -no-noassert

@rules_ocaml//cfg/opaque

disabled

-opaque, -no-opaque

@rules_ocaml//cfg/short-paths

enabled

-short-paths, -no-short-paths

@rules_ocaml//cfg/strict-formats

enabled

-strict-formats, -no-strict-formats

@rules_ocaml//cfg/strict-sequence

enabled

-strict-sequence, -no-strict-sequence

@rules_ocaml//cfg/verbose1

disabled

-verbose, -no-verbose

1 Each ocaml_* rule also has it’s own verbose flag.

ocaml_binary

Generates an OCaml executable binary.

CONFIGURABLE DEFAULTS for rule ocaml_binary

In addition to the Configurable defaults that apply to all ocaml_* rules, the following apply to this rule. (Note the difference between '/' and ':' in such labels):

Label Default opts attrib

@rules_ocaml//cfg/executable/linkall

True

-linkall, -no-linkall

@rules_ocaml//cfg/executable:warnings

@1..3@5..28@30..39@43@46..47@49..57@61..62-40

-w plus option value

NOTE These do not support :enable, :disable syntax.

ATTRIBUTES for rule ocaml_binary:

Name Description Type Mandatory Default

name

A unique name for this target.

Name

required

data

Runtime dependencies: list of labels of data files needed by this executable at runtime.

List of labels

optional

[]

cc_deps

Dictionary specifying C/C++ library dependencies. Key: a target label; value: a linkmode string, which determines which file to link. Valid linkmodes: 'default', 'static', 'dynamic', 'shared' (synonym for 'dynamic'). For more information see [CC Dependencies: Linkmode](../ug/cc_deps.md#linkmode).

Dictionary: Label -> String

optional

{}

cc_linkall

True: use -whole-archive (GCC toolchain) or -force_load (Clang toolchain). Deps in this attribute must also be listed in cc_deps.

List of labels

optional

[]

cc_linkopts

List of C/C link options. E.g. ["-lstd"].

List of strings

optional

[]

data_prefix_map

Map for replacing path prefixes of data files

Dictionary: String -> String

optional

{}

env

Env variables

Dictionary: String -> String

optional

{}

epilogue

List of OCaml dependencies.

List of labels

optional

[]

exe

By default, executable name is derived from 'name' attribute; use this to override.

String

optional

""

main

Label of module containing entry point of executable. In the list of dependencies, this will be placed after 'prologue' deps and before 'epilogue' deps.

Label

required

opts

List of compile options; overrides configurable default options. Supports -no- prefix for each option; for example, -no-linkall.

List of strings

optional

[]

prologue

List of OCaml dependencies.

List of labels

optional

[]

vm_runtime

@rules_ocaml//cfg/runtime:dynamic (default), @rules_ocaml//cfg/runtime:static, or a custom ocaml_vm_runtime target label

Label

optional

"@rules_ocaml//cfg/runtime:dynamic"

ocaml_exec_module

See documentation for ocaml_module.

ATTRIBUTES for rule ocaml_exec_module:

Name Description Type Mandatory Default

name

A unique name for this target.

Name

required

deps

List of dependencies.

List of labels

optional

[]

data

Runtime data dependencies: list of labels of data files needed by this module at runtime. This is a standard Bazel attribute; see Typical attributes.

List of labels

optional

[]

cc_deps

Static (.a) or dynamic (.so, .dylib) libraries. Must by built or imported using Bazel’s rules_cc ruleset (thus providing CcInfo output).

List of labels

optional

[]

cc_linkage

Dictionary specifying C/C++ library dependencies. Allows finer control over linking than the 'cc_deps' attribute. Key: a target label providing CcInfo; value: a linkmode string, which determines which file to link. Valid linkmodes: 'default', 'static', 'dynamic', 'shared' (synonym for 'dynamic'). For more information see CC Dependencies: Linkmode.

Dictionary: Label -> String

optional

{}

deps_runtime

Runtime module dependencies, e.g. .cmxs plugins. Use the data attribute for runtime data dependencies.

List of labels

optional

[]

env

Env variables

Dictionary: String -> String

optional

{}

module_name

Use this string as module name, instead of deriving it from sig or struct

String

optional

""

ns_resolver

NS resolver module for bottom-up namespacing. Modules may use this attribute to elect membership in a bottom-up namespace.

Label

optional

None

open

List of OCaml dependencies to be passed with -open.

List of labels

optional

[]

opts

List of compile options; overrides configurable default options. Supports -no- prefix for each option; for example, -no-linkall.

List of strings

optional

[]

pack

Experimental. List of pack submodules. They will be compiled with -for-pack, and this module will be compile with -pack.

List of labels

optional

[]

ppx

Label of ppx_executable target to be used to transform source before compilation.

Label

optional

None

ppx_args

Options to pass to PPX executable passed by the ppx attribute.

List of strings

optional

[]

ppx_data

PPX runtime data dependencies. List of labels of files needed by the PPX executable passed via the ppx attribute when it is executed to transform the source file. For example, a source file using ppx_optcomp may import a file using extension [%%import ]; this file should be listed in this attribute.

List of labels

optional

[]

ppx_print

Format of output of PPX transform: binary (default) or text. Value must be one of @rules_ocaml//ppx/print:binary! or @rules_ocaml//ppx/print:text!.

Label

optional

"@rules_ocaml//ppx/print"

ppx_verbose

-

Boolean

optional

False

sig

Single label of a target producing OcamlSignatureProvider (i.e. rule ocaml_signature) OR a sig source file. Optional.

Label

optional

None

struct

A single module (struct) source file label.

Label

required

ocaml_import

Imports pre-compiled OCaml files. [User Guide](../ug/ocaml_import.md).

ATTRIBUTES for rule ocaml_import:

Name Description Type Mandatory Default

name

A unique name for this target.

Name

required

deps

-

List of labels

optional

[]

srcs

-

List of labels

optional

[]

afiles

list of .a files that go with .cmxa files

List of labels

optional

[]

all

Glob all cm* files except for 'archive' or 'plugin' so theey can be added to action ldeps (rather than cmd line). I.e. the (transitive) deps of an archive, which must be accessible to the compiler (via search path, not command line), and so must be added to the action ldeps.

List of labels

optional

[]

archive

-

Label

optional

None

astructs

-

List of labels

optional

[]

cc_deps

C archive files (.a) for integrating OCaml and C libs

List of labels

optional

[]

cmtis

-

List of labels

optional

[]

cmts

-

List of labels

optional

[]

cmxs

-

Label

optional

None

doc

-

String

optional

""

jsoo_runtime

-

Label

optional

None

ocaml_version

-

String

optional

""

ofiles

list of .o files that go with .cmx files

List of labels

optional

[]

plugin

-

Label

optional

None

ppx_codeps

-

List of labels

optional

[]

sigs

-

List of labels

optional

[]

version

-

String

optional

""

vmlibs

Dynamically-loadable, for ocamlrun. Standard naming is 'dll<name>_stubs.so' or 'dll<name>.so'.

List of labels

optional

[]

ocaml_library

Aggregates a collection of OCaml modules. [User Guide](../ug/ocaml_library.md). Provides: [OcamlLibraryMarker](providers_ocaml.md#ocamllibraryprovider).

An ocaml_library is a collection of modules packaged into an OBazl target; it is not a single binary file. It is a OBazl convenience rule that allows a target to depend on a collection of deps under a single label, rather than having to list each individually.

Be careful not to confuse ocaml_library with ocaml_archive. The latter generates OCaml binaries (.cma, .cmxa, '.a' archive files); the former does not generate anything, it just passes on its dependencies under a single label, packaged in a [OcamlLibraryMarker](providers_ocaml.md#ocamllibraryprovider). For more information see [Collections: Libraries, Archives and Packages](../ug/collections.md).

ATTRIBUTES for rule ocaml_library:

Name Description Type Mandatory Default

name

A unique name for this target.

Name

required

archive_name

Name of generated archive file, without extension. If not provided, name will be derived from target 'name' attribute. Ignored if archived == False.

String

optional

""

archived

-

Boolean

optional

False

cc_deps

Static (.a) or dynamic (.so, .dylib) libraries. Must deliver a CcInfo provider. Since ocaml rules may deliver CcInfo providers, we cannnot assume these deps are produced directly by rules_cc.

List of labels

optional

[]

cc_linkage

Dictionary specifying C/C++ library dependencies. Allows finer control over linking than the 'cc_deps' attribute. Key: a target label providing CcInfo; value: a linkmode string, which determines which file to link. Valid linkmodes: 'default', 'static', 'dynamic', 'shared' (synonym for 'dynamic'). For more information see CC Dependencies: Linkmode.

Dictionary: Label -> String

optional

{}

env

Env variables

Dictionary: String -> String

optional

{}

manifest

List of component modules, for libraries and archives.

List of labels

optional

[]

ns_name

-

String

optional

""

opts

List of compile options; overrides configurable default options. Supports -no- prefix for each option; for example, -no-linkall.

List of strings

optional

[]

shared

True: build a shared lib (.cmxs)

Boolean

optional

False

standalone

True: link total depgraph. False: link only direct deps.

Boolean

optional

False

vm_runtime

@rules_ocaml//cfg/runtime:dynamic (default), @rules_ocaml//cfg/runtime:static, or a custom ocaml_vm_runtime target label

Label

optional

"@rules_ocaml//cfg/runtime:dynamic"

ocaml_module

Compiles an OCaml module. The module name is determined by rule, based on the struct, sig, name, and module attributes:

  • If the sig attribute is the label of an ocaml_signature target, then the module name is derived from the name of the compiled sigfile, since compiled interface files cannot be renamed. The structfile will be renamed if it does not match the sigfile name.

  • If the sig attribute is a filename, then:

    • if its principal name is equal to the principal name of the file named in the struct attribute, then the module name is derived from it.

    • if the principal names of the sigfile and structfile do not match, then the module name is derived from from the name attribute. Both the sigfile and the structfile will be renamed accordingly.

    • The module attribute may be used to force the module name. Both the sigfile and the structfile will be renamed accordingly.

  • If the sig attribute is not specified (i.e. the structfile is "orphaned"), then the module name will be derived from the structfile name, unless the module attribute is specified, in which case it overrides.

CONFIGURABLE DEFAULTS for rule ocaml_module:

In addition to the Configurable defaults that apply to all ocaml_* rules, the following apply to this rule:

Options

Label Default Comments

@rules_ocaml//cfg/module:deps

@rules_ocaml//cfg:null

list of OCaml deps to add to all ocaml_module instances

@rules_ocaml//cfg/module:cc_deps1

@rules_ocaml//cfg:null

list of cc_deps to add to all ocaml_module instances

@rules_ocaml//cfg/module:cc_linkstatic1

@rules_ocaml//cfg:null

list of cc_deps to link statically (DEPRECATED)

@rules_ocaml//cfg/module:warnings

@1..3@5..28@30..39@43@46..47@49..57@61..62-40

sets -w option for all ocaml_module instances

1 See CC Dependencies for more information on CC deps.

Boolean Flags

These do not support :enable, :disable syntax.
Label Default opts attrib equivalent

@rules_ocaml//cfg/module/linkall

False

-linkall, -no-linkall

@rules_ocaml//cfg/module:verbose

False

-verbose, -no-verbose

ATTRIBUTES for rule ocaml_module:

Name Description Type Mandatory Default

name

A unique name for this target.

Name

required

deps

List of dependencies.

List of labels

optional

[]

data

Runtime data dependencies: list of labels of data files needed by this module at runtime. This is a standard Bazel attribute; see Typical attributes.

List of labels

optional

[]

cc_deps

Static (.a) or dynamic (.so, .dylib) libraries. Must by built or imported using Bazel’s rules_cc ruleset (thus providing CcInfo output).

List of labels

optional

[]

cc_linkage

Dictionary specifying C/C++ library dependencies. Allows finer control over linking than the 'cc_deps' attribute. Key: a target label providing CcInfo; value: a linkmode string, which determines which file to link. Valid linkmodes: 'default', 'static', 'dynamic', 'shared' (synonym for 'dynamic'). For more information see CC Dependencies: Linkmode.

Dictionary: Label -> String

optional

{}

deps_runtime

Runtime module dependencies, e.g. .cmxs plugins. Use the data attribute for runtime data dependencies.

List of labels

optional

[]

env

Env variables

Dictionary: String -> String

optional

{}

module_name

Use this string as module name, instead of deriving it from sig or struct

String

optional

""

ns_resolver

NS resolver module for bottom-up namespacing. Modules may use this attribute to elect membership in a bottom-up namespace.

Label

optional

None

open

List of OCaml dependencies to be passed with -open.

List of labels

optional

[]

opts

List of compile options; overrides configurable default options. Supports -no- prefix for each option; for example, -no-linkall.

List of strings

optional

[]

pack

Experimental. List of pack submodules. They will be compiled with -for-pack, and this module will be compile with -pack.

List of labels

optional

[]

ppx

Label of ppx_executable target to be used to transform source before compilation.

Label

optional

None

ppx_args

Options to pass to PPX executable passed by the ppx attribute.

List of strings

optional

[]

ppx_data

PPX runtime data dependencies. List of labels of files needed by the PPX executable passed via the ppx attribute when it is executed to transform the source file. For example, a source file using ppx_optcomp may import a file using extension [%%import ]; this file should be listed in this attribute.

List of labels

optional

[]

ppx_print

Format of output of PPX transform: binary (default) or text. Value must be one of @rules_ocaml//ppx/print:binary! or @rules_ocaml//ppx/print:text!.

Label

optional

"@rules_ocaml//ppx/print"

ppx_verbose

-

Boolean

optional

False

sig

Single label of a target producing OcamlSignatureProvider (i.e. rule ocaml_signature) OR a sig source file. Optional.

Label

optional

None

struct

A single module (struct) source file label.

Label

required

ocaml_ns_archive

Generate a 'namespace' module. [User Guide](../ug/ocaml_ns.md). Provides: [OcamlNsMarker](providers_ocaml.md#ocamlnsmoduleprovider).

Deprecated.  Use ocaml_ns_library with 'archived = True' instead.

NOTE 'name' must be a legal OCaml module name string. Leading underscore is illegal.

See [Namespacing](../ug/namespacing.md) for more information on namespaces.

ATTRIBUTES for rule ocaml_ns_archive:

Name Description Type Mandatory Default

name

A unique name for this target.

Name

required

archive_name

Name of generated archive file, without extension. If not provided, name will be derived from target 'name' attribute. Ignored if archived == False.

String

optional

""

cc_deps

Static (.a) or dynamic (.so, .dylib) libraries. Must by built or imported using Bazel’s rules_cc ruleset (thus providing CcInfo output).

List of labels

optional

[]

cc_linkage

Dictionary specifying C/C++ library dependencies. Allows finer control over linking than the 'cc_deps' attribute. Key: a target label providing CcInfo; value: a linkmode string, which determines which file to link. Valid linkmodes: 'default', 'static', 'dynamic', 'shared' (synonym for 'dynamic'). For more information see CC Dependencies: Linkmode.

Dictionary: Label -> String

optional

{}

env

Env variables

Dictionary: String -> String

optional

{}

manifest

List of namespaced submodules; will be renamed by prefixing the namespace,

List of labels

optional

[]

ns_name

Namespace name is derived from 'name' attribute by default; use this to override.

String

optional

""

opts

List of compile options; overrides configurable default options. Supports -no- prefix for each option; for example, -no-linkall.

List of strings

optional

[]

shared

True: build a shared lib (.cmxs)

Boolean

optional

False

ocaml_ns_library

Generate a 'namespace' module. [User Guide](../ug/ocaml_ns.md). Provides: [OcamlNsMarker](providers_ocaml.md#ocamlnsmoduleprovider).

NOTE 'name' must be a legal OCaml module name string. Leading underscore is illegal.

See [Namespacing](../ug/namespacing.md) for more information on namespaces.

ATTRIBUTES for rule ocaml_ns_library:

Name Description Type Mandatory Default

name

A unique name for this target.

Name

required

archive_name

Name of generated archive file, without extension. If not provided, name will be derived from target 'name' attribute. Ignored if archived == False.

String

optional

""

archived

-

Boolean

optional

False

cc_deps

Static (.a) or dynamic (.so, .dylib) libraries. Must by built or imported using Bazel’s rules_cc ruleset (thus providing CcInfo output).

List of labels

optional

[]

cc_linkage

Dictionary specifying C/C++ library dependencies. Allows finer control over linking than the 'cc_deps' attribute. Key: a target label providing CcInfo; value: a linkmode string, which determines which file to link. Valid linkmodes: 'default', 'static', 'dynamic', 'shared' (synonym for 'dynamic'). For more information see CC Dependencies: Linkmode.

Dictionary: Label -> String

optional

{}

env

Env variables

Dictionary: String -> String

optional

{}

manifest

List of namespaced submodules; will be renamed by prefixing the namespace,

List of labels

optional

[]

ns_name

Namespace name is derived from 'name' attribute by default; use this to override.

String

optional

""

opts

List of compile options; overrides configurable default options. Supports -no- prefix for each option; for example, -no-linkall.

List of strings

optional

[]

shared

True: build a shared lib (.cmxs)

Boolean

optional

False

ocaml_ns_resolver

OBSOLETE DOCSTRING! under revision…​

This rule initializes a 'namespace evaluation environment' consisting of a pseudo-namespace prefix string and optionally an ns resolver module. A pseudo-namespace prefix string is a string that is used to form (by prefixation) a (presumably) globally unique name for a module. An ns resolver module is a module that contains nothing but alias equations mapping module names to pseudo-namespaced module names.

This rule is designed to work in conjujnction with rules [ocaml_module](rules_ocaml.md#ocaml_module) and [ocaml_ns_module](rules_ocaml.md#ocaml_ns_module). An ocaml_module instance can use the prefix string of an ppx_ns to rename its source file by using attribute ns to reference the label of an ppx_ns target. Instances of ocaml_ns_module can list such modules as submodule dependencies. They can also use an ppx_ns prefix string to name themselves, by using their ns attribute similarly. This allows ns modules to be (pseudo-)namespaced in the same way submodules are namespaced.

The prefix string defaults to the (Bazel) package name string, with each segment capitalized and the path separator ('/') replaced by the sep string (default: _). If you pass a prefix string it must be a legal OCaml module path; each segment will be capitalized and the segment separator ('.') will be replaced by the sep string. The resulting prefix may be used by ocaml_module rules (via the ns attribute) to rename their source files, and, if module = True, by this rule to generate alias equations.

For example, if package //alpha/beta/gamma contains`foo.ml`:

ns_resolver() => Alpha_Beta_Gamma__foo.ml
ns_resolver(sep="") => AlphaBetaGamma__foo.ml
ns_resolver(sep="__") => Alpha__Beta__Gamma__foo.ml
ns_resolver(prefix="foo.bar") => Foo_Bar__foo.ml (pkg path ignored)
ns_resolver(prefix="foo.bar", sep="") => FooBar__foo.ml

The optional ns resolver module will be named <prefix>__00.ml; since 0 is not a legal initial character for an OCaml module name, this ensures it will never clash with a user-defined module.

The ns resolver module will contain alias equations mapping module names derived from the srcs list to pseudo-namespaced module names (and thus indirectly filenames). For example, if srcs contains foo.ml, and the prefix is a.b, then the resolver module will contain module Foo = A_b_foo.

Submodule file names will be formed by prefixing the pseudo-ns prefix to the (original, un-namespaced) module name, separated by 'sep' (default: ''). For example, if the prefix is 'Foo_bar' and the module is 'baz.ml', the submodule file name will be 'Foo_barbaz.ml'.

The main namespace module will contain aliasing equations that map module names to these prefixed module names.

By default, the ns prefix string is formed from the package name, with '/' replaced by '_'. You can use the 'ns' attribute to change this:

ns(ns = "foobar", srcs = glob(["*.ml"]))

ATTRIBUTES for rule ocaml_ns_resolver:

Name Description Type Mandatory Default

name

A unique name for this target.

Name

required

deps

List of dependencies.

List of labels

optional

[]

data

Runtime data dependencies: list of labels of data files needed by this module at runtime. This is a standard Bazel attribute; see Typical attributes.

List of labels

optional

[]

cc_deps

Static (.a) or dynamic (.so, .dylib) libraries. Must by built or imported using Bazel’s rules_cc ruleset (thus providing CcInfo output).

List of labels

optional

[]

cc_linkage

Dictionary specifying C/C++ library dependencies. Allows finer control over linking than the 'cc_deps' attribute. Key: a target label providing CcInfo; value: a linkmode string, which determines which file to link. Valid linkmodes: 'default', 'static', 'dynamic', 'shared' (synonym for 'dynamic'). For more information see CC Dependencies: Linkmode.

Dictionary: Label -> String

optional

{}

deps_runtime

Runtime module dependencies, e.g. .cmxs plugins. Use the data attribute for runtime data dependencies.

List of labels

optional

[]

embed

Exogenous namespaces (resolver modules).

Dictionary: Label -> String

optional

{}

env

Env variables

Dictionary: String -> String

optional

{}

include

Exogenous (sub)modules, namespaced or non-namespaced. Aliased names will not be prefixed with ns name of this ns_resolver.

Keys: labels of modules; Values: alias name to be used in this resolver.

e.g. '//mwe/rgb:R': 'Red' will generate

module R = Red

Dictionary: Label -> String

optional

{}

manifest

List of strings from which submodule names are to be derived for aliasing. Bazel labels may be used; the submodule name will be derived from the target part. For example, '//a/b:c' normalizes to C. But they are just strings, and will not be checked against any files.

The normalized submodule names must match the names of the modules electing membership via the 'ns_resolver' attribute.

Module source code generated by ocamllex and ocamlyacc can be accomodated by using the module name for the source file and generating a .ml source file of the same name, e.g. lexer.mll → lexer.ml.

List of strings

optional

[]

merge

Includes all submodules of an exogenous namespace.

List of labels

optional

[]

module_name

Use this string as module name, instead of deriving it from sig or struct

String

optional

""

ns

-

String

required

open

List of OCaml dependencies to be passed with -open.

List of labels

optional

[]

opts

List of compile options; overrides configurable default options. Supports -no- prefix for each option; for example, -no-linkall.

List of strings

optional

[]

pack

Experimental. List of pack submodules. They will be compiled with -for-pack, and this module will be compile with -pack.

List of labels

optional

[]

ppx

Label of ppx_executable target to be used to transform source before compilation.

Label

optional

None

ppx_args

Options to pass to PPX executable passed by the ppx attribute.

List of strings

optional

[]

ppx_data

PPX runtime data dependencies. List of labels of files needed by the PPX executable passed via the ppx attribute when it is executed to transform the source file. For example, a source file using ppx_optcomp may import a file using extension [%%import ]; this file should be listed in this attribute.

List of labels

optional

[]

ppx_print

Format of output of PPX transform: binary (default) or text. Value must be one of @rules_ocaml//ppx/print:binary! or @rules_ocaml//ppx/print:text!.

Label

optional

"@rules_ocaml//ppx/print"

ppx_verbose

-

Boolean

optional

False

sig

Single label of a target producing OcamlSignatureProvider (i.e. rule ocaml_signature) OR a sig source file. Optional.

Label

optional

None

struct

A single module (struct) source file label.

Label

optional

None

ocaml_signature

Generates OCaml .cmi (inteface) file. [User Guide](../ug/ocaml_signature.md). Provides OcamlSignatureProvider.

CONFIGURABLE DEFAULTS for rule ocaml_signature

In addition to the Configurable defaults that apply to all ocaml_* rules, the following apply to this rule. (Note the difference between '/' and ':' in such labels):

Label Default opts attrib

@rules_ocaml//cfg/signature/linkall

True

-linkall, -no-linkall

@rules_ocaml//cfg/signature:warnings

@1..3@5..28@30..39@43@46..47@49..57@61..62-40

-w plus option value

ATTRIBUTES for rule ocaml_signature:

Name Description Type Mandatory Default

name

A unique name for this target.

Name

required

deps

List of OCaml dependencies. Use this for compiling a .mli source file with deps. See [Dependencies](#deps) for details.

List of labels

optional

[]

src

A single .mli source file label

Label

optional

None

data

-

List of labels

optional

[]

env

Env variables

Dictionary: String -> String

optional

{}

module

Set module (sig) name to this string

String

optional

""

ns_resolver

Bottom-up namespacing

Label

optional

None

open

List of OCaml dependencies to be passed with -open.

List of labels

optional

[]

opts

List of compile options; overrides configurable default options. Supports -no- prefix for each option; for example, -no-linkall.

List of strings

optional

[]

pack

Experimental

String

optional

""

ppx

Label of ppx_executable target to be used to transform source before compilation.

Label

optional

None

ppx_args

Options to pass to PPX executable passed by the ppx attribute.

List of strings

optional

[]

ppx_data

PPX runtime data dependencies. List of labels of files needed by the PPX executable passed via the ppx attribute when it is executed to transform the source file. For example, a source file using ppx_optcomp may import a file using extension [%%import ]; this file should be listed in this attribute.

List of labels

optional

[]

ppx_print

Format of output of PPX transform: binary (default) or text. Value must be one of @rules_ocaml//ppx/print:binary! or @rules_ocaml//ppx/print:text!.

Label

optional

"@rules_ocaml//ppx/print"

ppx_verbose

-

Boolean

optional

False

xmo

Cross-module optimization. If false, compile with -opaque

Boolean

optional

True

ocaml_test

OCaml test rule.

CONFIGURABLE DEFAULTS for rule ocaml_test

In addition to the [OCaml configurable defaults](#configdefs) that apply to all ocaml_* rules, the following apply to this rule:

| Label | Default | opts attrib | | ----- | ------- | ------- | | @rules_ocaml//cfg/executable:linkall | True | -linkall, -no-linkall| | @rules_ocaml//cfg/executable:threads | False | true: -I +thread| | @rules_ocaml//cfg/executable:warnings | @1..3@5..28@30..39@43@46..47@49..57@61..62-40| -w plus option value |

NOTE These do not support :enable, :disable syntax.

See [Configurable Defaults](../ug/configdefs_doc.md) for more information.

ATTRIBUTES for rule ocaml_test:

Name Description Type Mandatory Default

name

A unique name for this target.

Name

required

data

Runtime dependencies: list of labels of data files needed by this executable at runtime.

List of labels

optional

[]

cc_deps

Dictionary specifying C/C++ library dependencies. Key: a target label; value: a linkmode string, which determines which file to link. Valid linkmodes: 'default', 'static', 'dynamic', 'shared' (synonym for 'dynamic'). For more information see [CC Dependencies: Linkmode](../ug/cc_deps.md#linkmode).

Dictionary: Label -> String

optional

{}

cc_libs

-

List of labels

optional

[]

cc_linkall

True: use -whole-archive (GCC toolchain) or -force_load (Clang toolchain). Deps in this attribute must also be listed in cc_deps.

List of labels

optional

[]

cc_linkopts

List of C/C link options. E.g. ["-lstd"].

List of strings

optional

[]

data_prefix_map

Map for replacing path prefixes of data files

Dictionary: String -> String

optional

{}

diff_cmd

-

Label

optional

None

env

Env variables

Dictionary: String -> String

optional

{}

epilogue

List of OCaml dependencies.

List of labels

optional

[]

exe

By default, executable name is derived from 'name' attribute; use this to override.

String

optional

""

main

Label of module containing entry point of executable. In the list of dependencies, this will be placed after 'prologue' deps and before 'epilogue' deps.

Label

required

opts

List of compile options; overrides configurable default options. Supports -no- prefix for each option; for example, -no-linkall.

List of strings

optional

[]

prologue

List of OCaml dependencies.

List of labels

optional

[]

vm_runtime

@rules_ocaml//cfg/runtime:dynamic (default), @rules_ocaml//cfg/runtime:static, or a custom ocaml_vm_runtime target label

Label

optional

"@rules_ocaml//cfg/runtime:dynamic"

ocaml_vm_runtime

ocaml_vm_runtime(name, deps)

User-defined runtime, using ocamlc -make-runtime

ATTRIBUTES for rule ocaml_vm_runtime:

Name Description Type Mandatory Default

name

A unique name for this target.

Name

required

deps

Libraries whose cc deps should be included in the runtime

List of labels

optional

[]

ocamllex

ocamllex(name, src, out, opts)

Generates an OCaml source file from an ocamllex source file.

ATTRIBUTES for rule ocamllex:

Name Description Type Mandatory Default

name

A unique name for this target.

Name

required

src

A single .mll source file label

Label

optional

None

out

Output filename.

Label

required

opts

Options

List of strings

optional

[]

ocamlyacc

ocamlyacc(name, src, outs, opts)

Generates OCaml source files from an ocamlyacc source file.

ATTRIBUTES for rule ocamlyacc:

Name Description Type Mandatory Default

name

A unique name for this target.

Name

required

src

A single .mly ocamlyacc source file label

Label

optional

None

outs

Output filenames.

List of labels

required

opts

Options

List of strings

optional

[]

ppx_executable

Generates a PPX executable. Provides: [PpxExecutableMarker](providers_ppx.md#ppxexecutableprovider).

ATTRIBUTES for rule ppx_executable:

Name Description Type Mandatory Default

name

A unique name for this target.

Name

required

data

Runtime data dependencies. E.g. a file used by %%import from ppx_optcomp.

List of labels

optional

[]

bin

Precompiled ppx executable

Label

optional

None

cc_deps

C/C++ library dependencies

Dictionary: Label -> String

optional

{}

cc_linkall

True: use -whole-archive (GCC toolchain) or -force_load (Clang toolchain). Deps in this attribute must also be listed in cc_deps.

List of labels

optional

[]

cc_linkopts

List of C/C link options. E.g. `["-lstd"]`.

List of strings

optional

[]

data_prefix_map

Map for replacing path prefixes of data files. May be used to strip a path prefix (set value to empty string "").

Dictionary: String -> String

optional

{}

env

Env variables

Dictionary: String -> String

optional

{}

epilogue

List of OCaml dependencies.

List of labels

optional

[]

exe

Name for output executable file. Overrides 'name' attribute.

String

optional

""

main

A module to be listed after those in 'prologue' and before those in 'epilogue'. For more information see [Main Module](../ug/ppx.md#main_module).

Label

required

opts

List of compile options; overrides configurable default options. Supports -no- prefix for each option; for example, -no-linkall.

List of strings

optional

[]

ppx_codeps

List of non-opam adjunct dependencies (labels).

List of labels

optional

[]

prologue

List of OCaml dependencies.

List of labels

optional

[]

vm_runtime

@ocaml_rules//cfg/runtime:dynamic (default), @ocaml_rules//cfg/runtime:static, or a custom ocaml_vm_runtime target label

Label

optional

"@rules_ocaml//cfg/runtime:dynamic"

ppx_module

Compiles a PPX module. Same as ocaml_module but with added ppx_codeps attribute. A ppx_module may depend on a standard ocaml_module, but not the other way around.

The module name is determined by rule, based on the struct, sig, name, and module attributes:

  • If the sig attribute is the label of an ocaml_signature target, then the module name is derived from the name of the compiled sigfile, since compiled interface files cannot be renamed. The structfile will be renamed if it does not match the sigfile name.

  • If the sig attribute is a filename, then:

    • if its principal name is equal to the principal name of the file named in the struct attribute, then the module name is derived from it.

    • if the principal names of the sigfile and structfile do not match, then the module name is derived from from the name attribute. Both the sigfile and the structfile will be renamed accordingly.

    • The module attribute may be used to force the module name. Both the sigfile and the structfile will be renamed accordingly.

  • If the sig attribute is not specified (i.e. the structfile is "orphaned"), then the module name will be derived from the structfile name, unless the module attribute is specified, in which case it overrides.

CONFIGURABLE DEFAULTS for rule ppx_module:

In addition to the Configurable defaults that apply to all ocaml_* rules, the following apply to this rule:

Options

Label Default Comments

@rules_ocaml//cfg/module:deps

@rules_ocaml//cfg:null

list of OCaml deps to add to all ocaml_module instances

@rules_ocaml//cfg/module:cc_deps1

@rules_ocaml//cfg:null

list of cc_deps to add to all ocaml_module instances

@rules_ocaml//cfg/module:cc_linkstatic1

@rules_ocaml//cfg:null

list of cc_deps to link statically (DEPRECATED)

@rules_ocaml//cfg/module:warnings

@1..3@5..28@30..39@43@46..47@49..57@61..62-40

sets -w option for all ocaml_module instances

1 See CC Dependencies for more information on CC deps.

Boolean Flags

These do not support :enable, :disable syntax.
Label Default opts attrib equivalent

@rules_ocaml//cfg/module/linkall

False

-linkall, -no-linkall

@rules_ocaml//cfg/module:verbose

False

-verbose, -no-verbose

ATTRIBUTES for rule ppx_module:

Name Description Type Mandatory Default

name

A unique name for this target.

Name

required

deps

List of dependencies.

List of labels

optional

[]

data

Runtime data dependencies: list of labels of data files needed by this module at runtime. This is a standard Bazel attribute; see Typical attributes.

List of labels

optional

[]

cc_deps

Static (.a) or dynamic (.so, .dylib) libraries. Must by built or imported using Bazel’s rules_cc ruleset (thus providing CcInfo output).

List of labels

optional

[]

cc_linkage

Dictionary specifying C/C++ library dependencies. Allows finer control over linking than the 'cc_deps' attribute. Key: a target label providing CcInfo; value: a linkmode string, which determines which file to link. Valid linkmodes: 'default', 'static', 'dynamic', 'shared' (synonym for 'dynamic'). For more information see CC Dependencies: Linkmode.

Dictionary: Label -> String

optional

{}

deps_runtime

Runtime module dependencies, e.g. .cmxs plugins. Use the data attribute for runtime data dependencies.

List of labels

optional

[]

env

Env variables

Dictionary: String -> String

optional

{}

module_name

Use this string as module name, instead of deriving it from sig or struct

String

optional

""

ns_resolver

NS resolver module for bottom-up namespacing. Modules may use this attribute to elect membership in a bottom-up namespace.

Label

optional

None

open

List of OCaml dependencies to be passed with -open.

List of labels

optional

[]

opts

List of compile options; overrides configurable default options. Supports -no- prefix for each option; for example, -no-linkall.

List of strings

optional

[]

pack

Experimental. List of pack submodules. They will be compiled with -for-pack, and this module will be compile with -pack.

List of labels

optional

[]

ppx

Label of ppx_executable target to be used to transform source before compilation.

Label

optional

None

ppx_args

Options to pass to PPX executable passed by the ppx attribute.

List of strings

optional

[]

ppx_codeps

List of non-opam adjunct dependencies (labels).

List of labels

optional

[]

ppx_compile_codeps

List labels of compile-time dependencies. These are required to compile any file transformed by this ppx.

List of labels

optional

[]

ppx_data

PPX runtime data dependencies. List of labels of files needed by the PPX executable passed via the ppx attribute when it is executed to transform the source file. For example, a source file using ppx_optcomp may import a file using extension [%%import ]; this file should be listed in this attribute.

List of labels

optional

[]

ppx_link_codeps

List labels of link-time dependencies. These are required to link any file transformed by this ppx.

List of labels

optional

[]

ppx_print

Format of output of PPX transform: binary (default) or text. Value must be one of @rules_ocaml//ppx/print:binary! or @rules_ocaml//ppx/print:text!.

Label

optional

"@rules_ocaml//ppx/print"

ppx_verbose

-

Boolean

optional

False

sig

Single label of a target producing OcamlSignatureProvider (i.e. rule ocaml_signature) OR a sig source file. Optional.

Label

optional

None

struct

A single module (struct) source file label.

Label

required

ppx_transform

ppx_transform(name, src, data, args, env, opts, ppx, print)

Runs a ppx executable to transform a source file. Also propagates ppx_codeps from the provider of the ppx dependency.

ATTRIBUTES for rule ppx_transform:

Name Description Type Mandatory Default

name

A unique name for this target.

Name

required

src

A single source file (struct or sig) label.

Label

required

data

Runtime data dependencies: list of labels of data files needed by ppx executable at runtime.

List of labels

optional

[]

args

List of args to pass to ppx executable at runtime.

List of strings

optional

[]

env

Env variables

Dictionary: String -> String

optional

{}

opts

List of compile options; overrides configurable default options. Supports -no- prefix for each option; for example, -no-linkall.

List of strings

optional

[]

ppx

Label of ppx_executable target to be used to transform source before compilation.

Label

optional

None

print

Format of output of PPX transform. Value must be one of @rules_ocaml//ppx/print:binary, @rules_ocaml//ppx/print:text. See PPX Support for more information

Label

optional

"@rules_ocaml//ppx/print"