Skip to content

Commit c06ddbf

Browse files
authored
Merge pull request #105 from tweag/bazel
Bazel build files for inline-java
2 parents abbef72 + 1767306 commit c06ddbf

File tree

8 files changed

+262
-2
lines changed

8 files changed

+262
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
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

Lines changed: 60 additions & 0 deletions
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+
)

WORKSPACE

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

jni/BUILD

Lines changed: 38 additions & 0 deletions
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+
)

jvm-streaming/BUILD

Lines changed: 41 additions & 0 deletions
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+
)

jvm/BUILD

Lines changed: 26 additions & 0 deletions
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+
)

nixpkgs.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
import (fetchTarball "https://github.com/nixos/nixpkgs/archive/1354099daf98b7a1f79e6c41ce6bfda5c40177ae.tar.gz")
1+
import (fetchTarball "https://github.com/nixos/nixpkgs/archive/4026ea9c8afd09b60896b861a04cc5748fdcdfb4.tar.gz")

src/Language/Java/Inline/Magic.hsc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
{-# LANGUAGE RankNTypes #-}
1717
{-# LANGUAGE RecordWildCards #-}
1818
{-# LANGUAGE UndecidableInstances #-}
19-
{-# OPTIONS_GHC -ddump-ds #-}
2019

2120
module Language.Java.Inline.Magic
2221
( DotClass(..)

0 commit comments

Comments
 (0)