Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.gradle
build/
jni/src/Foreign/JNI.c
bazel-*
60 changes: 60 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package(default_visibility = ["//visibility:public"])

load(
"@io_tweag_rules_haskell//haskell:haskell.bzl",
"haskell_test",
"haskell_library",
"haskell_toolchain",
)

haskell_toolchain(
name = "inline-java-toolchain",
version = "8.2.2",
tools = "@inline-java-toolchain//:bin",
)

haskell_library(
name = "inline-java",
src_strip_prefix = "src",
srcs = glob(['src/**/*.hs', 'src/**/*.hsc']),
deps = [
"//jni",
"//jvm"
],
external_deps = [
"cbits/bctable.h"
],
c_sources = ["cbits/bctable.c"],
prebuilt_dependencies = [
"base",
"bytestring",
"Cabal",
"directory",
"filepath",
"filemanip",
"ghc",
"language-java",
"mtl",
"process",
"text",
"template-haskell",
"temporary"
],
)

haskell_test(
name = "spec",
src_strip_prefix = "tests",
srcs = glob(["tests/**/*.hs"]),
deps = [
"//jni",
"//jvm",
":inline-java"
],
prebuilt_dependencies = [
"base",
"hspec",
"text",
],
size = "small",
)
95 changes: 95 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
workspace(name = "io_tweag_inline_java")

http_archive(
name = "io_tweag_rules_haskell",
strip_prefix = "rules_haskell-8120ec9c600bc70a1268c05892f2f267248eb560",
urls = ["https://github.com/tweag/rules_haskell/archive/8120ec9c600bc70a1268c05892f2f267248eb560.tar.gz"]
)

http_archive(
name = "io_tweag_rules_nixpkgs",
strip_prefix = "rules_nixpkgs-53700e429928530f1566cfff3ec00283a123f17f",
urls = ["https://github.com/tweag/rules_nixpkgs/archive/53700e429928530f1566cfff3ec00283a123f17f.tar.gz"],
)

# Required due to rules_haskell use of skylib.
http_archive(
name = "bazel_skylib",
strip_prefix = "bazel-skylib-0.2.0",
urls = ["https://github.com/bazelbuild/bazel-skylib/archive/0.2.0.tar.gz"]
)

load("@io_tweag_rules_nixpkgs//nixpkgs:nixpkgs.bzl",
"nixpkgs_git_repository",
"nixpkgs_package",
)

nixpkgs_git_repository(
name = "nixpkgs",
# Keep consistent with ./nixpkgs.nix.
revision = "4026ea9c8afd09b60896b861a04cc5748fdcdfb4",
)

prebuilt_packages = [
"Cabal",
"base",
"bytestring",
"choice",
"constraints",
"containers",
"deepseq",
"directory",
"distributed-closure",
"exceptions",
"filemanip",
"filepath",
"ghc",
"hspec",
"inline-c",
"language-java",
"mtl",
"process",
"singletons",
"streaming",
"template-haskell",
"temporary",
"text",
"vector",
]

nixpkgs_package(
name = "inline-java-toolchain",
repository = "@nixpkgs",
nix_file_content = """
let pkgs = import <nixpkgs> {{}};
in pkgs.buildEnv {{
name = "inline-java-toolchain";
paths = with pkgs; [
(haskell.packages.ghc822.ghcWithPackages (p: with p; [{0}]))
openjdk
];
}}
""".format(" ".join(prebuilt_packages)))

nixpkgs_package(
name = "openjdk",
repository = "@nixpkgs",
build_file_content = """
filegroup (
name = "lib",
srcs = ["nix/lib/openjdk/jre/lib/amd64/server/libjvm.so"],
visibility = ["//visibility:public"],
)
filegroup (
name = "jni_header",
srcs = ["nix/include/jni.h"],
visibility = ["//visibility:public"],
)
filegroup (
name = "jni_md_header",
srcs = ["nix/include/jni_md.h"],
visibility = ["//visibility:public"],
)"""
)

register_toolchains("//:inline-java-toolchain")
38 changes: 38 additions & 0 deletions jni/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package(default_visibility = ["//visibility:public"])

load(
"@io_tweag_rules_haskell//haskell:haskell.bzl",
"haskell_import",
"haskell_library",
)

haskell_import(
name = "openjdk",
shared_library = "@openjdk//:lib"
)

haskell_library(
name = "jni",
src_strip_prefix = "src",
srcs = glob(['src/**/*.hs', 'src/**/*.hsc']),
c_sources = glob(['src/**/*.c']),
c_options = ["-std=c11"],
deps = [
":openjdk"
],
# https://stackoverflow.com/questions/46160790/bazel-for-jni-jni-h-file-not-found
external_deps = [
"@openjdk//:jni_header",
"@openjdk//:jni_md_header",
],
prebuilt_dependencies = [
"base",
"bytestring",
"choice",
"containers",
"constraints",
"deepseq",
"inline-c",
"singletons",
],
)
41 changes: 41 additions & 0 deletions jvm-streaming/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package(default_visibility = ["//visibility:public"])

load(
"@io_tweag_rules_haskell//haskell:haskell.bzl",
"haskell_test",
"haskell_library",
)

haskell_library(
name = "jvm-streaming",
src_strip_prefix = "src",
srcs = glob(['src/**/*.hs']),
deps = [
"//jni",
"//:inline-java",
"//jvm",
],
prebuilt_dependencies = [
"base",
"distributed-closure",
"singletons",
"streaming",
],
)

haskell_test(
name = "spec",
src_strip_prefix = "tests",
srcs = glob(['tests/**/*.hs']),
deps = [
":jvm-streaming",
"//jvm",
"//:inline-java",
],
prebuilt_dependencies = [
"base",
"hspec",
"streaming",
],
size = "small",
)
26 changes: 26 additions & 0 deletions jvm/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package(default_visibility = ["//visibility:public"])

load(
"@io_tweag_rules_haskell//haskell:haskell.bzl",
"haskell_library",
)

haskell_library(
name = "jvm",
src_strip_prefix = "src",
srcs = glob(['src/**/*.hs']),
deps = [
"//jni",
],
prebuilt_dependencies = [
"base",
"bytestring",
"constraints",
"choice",
"distributed-closure",
"exceptions",
"singletons",
"text",
"vector",
],
)
2 changes: 1 addition & 1 deletion nixpkgs.nix
Original file line number Diff line number Diff line change
@@ -1 +1 @@
import (fetchTarball "https://github.com/nixos/nixpkgs/archive/1354099daf98b7a1f79e6c41ce6bfda5c40177ae.tar.gz")
import (fetchTarball "https://github.com/nixos/nixpkgs/archive/4026ea9c8afd09b60896b861a04cc5748fdcdfb4.tar.gz")
1 change: 0 additions & 1 deletion src/Language/Java/Inline/Magic.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -ddump-ds #-}

module Language.Java.Inline.Magic
( DotClass(..)
Expand Down