Giter Club home page Giter Club logo

rules_ocaml's Introduction

OCaml rules for Bazel

Rules

Overview

Build OCaml with Bazel. Very experimental.

Setup

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.

Rules

ocaml_native_binary/ocaml_bytecode_binary

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)

Example

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

Name, required

A unique name for this target

srcs

List of labels, required

List of OCaml .ml source files used to build the library

src_root

Label, optional

The OCaml .ml source file used for the binary's entry point.

Defaults to main.ml if not specified.

opam_packages

List of strings, optional

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 ocaml_repositories().

ocaml_interface

Generates a .mli file of the source file.

ocaml_interface(name, src)
Attributes
name

Name, required

A unique name for this target

src

Label

The OCaml .ml source file used for generating the interface file

Example

ocaml_interface(
    name = "hello_world_interface",
    src = "examples/hello_world.ml",
)

Projects using rules_ocaml

rules_ocaml's People

Contributors

jin avatar liyistc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

rules_ocaml's Issues

Make src_root optional when there's only one srcs

It would be nice to allow this:

ocaml_native_binary(
    name = "ocaml",
    srcs = "hello.ml",
)

In other words, when there's only one source file, it should be used as the root one.

Suggestion: Maybe rename src_root to main? I think it's a more common name.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.