about summary refs log tree commit diff
path: root/third_party/bazel/rules_haskell/tests/indirect-link
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/bazel/rules_haskell/tests/indirect-link')
-rw-r--r--third_party/bazel/rules_haskell/tests/indirect-link/BUILD.bazel52
-rw-r--r--third_party/bazel/rules_haskell/tests/indirect-link/cbits/impl.c9
-rw-r--r--third_party/bazel/rules_haskell/tests/indirect-link/cbits/intf.c10
-rw-r--r--third_party/bazel/rules_haskell/tests/indirect-link/src/MyModule.hs11
-rw-r--r--third_party/bazel/rules_haskell/tests/indirect-link/test/Main.hs9
5 files changed, 91 insertions, 0 deletions
diff --git a/third_party/bazel/rules_haskell/tests/indirect-link/BUILD.bazel b/third_party/bazel/rules_haskell/tests/indirect-link/BUILD.bazel
new file mode 100644
index 000000000000..60403a4ef277
--- /dev/null
+++ b/third_party/bazel/rules_haskell/tests/indirect-link/BUILD.bazel
@@ -0,0 +1,52 @@
+load("@io_tweag_rules_haskell//haskell:haskell.bzl", "haskell_library", "haskell_test", "haskell_toolchain_library")
+
+cc_library(
+    name = "cbits-indirect",
+    srcs = ["cbits/impl.c"],
+)
+
+cc_library(
+    name = "cbits",
+    srcs = ["cbits/intf.c"],
+    deps = ["cbits-indirect"],
+)
+
+haskell_library(
+    name = "mypkg",
+    srcs = ["src/MyModule.hs"],
+    src_strip_prefix = "src",
+    deps = [
+        ":cbits",
+        "//tests/hackage:base",
+    ],
+)
+
+haskell_test(
+    name = "indirect-link-static",
+    srcs = ["test/Main.hs"],
+    linkstatic = True,
+    src_strip_prefix = "test",
+    deps = [
+        ":mypkg",
+        "//tests/hackage:base",
+    ],
+)
+
+haskell_test(
+    name = "indirect-link-dynamic",
+    srcs = ["test/Main.hs"],
+    linkstatic = False,
+    src_strip_prefix = "test",
+    deps = [
+        ":mypkg",
+        "//tests/hackage:base",
+    ],
+)
+
+test_suite(
+    name = "indirect-link",
+    tests = [
+        ":indirect-link-dynamic",
+        ":indirect-link-static",
+    ],
+)
diff --git a/third_party/bazel/rules_haskell/tests/indirect-link/cbits/impl.c b/third_party/bazel/rules_haskell/tests/indirect-link/cbits/impl.c
new file mode 100644
index 000000000000..666ce43962a3
--- /dev/null
+++ b/third_party/bazel/rules_haskell/tests/indirect-link/cbits/impl.c
@@ -0,0 +1,9 @@
+static int thing;
+
+int real_get_thing(void) {
+  return thing;
+}
+
+void real_set_thing(int value) {
+  thing = value;
+}
diff --git a/third_party/bazel/rules_haskell/tests/indirect-link/cbits/intf.c b/third_party/bazel/rules_haskell/tests/indirect-link/cbits/intf.c
new file mode 100644
index 000000000000..f7a8f5e9f2e8
--- /dev/null
+++ b/third_party/bazel/rules_haskell/tests/indirect-link/cbits/intf.c
@@ -0,0 +1,10 @@
+extern int real_get_thing(void);
+extern void real_set_thing(int value);
+
+int get_thing(void) {
+  return real_get_thing();
+}
+
+void set_thing(int value) {
+  real_set_thing(value);
+}
diff --git a/third_party/bazel/rules_haskell/tests/indirect-link/src/MyModule.hs b/third_party/bazel/rules_haskell/tests/indirect-link/src/MyModule.hs
new file mode 100644
index 000000000000..4b75cee13989
--- /dev/null
+++ b/third_party/bazel/rules_haskell/tests/indirect-link/src/MyModule.hs
@@ -0,0 +1,11 @@
+module MyModule where
+
+foreign import ccall get_thing :: IO Int
+
+getThing :: IO Int
+getThing = get_thing
+
+foreign import ccall set_thing :: Int -> IO ()
+
+setThing :: Int -> IO ()
+setThing = set_thing
diff --git a/third_party/bazel/rules_haskell/tests/indirect-link/test/Main.hs b/third_party/bazel/rules_haskell/tests/indirect-link/test/Main.hs
new file mode 100644
index 000000000000..0b3d188d736a
--- /dev/null
+++ b/third_party/bazel/rules_haskell/tests/indirect-link/test/Main.hs
@@ -0,0 +1,9 @@
+module Main (main) where
+
+import qualified MyModule
+
+main :: IO ()
+main = do
+  print =<< MyModule.getThing
+  MyModule.setThing 123
+  print =<< MyModule.getThing