Skip to content

Commit a90c744

Browse files
Make cat-tokens into a Haskell binary
1 parent 2d2ddf4 commit a90c744

File tree

6 files changed

+38
-67
lines changed

6 files changed

+38
-67
lines changed

WORKSPACE

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,6 @@ haskell_register_ghc_nixpkgs(
153153
],
154154
)
155155

156-
nixpkgs_package(
157-
name = "sed",
158-
attribute_path = "gnused",
159-
repository = "@nixpkgs",
160-
)
161-
162156
nixpkgs_package(
163157
name = "hspec-discover",
164158
attribute_path = "haskellPackages.hspec-discover",

jni/BUILD.bazel

Lines changed: 17 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,10 @@
11
load(
22
"@rules_haskell//haskell:defs.bzl",
3+
"haskell_binary",
34
"haskell_library",
45
"haskell_test",
56
)
67

7-
# Note cat-tokens
8-
#
9-
# This is a script to concatenate tokens after CPP preprocessing.
10-
#
11-
# On OSX we used to rely on cpphs to concatenate tokens in
12-
# definitions like
13-
#
14-
# define GET_FIELD(name, hs_rettype, c_rettype) \
15-
# get/**/name/**/Field :: Coercible o (J a) => o -> JFieldID -> IO hs_rettype;
16-
#
17-
# The C preprocessor in OSX would otherwise replace the
18-
# comments with whitespaces.
19-
#
20-
# Using cpphs, however, required a couple of hacks to workaround
21-
# https://github.com/haskell/cabal/issues/4278
22-
# https://gitlab.haskell.org/ghc/ghc/-/issues/17185
23-
#
24-
# And moreover, when using rules_haskell, ghc passes response files to cpphs,
25-
# which are unsupported.
26-
# https://github.com/tweag/rules_haskell/pull/836
27-
#
28-
# Therefore, we currently resolve concatenation with a custom
29-
# preprocessor to avoid the pile of hacks. The concatenator operator is ####.
30-
#
31-
# define GET_FIELD(name, hs_rettype, c_rettype) \
32-
# get####name####Field :: Coercible o (J a) => o -> JFieldID -> IO hs_rettype;
33-
#
34-
genrule(
35-
name = "cat-tokens-sh",
36-
srcs = [],
37-
outs = ["cat-tokens.sh"],
38-
cmd = """
39-
cat > $@ <<END
40-
#!/bin/sh
41-
( echo "{-# LINE 1 \\"\\$$1\\" #-}" ; $(location @sed//:bin) 's/####//g' \\$$2) > \\$$3
42-
exit \\$$?
43-
END
44-
""",
45-
executable = 1,
46-
tools = ["@sed//:bin"],
47-
)
48-
498
# rule generated from jni/jni.cabal by gazelle_cabal
509
haskell_library(
5110
name = "jni",
@@ -63,15 +22,11 @@ haskell_library(
6322
"src/linear-types/Foreign/JNI/Safe.hs",
6423
"src/linear-types/Foreign/JNI/Types/Safe.hs",
6524
],
66-
extra_srcs = ["//jni:cat-tokens-sh"],
67-
# keep
6825
ghcopts = [
6926
"-DVERSION_jni=\"0.8.0\"",
70-
"-F",
71-
"-pgmF$(location cat-tokens-sh)",
27+
"-DJNI_CAT_TOKENS_PATH=$(location :cat-tokens)",
7228
],
73-
# keep
74-
tools = ["@sed//:bin"],
29+
tools = [":cat-tokens"],
7530
version = "0.8.0",
7631
visibility = ["//visibility:public"],
7732
deps = [
@@ -120,3 +75,17 @@ haskell_test(
12075
"@stackage//:singletons-base",
12176
],
12277
)
78+
79+
# rule generated from jni/jni.cabal by gazelle_cabal
80+
haskell_binary(
81+
name = "cat-tokens",
82+
srcs = ["cat-tokens/Main.hs"],
83+
ghcopts = ["-DVERSION_jni=\"0.8.0\""],
84+
main_file = "cat-tokens/Main.hs",
85+
version = "0.8.0",
86+
visibility = ["//visibility:public"],
87+
deps = [
88+
"@stackage//:base",
89+
"@stackage//:bytestring",
90+
],
91+
)

jni/cat-tokens.sh

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

jni/jni.cabal

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ maintainer: [email protected]
1010
copyright: 2015-2016 EURL Tweag.
1111
category: FFI, JVM, Java
1212
build-type: Simple
13-
cabal-version: >=2.0
14-
extra-source-files: README.md cat-tokens.sh
13+
cabal-version: 2.0
14+
extra-source-files: README.md
1515

1616
source-repository head
1717
type: git
@@ -25,10 +25,6 @@ flag linear-types
2525
library
2626
hs-source-dirs: src/common src/linear-types
2727
cc-options: -std=c11
28-
-- XXX issues with CPP make more convenient using
29-
-- a custom preprocessor to deal with concatenation.
30-
-- See note cat-tokens in jni/BUILD.bazel.
31-
ghc-options: -F -pgmF./cat-tokens.sh
3228
extra-libraries: jvm
3329
exposed-modules:
3430
Foreign.JNI
@@ -57,6 +53,20 @@ library
5753
stm >= 2.3,
5854
text >= 1.2.3
5955
default-language: Haskell2010
56+
-- XXX issues with CPP make more convenient using
57+
-- a custom preprocessor to deal with concatenation.
58+
-- See jni/cat-tokens/Main.hs.
59+
cpp-options: -DJNI_CAT_TOKENS_PATH=cat-tokens
60+
build-tool-depends:
61+
jni:cat-tokens
62+
63+
executable cat-tokens
64+
hs-source-dirs: cat-tokens
65+
main-is: Main.hs
66+
build-depends:
67+
base,
68+
bytestring
69+
default-language: Haskell2010
6070

6171
test-suite spec
6272
type:

jni/src/common/Foreign/JNI/Unsafe/Internal.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
{-# LANGUAGE TemplateHaskell #-}
1111
{-# LANGUAGE ViewPatterns #-}
1212

13-
{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
13+
{-# OPTIONS_GHC -fno-warn-name-shadowing -F -pgmF JNI_CAT_TOKENS_PATH #-}
1414

1515
-- XXX This file uses #### for concatenating tokens with a preprocessor in
16-
-- a portable way. See note cat-tokens in jni/BUILD.bazel.
16+
-- a portable way. See note cat-tokens in jni/cat-tokens/Main.hs.
1717

1818
module Foreign.JNI.Unsafe.Internal
1919
( -- * JNI functions

jni/src/linear-types/Foreign/JNI/Safe.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@
6060
{-# LANGUAGE LinearTypes #-}
6161
{-# LANGUAGE NoImplicitPrelude #-}
6262

63+
{-# OPTIONS_GHC -fno-warn-name-shadowing -F -pgmF JNI_CAT_TOKENS_PATH #-}
64+
6365
-- XXX This file uses #### for concatenating tokens with a preprocessor in
64-
-- a portable way. See note cat-tokens in jni/BUILD.bazel.
66+
-- a portable way. See cat-tokens/Main.hs.
6567

6668
module Foreign.JNI.Safe
6769
( module Foreign.JNI.Safe

0 commit comments

Comments
 (0)