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

Initial haskell_binary implementation. #1

Merged
merged 2 commits into from
Nov 13, 2017
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
4 changes: 4 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
load("@io_tweag_rules_haskell//haskell:haskell.bzl",
"haskell_library",
"haskell_binary",
)
38 changes: 38 additions & 0 deletions haskell/haskell.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
HASKELL_FILETYPE = FileType([".hs"])

# TODO
haskell_library = 1

_haskell_common_attrs = {
"srcs": attr.label_list(allow_files = HASKELL_FILETYPE),
"deps": attr.label_list(),
}

def _haskell_binary_impl(ctx):
haskell_binary = ctx.outputs.executable

compile_inputs = ctx.files.srcs

ctx.actions.run(
inputs = compile_inputs,
outputs = [haskell_binary],
mnemonic = "Ghc",
executable = "ghc",
arguments = [
"-o",
haskell_binary.path,
] + [
src.path for src in compile_inputs
],
use_default_shell_env = True,
progress_message = ("Compiling Haskell binary %s (%d files)"
% (ctx.label.name, len(ctx.files.srcs))))

return struct(haskell_srcs = ctx.files.srcs,
haskell_deps = ctx.attr.deps)

haskell_binary = rule(
_haskell_binary_impl,
attrs = _haskell_common_attrs,
executable = True,
)
21 changes: 21 additions & 0 deletions tests/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package(default_testonly = 1)

load("//haskell:haskell.bzl",
"haskell_library",
"haskell_binary",
)

haskell_binary(
name = "hello",
srcs = ["hello.hs"],
# main_is = "hello.hs",
)

[sh_test(
name = "Run" + binary,
srcs = ["test_binary.sh"],
args = ["$(location %s)" % binary],
data = [":%s" % binary],
) for binary in [
"hello",
]]
4 changes: 4 additions & 0 deletions tests/hello.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Main where

main = do
putStrLn "hello"
4 changes: 4 additions & 0 deletions tests/test_binary.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh

echo "Executing: " $@
$@