Build OCaml with Bazel. Very experimental.
Add the following to your WORKSPACE
file.
git_repository(
name = "io_bazel_rules_ocaml",
remote = "https://github.com/jin/rules_ocaml.git",
commit = "7a0a6e5226af5f09eb6e3379b901d8f2ffdb8bbf",
)
load("@io_bazel_rules_ocaml//ocaml:repo.bzl", "ocaml_repositories")
ocaml_repositories(
opam_packages = {
# Put your OPAM dependencies here
"lwt": "3.1.0",
"yojson": "1.4.0",
},
)
and this to your BUILD files.
load("@io_bazel_rules_ocaml//ocaml:ocaml.bzl", "ocaml_native_binary", "ocaml_bytecode_binary", "ocaml_interface")
ocaml_repositories()
will download and compile the OCaml toolchain, including ocamlbuild
, ocamlfind
and OPAM
itself, as the official source doesn't release binaries directly and requires the use of OPAM for installations.
The initial load time of toolchain compilation will take a few minutes and will not happen again for the same project.
Generates a native binary using ocamlopt
or bytecode binary using ocamlc
.
ocaml_native_library(name, srcs, src_root, opam_packages)
ocaml_bytecode_library(name, srcs, src_root, opam_packages)
ocaml_native_binary(
name = "hello_world",
srcs = glob(["examples/*.ml"]),
src_root = "examples/hello_world.ml",
opam_packages = ["yojson", "lwt"],
)
ocaml_bytecode_binary(
name = "other_binary",
srcs = [
"examples/foo.ml",
"examples/bar.ml",
"examples/entry.ml",
],
src_root = "examples/entry.ml",
opam_packages = ["pkg_foo", "pkg_bar"],
)
Attributes | |
---|---|
name |
A unique name for this target |
srcs |
List of OCaml |
src_root |
The OCaml
Defaults to |
opam_packages |
The name of the OPAM package dependencies required by this binary. The packages (and their versions) must already be defined in your WORKSPACE file's |
Generates a .mli
file of the source file.
ocaml_interface(name, src)
Attributes | |
---|---|
name |
A unique name for this target |
src |
The OCaml
|
ocaml_interface(
name = "hello_world_interface",
src = "examples/hello_world.ml",
)