Build OCaml with Bazel. Very experimental. API is expected to change.
This is a wrapper around ocamlbuild
. Ensure that the OCaml toolchain (ocamlbuild
, ocamlfind
, etc) is reachable in your PATH
. TODO: have ocaml_repositories
download the toolchain.
Add the following to your WORKSPACE
file.
git_repository(
name = "io_bazel_rules_ocaml",
remote = "https://github.com/jin/rules_ocaml.git",
commit = "de567d0e6653f9e8208a42bfe26b30d58e6beeaa",
)
load("@io_bazel_rules_ocaml//ocaml:ocaml.bzl", "ocaml_repositories")
ocaml_repositories()
# this downloads the OPAM precompiled binaries into your bazel cache, but doesn't use them directly yet.
and this to your BUILD files.
load("@io_bazel_rules_ocaml//ocaml:ocaml.bzl", "ocaml_native_binary", "ocaml_bytecode_binary")
Generates a native binary.
ocaml_native_binary(
name = "hello_world",
srcs = glob(["examples/*.ml"]),
opam_packages = ["pkg_foo", "pkg_bar"],
src_root = "examples/hello_world.ml", # Optional, defaults to the first main.ml found while loading the sources.
)
Generates a bytecode binary.
ocaml_bytecode_binary(
name = "hello_world",
srcs = glob(["examples/*.ml"]),
opam_packages = ["pkg_foo", "pkg_bar"],
src_root = "examples/hello_world.ml", # Optional, defaults to the first main.ml found while loading the sources.
)
Generates a .mli
file of the source.
ocaml_interface(
name = "hello_world_interface",
src = "examples/hello_world.ml",
)