Deprecated. Use ocaml_ns_library with 'archived = True' instead.
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 |
|
@rules_ocaml//cfg/cmt |
disabled |
|
@rules_ocaml//cfg/keep-locs |
enabled |
|
@rules_ocaml//cfg/noassert |
enabled |
|
@rules_ocaml//cfg/opaque |
disabled |
|
@rules_ocaml//cfg/short-paths |
enabled |
|
@rules_ocaml//cfg/strict-formats |
enabled |
|
@rules_ocaml//cfg/strict-sequence |
enabled |
|
@rules_ocaml//cfg/verbose1 |
disabled |
|
1 Each ocaml_*
rule also has it’s own verbose
flag.
ocaml_binary
ocaml_binary(name, data, cc_deps, cc_linkall, cc_linkopts, data_prefix_map, env, epilogue, exe, main, opts, prologue, vm_runtime)
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 |
|
@rules_ocaml//cfg/executable:warnings |
|
|
NOTE These do not support :enable
, :disable
syntax.
ATTRIBUTES for rule ocaml_binary:
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
A unique name for this target. |
required |
|||
Runtime dependencies: list of labels of data files needed by this executable at runtime. |
optional |
[] |
||
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). |
optional |
{} |
||
True: use |
optional |
[] |
||
List of C/C link options. E.g. ["-lstd"]. |
List of strings |
optional |
[] |
|
Map for replacing path prefixes of data files |
optional |
{} |
||
Env variables |
optional |
{} |
||
List of OCaml dependencies. |
optional |
[] |
||
By default, executable name is derived from 'name' attribute; use this to override. |
String |
optional |
"" |
|
Label of module containing entry point of executable. In the list of dependencies, this will be placed after 'prologue' deps and before 'epilogue' deps. |
required |
|||
List of compile options; overrides configurable default options. Supports |
List of strings |
optional |
[] |
|
List of OCaml dependencies. |
optional |
[] |
||
@rules_ocaml//cfg/runtime:dynamic (default), @rules_ocaml//cfg/runtime:static, or a custom ocaml_vm_runtime target label |
optional |
"@rules_ocaml//cfg/runtime:dynamic" |
ocaml_exec_module
ocaml_exec_module(name, deps, data, cc_deps, cc_linkage, deps_runtime, env, module_name, ns_resolver, open, opts, pack, ppx, ppx_args, ppx_data, ppx_print, ppx_verbose, sig, struct)
See documentation for ocaml_module.
ATTRIBUTES for rule ocaml_exec_module:
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
A unique name for this target. |
required |
|||
List of dependencies. |
optional |
[] |
||
Runtime data dependencies: list of labels of data files needed by this module at runtime. This is a standard Bazel attribute; see Typical attributes. |
optional |
[] |
||
Static (.a) or dynamic (.so, .dylib) libraries. Must by built or imported using Bazel’s rules_cc ruleset (thus providing CcInfo output). |
optional |
[] |
||
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. |
optional |
{} |
||
Runtime module dependencies, e.g. .cmxs plugins. Use the |
optional |
[] |
||
Env variables |
optional |
{} |
||
Use this string as module name, instead of deriving it from sig or struct |
String |
optional |
"" |
|
NS resolver module for bottom-up namespacing. Modules may use this attribute to elect membership in a bottom-up namespace. |
optional |
None |
||
List of OCaml dependencies to be passed with |
optional |
[] |
||
List of compile options; overrides configurable default options. Supports |
List of strings |
optional |
[] |
|
Experimental. List of pack submodules. They will be compiled with -for-pack, and this module will be compile with -pack. |
optional |
[] |
||
Label of |
optional |
None |
||
Options to pass to PPX executable passed by the |
List of strings |
optional |
[] |
|
PPX runtime data dependencies. List of labels of files needed by the PPX executable passed via the |
optional |
[] |
||
Format of output of PPX transform: binary (default) or text. Value must be one of |
optional |
"@rules_ocaml//ppx/print" |
||
- |
Boolean |
optional |
False |
|
Single label of a target producing |
optional |
None |
||
A single module (struct) source file label. |
required |
ocaml_import
ocaml_import(name, deps, srcs, afiles, all, archive, astructs, cc_deps, cmtis, cmts, cmxs, doc, jsoo_runtime, ocaml_version, ofiles, plugin, ppx_codeps, sigs, version, vmlibs)
Imports pre-compiled OCaml files. [User Guide](../ug/ocaml_import.md).
ATTRIBUTES for rule ocaml_import:
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
A unique name for this target. |
required |
|||
- |
optional |
[] |
||
- |
optional |
[] |
||
list of .a files that go with .cmxa files |
optional |
[] |
||
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. |
optional |
[] |
||
- |
optional |
None |
||
- |
optional |
[] |
||
C archive files (.a) for integrating OCaml and C libs |
optional |
[] |
||
- |
optional |
[] |
||
- |
optional |
[] |
||
- |
optional |
None |
||
- |
String |
optional |
"" |
|
- |
optional |
None |
||
- |
String |
optional |
"" |
|
list of .o files that go with .cmx files |
optional |
[] |
||
- |
optional |
None |
||
- |
optional |
[] |
||
- |
optional |
[] |
||
- |
String |
optional |
"" |
|
Dynamically-loadable, for ocamlrun. Standard naming is 'dll<name>_stubs.so' or 'dll<name>.so'. |
optional |
[] |
ocaml_library
ocaml_library(name, archive_name, archived, cc_deps, cc_linkage, env, manifest, ns_name, opts, shared, standalone, vm_runtime)
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 |
---|---|---|---|---|
A unique name for this target. |
required |
|||
Name of generated archive file, without extension. If not provided, name will be derived from target 'name' attribute. Ignored if archived == False. |
String |
optional |
"" |
|
- |
Boolean |
optional |
False |
|
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. |
optional |
[] |
||
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. |
optional |
{} |
||
Env variables |
optional |
{} |
||
List of component modules, for libraries and archives. |
optional |
[] |
||
- |
String |
optional |
"" |
|
List of compile options; overrides configurable default options. Supports |
List of strings |
optional |
[] |
|
True: build a shared lib (.cmxs) |
Boolean |
optional |
False |
|
True: link total depgraph. False: link only direct deps. |
Boolean |
optional |
False |
|
@rules_ocaml//cfg/runtime:dynamic (default), @rules_ocaml//cfg/runtime:static, or a custom ocaml_vm_runtime target label |
optional |
"@rules_ocaml//cfg/runtime:dynamic" |
ocaml_module
ocaml_module(name, deps, data, cc_deps, cc_linkage, deps_runtime, env, module_name, ns_resolver, open, opts, pack, ppx, ppx_args, ppx_data, ppx_print, ppx_verbose, sig, struct)
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 anocaml_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 themodule
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 |
|
list of OCaml deps to add to all |
@rules_ocaml//cfg/module:cc_deps1 |
|
list of cc_deps to add to all |
@rules_ocaml//cfg/module:cc_linkstatic1 |
|
list of cc_deps to link statically (DEPRECATED) |
@rules_ocaml//cfg/module:warnings |
|
sets |
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 |
|
@rules_ocaml//cfg/module:verbose |
False |
|
ATTRIBUTES for rule ocaml_module:
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
A unique name for this target. |
required |
|||
List of dependencies. |
optional |
[] |
||
Runtime data dependencies: list of labels of data files needed by this module at runtime. This is a standard Bazel attribute; see Typical attributes. |
optional |
[] |
||
Static (.a) or dynamic (.so, .dylib) libraries. Must by built or imported using Bazel’s rules_cc ruleset (thus providing CcInfo output). |
optional |
[] |
||
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. |
optional |
{} |
||
Runtime module dependencies, e.g. .cmxs plugins. Use the |
optional |
[] |
||
Env variables |
optional |
{} |
||
Use this string as module name, instead of deriving it from sig or struct |
String |
optional |
"" |
|
NS resolver module for bottom-up namespacing. Modules may use this attribute to elect membership in a bottom-up namespace. |
optional |
None |
||
List of OCaml dependencies to be passed with |
optional |
[] |
||
List of compile options; overrides configurable default options. Supports |
List of strings |
optional |
[] |
|
Experimental. List of pack submodules. They will be compiled with -for-pack, and this module will be compile with -pack. |
optional |
[] |
||
Label of |
optional |
None |
||
Options to pass to PPX executable passed by the |
List of strings |
optional |
[] |
|
PPX runtime data dependencies. List of labels of files needed by the PPX executable passed via the |
optional |
[] |
||
Format of output of PPX transform: binary (default) or text. Value must be one of |
optional |
"@rules_ocaml//ppx/print" |
||
- |
Boolean |
optional |
False |
|
Single label of a target producing |
optional |
None |
||
A single module (struct) source file label. |
required |
ocaml_ns_archive
ocaml_ns_archive(name, archive_name, cc_deps, cc_linkage, env, manifest, ns_name, opts, shared)
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_archive:
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
A unique name for this target. |
required |
|||
Name of generated archive file, without extension. If not provided, name will be derived from target 'name' attribute. Ignored if archived == False. |
String |
optional |
"" |
|
Static (.a) or dynamic (.so, .dylib) libraries. Must by built or imported using Bazel’s rules_cc ruleset (thus providing CcInfo output). |
optional |
[] |
||
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. |
optional |
{} |
||
Env variables |
optional |
{} |
||
List of namespaced submodules; will be renamed by prefixing the namespace, |
optional |
[] |
||
Namespace name is derived from 'name' attribute by default; use this to override. |
String |
optional |
"" |
|
List of compile options; overrides configurable default options. Supports |
List of strings |
optional |
[] |
|
True: build a shared lib (.cmxs) |
Boolean |
optional |
False |
ocaml_ns_library
ocaml_ns_library(name, archive_name, archived, cc_deps, cc_linkage, env, manifest, ns_name, opts, shared)
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 |
---|---|---|---|---|
A unique name for this target. |
required |
|||
Name of generated archive file, without extension. If not provided, name will be derived from target 'name' attribute. Ignored if archived == False. |
String |
optional |
"" |
|
- |
Boolean |
optional |
False |
|
Static (.a) or dynamic (.so, .dylib) libraries. Must by built or imported using Bazel’s rules_cc ruleset (thus providing CcInfo output). |
optional |
[] |
||
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. |
optional |
{} |
||
Env variables |
optional |
{} |
||
List of namespaced submodules; will be renamed by prefixing the namespace, |
optional |
[] |
||
Namespace name is derived from 'name' attribute by default; use this to override. |
String |
optional |
"" |
|
List of compile options; overrides configurable default options. Supports |
List of strings |
optional |
[] |
|
True: build a shared lib (.cmxs) |
Boolean |
optional |
False |
ocaml_ns_resolver
ocaml_ns_resolver(name, deps, data, cc_deps, cc_linkage, deps_runtime, embed, env, include, manifest, merge, module_name, ns, open, opts, pack, ppx, ppx_args, ppx_data, ppx_print, ppx_verbose, sig, struct)
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 |
---|---|---|---|---|
A unique name for this target. |
required |
|||
List of dependencies. |
optional |
[] |
||
Runtime data dependencies: list of labels of data files needed by this module at runtime. This is a standard Bazel attribute; see Typical attributes. |
optional |
[] |
||
Static (.a) or dynamic (.so, .dylib) libraries. Must by built or imported using Bazel’s rules_cc ruleset (thus providing CcInfo output). |
optional |
[] |
||
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. |
optional |
{} |
||
Runtime module dependencies, e.g. .cmxs plugins. Use the |
optional |
[] |
||
Exogenous namespaces (resolver modules). |
optional |
{} |
||
Env variables |
optional |
{} |
||
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 |
optional |
{} |
||
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 |
[] |
|
Includes all submodules of an exogenous namespace. |
optional |
[] |
||
Use this string as module name, instead of deriving it from sig or struct |
String |
optional |
"" |
|
- |
String |
required |
||
List of OCaml dependencies to be passed with |
optional |
[] |
||
List of compile options; overrides configurable default options. Supports |
List of strings |
optional |
[] |
|
Experimental. List of pack submodules. They will be compiled with -for-pack, and this module will be compile with -pack. |
optional |
[] |
||
Label of |
optional |
None |
||
Options to pass to PPX executable passed by the |
List of strings |
optional |
[] |
|
PPX runtime data dependencies. List of labels of files needed by the PPX executable passed via the |
optional |
[] |
||
Format of output of PPX transform: binary (default) or text. Value must be one of |
optional |
"@rules_ocaml//ppx/print" |
||
- |
Boolean |
optional |
False |
|
Single label of a target producing |
optional |
None |
||
A single module (struct) source file label. |
optional |
None |
ocaml_signature
ocaml_signature(name, deps, src, data, env, module, ns_resolver, open, opts, pack, ppx, ppx_args, ppx_data, ppx_print, ppx_verbose, xmo)
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 |
|
@rules_ocaml//cfg/signature:warnings |
|
|
ATTRIBUTES for rule ocaml_signature:
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
A unique name for this target. |
required |
|||
List of OCaml dependencies. Use this for compiling a .mli source file with deps. See [Dependencies](#deps) for details. |
optional |
[] |
||
A single .mli source file label |
optional |
None |
||
- |
optional |
[] |
||
Env variables |
optional |
{} |
||
Set module (sig) name to this string |
String |
optional |
"" |
|
Bottom-up namespacing |
optional |
None |
||
List of OCaml dependencies to be passed with -open. |
optional |
[] |
||
List of compile options; overrides configurable default options. Supports |
List of strings |
optional |
[] |
|
Experimental |
String |
optional |
"" |
|
Label of |
optional |
None |
||
Options to pass to PPX executable passed by the |
List of strings |
optional |
[] |
|
PPX runtime data dependencies. List of labels of files needed by the PPX executable passed via the |
optional |
[] |
||
Format of output of PPX transform: binary (default) or text. Value must be one of |
optional |
"@rules_ocaml//ppx/print" |
||
- |
Boolean |
optional |
False |
|
Cross-module optimization. If false, compile with -opaque |
Boolean |
optional |
True |
ocaml_test
ocaml_test(name, data, cc_deps, cc_libs, cc_linkall, cc_linkopts, data_prefix_map, diff_cmd, env, epilogue, exe, main, opts, prologue, vm_runtime)
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 |
---|---|---|---|---|
A unique name for this target. |
required |
|||
Runtime dependencies: list of labels of data files needed by this executable at runtime. |
optional |
[] |
||
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). |
optional |
{} |
||
- |
optional |
[] |
||
True: use |
optional |
[] |
||
List of C/C link options. E.g. ["-lstd"]. |
List of strings |
optional |
[] |
|
Map for replacing path prefixes of data files |
optional |
{} |
||
- |
optional |
None |
||
Env variables |
optional |
{} |
||
List of OCaml dependencies. |
optional |
[] |
||
By default, executable name is derived from 'name' attribute; use this to override. |
String |
optional |
"" |
|
Label of module containing entry point of executable. In the list of dependencies, this will be placed after 'prologue' deps and before 'epilogue' deps. |
required |
|||
List of compile options; overrides configurable default options. Supports |
List of strings |
optional |
[] |
|
List of OCaml dependencies. |
optional |
[] |
||
@rules_ocaml//cfg/runtime:dynamic (default), @rules_ocaml//cfg/runtime:static, or a custom ocaml_vm_runtime target label |
optional |
"@rules_ocaml//cfg/runtime:dynamic" |
ocaml_vm_runtime
User-defined runtime, using ocamlc -make-runtime
ATTRIBUTES for rule ocaml_vm_runtime:
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
A unique name for this target. |
required |
|||
Libraries whose cc deps should be included in the runtime |
optional |
[] |
ocamllex
Generates an OCaml source file from an ocamllex source file.
ATTRIBUTES for rule ocamllex:
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
A unique name for this target. |
required |
|||
A single .mll source file label |
optional |
None |
||
Output filename. |
required |
|||
Options |
List of strings |
optional |
[] |
ocamlyacc
Generates OCaml source files from an ocamlyacc source file.
ATTRIBUTES for rule ocamlyacc:
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
A unique name for this target. |
required |
|||
A single .mly ocamlyacc source file label |
optional |
None |
||
Output filenames. |
List of labels |
required |
||
Options |
List of strings |
optional |
[] |
ppx_executable
ppx_executable(name, data, bin, cc_deps, cc_linkall, cc_linkopts, data_prefix_map, env, epilogue, exe, main, opts, ppx_codeps, prologue, vm_runtime)
Generates a PPX executable. Provides: [PpxExecutableMarker](providers_ppx.md#ppxexecutableprovider).
ATTRIBUTES for rule ppx_executable:
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
A unique name for this target. |
required |
|||
Runtime data dependencies. E.g. a file used by %%import from ppx_optcomp. |
optional |
[] |
||
Precompiled ppx executable |
optional |
None |
||
C/C++ library dependencies |
optional |
{} |
||
True: use |
optional |
[] |
||
List of C/C link options. E.g. `["-lstd"]`. |
List of strings |
optional |
[] |
|
Map for replacing path prefixes of data files. May be used to strip a path prefix (set value to empty string ""). |
optional |
{} |
||
Env variables |
optional |
{} |
||
List of OCaml dependencies. |
optional |
[] |
||
Name for output executable file. Overrides 'name' attribute. |
String |
optional |
"" |
|
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). |
required |
|||
List of compile options; overrides configurable default options. Supports |
List of strings |
optional |
[] |
|
List of non-opam adjunct dependencies (labels). |
optional |
[] |
||
List of OCaml dependencies. |
optional |
[] |
||
@ocaml_rules//cfg/runtime:dynamic (default), @ocaml_rules//cfg/runtime:static, or a custom ocaml_vm_runtime target label |
optional |
"@rules_ocaml//cfg/runtime:dynamic" |
ppx_module
ppx_module(name, deps, data, cc_deps, cc_linkage, deps_runtime, env, module_name, ns_resolver, open, opts, pack, ppx, ppx_args, ppx_codeps, ppx_compile_codeps, ppx_data, ppx_link_codeps, ppx_print, ppx_verbose, sig, struct)
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 anocaml_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 themodule
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 |
|
list of OCaml deps to add to all |
@rules_ocaml//cfg/module:cc_deps1 |
|
list of cc_deps to add to all |
@rules_ocaml//cfg/module:cc_linkstatic1 |
|
list of cc_deps to link statically (DEPRECATED) |
@rules_ocaml//cfg/module:warnings |
|
sets |
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 |
|
@rules_ocaml//cfg/module:verbose |
False |
|
ATTRIBUTES for rule ppx_module:
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
A unique name for this target. |
required |
|||
List of dependencies. |
optional |
[] |
||
Runtime data dependencies: list of labels of data files needed by this module at runtime. This is a standard Bazel attribute; see Typical attributes. |
optional |
[] |
||
Static (.a) or dynamic (.so, .dylib) libraries. Must by built or imported using Bazel’s rules_cc ruleset (thus providing CcInfo output). |
optional |
[] |
||
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. |
optional |
{} |
||
Runtime module dependencies, e.g. .cmxs plugins. Use the |
optional |
[] |
||
Env variables |
optional |
{} |
||
Use this string as module name, instead of deriving it from sig or struct |
String |
optional |
"" |
|
NS resolver module for bottom-up namespacing. Modules may use this attribute to elect membership in a bottom-up namespace. |
optional |
None |
||
List of OCaml dependencies to be passed with |
optional |
[] |
||
List of compile options; overrides configurable default options. Supports |
List of strings |
optional |
[] |
|
Experimental. List of pack submodules. They will be compiled with -for-pack, and this module will be compile with -pack. |
optional |
[] |
||
Label of |
optional |
None |
||
Options to pass to PPX executable passed by the |
List of strings |
optional |
[] |
|
List of non-opam adjunct dependencies (labels). |
optional |
[] |
||
List labels of compile-time dependencies. These are required to compile any file transformed by this ppx. |
optional |
[] |
||
PPX runtime data dependencies. List of labels of files needed by the PPX executable passed via the |
optional |
[] |
||
List labels of link-time dependencies. These are required to link any file transformed by this ppx. |
optional |
[] |
||
Format of output of PPX transform: binary (default) or text. Value must be one of |
optional |
"@rules_ocaml//ppx/print" |
||
- |
Boolean |
optional |
False |
|
Single label of a target producing |
optional |
None |
||
A single module (struct) source file label. |
required |
ppx_transform
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 |
---|---|---|---|---|
A unique name for this target. |
required |
|||
A single source file (struct or sig) label. |
required |
|||
Runtime data dependencies: list of labels of data files needed by ppx executable at runtime. |
optional |
[] |
||
List of args to pass to ppx executable at runtime. |
List of strings |
optional |
[] |
|
Env variables |
optional |
{} |
||
List of compile options; overrides configurable default options. Supports |
List of strings |
optional |
[] |
|
Label of |
optional |
None |
||
Format of output of PPX transform. Value must be one of |
optional |
"@rules_ocaml//ppx/print" |