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

Add node to PATH of asterius cabal actions #1643

Merged
merged 2 commits into from
Nov 26, 2021
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
9 changes: 4 additions & 5 deletions haskell/asterius/asterius_config.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@ ASTERIUS_BINARIES = {

def asterius_tools_config(exec_cc_toolchain, posix_toolchain, node_toolchain, tools_for_ghc_pkg):
""" Tools, PATH directories and config specific to asterius. """
node_paths = [f.dirname for f in node_toolchain.nodeinfo.tool_files]
return struct(
# Asterius needs node in the path to evaluate template
# haskell. And the asterius bundle depends on the posix toolchain
# because it containts wrapper scripts.
path_for_run_ghc = ":".join(
posix_toolchain.paths +
[f.dirname for f in node_toolchain.nodeinfo.tool_files],
),
tools_for_run_ghc = node_toolchain.nodeinfo.tool_files,
path_for_run_ghc = posix_toolchain.paths + node_paths,
path_for_cabal = node_paths,
tools_for_ghc = node_toolchain.nodeinfo.tool_files,
tools_for_ghc_pkg = tools_for_ghc_pkg,

# Asterius does not behave as other ghc cross compilers yet
Expand Down
9 changes: 6 additions & 3 deletions haskell/cabal.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,10 @@ def _prepare_cabal_inputs(
transitive_compile_libs = get_ghci_library_files(hs, cc.cc_libraries_info, cc.transitive_libraries)
transitive_link_libs = _concat(get_library_files(hs, cc.cc_libraries_info, cc.transitive_libraries))
env = dicts.add(hs.env, cc.env)
env["PATH"] = join_path_list(hs, _binary_paths(tool_inputs) + posix.paths)
env["PATH"] = join_path_list(
hs.toolchain.is_windows,
_binary_paths(tool_inputs) + posix.paths + hs.tools_config.path_for_cabal,
)
if hs.toolchain.is_darwin:
env["SDKROOT"] = "macosx" # See haskell/private/actions/link.bzl

Expand Down Expand Up @@ -554,7 +557,7 @@ def _haskell_cabal_library_impl(ctx):
arguments = [json_args.path],
inputs = depset([json_args], transitive = [c.inputs]),
input_manifests = c.input_manifests + runghc_manifest,
tools = [c.cabal_wrapper, ctx.executable._runghc],
tools = [c.cabal_wrapper, ctx.executable._runghc] + hs.tools_config.tools_for_ghc,
outputs = outputs,
env = c.env,
mnemonic = "HaskellCabalLibrary",
Expand Down Expand Up @@ -853,7 +856,7 @@ def _haskell_cabal_binary_impl(ctx):
binary,
data_dir,
],
tools = [c.cabal_wrapper, ctx.executable._runghc],
tools = [c.cabal_wrapper, ctx.executable._runghc] + hs.tools_config.tools_for_ghc,
env = c.env,
mnemonic = "HaskellCabalBinary",
progress_message = "HaskellCabalBinary {}".format(hs.label),
Expand Down
9 changes: 5 additions & 4 deletions haskell/private/context.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

load("@bazel_skylib//lib:paths.bzl", "paths")
load("//haskell:providers.bzl", "HaskellLibraryInfo", "all_dependencies_package_ids")
load(":private/path_utils.bzl", "join_path_list")

HaskellContext = provider()

def append_to_path(env, path):
if path:
def append_to_path(env, is_windows, path_list):
if path_list:
if "PATH" in env and env["PATH"]:
env["PATH"] = ":".join([env["PATH"], path])
env["PATH"] = join_path_list(is_windows, [env["PATH"]] + path_list)
else:
env["PATH"] = path
env["PATH"] = join_path_list(is_windows, path_list)

def haskell_context(ctx, attr = None):
toolchain = ctx.toolchains["@rules_haskell//haskell:toolchain"]
Expand Down
4 changes: 2 additions & 2 deletions haskell/private/path_utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,13 @@ def declare_compiled(hs, src, ext, directory = None, rel_path = None):

return hs.actions.declare_file(fp_with_dir)

def join_path_list(hs, paths):
def join_path_list(is_windows, paths):
"""Join the given paths suitable for env vars like PATH.

Joins the list of given paths into a single string separated by ':' on Unix
or ';' on Windows.
"""
sep = ";" if hs.toolchain.is_windows else ":"
sep = ";" if is_windows else ":"
return sep.join(paths)

def mangle_static_library(hs, posix, dynamic_lib, static_lib, outdir):
Expand Down
9 changes: 5 additions & 4 deletions haskell/toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ def _run_ghc(hs, cc, inputs, outputs, mnemonic, arguments, env, params_file = No
else:
input_manifests = cc.manifests

tools.extend(hs.tools_config.tools_for_run_ghc)
append_to_path(env, hs.tools_config.path_for_run_ghc)
tools.extend(hs.tools_config.tools_for_ghc)
append_to_path(env, hs.toolchain.is_windows, hs.tools_config.path_for_run_ghc)

hs.actions.run(
inputs = inputs,
Expand All @@ -97,8 +97,9 @@ def _run_ghc(hs, cc, inputs, outputs, mnemonic, arguments, env, params_file = No
return args

default_tools_config = struct(
path_for_run_ghc = "",
tools_for_run_ghc = [],
path_for_run_ghc = [],
tools_for_ghc = [],
path_for_cabal = [],
tools_for_ghc_pkg = [],

# for cross compiling we will pass ghc a cross compiling cc_toolchain,
Expand Down
2 changes: 2 additions & 0 deletions tests/haskell_cabal_binary/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ module Main where

main :: IO ()
main = return ()

{-# ANN module "Test annotations in cabal package" #-}