Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jin/rules_ocaml
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.0.1
Choose a base ref
...
head repository: jin/rules_ocaml
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Jun 30, 2020

  1. Update for Bazel 3.3

    jin committed Jun 30, 2020
    Copy the full SHA
    96df1a1 View commit details
  2. More fixes for 3.3

    jin committed Jun 30, 2020
    Copy the full SHA
    737e7fa View commit details
Showing with 35 additions and 30 deletions.
  1. +27 −22 ocaml/ocaml.bzl
  2. +8 −8 ocaml/repo.bzl
49 changes: 27 additions & 22 deletions ocaml/ocaml.bzl
Original file line number Diff line number Diff line change
@@ -1,49 +1,55 @@
load("//ocaml:repo.bzl", "OPAM_ROOT_DIR", "OCAML_VERSION", "COMPILER_NAME")
OCAML_FILETYPES = FileType([
OCAML_FILETYPES = [
".ml", ".mli", ".cmx", ".cmo", ".cma"
])
]

_ocaml_toolchain_attrs = {
"_opam": attr.label(
default = Label("@opam//:opam"),
executable = True,
single_file = True,
allow_files = True,
allow_single_file = True,
cfg = "host",
),
"_ocamlc": attr.label(
default = Label("@ocaml_toolchain//:ocamlc"),
executable = True,
single_file = True,
allow_files = True,
allow_single_file = True,
cfg = "host",
),
"_ocamlopt": attr.label(
default = Label("@ocaml_toolchain//:ocamlopt"),
executable = True,
single_file = True,
allow_files = True,
allow_single_file = True,
cfg = "host",
),
"_ocamlfind": attr.label(
default = Label("@ocaml_toolchain//:ocamlfind"),
executable = True,
single_file = True,
allow_files = True,
allow_single_file = True,
cfg = "host",
),
"_ocamlbuild": attr.label(
default = Label("@ocaml_toolchain//:ocamlbuild"),
executable = True,
single_file = True,
allow_files = True,
allow_single_file = True,
cfg = "host",
)
}

def _add(attrs, *others):
new = {}
new.update(attrs)
for o in others:
for name in o.keys():
if name in new:
fail("Attr '%s' is defined twice." % name)
new[name] = o[name]
return new

def _ocaml_interface_impl(ctx):
ctx.actions.run_shell(
inputs = [ctx.file.src, ctx.executable._ocamlc],
tools = [ctx.executable._ocamlc],
inputs = [ctx.file.src],
outputs = [ctx.outputs.mli],
progress_message = "Compiling interface file %s" % ctx.label,
mnemonic="OCamlc",
@@ -54,12 +60,11 @@ def _ocaml_interface_impl(ctx):

ocaml_interface = rule(
implementation = _ocaml_interface_impl,
attrs = {
attrs = _add({
"src": attr.label(
allow_files = OCAML_FILETYPES,
single_file = True,
allow_single_file = OCAML_FILETYPES,
),
} + _ocaml_toolchain_attrs,
}, _ocaml_toolchain_attrs),
outputs = { "mli": "%{name}.mli" },
)

@@ -120,7 +125,8 @@ def _ocaml_binary_impl(ctx):
])

ctx.actions.run_shell(
inputs = ctx.files.srcs + [ocamlfind, ocamlbuild, opam],
tools = [ocamlfind, ocamlbuild, opam],
inputs = ctx.files.srcs,
outputs = [ctx.outputs.executable, ctx.outputs.build_dir],
command = command,
mnemonic = "Ocamlbuild",
@@ -132,19 +138,18 @@ def _ocaml_binary_impl(ctx):

_ocaml_binary = rule(
implementation = _ocaml_binary_impl,
attrs = {
attrs = _add({
"srcs": attr.label_list(
allow_files = OCAML_FILETYPES
),
"deps": attr.label_list(),
"src_root": attr.label(
allow_files = OCAML_FILETYPES,
single_file = True,
allow_single_file = OCAML_FILETYPES,
mandatory = True,
),
"opam_packages": attr.string_list(default = []),
"bin_type": attr.string(default = "native")
} + _ocaml_toolchain_attrs,
}, _ocaml_toolchain_attrs),
executable = True,
outputs = { "build_dir": "_build_%{name}" },
)
16 changes: 8 additions & 8 deletions ocaml/repo.bzl
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ COMPILER_NAME = "ocaml-base-compiler.%s" % OCAML_VERSION
DEBUG_QUIET = True

# The path to the root opam directory
OPAM_ROOT_DIR = "OPAM_ROOT_DIR"
OPAM_ROOT_DIR = ".opam_root_dir"

# Set up OCaml's toolchain (ocamlc, ocamlbuild, ocamlfind)
_OCAML_TOOLCHAIN_BUILD = """
@@ -42,23 +42,23 @@ filegroup(
def _ocaml_toolchain_impl(repository_ctx):
opam_bin = repository_ctx.path(repository_ctx.attr._opam)

# Initialize opam and its root directory
repository_ctx.report_progress("Initializing opam and its root directory..")
repository_ctx.execute([
opam_bin,
"init",
"--root", OPAM_ROOT_DIR,
"--no-setup",
"--comp", COMPILER_NAME
], quiet = DEBUG_QUIET)
], quiet = False)

# Download the OCaml compiler
repository_ctx.report_progress("Downloading the OCaml compiler..")
repository_ctx.execute([
opam_bin,
"switch", COMPILER_NAME,
"--root", OPAM_ROOT_DIR
], quiet = DEBUG_QUIET)

# Install OCamlbuild
repository_ctx.report_progress("Installing ocamlbuild..")
repository_ctx.execute([
opam_bin,
"install",
@@ -67,7 +67,7 @@ def _ocaml_toolchain_impl(repository_ctx):
"--root", OPAM_ROOT_DIR
], quiet = DEBUG_QUIET)

# Install OCamlfind
repository_ctx.report_progress("Installing ocamlfind..")
repository_ctx.execute([
opam_bin,
"install",
@@ -76,6 +76,7 @@ def _ocaml_toolchain_impl(repository_ctx):
"--root", OPAM_ROOT_DIR
], quiet = DEBUG_QUIET)

repository_ctx.report_progress("Installing opam packages..")
[repository_ctx.execute([
opam_bin,
"install",
@@ -94,8 +95,7 @@ _ocaml_toolchain_repo = repository_rule(
"_opam": attr.label(
default = Label("@opam//:opam"),
executable = True,
single_file = True,
allow_files = True,
allow_single_file = True,
cfg = "host",
),
"opam_packages": attr.string_dict(default = {}),