Skip to content

Commit

Permalink
Update rules_haskell.
Browse files Browse the repository at this point in the history
  • Loading branch information
facundominguez committed Dec 2, 2020
1 parent b515380 commit d9ef23d
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 79 deletions.
15 changes: 4 additions & 11 deletions BUILD
Original file line number Diff line number Diff line change
@@ -1,30 +1,23 @@
package(default_visibility = ["//visibility:public"])

load(
"@io_tweag_rules_haskell//haskell:haskell.bzl",
"@rules_haskell//haskell:defs.bzl",
"haskell_binary",
"haskell_test",
"haskell_toolchain",
"haskell_import",
"haskell_toolchain_library",
)
load(
"@io_tweag_clodl//clodl:clodl.bzl",
"library_closure",
"binary_closure",
)

haskell_toolchain(
name = "ghc",
tools = "@ghc//:bin",
version = "8.2.2",
)

cc_library(
name = "bootstrap-bz",
srcs = ["src/main/cc/bootstrap.c"],
copts = ["-std=c99"],
deps = [
"@ghc//:include",
"@rules_haskell_ghc_nixpkgs//:include",
"@openjdk//:include",
],
)
Expand All @@ -42,7 +35,7 @@ java_library(
)


haskell_import(name = "base")
haskell_toolchain_library(name = "base", package = "base")
haskell_binary(
name = "hello-hs",
testonly = True,
Expand Down
80 changes: 43 additions & 37 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
workspace(name = "io_tweag_clodl")

http_archive(
name = "io_tweag_rules_haskell",
strip_prefix = "rules_haskell-5c94b23107809026d7e6de25a891bd3874dbc522",
urls = ["https://github.com/tweag/rules_haskell/archive/5c94b23107809026d7e6de25a891bd3874dbc522.tar.gz"],
)

load("@io_tweag_rules_haskell//haskell:repositories.bzl", "haskell_repositories")

haskell_repositories()
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "io_tweag_rules_nixpkgs",
strip_prefix = "rules_nixpkgs-0.2.1",
urls = ["https://github.com/tweag/rules_nixpkgs/archive/v0.2.1.tar.gz"],
name = "rules_haskell",
sha256 = "5760599f3866aaf01ac30d5ca740a6fe9aa16945c0de7ed1ee17e07d990779ef",
strip_prefix = "rules_haskell-42b8b43623b82a6b7cfb151f01986735a135e0a9",
urls = ["https://github.com/tweag/rules_haskell/archive/42b8b43623b82a6b7cfb151f01986735a135e0a9.tar.gz"],
)

new_http_archive(
http_archive(
name = "org_nixos_patchelf",
build_file_content = """
cc_binary(
Expand All @@ -30,6 +23,9 @@ cc_binary(
urls = ["https://github.com/NixOS/patchelf/archive/1fa4d36fead44333528cbee4b5c04c207ce77ca4.tar.gz"],
)

load("@rules_haskell//haskell:repositories.bzl", "haskell_repositories")
haskell_repositories()

load(
"@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl",
"nixpkgs_git_repository",
Expand All @@ -38,12 +34,37 @@ load(

nixpkgs_git_repository(
name = "nixpkgs",
# Nixpkgs from 2018-07-19
revision = "80d44926bf7099f2bc77ca5e9288c0c0ca35e99d",
revision = "e7ebd6be80d80000ea9efb62c589a827ba4c22dc",
)

load("@rules_haskell//haskell:nixpkgs.bzl", "haskell_register_ghc_nixpkgs")

nixpkgs_package(
name = "ghc",
name = "glibc_locales",
attribute_path = "glibcLocales",
build_file_content = """
package(default_visibility = ["//visibility:public"])
filegroup(
name = "locale-archive",
srcs = ["lib/locale/locale-archive"],
)
""",
repository = "@nixpkgs",
)

haskell_register_ghc_nixpkgs(
attribute_path = "haskell.compiler.ghc8102",
locale_archive = "@glibc_locales//:locale-archive",
repositories = {"nixpkgs": "@nixpkgs"},
version = "8.10.2",
compiler_flags = [
"-Werror",
"-Wall",
"-Wcompat",
"-Wincomplete-record-updates",
"-Wredundant-constraints",
],
build_file_content = """
package(default_visibility = [ "//visibility:public" ])
Expand All @@ -52,21 +73,14 @@ filegroup(
srcs = glob(["bin/*"]),
)
cc_library(
cc_library(
name = "include",
hdrs = glob(["lib/ghc-*/include/**/*.h"]),
strip_include_prefix = glob(["lib/ghc-*/include"], exclude_directories=0)[0],
)
""",
nix_file_content = """
let pkgs = import <nixpkgs> {{}};
in pkgs.haskell.packages.ghc822.ghcWithPackages (p: with p; [{0}])
""".format("base"),
repository = "@nixpkgs",
)

register_toolchains("//:ghc")

nixpkgs_package(
name = "openjdk",
build_file_content = """
Expand All @@ -81,20 +95,12 @@ cc_library(
repository = "@nixpkgs",
)

# For Skydoc

http_archive(
name = "io_bazel_rules_sass",
strip_prefix = "rules_sass-0.0.3",
urls = ["https://github.com/bazelbuild/rules_sass/archive/0.0.3.tar.gz"],
name = "io_bazel_stardoc",
strip_prefix = "stardoc-0.4.0",
urls = ["https://github.com/bazelbuild/stardoc/archive/0.4.0.tar.gz"],
)
load("@io_bazel_rules_sass//sass:sass.bzl", "sass_repositories")
sass_repositories()

http_archive(
name = "io_bazel_skydoc",
strip_prefix = "skydoc-f531844d137c7accc44d841c08a2a2a366688571",
urls = ["https://github.com/bazelbuild/skydoc/archive/f531844d137c7accc44d841c08a2a2a366688571.tar.gz"],
)
load("@io_bazel_skydoc//skylark:skylark.bzl", "skydoc_repositories")
skydoc_repositories()
load("@io_bazel_stardoc//:setup.bzl", "stardoc_repositories")
stardoc_repositories()
57 changes: 32 additions & 25 deletions clodl/clodl.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Library and binary closures"""

load("@bazel_skylib//:lib.bzl", "paths")
load("@bazel_skylib//lib:paths.bzl", "paths")

def _rename_as_solib_impl(ctx):
"""Renames files as libraries."""
Expand Down Expand Up @@ -99,7 +99,8 @@ def _shared_lib_paths_impl(ctx):
args.add(libs_file)
ctx.actions.run_shell(
outputs = [libs_file],
inputs = depset([ctx.executable._deps_tool, bash, grep, ldd, scanelf], transitive = [runfiles, files]),
inputs = depset([bash, grep, ldd, scanelf], transitive = [runfiles, files]),
tools = [ctx.executable._deps_tool],
arguments = [args],
command = """
set -eo pipefail
Expand Down Expand Up @@ -174,7 +175,7 @@ def _add_runfiles_impl(ctx):
output_libs[f.basename] = ctx.actions.declare_file(paths.join(outputdir, f.basename))

for dep in ctx.attr.deps:
for lib in dep.default_runfiles.files:
for lib in dep.default_runfiles.files.to_list():
# Runfiles might appear in inputs too. We don't duplicate them.
if files.get(lib.basename, None) == None:
# Skip non-library files.
Expand Down Expand Up @@ -241,9 +242,28 @@ Example:
"""

def library_closure(name, srcs, outzip = "", excludes = [], executable = False, **kwargs):
"""Produces a zip file containing a closure of all the shared
"""
Produce a closure of the given shared libraries.
Produces a zip file containing a closure of all the shared
libraries needed to load the given shared libraries.
Example:
```bzl
library_closure(
name = "closure"
srcs = [":lib1", ":lib2"]
excludes = ["libexclude_this\.so", "libthis_too\.so"]
outzip = "file.zip"
...
)
```
The zip file `<generated_dir>/file.zip` is created, with all the
shared libraries required by `:lib1` and `:lib2` except those in
excludes. `<generated_dir>` is a name which depends on `name`.
Args:
name: A unique name for this rule.
Expand All @@ -263,22 +283,6 @@ def library_closure(name, srcs, outzip = "", excludes = [], executable = False,
is just a shared library `lib<name>_wrapper.so` that depends on
all the other libraries in the closure.
Example:
```bzl
library_closure(
name = "closure"
srcs = [":lib1", ":lib2"]
excludes = ["libexclude_this\.so", "libthis_too\.so"]
outzip = "file.zip"
...
)
```
The zip file `<generated_dir>/file.zip` is created, with all the
shared libraries required by `:lib1` and `:lib2` except those in
excludes. `<generated_dir>` is a name which depends on `name`.
"""
libs_file = "%s-libs" % name
srclibs = "%s-as-libs" % name
Expand Down Expand Up @@ -429,16 +433,13 @@ def library_closure(name, srcs, outzip = "", excludes = [], executable = False,

def binary_closure(name, src, excludes = [], **kwargs):
"""
Produce a closure of a given position independent executable.
Produces a zip file containing a closure of all the shared libraries needed
to load the given position independent executable or shared library defining
symbol main. The zipfile is prepended with a script that uncompresses the
zip file and executes main.
Args:
name: A unique name for this rule
src: The position independent executable or a shared library.
excludes: Same purpose as in library_closure
Example:
```bzl
cc_binary(
Expand All @@ -457,6 +458,12 @@ def binary_closure(name, src, excludes = [], **kwargs):
```
The zip file closure is created, with all the
shared libraries required by "hello-cc" except those in excludes.
Args:
name: A unique name for this rule
src: The position independent executable or a shared library.
excludes: Same purpose as in library_closure
"""
zip_name = "%s-closure" % name
library_closure(
Expand Down
9 changes: 5 additions & 4 deletions docs/BUILD
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
load("@io_bazel_skydoc//skylark:skylark.bzl", "skylark_doc")
load("@io_bazel_stardoc//stardoc:stardoc.bzl", "stardoc")

skylark_doc(
stardoc(
name = "docs",
srcs = ["//clodl:clodl.bzl"],
format = "html",
input = "//clodl:clodl.bzl",
out = "doc.md",
deps = ["@bazel_skylib//lib:paths"],
)
2 changes: 1 addition & 1 deletion nixpkgs.nix
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import (fetchTarball "https://github.com/nixos/nixpkgs/archive/80d44926bf7099f2bc77ca5e9288c0c0ca35e99d.tar.gz")
import (fetchTarball "https://github.com/tweag/nixpkgs/archive/e7ebd6be80d80000ea9efb62c589a827ba4c22dc.tar.gz")
5 changes: 4 additions & 1 deletion shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ mkShell {
buildInputs = [
bazel
binutils
cacert
git
nix
openjdk11
python3
pax-utils
python
unzip
which
zip
Expand Down

0 comments on commit d9ef23d

Please sign in to comment.