ocaml_module Last updated Mar 27, 2025
load("@rules_ocaml//build:rules.bzl", "ocaml_module")
ocaml_module(name, deps, data, cc_deps, cc_linkage, deps_runtime, env, module_name, ns, 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.
Examples
Configurable defaults
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
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
A unique name for this target. |
required |
|||
List of dependencies. May include C/C++ libraries produced by rules_cc. |
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). CC libraries listed here will be built with compilation_mode set to |
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 |
"" |
|
Label of an ocaml_ns target, which must list this module in its |
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 |
None |
||
- |
Boolean |
optional |
False |
|
Single label of a target producing |
optional |
None |
||
A single module (struct) source file label. |
required |