about summary refs log tree commit diff
path: root/third_party/bazel/rules_haskell/tutorial
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/bazel/rules_haskell/tutorial')
l---------third_party/bazel/rules_haskell/tutorial/.bazelrc1
-rw-r--r--third_party/bazel/rules_haskell/tutorial/.gitignore1
-rw-r--r--third_party/bazel/rules_haskell/tutorial/README.md30
-rw-r--r--third_party/bazel/rules_haskell/tutorial/WORKSPACE49
-rw-r--r--third_party/bazel/rules_haskell/tutorial/lib/BUILD.bazel10
-rw-r--r--third_party/bazel/rules_haskell/tutorial/lib/Bool.hs19
-rw-r--r--third_party/bazel/rules_haskell/tutorial/main/BUILD.bazel17
-rw-r--r--third_party/bazel/rules_haskell/tutorial/main/Main.hs16
-rw-r--r--third_party/bazel/rules_haskell/tutorial/tools/build_rules/BUILD.bazel0
-rw-r--r--third_party/bazel/rules_haskell/tutorial/tools/build_rules/prelude_bazel5
10 files changed, 148 insertions, 0 deletions
diff --git a/third_party/bazel/rules_haskell/tutorial/.bazelrc b/third_party/bazel/rules_haskell/tutorial/.bazelrc
new file mode 120000
index 0000000000..adb61980d2
--- /dev/null
+++ b/third_party/bazel/rules_haskell/tutorial/.bazelrc
@@ -0,0 +1 @@
+../.bazelrc
\ No newline at end of file
diff --git a/third_party/bazel/rules_haskell/tutorial/.gitignore b/third_party/bazel/rules_haskell/tutorial/.gitignore
new file mode 100644
index 0000000000..a6ef824c1f
--- /dev/null
+++ b/third_party/bazel/rules_haskell/tutorial/.gitignore
@@ -0,0 +1 @@
+/bazel-*
diff --git a/third_party/bazel/rules_haskell/tutorial/README.md b/third_party/bazel/rules_haskell/tutorial/README.md
new file mode 100644
index 0000000000..34a5bb27f4
--- /dev/null
+++ b/third_party/bazel/rules_haskell/tutorial/README.md
@@ -0,0 +1,30 @@
+# Tutorial code
+
+Code for the [Bazel Haskell tutorial][bazel-haskell-tutorial].
+
+[bazel-haskell-tutorial]: https://rules-haskell.readthedocs.io/en/latest/haskell.html
+
+## Tutorial Workspace
+
+Build everything in the tutorial workspace with;
+
+```
+$ bazel build @io_tweag_rules_haskell_tutorial//...
+```
+
+Show everything in the tutorial;
+
+```
+$ bazel query @io_tweag_rules_haskell_tutorial//...
+@io_tweag_rules_haskell_tutorial//main:demorgan
+@io_tweag_rules_haskell_tutorial//main:base
+@io_tweag_rules_haskell_tutorial//lib:booleans
+```
+
+Build and run the tutorial example;
+
+```
+$ bazel build @io_tweag_rules_haskell_tutorial//lib:booleans
+$ bazel build @io_tweag_rules_haskell_tutorial//main:demorgan
+$ bazel run @io_tweag_rules_haskell_tutorial//main:demorgan
+```
diff --git a/third_party/bazel/rules_haskell/tutorial/WORKSPACE b/third_party/bazel/rules_haskell/tutorial/WORKSPACE
new file mode 100644
index 0000000000..21d25c2472
--- /dev/null
+++ b/third_party/bazel/rules_haskell/tutorial/WORKSPACE
@@ -0,0 +1,49 @@
+workspace(name = "io_tweag_rules_haskell_tutorial")
+
+local_repository(
+    name = "io_tweag_rules_haskell",
+    path = "..",
+)
+
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
+load("@io_tweag_rules_haskell//haskell:repositories.bzl", "haskell_repositories")
+
+haskell_repositories()
+
+rules_nixpkgs_version = "0.5.2"
+
+http_archive(
+    name = "io_tweag_rules_nixpkgs",
+    sha256 = "5a384daa57b49abf9f0b672852f1a66a3c52aecf9d4d2ac64f6de0fd307690c8",
+    strip_prefix = "rules_nixpkgs-%s" % rules_nixpkgs_version,
+    urls = ["https://github.com/tweag/rules_nixpkgs/archive/v%s.tar.gz" % rules_nixpkgs_version],
+)
+
+load(
+    "@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl",
+    "nixpkgs_cc_configure",
+)
+
+nixpkgs_cc_configure(
+    nix_file = "@io_tweag_rules_haskell//nixpkgs:cc-toolchain.nix",
+    repository = "@io_tweag_rules_haskell//nixpkgs:default.nix",
+)
+
+load(
+    "@io_tweag_rules_haskell//haskell:nixpkgs.bzl",
+    "haskell_register_ghc_nixpkgs",
+)
+
+haskell_register_ghc_nixpkgs(
+    repositories = {
+        "nixpkgs": "@io_tweag_rules_haskell//nixpkgs:default.nix",
+    },
+    version = "8.6.4",
+)
+
+load(
+    "@io_tweag_rules_haskell//haskell:haskell.bzl",
+    "haskell_register_ghc_bindists",
+)
+
+haskell_register_ghc_bindists(version = "8.6.4")
diff --git a/third_party/bazel/rules_haskell/tutorial/lib/BUILD.bazel b/third_party/bazel/rules_haskell/tutorial/lib/BUILD.bazel
new file mode 100644
index 0000000000..1afb982241
--- /dev/null
+++ b/third_party/bazel/rules_haskell/tutorial/lib/BUILD.bazel
@@ -0,0 +1,10 @@
+load(
+    "@io_tweag_rules_haskell//haskell:haskell.bzl",
+    "haskell_library",
+)
+
+haskell_library(
+    name = "booleans",
+    srcs = ["Bool.hs"],
+    visibility = ["//main:__pkg__"],
+)
diff --git a/third_party/bazel/rules_haskell/tutorial/lib/Bool.hs b/third_party/bazel/rules_haskell/tutorial/lib/Bool.hs
new file mode 100644
index 0000000000..7390fcc0b8
--- /dev/null
+++ b/third_party/bazel/rules_haskell/tutorial/lib/Bool.hs
@@ -0,0 +1,19 @@
+-- base is not available when no dependencies, so we have to define everything
+-- from scratch.
+{-# LANGUAGE NoImplicitPrelude #-}
+
+module Bool where
+
+data Bool = False | True
+
+not :: Bool -> Bool
+not False = True
+not True = False
+
+and :: Bool -> Bool -> Bool
+and True True = True
+and _ _ = False
+
+or :: Bool -> Bool -> Bool
+or False False = False
+or _ _ = True
diff --git a/third_party/bazel/rules_haskell/tutorial/main/BUILD.bazel b/third_party/bazel/rules_haskell/tutorial/main/BUILD.bazel
new file mode 100644
index 0000000000..e2e7d3f422
--- /dev/null
+++ b/third_party/bazel/rules_haskell/tutorial/main/BUILD.bazel
@@ -0,0 +1,17 @@
+load(
+    "@io_tweag_rules_haskell//haskell:haskell.bzl",
+    "haskell_test",
+    "haskell_toolchain_library",
+)
+
+haskell_toolchain_library(name = "base")
+
+haskell_test(
+    name = "demorgan",
+    srcs = ["Main.hs"],
+    compiler_flags = ["-threaded"],
+    deps = [
+        ":base",
+        "//lib:booleans",
+    ],
+)
diff --git a/third_party/bazel/rules_haskell/tutorial/main/Main.hs b/third_party/bazel/rules_haskell/tutorial/main/Main.hs
new file mode 100644
index 0000000000..325fd61d0a
--- /dev/null
+++ b/third_party/bazel/rules_haskell/tutorial/main/Main.hs
@@ -0,0 +1,16 @@
+{-# LANGUAGE StandaloneDeriving #-}
+
+module Main where
+
+import Bool
+import qualified Prelude
+import Prelude ((++), (==), ($))
+
+deriving instance Prelude.Eq Bool
+
+bools :: [Bool]
+bools = [False, True]
+
+main =
+    Prelude.print $ Prelude.and $
+      [ not (x `and` y) == not x `or` not y | x <- bools, y <- bools]
diff --git a/third_party/bazel/rules_haskell/tutorial/tools/build_rules/BUILD.bazel b/third_party/bazel/rules_haskell/tutorial/tools/build_rules/BUILD.bazel
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/third_party/bazel/rules_haskell/tutorial/tools/build_rules/BUILD.bazel
diff --git a/third_party/bazel/rules_haskell/tutorial/tools/build_rules/prelude_bazel b/third_party/bazel/rules_haskell/tutorial/tools/build_rules/prelude_bazel
new file mode 100644
index 0000000000..7d275159b5
--- /dev/null
+++ b/third_party/bazel/rules_haskell/tutorial/tools/build_rules/prelude_bazel
@@ -0,0 +1,5 @@
+load("@io_tweag_rules_haskell//haskell:haskell.bzl",
+     "haskell_binary",
+     "haskell_toolchain_library",
+     "haskell_library",
+)