Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove HaskellPrebuiltPackageInfo #442

Merged
merged 34 commits into from
Nov 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
2052b69
nix: Give direct access to the GHC packages
Sep 19, 2018
b00ab8d
Add first version of the new `haskell_import`
Sep 19, 2018
e9a2eac
Add test for `haskell_import_new`
Sep 19, 2018
14d2c36
Add addhock support
Sep 19, 2018
a406c30
Generate `haskell_import` statements from nix packages
Sep 19, 2018
9566811
Generate `haskell_import` from the whole `haskellPackages`
Sep 19, 2018
4c1bc77
Rewrite the tests to use the new `haskell_import` rule
Sep 19, 2018
85e26d2
Fix the CI run
Sep 19, 2018
11a4c0e
Fix netlify deployment
Sep 19, 2018
f7fe774
Add nix_import* rules to the documentation
Sep 20, 2018
2cef8d1
Documentation typo
Sep 21, 2018
2ede9d6
Fix dependency circle with Cabal "internal libraries"
Sep 24, 2018
7014361
Export all the package confs for multi-library packages
Sep 26, 2018
e66a95a
Explain why we may already have an `HaddockInfo` in the haddock context
Oct 1, 2018
627ac0e
Move path-related functions to `path_utils.bzl`
Oct 1, 2018
17c19e0
Typo
Oct 1, 2018
146bfd1
Quote bash strings in a slightly more robust way
Oct 1, 2018
94d781e
Rename and document `gen_packages_list`
Oct 2, 2018
4177d80
Remove dead code
Oct 2, 2018
f6ae403
Add a link to `rules_nixpkgs`
Oct 2, 2018
521f8be
Buildify the world
Oct 2, 2018
7dbbc1d
Make <bazel_haskell_wrapper> optional in ghc.nix
Oct 11, 2018
5bc69c4
haskell_import: Only add haddock htmls there is an haddock file
Oct 11, 2018
2b91c29
fixup! Add test for `haskell_import_new`
Oct 11, 2018
79267dc
netlify: Update comment on dummy `nix-build`
Oct 11, 2018
835471c
Remove `*args` forwarding in `nix.bzl`
Oct 23, 2018
d640b4f
Remove spurious arguments in new haskell_import
Oct 23, 2018
20a70a5
Rework the user API
Oct 23, 2018
41f4bf3
Buildify
Oct 23, 2018
02872ac
ci: Limit the number of bazel threads in analysis
Oct 30, 2018
6545552
fixup! ci: Limit the number of bazel threads in analysis
Oct 30, 2018
180ff47
fixup! Rewrite the tests to use the new `haskell_import` rule
Oct 31, 2018
18b59c3
Fix the haddock for external dependencies
Oct 31, 2018
a3a15fc
fixup! fixup! Rewrite the tests to use the new `haskell_import` rule
Oct 31, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# See https://docs.bazel.build/versions/master/user-manual.html#bazelrc.

build:ci --loading_phase_threads=8
#build:ci --all_incompatible_changes
build:ci --sandbox_debug
build:ci --verbose_failures
Expand Down
19 changes: 19 additions & 0 deletions .netlify/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,22 @@ V=0.16.0
curl -LO https://github.com/bazelbuild/bazel/releases/download/$V/bazel-$V-installer-linux-x86_64.sh
chmod +x bazel-$V-installer-linux-x86_64.sh
./bazel-$V-installer-linux-x86_64.sh --user

# XXX: Hack to prevent the `haskell_nixpkgs_package_list` rule from crashing:
# This rule expects a `nix-build` executable which is used to generate a
# store-path containing an `all-haskell-packages.bzl` file which defines the
# `package` list. Since actually installing `nix-build` on the netlify image
# seems difficult, we provide a dummy shell script which does exactly that.
packages_list=$(mktemp -d)
cat <<EOF > $packages_list/all-haskell-packages.bzl
packages = []
EOF

mkdir -p $HOME
cat <<EOF > $HOME/bin/nix-build
#!/usr/bin/env bash

echo $packages_list
EOF

chmod +x $HOME/bin/nix-build
50 changes: 22 additions & 28 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,28 @@ haskell_repositories()

http_archive(
name = "io_tweag_rules_nixpkgs",
strip_prefix = "rules_nixpkgs-0.2.3",
urls = ["https://github.com/tweag/rules_nixpkgs/archive/v0.2.3.tar.gz"],
sha256 = "2647bc9d5476fba95d9b4cc300be1ba9ad353e4e33bee01e041886aa4f4b554a",
strip_prefix = "rules_nixpkgs-0.3.1",
urls = ["https://github.com/tweag/rules_nixpkgs/archive/v0.3.1.tar.gz"],
sha256 = "1dc7ad9d4e0e7e690962317fa70bf5ab3bac5b4944e4f40eff3c2d6f5255eb20",
)

load("@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl",
"nixpkgs_git_repository",
"nixpkgs_package",
)
load("@io_tweag_rules_haskell//haskell:nix.bzl",
"haskell_nixpkgs_packages",
"haskell_nixpkgs_package",
"haskell_nixpkgs_packageset")

nixpkgs_package(
haskell_nixpkgs_package(
name = "ghc",
# rules_nixpkgs assumes we want to read from `<nixpkgs>` implicitly
# if `repository` is not set, but our nix_file uses `./nixpkgs/`.
# TODO(Profpatsch)
repository = "//nixpkgs:NOTUSED",
repositories = { "nixpkgs": "//nixpkgs:NOTUSED" },
nix_file = "//tests:ghc.nix",
attribute_path = "haskellPackages.ghc",
build_file = "//haskell:ghc.BUILD",
)

Expand All @@ -32,26 +37,6 @@ http_archive(
urls = ["https://github.com/google/protobuf/archive/v3.5.0.zip"],
)

nixpkgs_package(
name = "protoc_gen_haskell",
# this is a trick to set <nixpkgs> to reference a nix file
# TODO(Profpatsch) document & fix upstream
repository = "//nixpkgs:default.nix",
attribute_path = "haskell.packages.ghc844.proto-lens-protoc"
)

nixpkgs_package(
name = "doctest",
repository = "//nixpkgs:default.nix",
attribute_path = "haskell.packages.ghc844.doctest",
)

nixpkgs_package(
name = "c2hs",
repository = "//nixpkgs:default.nix",
attribute_path = "haskell.packages.ghc844.c2hs",
)

register_toolchains(
"//tests:ghc",
"//tests:doctest-toolchain",
Expand All @@ -60,7 +45,7 @@ register_toolchains(

nixpkgs_package(
name = "zlib",
repository = "//nixpkgs:default.nix",
repositories = { "nixpkgs": "//nixpkgs:default.nix" },
build_file_content = """
package(default_visibility = ["//visibility:public"])

Expand All @@ -78,7 +63,7 @@ filegroup (

nixpkgs_package(
name = "zlib.dev",
repository = "//nixpkgs:default.nix",
repositories = { "nixpkgs": "//nixpkgs:default.nix" },
build_file_content = """
load("@io_tweag_rules_haskell//haskell:haskell.bzl", "haskell_cc_import")
package(default_visibility = ["//visibility:public"])
Expand All @@ -101,7 +86,7 @@ haskell_cc_import(

nixpkgs_package(
name = "glib_locales",
repository = "//nixpkgs:default.nix",
repositories = { "nixpkgs": "//nixpkgs:default.nix" },
attribute_path = "glibcLocales",
build_file_content = """
package(default_visibility = ["//visibility:public"])
Expand All @@ -113,6 +98,15 @@ filegroup(
"""
)

haskell_nixpkgs_packageset(
name = "hackage-packages",
repositories = { "nixpkgs": "//nixpkgs:default.nix" },
nix_file = "//tests:ghc.nix",
base_attribute_path = "haskellPackages",
)
load("@hackage-packages//:packages.bzl", "import_packages")
import_packages(name = "hackage")

# zlib as a Haskell library

new_http_archive(
Expand Down
1 change: 1 addition & 0 deletions docs/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ skylark_doc(
"//haskell:cc.bzl",
"//haskell:repositories.bzl",
"//haskell:ghc_bindist.bzl",
"//haskell:nix.bzl",
],
format = "html",
)
Expand Down
7 changes: 6 additions & 1 deletion haskell/haddock.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ def _haskell_doc_aspect_impl(target, ctx):
if HaskellBuildInfo not in target or HaskellLibraryInfo not in target:
return []

# Packages imported via `//haskell:import.bzl%haskell_import` already
# contain an `HaddockInfo` provider, so we just forward it
if HaddockInfo in target:
return []

hs = haskell_context(ctx, ctx.rule.attr)

package_id = target[HaskellLibraryInfo].package_id
Expand Down Expand Up @@ -194,7 +199,7 @@ def _haskell_doc_rule_impl(ctx):
command = """
mkdir -p "{doc_dir}"
# Copy Haddocks of a dependency.
cp -r "{html_dir}" "{target_dir}"
cp -R -L "{html_dir}" "{target_dir}"
""".format(
doc_dir = doc_root_path,
html_dir = html_dir.path,
Expand Down
107 changes: 107 additions & 0 deletions haskell/import.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
"""Importing prebuilt packages into bazel"""

load(":private/context.bzl", "haskell_context")
load(":private/actions/package.bzl", "package")
load(
":private/providers.bzl",
"HaddockInfo",
"HaskellBuildInfo",
"HaskellLibraryInfo",
)
load(":private/set.bzl", "set")
load(":private/path_utils.bzl", "copy_all", "link_forest", "ln")
load("@bazel_skylib//:lib.bzl", "paths")

def _haskell_import_impl(ctx):
hs = haskell_context(ctx)

package_cache = ctx.actions.declare_file(
paths.join("package.conf.d", "package.cache"),
)

local_package_confs = link_forest(
ctx = ctx,
srcs = ctx.attr.package_confs.files,
sibling = package_cache,
)

local_haddock_html = ctx.actions.declare_directory("haddock-html")
copy_all(
ctx = ctx,
srcs = ctx.attr.haddock_html.files,
dest = local_haddock_html,
)
Profpatsch marked this conversation as resolved.
Show resolved Hide resolved

ctx.actions.run(
outputs = [package_cache],
inputs = local_package_confs,
mnemonic = "HaskellCreatePackageCache",
executable = hs.tools.ghc_pkg,
arguments = [
"recache",
"--package-db",
package_cache.dirname,
],
)
ln(ctx, package_cache, ctx.outputs.cache)

dependencies_caches = set.singleton(package_cache)
for dep in ctx.attr.deps:
if HaskellBuildInfo in dep:
set.mutable_union(dependencies_caches, dep[HaskellBuildInfo].package_caches)

deps_ids = [
dep[HaskellLibraryInfo].package_id
for dep in ctx.attr.deps
if HaskellLibraryInfo in dep
]

libInfo = HaskellLibraryInfo(
package_id = ctx.attr.package_id,
version = ctx.attr.version,
import_dirs = [],
header_files = set.empty(),
boot_files = set.empty(),
source_files = set.empty(),
extra_source_files = set.empty(),
ghc_args = [],
)
buildInfo = HaskellBuildInfo(
package_ids = set.from_list([ctx.attr.package_id] + deps_ids),
package_confs = set.from_list(local_package_confs),
package_caches = dependencies_caches,
static_libraries = [],
static_libraries_prof = [],
dynamic_libraries = set.empty(),
interface_dirs = set.empty(),
prebuilt_dependencies = set.empty(),
external_libraries = {},
direct_prebuilt_deps = set.empty(),
)
html_files = list(ctx.attr.haddock_html.files)
transitive_html = {ctx.attr.package_id: local_haddock_html} if html_files != [] else {}
interface_files = list(ctx.attr.haddock_interfaces.files)
transitive_haddocks = {ctx.attr.package_id: interface_files[0]} if interface_files != [] else {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding an explanatory comment to this line is the last thing from my side, then +1 for the merge.


haddockInfo = HaddockInfo(
package_id = ctx.attr.package_id,
transitive_html = transitive_html,
transitive_haddocks = transitive_haddocks,
)
return [buildInfo, libInfo, haddockInfo]

haskell_import = rule(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the haskell_import rule from haskell/haskell.bzl? Shouldn’t it be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eventually yes, though we probably should have a way to generate the correct (new) haskell_import statements for other inputs than nix (like ghc bindist or an external ghc) first.

_haskell_import_impl,
attrs = dict(
package_id = attr.string(doc = "Workspace unique package identifier"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need this? I think we ought to derive the package_id from the target name.

deps = attr.label_list(doc = "Haskell dependencies for the package"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need both deps and deps_ids?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed we don't need it.
I didn't try at all to minimize the interface for this rule since it isn't intended to be hand-written anyways so having a bit too much information in exchange of making its implementation easier isn't a big deal, but in this case it's trivial to extract it, so we can remove the deps_ids argument

version = attr.string(doc = "Package version."),
haddock_interfaces = attr.label(doc = "List of haddock interfaces"),
haddock_html = attr.label(doc = "List of haddock html dirs"),
package_confs = attr.label(doc = "List of ghc-pkg package.conf files"),
),
outputs = {
"cache": "%{name}-cache",
},
toolchains = ["@io_tweag_rules_haskell//haskell:toolchain"],
)
Loading