Skip to content

Commit

Permalink
Don't autodetect static GHC RTS
Browse files Browse the repository at this point in the history
Addressing review comment #970 (comment)

The predifined bindists only come with a static GHC on Windows.

Nixpkgs defaults to a dynamic GHC, but the user can override that
default.
  • Loading branch information
aherrmann committed Jul 10, 2019
1 parent 5afbc0d commit 1cb09ac
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 35 deletions.
7 changes: 2 additions & 5 deletions haskell/ghc_bindist.bzl
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
"""Workspace rules (GHC binary distributions)"""

load("@bazel_tools//tools/build_defs/repo:utils.bzl", "patch")
load(
":private/workspace_utils.bzl",
"ghc_is_static",
)
load("@bazel_tools//tools/cpp:lib_cc_configure.bzl", "get_cpu_value")

_GHC_DEFAULT_VERSION = "8.6.5"

Expand Down Expand Up @@ -266,7 +263,7 @@ haskell_toolchain(
""".format(
toolchain_libraries = toolchain_libraries,
version = ctx.attr.version,
is_static = ghc_is_static(ctx),
is_static = os == "windows",
compiler_flags = ctx.attr.compiler_flags,
haddock_flags = ctx.attr.haddock_flags,
repl_ghci_args = ctx.attr.repl_ghci_args,
Expand Down
9 changes: 4 additions & 5 deletions haskell/nixpkgs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ load(
"@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl",
"nixpkgs_package",
)
load(
":private/workspace_utils.bzl",
"ghc_is_static",
)

def _ghc_nixpkgs_haskell_toolchain_impl(repository_ctx):
compiler_flags_select = "select({})".format(
Expand Down Expand Up @@ -81,7 +77,7 @@ haskell_toolchain(
toolchain_libraries = toolchain_libraries,
tools = ["@io_tweag_rules_haskell_ghc_nixpkgs//:bin"],
version = repository_ctx.attr.version,
is_static = ghc_is_static(repository_ctx),
is_static = repository_ctx.attr.is_static,
compiler_flags = repository_ctx.attr.compiler_flags,
compiler_flags_select = compiler_flags_select,
haddock_flags = repository_ctx.attr.haddock_flags,
Expand All @@ -97,6 +93,7 @@ _ghc_nixpkgs_haskell_toolchain = repository_rule(
# These attributes just forward to haskell_toolchain.
# They are documented there.
"version": attr.string(),
"is_static": attr.bool(),
"compiler_flags": attr.string_list(),
"compiler_flags_select": attr.string_list_dict(),
"haddock_flags": attr.string_list(),
Expand Down Expand Up @@ -150,6 +147,7 @@ _ghc_nixpkgs_toolchain = repository_rule(_ghc_nixpkgs_toolchain_impl)

def haskell_register_ghc_nixpkgs(
version,
is_static = False,
build_file = None,
build_file_content = None,
compiler_flags = None,
Expand Down Expand Up @@ -211,6 +209,7 @@ def haskell_register_ghc_nixpkgs(
_ghc_nixpkgs_haskell_toolchain(
name = haskell_toolchain_repo_name,
version = version,
is_static = is_static,
compiler_flags = compiler_flags,
compiler_flags_select = compiler_flags_select,
haddock_flags = haddock_flags,
Expand Down
25 changes: 0 additions & 25 deletions haskell/private/workspace_utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,3 @@ def _find_ghc(repository_ctx):
fail("Cannot find GHC executable in {}.".format(ghc))

return ghc

def ghc_is_static(repository_ctx):
"""Query GHC for whether the RTS is static or dynamic
Requires the GHC executable to exist under `bin/` in the current workspace.
Returns:
Bool, True for static RTS, False for dynamic RTS.
"""
ghc = _find_ghc(repository_ctx)
repository_ctx.file(
"_ghc_is_dynamic.ghci",
content = 'foreign import ccall unsafe "rts_isDynamic" isDynamic :: IO Int',
executable = False,
)
result = execute_or_fail_loudly(repository_ctx, [
ghc,
"--interactive",
"-ghci-script",
"_ghc_is_dynamic.ghci",
"-e",
"isDynamic",
])
return result.stdout.strip() == "0"
3 changes: 3 additions & 0 deletions haskell/toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ Label pointing to the locale archive file to use. Mostly useful on NixOS.
def haskell_toolchain(
name,
version,
is_static,
tools,
libraries,
compiler_flags = [],
Expand All @@ -283,6 +284,7 @@ def haskell_toolchain(
haskell_toolchain(
name = "ghc",
version = "1.2.3",
is_static = is_static,
tools = ["@sys_ghc//:bin"],
compiler_flags = ["-Wall"],
)
Expand All @@ -304,6 +306,7 @@ def haskell_toolchain(
_haskell_toolchain(
name = name,
version = version,
is_static = is_static,
tools = tools,
libraries = libraries,
compiler_flags = compiler_flags,
Expand Down

0 comments on commit 1cb09ac

Please sign in to comment.