Skip to content

Commit 4055ed9

Browse files
Merge pull request #201 from tweag/fd/cabal-the-return
Add back cabal files for jni, jvm, and inline-java
2 parents 8176855 + 47526f6 commit 4055ed9

30 files changed

Lines changed: 765 additions & 236 deletions

File tree

.github/workflows/build.yml

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ env:
77

88
jobs:
99
run-tests-with-ubuntu:
10-
name: Run Tests with ubuntu runner
10+
name: with bazel
1111
runs-on: ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@v3
@@ -28,6 +28,7 @@ jobs:
2828
restore-keys: |
2929
repo-cache-${{ runner.os }}-nixpkgs-${{ env.cache-version }}-
3030
- run: |
31+
nix-shell --pure --run "bazel run $BAZEL_ARGS //:gazelle"
3132
nix-shell --pure --run "bazel test --test_output=all //... $BAZEL_ARGS"
3233
- uses: actions/cache/save@v3
3334
if: github.ref == 'refs/heads/master'
@@ -36,9 +37,48 @@ jobs:
3637
~/repo-cache
3738
~/disk-cache
3839
key: repo-cache-${{ runner.os }}-nixpkgs-${{ env.cache-version }}-${{ github.run_id }}-${{ github.run_attempt }}
40+
- name: gazelle check
41+
run: |
42+
if ! git diff --exit-code
43+
then
44+
echo Repository files have changed
45+
echo You might need to run: nix-shell --run "\"bazel run //:gazelle\""
46+
echo and commit the resulting changes.
47+
exit 1
48+
fi
49+
50+
run-tests-with-stack:
51+
name: with stack
52+
runs-on: ubuntu-latest
53+
steps:
54+
- uses: actions/checkout@v3
55+
- uses: cachix/install-nix-action@v22
56+
- name: Configure
57+
run: |
58+
mkdir -p ~/repo-cache ~/disk-cache
59+
echo build --host_platform=@io_tweag_rules_nixpkgs//nixpkgs/platforms:host > .bazelrc.local
60+
- name: Get Stack snapshot install directory
61+
id: stack-snapshot
62+
# NOTE: `stack path` must run at least once prior to caching to ensure the directory
63+
# exists and is populated.
64+
run: |
65+
stack --nix path --snapshot-install-root
66+
echo "dir=$(stack --nix path --snapshot-install-root)" > "${GITHUB_OUTPUT}"
67+
- uses: actions/cache@v4
68+
with:
69+
path: ${{ steps.stack-snapshot.outputs.dir }}
70+
key: ${{ runner.os }}-stack-${{ hashFiles('**/*.cabal') }}
71+
restore-keys: ${{ runner.os }}-stack-
72+
- name: Build
73+
run: |
74+
stack --nix build
75+
- name: Test
76+
if: ${{ runner.os == 'Linux' }}
77+
run: |
78+
stack --nix test
3979
4080
run-tests-with-darwin:
41-
name: Run Tests with darwin runner
81+
name: with bazel in darwin
4282
runs-on: macos-11
4383

4484
steps:

BUILD.bazel

Lines changed: 109 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,80 @@
11
exports_files(["nixpkgs.nix"])
22

3+
# gazelle:exclude {benchmarks,examples,jvm-streaming,jvm-batching}
4+
# gazelle:resolve gazelle_cabal jvm @openjdk//:lib
5+
36
load(
47
"@rules_haskell//haskell:defs.bzl",
58
"ghc_plugin",
9+
"haskell_binary",
610
"haskell_library",
11+
"haskell_test",
712
)
813

914
cc_library(
1015
name = "bctable",
11-
hdrs = ["cbits/bctable.h"],
1216
srcs = ["cbits/bctable.c"],
17+
hdrs = ["cbits/bctable.h"],
1318
strip_include_prefix = "cbits",
1419
)
1520

21+
ghc_plugin(
22+
name = "inline-java-plugin",
23+
args = ["$(JAVABASE)/bin/javac"],
24+
module = "Language.Java.Inline.Plugin",
25+
toolchains = ["@bazel_tools//tools/jdk:current_java_runtime"],
26+
tools = ["@bazel_tools//tools/jdk:current_java_runtime"],
27+
visibility = ["//visibility:public"],
28+
deps = [":inline-java"],
29+
)
30+
31+
load(
32+
"@bazel_gazelle//:def.bzl",
33+
"DEFAULT_LANGUAGES",
34+
"gazelle",
35+
"gazelle_binary",
36+
)
37+
38+
gazelle(
39+
name = "gazelle",
40+
gazelle = ":gazelle_binary",
41+
)
42+
43+
gazelle_binary(
44+
name = "gazelle_binary",
45+
languages = DEFAULT_LANGUAGES + ["@io_tweag_gazelle_cabal//gazelle_cabal"],
46+
)
47+
48+
# rule generated from inline-java.cabal by gazelle_cabal
1649
haskell_library(
1750
name = "inline-java",
1851
# cbits/bctable.h is included here so it can be found by Plugin.hs
1952
# at the same location when building with bazel as with stack.
20-
srcs = glob(['src/**/*.hs',
21-
'src/**/*.hsc',
22-
'cbits/bctable.h',
23-
]),
53+
srcs = [
54+
"cbits/bctable.h", # keep
55+
"src/GhcPlugins/Extras.hs",
56+
"src/Language/Java/Inline.hs",
57+
"src/Language/Java/Inline/Internal.hs",
58+
"src/Language/Java/Inline/Internal/Magic.hsc",
59+
"src/Language/Java/Inline/Internal/QQMarker.hs",
60+
"src/Language/Java/Inline/Internal/QQMarker/Names.hs",
61+
"src/Language/Java/Inline/Internal/QQMarker/Safe.hs",
62+
"src/Language/Java/Inline/Plugin.hs",
63+
"src/Language/Java/Inline/Safe.hs",
64+
"src/Language/Java/Inline/Unsafe.hs",
65+
],
66+
ghcopts = ["-DVERSION_inline_java=\"0.10.0\""],
67+
hidden_modules = ["GhcPlugins.Extras"],
68+
version = "0.10.0",
2469
visibility = ["//visibility:public"],
2570
deps = [
71+
":bctable", # keep
2672
"//jni",
2773
"//jvm",
28-
":bctable",
2974
"@stackage//:Cabal",
3075
"@stackage//:base",
3176
"@stackage//:bytestring",
3277
"@stackage//:directory",
33-
"@stackage//:filemanip",
3478
"@stackage//:filepath",
3579
"@stackage//:ghc",
3680
"@stackage//:language-java",
@@ -43,12 +87,63 @@ haskell_library(
4387
],
4488
)
4589

46-
ghc_plugin(
47-
name = "inline-java-plugin",
48-
args = ["$(JAVABASE)/bin/javac"],
49-
module = "Language.Java.Inline.Plugin",
50-
toolchains = ["@bazel_tools//tools/jdk:current_java_runtime"],
51-
tools = ["@bazel_tools//tools/jdk:current_java_runtime"],
90+
# rule generated from inline-java.cabal by gazelle_cabal
91+
haskell_test(
92+
name = "spec",
93+
srcs = [
94+
"tests/Language/Java/Inline/SafeSpec.hs",
95+
"tests/Language/Java/InlineSpec.hs",
96+
"tests/Main.hs",
97+
"tests/SafeSpec.hs",
98+
"tests/Spec.hs",
99+
],
100+
extra_srcs = ["@openjdk//:rpath"], # keep
101+
ghcopts = [
102+
"-optl-Wl,@$(location @openjdk//:rpath)", # keep
103+
"-DVERSION_inline_java=\"0.10.0\"",
104+
"-threaded",
105+
"-DHSPEC_DISCOVER_HSPEC_DISCOVER_PATH=$(location @stackage-exe//hspec-discover)",
106+
],
107+
main_file = "tests/Main.hs",
108+
plugins = [":inline-java-plugin"],
109+
tools = ["@stackage-exe//hspec-discover"],
110+
version = "0.10.0",
52111
visibility = ["//visibility:public"],
53-
deps = [":inline-java"],
112+
deps = [
113+
"//:inline-java", # keep
114+
"//jni",
115+
"//jvm",
116+
"@stackage//:QuickCheck",
117+
"@stackage//:base",
118+
"@stackage//:hspec",
119+
"@stackage//:linear-base",
120+
"@stackage//:quickcheck-unicode",
121+
"@stackage//:text",
122+
"@stackage//:vector",
123+
],
124+
)
125+
126+
# rule generated from inline-java.cabal by gazelle_cabal
127+
haskell_binary(
128+
name = "micro-benchmarks",
129+
srcs = ["benchmarks/micro/Main.hs"],
130+
extra_srcs = ["@openjdk//:rpath"], # keep
131+
ghcopts = [
132+
"-optl-Wl,@$(location @openjdk//:rpath)", # keep
133+
"-DVERSION_inline_java=\"0.10.0\"",
134+
"-threaded",
135+
],
136+
main_file = "benchmarks/micro/Main.hs",
137+
plugins = [":inline-java-plugin"],
138+
version = "0.10.0",
139+
visibility = ["//visibility:public"],
140+
deps = [
141+
"//:inline-java", # keep
142+
"//jni",
143+
"//jvm",
144+
"@stackage//:base",
145+
"@stackage//:criterion",
146+
"@stackage//:deepseq",
147+
"@stackage//:singletons",
148+
],
54149
)

Setup.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import Distribution.Simple
2+
main = defaultMain

WORKSPACE

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ stack_snapshot(
6464
"filepath",
6565
"ghc",
6666
"hspec",
67+
"hspec-discover",
6768
"inline-c",
6869
"language-java",
6970
"monad-logger",
@@ -98,6 +99,10 @@ stack_snapshot(
9899
"ghc-boot-th",
99100
"pretty",
100101
"transformers",
102+
# gazelle_cabal dependencies
103+
"json", # keep
104+
"path", # keep
105+
"path-io", # keep
101106
],
102107
extra_deps = { "zlib" : ["@zlib.dev//:zlib"] },
103108
components_dependencies = {
@@ -109,6 +114,10 @@ stack_snapshot(
109114
"lib",
110115
"lib:attoparsec-internal",
111116
],
117+
"hspec-discover": [
118+
"lib",
119+
"exe",
120+
],
112121
},
113122
local_snapshot = "//:snapshot-9.0.2.yaml",
114123
# stack = "@stack_ignore_global_hints//:bin/stack" if ghc_version == "9.0.1" else None,
@@ -144,12 +153,6 @@ haskell_register_ghc_nixpkgs(
144153
],
145154
)
146155

147-
nixpkgs_package(
148-
name = "sed",
149-
attribute_path = "gnused",
150-
repository = "@nixpkgs",
151-
)
152-
153156
nixpkgs_package(
154157
name = "hspec-discover",
155158
attribute_path = "haskellPackages.hspec-discover",
@@ -250,3 +253,69 @@ maven_install(
250253
"https://repo1.maven.org/maven2",
251254
],
252255
)
256+
257+
# gazelle setup
258+
259+
http_archive(
260+
name = "rules_nixpkgs_go",
261+
sha256 = "30271f7bd380e4e20e4d7132c324946c4fdbc31ebe0bbb6638a0f61a37e74397",
262+
strip_prefix = "rules_nixpkgs-0.13.0/toolchains/go",
263+
urls = ["https://github.com/tweag/rules_nixpkgs/releases/download/v0.13.0/rules_nixpkgs-0.13.0.tar.gz"],
264+
)
265+
266+
http_archive(
267+
name = "io_bazel_rules_go",
268+
sha256 = "f2dcd210c7095febe54b804bb1cd3a58fe8435a909db2ec04e31542631cf715c",
269+
urls = [
270+
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.31.0/rules_go-v0.31.0.zip",
271+
"https://github.com/bazelbuild/rules_go/releases/download/v0.31.0/rules_go-v0.31.0.zip",
272+
],
273+
)
274+
275+
http_archive(
276+
name = "bazel_gazelle",
277+
sha256 = "de69a09dc70417580aabf20a28619bb3ef60d038470c7cf8442fafcf627c21cb",
278+
urls = [
279+
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.24.0/bazel-gazelle-v0.24.0.tar.gz",
280+
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.24.0/bazel-gazelle-v0.24.0.tar.gz",
281+
],
282+
)
283+
284+
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository")
285+
286+
############################################################
287+
# Define your own dependencies here using go_repository.
288+
# Else, dependencies declared by rules_go/gazelle will be used.
289+
# The first declaration of an external repository "wins".
290+
############################################################
291+
292+
load("@rules_nixpkgs_go//:go.bzl", "nixpkgs_go_configure")
293+
294+
nixpkgs_go_configure(
295+
repository = "@nixpkgs",
296+
)
297+
298+
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
299+
300+
go_rules_dependencies()
301+
302+
gazelle_dependencies()
303+
304+
305+
http_archive(
306+
name = "io_tweag_gazelle_cabal",
307+
strip_prefix = "gazelle_cabal-ca8f68e250bea33815fb373320f9610582c42083",
308+
sha256 = "bd2ee67943007723b3425bf2fcbdb6b41b269c7bc03f01e40683d4b5f3984b3b",
309+
url = "https://github.com/tweag/gazelle_cabal/archive/ca8f68e.zip",
310+
)
311+
312+
load("@rules_haskell//haskell:cabal.bzl", "stack_snapshot")
313+
load("@io_tweag_gazelle_cabal//:defs.bzl", "gazelle_cabal_dependencies")
314+
gazelle_cabal_dependencies()
315+
316+
go_repository(
317+
name = "org_golang_x_xerrors",
318+
importpath = "golang.org/x/xerrors",
319+
sum = "h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=",
320+
version = "v0.0.0-20200804184101-5ec99f83aff1",
321+
)

benchmarks/micro/BUILD.bazel

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)