From d9ef23d9548dfcc179df51aa585d71e378b75329 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Facundo=20Dom=C3=ADnguez?= Date: Thu, 19 Nov 2020 17:11:35 +0000 Subject: [PATCH] Update rules_haskell. --- BUILD | 15 +++------- WORKSPACE | 80 ++++++++++++++++++++++++++----------------------- clodl/clodl.bzl | 57 +++++++++++++++++++---------------- docs/BUILD | 9 +++--- nixpkgs.nix | 2 +- shell.nix | 5 +++- 6 files changed, 89 insertions(+), 79 deletions(-) diff --git a/BUILD b/BUILD index adcceb3..d482fe7 100644 --- a/BUILD +++ b/BUILD @@ -1,11 +1,10 @@ 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", @@ -13,18 +12,12 @@ load( "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", ], ) @@ -42,7 +35,7 @@ java_library( ) -haskell_import(name = "base") +haskell_toolchain_library(name = "base", package = "base") haskell_binary( name = "hello-hs", testonly = True, diff --git a/WORKSPACE b/WORKSPACE index b51d592..0952074 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -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( @@ -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", @@ -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" ]) @@ -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 {{}}; -in pkgs.haskell.packages.ghc822.ghcWithPackages (p: with p; [{0}]) -""".format("base"), - repository = "@nixpkgs", ) -register_toolchains("//:ghc") - nixpkgs_package( name = "openjdk", build_file_content = """ @@ -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() diff --git a/clodl/clodl.bzl b/clodl/clodl.bzl index ff6e82e..5534630 100644 --- a/clodl/clodl.bzl +++ b/clodl/clodl.bzl @@ -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.""" @@ -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 @@ -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. @@ -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 `/file.zip` is created, with all the + shared libraries required by `:lib1` and `:lib2` except those in + excludes. `` is a name which depends on `name`. + Args: name: A unique name for this rule. @@ -263,22 +283,6 @@ def library_closure(name, srcs, outzip = "", excludes = [], executable = False, is just a shared library `lib_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 `/file.zip` is created, with all the - shared libraries required by `:lib1` and `:lib2` except those in - excludes. `` is a name which depends on `name`. - """ libs_file = "%s-libs" % name srclibs = "%s-as-libs" % name @@ -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( @@ -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( diff --git a/docs/BUILD b/docs/BUILD index 203549f..c652dbe 100644 --- a/docs/BUILD +++ b/docs/BUILD @@ -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"], ) diff --git a/nixpkgs.nix b/nixpkgs.nix index 4d1a7b7..10b9700 100644 --- a/nixpkgs.nix +++ b/nixpkgs.nix @@ -1 +1 @@ -import (fetchTarball "https://github.com/nixos/nixpkgs/archive/80d44926bf7099f2bc77ca5e9288c0c0ca35e99d.tar.gz") +import (fetchTarball "https://github.com/tweag/nixpkgs/archive/e7ebd6be80d80000ea9efb62c589a827ba4c22dc.tar.gz") diff --git a/shell.nix b/shell.nix index 489d2a6..f41d260 100644 --- a/shell.nix +++ b/shell.nix @@ -6,9 +6,12 @@ mkShell { buildInputs = [ bazel binutils + cacert + git nix + openjdk11 + python3 pax-utils - python unzip which zip