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

Handling of toolchain libraries in stack_snapshot #1685

Merged
merged 6 commits into from
Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).

[Unreleased]: https://github.com/tweag/rules_haskell/compare/v0.14...master

### Changed

* By default, the `stack_snapshot` rule now relies on stack to determine toolchain libraries.
This can be a breaking change on windows if we rely on a stack snapshot containing `Win32 <= 2.13.2.0`,
as we encounter [this issue](https://github.com/haskell/win32/issues/193).
In this case, to ensure the toolchain `Win32` library is used (instead of trying to compile a new one),
it can be droped from a custom stack snapshot as in the [./stackage_snapshot.yaml](./stackage_snapshot.yaml) file.

## [0.14.0] 2021-12-21

[0.14.0]: https://github.com/tweag/rules_haskell/compare/v0.13...v0.14
Expand Down
27 changes: 24 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ load(
"@rules_haskell//:constants.bzl",
"test_asterius_version",
"test_ghc_version",
"test_stack_snapshot",
)
load("@rules_haskell//haskell:cabal.bzl", "stack_snapshot")

Expand All @@ -53,6 +52,7 @@ stack_snapshot(
"exe",
],
},
local_snapshot = "//:stackage_snapshot.yaml",
packages = [
# Core libraries
"array",
Expand Down Expand Up @@ -90,7 +90,6 @@ stack_snapshot(
"temporary",
],
setup_deps = {"polysemy": ["cabal-doctest"]},
snapshot = test_stack_snapshot,
stack_snapshot_json = "//:stackage_snapshot.json" if not is_windows else None,
tools = [
# This is not required, as `stack_snapshot` would build alex
Expand All @@ -108,8 +107,8 @@ stack_snapshot(
stack_snapshot(
name = "stackage-zlib",
extra_deps = {"zlib": ["//tests:zlib"]},
local_snapshot = "//:stackage_snapshot.yaml",
packages = ["zlib"],
snapshot = test_stack_snapshot,
stack_snapshot_json = "//:stackage-zlib-snapshot.json" if not is_windows else None,
)

Expand Down Expand Up @@ -289,6 +288,7 @@ load(
"asterius_dependencies_bindist",
"asterius_dependencies_nix",
"rules_haskell_asterius_toolchains",
"toolchain_libraries",
)

(asterius_dependencies_nix(
Expand Down Expand Up @@ -584,6 +584,27 @@ load("//tools:repositories.bzl", "rules_haskell_worker_dependencies")

rules_haskell_worker_dependencies()

# Stack snapshot repository for testing non standard toolchains
# The toolchain_libraries rule provide a default value for the toolchain_libraries
# variable, so we can load it even if we are not on linux.

toolchain_libraries(
name = "toolchains_libraries",
repository = "linux_amd64_asterius" if is_linux else "",
)

load("@toolchains_libraries//:toolchain_libraries.bzl", "toolchain_libraries")

stack_snapshot(
name = "stackage_asterius",
local_snapshot = "@rules_haskell//tests/asterius/stack_toolchain_libraries:snapshot.yaml",
packages = [
"xhtml",
],
stack_snapshot_json = "@rules_haskell//tests/asterius/stack_toolchain_libraries:snapshot.json",
toolchain_libraries = toolchain_libraries,
) if is_linux else None

local_repository(
name = "tutorial",
path = "tutorial",
Expand Down
1 change: 0 additions & 1 deletion constants.bzl
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
test_ghc_version = "8.10.7"
test_stack_snapshot = "lts-18.18"
test_asterius_version = "0.0.1"
68 changes: 34 additions & 34 deletions ghcide-snapshot.json

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions ghcide-stack-snapshot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,12 @@ packages:
- implicit-hie-cradle-0.3.0.2
- lsp-test-0.11.0.7
- retrie-0.1.1.1

# We drop the Win32 package from the stack snapshot so that stack considers it a toolchain library.
# In this case we will use the Win32 provided by the compiler instead of recompiling it.
#
# Recompiling it should be fine for future versions of Win32,
# but with versions <= 2.13.2.0 we encounter the following issue:
# https://github.com/haskell/win32/issues/193
drop-packages:
- Win32
Comment on lines +20 to +21
Copy link
Member

Choose a reason for hiding this comment

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

Maybe worth a comment as to why this is being dropped.

7 changes: 7 additions & 0 deletions haskell/asterius/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ platform(
],
)

config_setting(
name = "asterius",
constraint_values = [
"@platforms//cpu:wasm32",
],
)

# Toolchain type for asterius specific tools such as ahc-dist,
# which are not part of the regular haskell toolchain.
toolchain_type(
Expand Down
39 changes: 38 additions & 1 deletion haskell/asterius/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,20 @@ def _ahc_impl(ctx):
"BUILD",
filepaths["@rules_haskell//haskell:ahc.BUILD.tpl"],
substitutions = {
"%{toolchain_libraries}": toolchain_libraries,
"%{toolchain_libraries}": toolchain_libraries["file_content"],
"%{toolchain}": toolchain,
"%{asterius_toolchain}": asterius_toolchain,
},
executable = False,
)

# We make the list of toolchain libraries available for loading in the WORKSPACE file.
ctx.file(
"toolchain_libraries.bzl",
executable = False,
content = "toolchain_libraries = {}".format(toolchain_libraries["toolchain_libraries"]),
)

_ahc = repository_rule(
_ahc_impl,
local = False,
Expand Down Expand Up @@ -356,3 +363,33 @@ def asterius_dependencies_custom(**kwargs):
```
"""
_asterius_dependencies_custom(**kwargs)

def _toolchain_libraries_impl(repository_ctx):
if repository_ctx.attr.repository:
repository_ctx.file(
"toolchain_libraries.bzl",
executable = False,
content = """\
load("@{}//:toolchain_libraries.bzl", _toolchain_libraries = "toolchain_libraries")
toolchain_libraries = _toolchain_libraries
""".format(repository_ctx.attr.repository),
)
else:
repository_ctx.file(
"toolchain_libraries.bzl",
executable = False,
content = "toolchain_libraries = None",
)

repository_ctx.file("BUILD", executable = False, content = "")

toolchain_libraries = repository_rule(
_toolchain_libraries_impl,
attrs = {
"repository": attr.string(
default = "",
doc = "An optional repository from which we recover the toolchain_libraries variable. If absent or empty, the toolchain_libraries variable will be equal to None.",
),
},
doc = "Optionally recovers the `toolchain_libraries` variable from another repository",
)
Loading