{"id":17992930,"url":"https://github.com/leostera/rules_reason","last_synced_at":"2025-10-05T06:36:09.440Z","repository":{"id":141534978,"uuid":"138081340","full_name":"leostera/rules_reason","owner":"leostera","description":"📐Reason/OCaml rules and tools for Bazel","archived":false,"fork":false,"pushed_at":"2018-09-26T07:05:14.000Z","size":327,"stargazers_count":19,"open_issues_count":3,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-21T01:11:08.197Z","etag":null,"topics":["bazel","bazel-rules","bucklescript","javascript","ocaml","reasonml"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leostera.png","metadata":{"files":{"readme":"README.rst","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,"governance":null}},"created_at":"2018-06-20T20:15:51.000Z","updated_at":"2021-09-07T10:45:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"70718f37-3858-42bb-8661-726037c0b125","html_url":"https://github.com/leostera/rules_reason","commit_stats":null,"previous_names":["leostera/rules_reason"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leostera%2Frules_reason","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leostera%2Frules_reason/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leostera%2Frules_reason/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leostera%2Frules_reason/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leostera","download_url":"https://codeload.github.com/leostera/rules_reason/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245571856,"owners_count":20637411,"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","bucklescript","javascript","ocaml","reasonml"],"created_at":"2024-10-29T20:09:39.412Z","updated_at":"2025-10-05T06:36:09.339Z","avatar_url":"https://github.com/leostera.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":".. role:: param(kbd)\n.. role:: type(emphasis)\n.. role:: value(code)\n.. |mandatory| replace:: **mandatory value**\n\n\nReasonML / BuckleScript Rules\n==============================\n\n.. image:: https://travis-ci.org/ostera/rules_reason.svg?branch=master\n  :target: https://travis-ci.org/ostera/rules_reason\n\nA collection of OCaml, ReasonML, and BuckleScript rules and tools for Bazel.\n\n  Note: this is alpha software! I'm building it to properly integrate a ReasonML\n  application into a bigger project that builds with Bazel.\n\nThis projet relies on two prerequisites:\n\n1. ``nix``, the purely functional package manager, which is used for installing the ReasonML tooling (``refmt`` specifically), ``opam``, ``yarn`` and ``node`` in an hermetic-ish fashion. At least you don't need to handle those yourself :)\n#. ``bazel``, naturally.\n\n\nIf you just cloned this repo and you have both those tools installed, feel free\nto start with a ``bazel build //...`` to get everything warmed up.\n\nThe examples works a separate workspace so you will need to run ``bazel build //...``\nthere as well if you wish to play around with them.\n\n  WARNING: because this rules handle all of their dependencies hermetically, a\n  clean install takes a good ~10 minutes on an early 2015 Macbook Pro.\n\n.. contents:: :depth: 2\n\nGetting Started\n---------------\n\nBegin by adding the following to your ``WORKSPACE``:\n\n.. code:: bzl\n\n  workspace(name = \"retool\")\n\n  ###\n  ### Reason Rules!\n  ###\n\n  rules_reason_version = \"f8b956b147bfcf22c90480e7ebea32e6769c1fe0\" # HEAD\n\n  http_archive(\n      name = \"com_github_ostera_rules_reason\",\n      sha256 = \"\",\n      strip_prefix = \"rules_reason-%s\" % (rules_reason_version,),\n      urls = [\"https://github.com/ostera/rules_reason/archive/%s.zip\" % (rules_reason_version,)],\n      )\n\n  ###\n  ### Nix Repositories\n  ###\n\n  load(\n      \"@com_github_ostera_rules_reason//reason/repositories:nix.bzl\",\n      \"nix_repositories\",\n  )\n\n  nix_repositories(\n      nix_sha256 = \"28121f6eb3d6c5b4c1fc9f716953ce8b0a793b841d0e9de095977b3ade06f92d\",\n      nix_version = \"20a78f74f8ac70d1099ff0d214cd00b25820da03\",\n  )\n\n  ###\n  ### Register Reason Toolchain\n  ###\n\n  load(\n      \"@com_github_ostera_rules_reason//reason:def.bzl\",\n      \"reason_register_toolchains\",\n  )\n\n  reason_register_toolchains(\n      bs_sha256 = \"db3f37eb27bc1653c3045e97adaa83e800dff55ce093d78ddfe85e85165e2125\",\n      bs_version = \"939ef1e1e874c80ff9df74b16dab1dbe2e2df289\",\n      nixpkgs_revision = \"d91a8a6ece07f5a6df82aa5dc02030d9c6724c27\",\n      nixpkgs_sha256 = \"0c5291bcf7d909cc4b18a24effef03f717d6374de377f91324725c646d494857\",\n  )\n\n  ################################################################################\n  #\n  #   Declare dependencies\n  #\n  ################################################################################\n\n  load(\n      \"//3rdparty:load.bzl\",\n      \"declare_dependencies\"\n  )\n\n  declare_dependencies()\n\n\nUse ``reason_module`` to compile a group of ``.re`` and ``.rei`` files into their\ncorresponding ``.ml`` and ``.mli`` counterparts.\n\nFurther consume these outputs with ``ocaml_module``, ``bs_module``,\n``ocaml_bytecode_binary``, or ``ocaml_native_binary``.\n\nCompiling to Javascript\n~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nYou can use ``bs_module`` to turn any ML source target into Javascript, this\nincludes the outputs from a ``reason_module`` rule too.\n\nUnfortunately ``bsc`` requires a ``bsconfig.json`` file at the place where you call\nit. This means that you need to have that file at the root of your project.\n\n.. code:: bzl\n\n  # BUILD file at //...\n  filegroup(\n    name = \"bsconfig\",\n    srcs = [\"bsconfig.json\"],\n  )\n\n  # BUILD file somewhere in your sources!\n  reason_module(\n    name = \"srcs.re\",\n    srcs = glob([\"*.re\"]),\n  )\n\n  bs_module(\n    name = \"srcs.js\",\n    config = [\"//:bsconfig\"],\n    srcs = [\":srcs.re\"],\n    deps = [\":deps\"],\n  )\n\nCompiling to Native and Bytecode\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nYou can use ``ocaml_native_binary`` and ``ocaml_bytecode_binary`` to compile your\nML sources into native or bytecode binaries, and yes you can use your\n``reason_module`` targets as sources!\n\n.. code:: bzl\n\n  # BUILD file somewhere in your sources!\n  reason_module(\n      name = \"srcs\",\n      srcs = glob([\"*.re\"]),\n      )\n\n  ocaml_native_binary(\n      name = \"native\",\n      srcs = [\":srcs\"],\n    )\n\n  ocaml_bytecode_binary(\n      name = \"bytecode\",\n      srcs = [\":srcs\"],\n    )\n\n\nWhat's next?\n------------\n\nIn no particular order:\n\n#. DevFlow: Top-Level\n#. DevFlow: Dependencies\n#. DevFlow: Generating Merlin and pointing IDEs to the right places\n#. Rules: ``*_test``\n#. DevFlow: Auto-rebuild\n#. Rules: ``node_binary``\n#. \u003c your suggestion here! \u003e\n\nRules\n------\n\n``reason_module``\n~~~~~~~~~~~~~~~~~~\n\nThis compiles down ReasonML code into a representation that is friendly for\nBuckleScript or the default Ocaml compiler.\n\nWhich one will it be compatible with is determined by how you write your\nReasonML code.\n\n+----------------------------+-----------------------------+------------------------------------------+\n| **Name**                   | **Type**                    | **Default value**                        |\n+----------------------------+-----------------------------+------------------------------------------+\n| :param:`name`              | :type:`string`              | |mandatory|                              |\n+----------------------------+-----------------------------+------------------------------------------+\n| A unique name for this rule.                                                                        |\n|                                                                                                     |\n+----------------------------+-----------------------------+------------------------------------------+\n| :param:`srcs`              | :type:`string_list`         | |mandatory|                              |\n+----------------------------+-----------------------------+------------------------------------------+\n| The sources of this library.                                                                        |\n|                                                                                                     |\n| The name of the sources will be preserved, and the outputs will replace the ``.re`` or ``.rei``     |\n| extension with ``.ml`` or ``.mli`` correspondingly.                                                 |\n|                                                                                                     |\n| Other ``bs_module`` rules can depend on this library to compile it down to Javascript code.         |\n|                                                                                                     |\n+----------------------------+-----------------------------+------------------------------------------+\n| :param:`toolchain`         | :type:`label`               | :value: \"//reason/toolchain:bs-platform\" |\n+----------------------------+-----------------------------+------------------------------------------+\n| The toolchain to use when building this rule.                                                       |\n|                                                                                                     |\n| It should include both ``refmt``, ``bsc`` and a filegroup containing the BuckleScript stdlib.       |\n|                                                                                                     |\n+----------------------------+-----------------------------+------------------------------------------+\n\nExample:\n\n.. code:: bzl\n\n  # //my_app/BUILD\n  load(\n      \"@com_github_ostera_rules_reason//reason:def.bzl\",\n      \"reason_module\",\n  )\n\n  reason_module(\n      name = \"my_app\",\n      srcs = glob([\"*.re\", \"*.rei\"])\n      visibility = [\"//my_app:__subpackages__\"],\n    )\n\n``bs_module``\n~~~~~~~~~~~~~~~~~~\n\nCompile Ocaml code into Javascript.\n\n+----------------------------+-----------------------------+-------------------------------------------+\n| **Name**                   | **Type**                    | **Default value**                         |\n+----------------------------+-----------------------------+-------------------------------------------+\n| :param:`name`              | :type:`string`              | |mandatory|                               |\n+----------------------------+-----------------------------+-------------------------------------------+\n| A unique name for this rule.                                                                         |\n|                                                                                                      |\n+----------------------------+-----------------------------+-------------------------------------------+\n| :param:`config`            | :type:`label`               | |mandatory|                               |\n+----------------------------+-----------------------------+-------------------------------------------+\n| The ``bsconfig.json`` file.                                                                          |\n|                                                                                                      |\n| The file must be located at the root of your WORKSPACE. Currently looking to work around this.       |\n|                                                                                                      |\n+----------------------------+-----------------------------+-------------------------------------------+\n| :param:`srcs`              | :type:`string_list`         | |mandatory|                               |\n+----------------------------+-----------------------------+-------------------------------------------+\n| The ML sources of this library.                                                                      |\n|                                                                                                      |\n| The name of the sources will be preserved, and the outputs will replace the ``.ml`` by their         |\n| compilation counterparts (``.cmi``, ``.cmj``, ``.cmt``, etc) and the ``.js`` output.                 |\n|                                                                                                      |\n| Other ``bs_module`` rules can depend on this library to compile it down to Javascript code.          |\n|                                                                                                      |\n+----------------------------+-----------------------------+-------------------------------------------+\n| :param:`deps`              | :type:`label_list`          | :value: []                                |\n+----------------------------+-----------------------------+-------------------------------------------+\n| Dependencies of this library, must include ``BsModuleInfo`` providers.                               |\n|                                                                                                      |\n+----------------------------+-----------------------------+-------------------------------------------+\n| :param:`toolchain`         | :type:`label`               | :value: \"//reason/toolchain:bs-platform\"  |\n+----------------------------+-----------------------------+-------------------------------------------+\n| The toolchain to use when building this rule.                                                        |\n|                                                                                                      |\n| It should include both ``refmt``, ``bsc`` and a filegroup containing the BuckleScript stdlib.        |\n|                                                                                                      |\n+----------------------------+-----------------------------+-------------------------------------------+\n\nExample:\n\n.. code:: bzl\n\n  load(\n      \"@com_github_ostera_rules_reason//reason:def.bzl\",\n      \"reason_module\",\n      \"bs_module\"\n  )\n\n  reason_module(\n      name = \"my_app\",\n      srcs = glob([\"*.re\", \"*.rei\"]),\n      )\n\n  bs_module(\n      visibility = [\"//examples/app:__subpackages__\"],\n      name = \"my_app.js\",\n      config = \"//:bs_config\",\n      srcs = [ \":my_app\" ],\n      deps = [ \"//examples/some/dependency\" ],\n      )\n\n``ocaml_native_binary`` and ``ocaml_bytecode_binary``\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nCompile ML code into bytecode or native binaries. For bytecode binaries it will\ncopmile them including the runtime, rather than separately. This is something\nthat I'd like to change in the future.\n\n+----------------------------+-----------------------------+-------------------------------------------+\n| **Name**                   | **Type**                    | **Default value**                         |\n+----------------------------+-----------------------------+-------------------------------------------+\n| :param:`name`              | :type:`string`              | |mandatory|                               |\n+----------------------------+-----------------------------+-------------------------------------------+\n| A unique name for this rule, used as the name of the output binary                                   |\n|                                                                                                      |\n+----------------------------+-----------------------------+-------------------------------------------+\n| :param:`srcs`              | :type:`string_list`         | |mandatory|                               |\n+----------------------------+-----------------------------+-------------------------------------------+\n| The ML sources of this library.                                                                      |\n|                                                                                                      |\n|                                                                                                      |\n+----------------------------+-----------------------------+-------------------------------------------+\n| :param:`deps`              | :type:`label_list`          | :value: []                                |\n+----------------------------+-----------------------------+-------------------------------------------+\n| Dependencies of this library, must include ``ReasonModuleInfo`` providers.                           |\n|                                                                                                      |\n+----------------------------+-----------------------------+-------------------------------------------+\n| :param:`toolchain`         | :type:`label`               | :value: \"//reason/toolchain:bs-platform\"  |\n+----------------------------+-----------------------------+-------------------------------------------+\n| The toolchain to use when building this rule.                                                        |\n|                                                                                                      |\n| It should include both ``ocamlc``, ``ocamlopt``, ``ocamldep``, ``ocamlrun``,  and a filegroup        |\n| containing the Ocaml stdlib.                                                                         |\n|                                                                                                      |\n+----------------------------+-----------------------------+-------------------------------------------+\n\nExample:\n\n.. code:: bzl\n\n  load(\n      \"@com_github_ostera_rules_reason//reason:def.bzl\",\n      \"reason_module\",\n      \"ocaml_native_binary\",\n  )\n\n  # BUILD file somewhere in your sources!\n  reason_module(\n      name = \"srcs\",\n      srcs = glob([\"*.re\"]),\n      )\n\n  # replace native with bytecode in the rule name and you get a bytecode binary\n  ocaml_native_binary(\n      name = \"my_bin_name\",\n      srcs = [\":srcs\"],\n    )\n\n\nToolchain\n--------\n\nThere is a ToolchainInfo that describes the fields required throughout the build\nrules to successfully compile from ReasonML down to Javascript.\n\nFeel free to register your own toolchain or use the default toolchain\nthat will be managed completely within Bazel.\n\n+--------------------------------+--------------------------------------------+\n| **Name**                       | **Type**                                   |\n+--------------------------------+--------------------------------------------+\n| :param:`bsc`                   | :type:`File`                               |\n+--------------------------------+--------------------------------------------+\n| The BuckleScript compiler file.                                             |\n|                                                                             |\n+--------------------------------+--------------------------------------------+\n| :param:`refmt`                 | :type:`File`                               |\n+--------------------------------+--------------------------------------------+\n| The ReasonML Formatter file.                                                |\n|                                                                             |\n+--------------------------------+--------------------------------------------+\n| :param:`bs_stdlib`             | :type:`Filegroup`                          |\n+--------------------------------+--------------------------------------------+\n| A Filegroup with all the source and compiled files for the BuckleScript     |\n| standard library that will be used for compiling Ocaml into Javascript      |\n|                                                                             |\n+--------------------------------+--------------------------------------------+\n| :param:`ocamlc`                | :type:`File`                               |\n+--------------------------------+--------------------------------------------+\n| The Ocaml bytecode compiler.                                                |\n|                                                                             |\n+--------------------------------+--------------------------------------------+\n| :param:`ocamlopt`              | :type:`File`                               |\n+--------------------------------+--------------------------------------------+\n| The Ocaml native compiler.                                                  |\n|                                                                             |\n+--------------------------------+--------------------------------------------+\n| :param:`ocamldep`              | :type:`File`                               |\n+--------------------------------+--------------------------------------------+\n| The Ocaml dependency tool.                                                  |\n|                                                                             |\n+--------------------------------+--------------------------------------------+\n| :param:`ocamlrun`              | :type:`File`                               |\n+--------------------------------+--------------------------------------------+\n| The Ocaml bytecode interpreter.                                             |\n|                                                                             |\n+--------------------------------+--------------------------------------------+\n+--------------------------------+--------------------------------------------+\n| :param:`ocaml_stdlib`          | :type:`Filegroup`                          |\n+--------------------------------+--------------------------------------------+\n| A Filegroup with Ocaml standard library.                                    |\n|                                                                             |\n+--------------------------------+--------------------------------------------+\n\nProviders\n---------\n\nThere are 2 providers included, that will carry information for the different\nstages of the build process.\n\n``ReasonModuleInfo``\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nThis provider is the output of the ``reason_module`` rule, and it represents a\ncompilation unit from ReasonML to Ocaml.\n\n+--------------------------------+--------------------------------------------+\n| **Name**                       | **Type**                                   |\n+--------------------------------+--------------------------------------------+\n| :param:`name`                  | :type:`string`                             |\n+--------------------------------+--------------------------------------------+\n| The name of your the colletion of files                                     |\n|                                                                             |\n+--------------------------------+--------------------------------------------+\n| :param:`srcs`                  | :type:`depset(File)`                       |\n+--------------------------------+--------------------------------------------+\n| A ``depset`` of all the ReasonML files that will be compiled to ML          |\n|                                                                             |\n+--------------------------------+--------------------------------------------+\n| :param:`outs`                  | :type:`depset(File)`                       |\n+--------------------------------+--------------------------------------------+\n| A ``depset`` of all the target ML files that will be generated              |\n|                                                                             |\n+--------------------------------+--------------------------------------------+\n\n``BsModuleInfo``\n~~~~~~~~~~~~~~~~~~~\n\nThis provider is the output of the ``bs_module`` rule, and it represents a\ncompilation unit from Ocaml to Javascript.\n\n+--------------------------------+--------------------------------------------+\n| **Name**                       | **Type**                                   |\n+--------------------------------+--------------------------------------------+\n| :param:`name`                  | :type:`string`                             |\n+--------------------------------+--------------------------------------------+\n| The name of your the colletion of files                                     |\n|                                                                             |\n+--------------------------------+--------------------------------------------+\n| :param:`srcs`                  | :type:`depset(File)`                       |\n+--------------------------------+--------------------------------------------+\n| A ``depset`` of all the Ocaml files that will be compiled to Javascript     |\n|                                                                             |\n+--------------------------------+--------------------------------------------+\n| :param:`outs`                  | :type:`depset(File)`                       |\n+--------------------------------+--------------------------------------------+\n| A ``depset`` of all the target ML and Js files that will be generated       |\n|                                                                             |\n+--------------------------------+--------------------------------------------+\n| :param:`deps`                  | :type:`depset(File)`                       |\n+--------------------------------+--------------------------------------------+\n| A ``depset`` of all the BuckleScript modules files that the ``srcs`` depend |\n| on                                                                          |\n|                                                                             |\n+--------------------------------+--------------------------------------------+\n\n``MlModuleInfo``\n~~~~~~~~~~~~~~~~~~~\n\nThis provider is the output of the ``bs_module`` rule, and it represents a\ncompilation unit from Ocaml to Javascript.\n\n+--------------------------------+--------------------------------------------+\n| **Name**                       | **Type**                                   |\n+--------------------------------+--------------------------------------------+\n| :param:`name`                  | :type:`string`                             |\n+--------------------------------+--------------------------------------------+\n| The name of your the colletion of files                                     |\n|                                                                             |\n+--------------------------------+--------------------------------------------+\n| :param:`srcs`                  | :type:`depset(File)`                       |\n+--------------------------------+--------------------------------------------+\n| A ``depset`` of all the Ocaml files that will to be compiled.               |\n|                                                                             |\n+--------------------------------+--------------------------------------------+\n| :param:`outs`                  | :type:`depset(File)`                       |\n+--------------------------------+--------------------------------------------+\n| A ``depset`` of all the target binary files.                                |\n|                                                                             |\n+--------------------------------+--------------------------------------------+\n| :param:`deps`                  | :type:`depset(File)`                       |\n+--------------------------------+--------------------------------------------+\n| A ``depset`` of all the Ocaml modules files that the ``srcs`` depend        |\n| on                                                                          |\n|                                                                             |\n+--------------------------------+--------------------------------------------+\n| :param:`target`                | :type:`\"native\" | \"bytecode\"`              |\n+--------------------------------+--------------------------------------------+\n| Whether this module is being compiled natively or as bytecode.              |\n|                                                                             |\n+--------------------------------+--------------------------------------------+\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleostera%2Frules_reason","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleostera%2Frules_reason","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleostera%2Frules_reason/lists"}