ocaml_library Last updated Mar 27, 2025

load("@rules_ocaml//build/_rules:ocaml_library.bzl", "ocaml_library")

ocaml_library(name, archive_name, env, linkage, manifest, opts)

Aggregates a collection of OCaml modules.

An ocaml_library is a collection of modules packaged into an OBazl target; it is not a single binary file. It is an 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.

By default, libraries are not archived unless the client explicitly requests archiving. If you build a library directly from the command line, you’ll get an archive. But if a rule depends on an ocaml_library target, no archive will be produced. This default policy can be overridden. For example, an ocaml_binary target can set force_archived_libdeps to True.

This feature - context-dependent archiving - is still under development.

Attributes

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.

String

optional

""

env

Env variables

Dictionary: String -> String

optional

{}

linkage

By default, libraries are not packaged as archives or cmxs files. "static": archive the library; "shared": build cmxs.

String

optional

""

manifest

List of component modules for libraries.

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

[]