Skip to main content

ocaml_binary

name

def name(
*,
name: str,
default_target_platform: None | str = ...,
target_compatible_with: list[str] = ...,
compatible_with: list[str] = ...,
exec_compatible_with: list[str] = ...,
visibility: list[str] = ...,
within_view: list[str] = ...,
metadata: OpaqueMetadata = ...,
tests: list[str] = ...,
modifiers: OpaqueMetadata = ...,
_apple_platforms: dict[str, str] = ...,
_cxx_toolchain: str = ...,
_ocaml_toolchain: str = ...,
bytecode_only: None | bool = ...,
compiler_flags: list[str] = ...,
contacts: list[str] = ...,
default_host_platform: None | str = ...,
deps: list[str] = ...,
labels: list[str] = ...,
licenses: list[str] = ...,
linker_flags: list[str] = ...,
ocamldep_flags: list[str] = ...,
platform: None | str = ...,
platform_compiler_flags: list[(str, list[str])] = ...,
platform_deps: list[(str, list[str])] = ...,
platform_linker_flags: list[(str, list[str])] = ...,
srcs: None | list[str] | dict[str, str] = ...,
warnings_flags: None | str = ...,
) -> None

A ocaml_binary() rule builds both native and bytecode executables from the supplied set of OCaml and C source files and dependencies.

Parameters

  • name: name of the target
  • default_target_platform: specifies the default target platform, used when no platforms are specified on the command line
  • target_compatible_with: a list of constraints that are required to be satisfied for this target to be compatible with a configuration
  • compatible_with: a list of constraints that are required to be satisfied for this target to be compatible with a configuration
  • exec_compatible_with: a list of constraints that are required to be satisfied for this target to be compatible with an execution platform
  • visibility: a list of visibility patterns restricting what targets can depend on this one
  • within_view: a list of visibility patterns restricting what this target can depend on
  • metadata: a key-value map of metadata associated with this target
  • tests: a list of targets that provide tests for this one
  • modifiers: an array of modifiers associated with this target
  • compiler_flags: The set of additional compiler flags to pass to ocaml compiler. It supports specifying ppx (see for example).
  • deps: The set of dependencies of this rule. It could include references to ocaml_library and cxx_library rules.
  • platform_deps: Platform specific dependencies. These should be specified as a list of pairs where the first element is an un-anchored regex (in java.util.regex.Pattern syntax) against which the platform name is matched, and the second element is a list of dependencies (same format as deps) that are exported if the platform matches the regex. See deps for more information.
  • srcs: The set of source files to be compiled by this rule. It supports *.ml, *.mli, *.mly, *.mll, and *.c files. (see this test as C interop example and this test as parser and lexer example).

Details

Note: Buck is currently tested with 4.X OCaml series.

Examples:

For more examples, check out our integration tests.


ocaml_binary(
name='greet',
srcs=[
'main.ml',
'lex.mll',
'parser.mly',
'hashtable.c',
],
deps=[
':greeting',
':bridge',
],
)

ocaml_library(
name='greeting',
srcs=[
'greeting.ml',
],
deps=[
':join',
],
)

ocaml_library(
name='join',
srcs=[
'join.ml',
],
)

cxx_library(
name='bridge',
srcs=[
'bridge.c',
],
)