{"id":15061190,"url":"https://github.com/jin/rules_ocaml","last_synced_at":"2025-04-10T06:37:23.376Z","repository":{"id":52659248,"uuid":"69768452","full_name":"jin/rules_ocaml","owner":"jin","description":"OCaml build rules for Bazel","archived":false,"fork":false,"pushed_at":"2021-04-22T00:04:49.000Z","size":28,"stargazers_count":37,"open_issues_count":3,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-24T07:41:10.839Z","etag":null,"topics":["bazel","bazel-rules","ocaml","skylark"],"latest_commit_sha":null,"homepage":"https://bazel.build","language":"Starlark","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-01T23:02:32.000Z","updated_at":"2024-03-05T12:34:11.000Z","dependencies_parsed_at":"2022-08-22T02:40:52.211Z","dependency_job_id":null,"html_url":"https://github.com/jin/rules_ocaml","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jin%2Frules_ocaml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jin%2Frules_ocaml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jin%2Frules_ocaml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jin%2Frules_ocaml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jin","download_url":"https://codeload.github.com/jin/rules_ocaml/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248171252,"owners_count":21059330,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bazel","bazel-rules","ocaml","skylark"],"created_at":"2024-09-24T23:11:22.669Z","updated_at":"2025-04-10T06:37:23.350Z","avatar_url":"https://github.com/jin.png","language":"Starlark","funding_links":[],"categories":["Package Management"],"sub_categories":[],"readme":"# OCaml rules for Bazel\n\n## Rules\n\n* [ocaml_native_binary](#ocaml_native_binary/ocaml_bytecode_binary)\n* [ocaml_bytecode_binary](#ocaml_native_binary/ocaml_bytecode_binary)\n* [ocaml_interface](#ocaml_interface)\n\n## Overview\n\nBuild OCaml with Bazel. Very experimental.\n\n## Setup\n\nAdd the following to your `WORKSPACE` file.\n\n```bzl\ngit_repository(\n    name = \"io_bazel_rules_ocaml\",\n    remote = \"https://github.com/jin/rules_ocaml.git\",\n    commit = \"7a0a6e5226af5f09eb6e3379b901d8f2ffdb8bbf\",\n)\n\nload(\"@io_bazel_rules_ocaml//ocaml:repo.bzl\", \"ocaml_repositories\")\nocaml_repositories(\n    opam_packages = {\n        # Put your OPAM dependencies here\n        \"lwt\": \"3.1.0\",\n        \"yojson\": \"1.4.0\",\n    },\n)\n```\n\nand this to your BUILD files.\n\n```bzl\nload(\"@io_bazel_rules_ocaml//ocaml:ocaml.bzl\", \"ocaml_native_binary\", \"ocaml_bytecode_binary\", \"ocaml_interface\")\n```\n\n`ocaml_repositories()` will download and compile the OCaml toolchain, including `ocamlbuild`, `ocamlfind` and `OPAM` itself, as the [official source](https://caml.inria.fr/download.en.html) doesn't release binaries directly and requires the use of OPAM for installations. \n\nThe initial load time of toolchain compilation will take a few minutes and will not happen again for the same project.\n\n\n## Rules\n\n### ocaml_native_binary/ocaml_bytecode_binary\n\nGenerates a native binary using `ocamlopt` or bytecode binary using `ocamlc`.\n\n```bzl\nocaml_native_library(name, srcs, src_root, opam_packages)\nocaml_bytecode_library(name, srcs, src_root, opam_packages)\n```\n\n#### Example\n\n```bzl\nocaml_native_binary(\n    name = \"hello_world\",\n    srcs = glob([\"examples/*.ml\"]),\n    src_root = \"examples/hello_world.ml\",\n    opam_packages = [\"yojson\", \"lwt\"],\n)\n\nocaml_bytecode_binary(\n    name = \"other_binary\",\n    srcs = [\n      \"examples/foo.ml\",\n      \"examples/bar.ml\",\n      \"examples/entry.ml\",\n    ],\n    src_root = \"examples/entry.ml\",\n    opam_packages = [\"pkg_foo\", \"pkg_bar\"],\n)\n```\n\n\u003ctable class=\"table table-condensed table-bordered table-params\"\u003e\n  \u003ccolgroup\u003e\n    \u003ccol class=\"col-param\" /\u003e\n    \u003ccol class=\"param-description\" /\u003e\n  \u003c/colgroup\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth colspan=\"2\"\u003eAttributes\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ccode\u003ename\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003e\n        \u003cp\u003e\u003ccode\u003eName, required\u003c/code\u003e\u003c/p\u003e\n        \u003cp\u003eA unique name for this target\u003c/p\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ccode\u003esrcs\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003e\n        \u003cp\u003e\u003ccode\u003eList of labels, required\u003c/code\u003e\u003c/p\u003e\n        \u003cp\u003eList of OCaml \u003ccode\u003e.ml\u003c/code\u003e source files used to build the\n        library\u003c/p\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ccode\u003esrc_root\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003e\n        \u003cp\u003e\u003ccode\u003eLabel, optional\u003c/code\u003e\u003c/p\u003e\n        \u003cp\u003eThe OCaml \u003ccode\u003e.ml\u003c/code\u003e source file used for the binary's entry point.\u003cp\u003e\n        \u003cp\u003eDefaults to \u003ccode\u003emain.ml\u003c/code\u003e if not specified.\n      \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ccode\u003eopam_packages\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003e\n        \u003cp\u003e\u003ccode\u003eList of strings, optional\u003c/code\u003e\u003c/p\u003e\n        \u003cp\u003eThe name of the OPAM package dependencies required by this binary.\u003c/p\u003e\n        \u003cp\u003eThe packages (and their versions) must already be defined in your WORKSPACE file's \u003ccode\u003eocaml_repositories()\u003c/code\u003e.\n      \u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n### ocaml_interface\n\nGenerates a `.mli` file of the source file.\n\n```bzl\nocaml_interface(name, src)\n```\n\n\u003ctable class=\"table table-condensed table-bordered table-params\"\u003e\n  \u003ccolgroup\u003e\n    \u003ccol class=\"col-param\" /\u003e\n    \u003ccol class=\"param-description\" /\u003e\n  \u003c/colgroup\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth colspan=\"2\"\u003eAttributes\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ccode\u003ename\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003e\n        \u003cp\u003e\u003ccode\u003eName, required\u003c/code\u003e\u003c/p\u003e\n        \u003cp\u003eA unique name for this target\u003c/p\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\u003ccode\u003esrc\u003c/code\u003e\u003c/td\u003e\n      \u003ctd\u003e\n        \u003cp\u003e\u003ccode\u003eLabel\u003c/code\u003e\u003c/p\u003e\n        \u003cp\u003eThe OCaml \u003ccode\u003e.ml\u003c/code\u003e source file used for generating the interface file\u003cp\u003e\n      \u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n#### Example\n\n```bzl\nocaml_interface(\n    name = \"hello_world_interface\",\n    src = \"examples/hello_world.ml\",\n)\n```\n\n## Projects using rules_ocaml\n\n- [https://github.com/jin/scheme.ml](https://github.com/jin/scheme.ml)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjin%2Frules_ocaml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjin%2Frules_ocaml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjin%2Frules_ocaml/lists"}