Skip to content

Commit fe76fde

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 run //:spec` which will build inline-java and run the spec tests. * I'm using GHC 8.0.2 as I was unable to quickly find working 8.2.2 set. * We're taking open JDK header files from bazel but the libraries from nix. Neither exposes both: tweag/rules_nixpkgs#9 * 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. * `rules_nixpkgs` commit points at a temporary branch which includes changes from two outstanding PRs, both of which are needed to build inline-java * `spec` target would be better as some `haskell_test` once that exists * We're giving too many shared openjdk libs during build: we only need libjvm.so and maybe libjni.so but we don't have granular control over the filegroup so we end up using every shared lib in openjdk package which is not ideal.
1 parent 16d564c commit fe76fde

File tree

6 files changed

+276
-0
lines changed

6 files changed

+276
-0
lines changed

.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-*

BUILD

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

WORKSPACE

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
workspace(name = "inline_java")
2+
3+
http_archive(
4+
name = "io_tweag_rules_haskell",
5+
strip_prefix = "rules_haskell-6258443403d1e59b1908daebec06fa329956eb3a",
6+
urls = ["https://github.com/tweag/rules_haskell/archive/6258443403d1e59b1908daebec06fa329956eb3a.tar.gz"]
7+
)
8+
9+
http_archive(
10+
name = "io_tweag_rules_nixpkgs",
11+
strip_prefix = "rules_nixpkgs-5bb86a4b5b5f78accb7582de0c60079b48c9dc50",
12+
urls = ["https://github.com/tweag/rules_nixpkgs/archive/5bb86a4b5b5f78accb7582de0c60079b48c9dc50.tar.gz"],
13+
)
14+
15+
load("@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl", "nixpkgs_git_repository", "nixpkgs_package")
16+
17+
nixpkgs_git_repository(
18+
name = "nixpkgs",
19+
revision = "17.09",
20+
)
21+
22+
jni_prebuilt = [
23+
"base",
24+
"bytestring",
25+
"choice",
26+
"containers",
27+
"constraints",
28+
"deepseq",
29+
"inline-c",
30+
"singletons"
31+
]
32+
33+
jvm_prebuilt = [
34+
"base",
35+
"bytestring",
36+
"constraints",
37+
"choice",
38+
"distributed-closure",
39+
"exceptions",
40+
"singletons",
41+
"text",
42+
"vector",
43+
]
44+
45+
inline_java_prebuilt = [
46+
"base",
47+
"bytestring",
48+
"Cabal",
49+
"directory",
50+
"filepath",
51+
"filemanip",
52+
"ghc",
53+
"language-java",
54+
"mtl",
55+
"process",
56+
"text",
57+
"template-haskell",
58+
"temporary",
59+
"hspec",
60+
]
61+
62+
jvm_streaming_prebuilt = [
63+
"base",
64+
"distributed-closure",
65+
"singletons",
66+
"streaming",
67+
"hspec",
68+
]
69+
70+
nixpkgs_package(
71+
name = "ghc",
72+
expression = "(import <nixpkgs> {{}}).haskell.packages.ghc802.ghcWithPackages (p: with p; [{0}])".format(
73+
" ".join(depset(jni_prebuilt + jvm_prebuilt + inline_java_prebuilt + jvm_streaming_prebuilt).to_list())
74+
),
75+
repository = "@nixpkgs",
76+
)
77+
78+
nixpkgs_package(
79+
name = "openjdk",
80+
repository = "@nixpkgs",
81+
)

jni/BUILD

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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']),
18+
c_sources = glob(['src/**/*.c']),
19+
c_options = ["-std=c11"],
20+
hscs = glob(['src/**/*.hsc']),
21+
deps = [
22+
":openjdk"
23+
],
24+
# https://stackoverflow.com/questions/46160790/bazel-for-jni-jni-h-file-not-found
25+
external_deps = [
26+
"@local_jdk//:jni_header",
27+
"@local_jdk//:jni_md_header-linux",
28+
],
29+
ghc_version = "8.0.2",
30+
prebuilt_dependencies = [
31+
"base",
32+
"bytestring",
33+
"choice",
34+
"containers",
35+
"constraints",
36+
"deepseq",
37+
"inline-c",
38+
"singletons",
39+
],
40+
build_tools = [
41+
"@ghc//:bin",
42+
],
43+
)

jvm-streaming/BUILD

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
load(
4+
"@io_tweag_rules_haskell//haskell:haskell.bzl",
5+
"haskell_binary",
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+
build_tools = [
25+
"@ghc//:bin",
26+
"@openjdk//:bin",
27+
],
28+
ghc_version = "8.0.2",
29+
)
30+
31+
haskell_binary(
32+
name = "spec",
33+
src_strip_prefix = "tests",
34+
srcs = glob(['tests/**/*.hs']),
35+
deps = [
36+
":jvm-streaming",
37+
"//jvm",
38+
"//:inline-java",
39+
],
40+
prebuilt_dependencies = [
41+
"base",
42+
"hspec",
43+
"streaming",
44+
],
45+
build_tools = [
46+
"@ghc//:bin",
47+
"@openjdk//:bin",
48+
],
49+
ghc_version = "8.0.2",
50+
)

jvm/BUILD

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
10+
haskell_import(
11+
name = "openjdk",
12+
shared_library = "@openjdk//:lib"
13+
)
14+
15+
16+
haskell_library(
17+
name = "jvm",
18+
src_strip_prefix = "src",
19+
srcs = glob(['src/**/*.hs']),
20+
deps = [
21+
"//jni",
22+
":openjdk",
23+
],
24+
prebuilt_dependencies = [
25+
"base",
26+
"bytestring",
27+
"constraints",
28+
"choice",
29+
"distributed-closure",
30+
"exceptions",
31+
"singletons",
32+
"text",
33+
"vector",
34+
],
35+
build_tools = [
36+
"@ghc//:bin",
37+
],
38+
ghc_version = "8.0.2",
39+
)

0 commit comments

Comments
 (0)