Skip to content

Commit 021cb30

Browse files
committed
Bazel build files for inline-java
This is a collection of build files that work with the given WORKSPACE file. This should allow the user to run `bazel test //...` which will build run all tests in `inline-java`: as of time of writing, this is spec tests in `inline-java` and `jvm-streaming`. * We're repeating ourselves a lot w.r.t. prebuilt dependencies. We need to have all the packages available to GHC at WORKSPACE level then we also need to know them at BUILD level. We can't just define them in WORKSPACE and refer to them from BUILD as WORKSPACE only works in current project: if user wants to use inline-java from another project, the WORKSPACE file here is irrelevant: indeed they'll have to define all these things in their own WORKSPACE.
1 parent 0c0df2b commit 021cb30

File tree

6 files changed

+285
-0
lines changed

6 files changed

+285
-0
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
.gradle
33
build/
44
jni/src/Foreign/JNI.c
5+
bazel-*

Diff for: BUILD

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
load(
4+
"@io_tweag_rules_haskell//haskell:haskell.bzl",
5+
"haskell_test",
6+
"haskell_library",
7+
"haskell_toolchain",
8+
)
9+
10+
haskell_toolchain(
11+
name = "inline-java-toolchain",
12+
version = "8.2.2",
13+
tools = "@inline-java-toolchain//:bin",
14+
)
15+
16+
haskell_library(
17+
name = "inline-java",
18+
src_strip_prefix = "src",
19+
srcs = glob(['src/**/*.hs', 'src/**/*.hsc']),
20+
deps = [
21+
"//jni",
22+
"//jvm"
23+
],
24+
external_deps = [
25+
"cbits/bctable.h"
26+
],
27+
c_sources = ["cbits/bctable.c"],
28+
prebuilt_dependencies = [
29+
"base",
30+
"bytestring",
31+
"Cabal",
32+
"directory",
33+
"filepath",
34+
"filemanip",
35+
"ghc",
36+
"language-java",
37+
"mtl",
38+
"process",
39+
"text",
40+
"template-haskell",
41+
"temporary"
42+
],
43+
)
44+
45+
haskell_test(
46+
name = "spec",
47+
src_strip_prefix = "tests",
48+
srcs = glob(["tests/**/*.hs"]),
49+
deps = [
50+
"//jni",
51+
"//jvm",
52+
":inline-java"
53+
],
54+
prebuilt_dependencies = [
55+
"base",
56+
"hspec",
57+
"text",
58+
],
59+
size = "small",
60+
)

Diff for: WORKSPACE

+119
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
workspace(name = "inline_java")
2+
3+
http_archive(
4+
name = "io_tweag_rules_haskell",
5+
strip_prefix = "rules_haskell-a1f5b6a21e6cc568ef476b8c63f4c1c60ffc5a03",
6+
urls = ["https://github.com/tweag/rules_haskell/archive/a1f5b6a21e6cc568ef476b8c63f4c1c60ffc5a03.tar.gz"]
7+
)
8+
9+
local_repository(
10+
name = "io_tweag_rules_haskell",
11+
path = "/home/shana/programming/rules_haskell",
12+
)
13+
14+
http_archive(
15+
name = "io_tweag_rules_nixpkgs",
16+
strip_prefix = "rules_nixpkgs-53700e429928530f1566cfff3ec00283a123f17f",
17+
urls = ["https://github.com/tweag/rules_nixpkgs/archive/53700e429928530f1566cfff3ec00283a123f17f.tar.gz"],
18+
)
19+
20+
# Required due to rules_haskell use of skylib.
21+
http_archive(
22+
name = "bazel_skylib",
23+
strip_prefix = "bazel-skylib-0.2.0",
24+
urls = ["https://github.com/bazelbuild/bazel-skylib/archive/0.2.0.tar.gz"]
25+
)
26+
27+
load("@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl", "nixpkgs_git_repository", "nixpkgs_package")
28+
29+
nixpkgs_git_repository(
30+
name = "nixpkgs",
31+
revision = "4026ea9c8afd09b60896b861a04cc5748fdcdfb4",
32+
)
33+
34+
jni_prebuilt = [
35+
"base",
36+
"bytestring",
37+
"choice",
38+
"containers",
39+
"constraints",
40+
"deepseq",
41+
"inline-c",
42+
"singletons"
43+
]
44+
45+
jvm_prebuilt = [
46+
"base",
47+
"bytestring",
48+
"constraints",
49+
"choice",
50+
"distributed-closure",
51+
"exceptions",
52+
"singletons",
53+
"text",
54+
"vector",
55+
]
56+
57+
inline_java_prebuilt = [
58+
"base",
59+
"bytestring",
60+
"Cabal",
61+
"directory",
62+
"filepath",
63+
"filemanip",
64+
"ghc",
65+
"language-java",
66+
"mtl",
67+
"process",
68+
"text",
69+
"template-haskell",
70+
"temporary",
71+
"hspec",
72+
]
73+
74+
jvm_streaming_prebuilt = [
75+
"base",
76+
"distributed-closure",
77+
"singletons",
78+
"streaming",
79+
"hspec",
80+
]
81+
82+
nixpkgs_package(
83+
name = "inline-java-toolchain",
84+
repository = "@nixpkgs",
85+
nix_file_content = """
86+
let pkgs = import <nixpkgs> {{}};
87+
in pkgs.buildEnv {{
88+
name = "inline-java-toolchain";
89+
paths = with pkgs; [
90+
(haskell.packages.ghc822.ghcWithPackages (p: with p; [{0}]))
91+
openjdk
92+
];
93+
}}
94+
""".format(
95+
" ".join(depset(jni_prebuilt + jvm_prebuilt + inline_java_prebuilt + jvm_streaming_prebuilt).to_list())
96+
))
97+
98+
nixpkgs_package(
99+
name = "openjdk",
100+
repository = "@nixpkgs",
101+
build_file_content = """
102+
filegroup (
103+
name = "lib",
104+
srcs = ["nix/lib/openjdk/jre/lib/amd64/server/libjvm.so"],
105+
visibility = ["//visibility:public"],
106+
)
107+
filegroup (
108+
name = "jni_header",
109+
srcs = ["nix/include/jni.h"],
110+
visibility = ["//visibility:public"],
111+
)
112+
filegroup (
113+
name = "jni_md_header",
114+
srcs = ["nix/include/jni_md.h"],
115+
visibility = ["//visibility:public"],
116+
)"""
117+
)
118+
119+
register_toolchains("//:inline-java-toolchain")

Diff for: jni/BUILD

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
load(
4+
"@io_tweag_rules_haskell//haskell:haskell.bzl",
5+
"haskell_import",
6+
"haskell_library",
7+
)
8+
9+
haskell_import(
10+
name = "openjdk",
11+
shared_library = "@openjdk//:lib"
12+
)
13+
14+
haskell_library(
15+
name = "jni",
16+
src_strip_prefix = "src",
17+
srcs = glob(['src/**/*.hs', 'src/**/*.hsc']),
18+
c_sources = glob(['src/**/*.c']),
19+
c_options = ["-std=c11"],
20+
deps = [
21+
":openjdk"
22+
],
23+
# https://stackoverflow.com/questions/46160790/bazel-for-jni-jni-h-file-not-found
24+
external_deps = [
25+
"@openjdk//:jni_header",
26+
"@openjdk//:jni_md_header",
27+
],
28+
prebuilt_dependencies = [
29+
"base",
30+
"bytestring",
31+
"choice",
32+
"containers",
33+
"constraints",
34+
"deepseq",
35+
"inline-c",
36+
"singletons",
37+
],
38+
)

Diff for: jvm-streaming/BUILD

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
load(
4+
"@io_tweag_rules_haskell//haskell:haskell.bzl",
5+
"haskell_test",
6+
"haskell_library",
7+
)
8+
9+
haskell_library(
10+
name = "jvm-streaming",
11+
src_strip_prefix = "src",
12+
srcs = glob(['src/**/*.hs']),
13+
deps = [
14+
"//jni",
15+
"//:inline-java",
16+
"//jvm",
17+
],
18+
prebuilt_dependencies = [
19+
"base",
20+
"distributed-closure",
21+
"singletons",
22+
"streaming",
23+
],
24+
)
25+
26+
haskell_test(
27+
name = "spec",
28+
src_strip_prefix = "tests",
29+
srcs = glob(['tests/**/*.hs']),
30+
deps = [
31+
":jvm-streaming",
32+
"//jvm",
33+
"//:inline-java",
34+
],
35+
prebuilt_dependencies = [
36+
"base",
37+
"hspec",
38+
"streaming",
39+
],
40+
size = "small",
41+
)

Diff for: jvm/BUILD

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
load(
4+
"@io_tweag_rules_haskell//haskell:haskell.bzl",
5+
"haskell_library",
6+
)
7+
8+
haskell_library(
9+
name = "jvm",
10+
src_strip_prefix = "src",
11+
srcs = glob(['src/**/*.hs']),
12+
deps = [
13+
"//jni",
14+
],
15+
prebuilt_dependencies = [
16+
"base",
17+
"bytestring",
18+
"constraints",
19+
"choice",
20+
"distributed-closure",
21+
"exceptions",
22+
"singletons",
23+
"text",
24+
"vector",
25+
],
26+
)

0 commit comments

Comments
 (0)