Skip to content

Commit a61576f

Browse files
authored
Merge pull request #65 from Anut-py/lens
Flag to disable lens
2 parents 113a642 + b759908 commit a61576f

9 files changed

Lines changed: 193 additions & 94 deletions

File tree

.github/workflows/cabal-build.yml

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ permissions:
1111

1212
jobs:
1313
cabal-build:
14-
name: GHC ${{ matrix.ghc-version }} on ${{ matrix.os }}
14+
name: "GHC ${{ matrix.ghc-version }} on ${{ matrix.os }} (lens: ${{ matrix.lens }})"
1515
runs-on: ${{ matrix.os }}
1616
strategy:
1717
fail-fast: false
1818
matrix:
1919
os: [ubuntu-latest, windows-latest, macos-latest]
20-
ghc-version: ["9.8", "9.6", "9.2"]
20+
ghc-version: ["9.12", "9.10", "9.6", "9.2"]
21+
lens: [true, false]
2122
exclude:
2223
- os: macos-latest
2324
ghc-version: "9.2"
@@ -43,33 +44,18 @@ jobs:
4344
sudo apt install -y x11proto-xext-dev libx11-dev xorg-dev freeglut3-dev
4445
4546
- name: Configure the build
47+
if: matrix.lens
4648
run: |
4749
cabal configure --enable-tests --enable-benchmarks --disable-documentation
4850
cabal build --dry-run
4951
# The last step generates dist-newstyle/cache/plan.json for the cache key.
5052

51-
# IMPT: Uncomment when adding steps after cabal build
52-
# - name: Restore cached dependencies
53-
# uses: actions/cache/restore@v4
54-
# id: cache
55-
# env:
56-
# key: ${{ runner.os }}-ghc-${{ steps.setup.outputs.ghc-version }}-cabal-${{ steps.setup.outputs.cabal-version }}
57-
# with:
58-
# path: ${{ steps.setup.outputs.cabal-store }}
59-
# key: ${{ env.key }}-plan-${{ hashFiles('**/plan.json') }}
60-
# restore-keys: ${{ env.key }}-
61-
62-
# - name: Install dependencies
63-
# run: cabal build all --only-dependencies
64-
65-
# # Cache dependencies already here, so that we do not have to rebuild them should the subsequent steps fail.
66-
# - name: Save cached dependencies
67-
# uses: actions/cache/save@v4
68-
# # Caches are immutable, trying to save with the same key would error.
69-
# if: ${{ steps.cache.outputs.cache-primary-key != steps.cache.outputs.cache-matched-key }}
70-
# with:
71-
# path: ${{ steps.setup.outputs.cabal-store }}
72-
# key: ${{ steps.cache.outputs.cache-primary-key }}
53+
- name: Configure the build (no lens)
54+
if: ${{ !matrix.lens }}
55+
run: |
56+
cabal configure --enable-tests --enable-benchmarks --disable-documentation -fdisable-lens
57+
cabal build --dry-run
58+
# The last step generates dist-newstyle/cache/plan.json for the cache key.
7359

7460
- name: Build
7561
run: cabal build all

cabal.project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
packages: *.cabal
22

3-
optimization: 2
3+
optimization: 0
44

55
package h-raylib
66
flags: +examples

h-raylib.cabal

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ data-files:
4545

4646
source-repository head
4747
type: git
48-
location: git://github.com/Anut-py/h-raylib.git
48+
location: https://github.com/Anut-py/h-raylib.git
4949

5050
flag detect-platform
5151
description:
@@ -101,6 +101,11 @@ flag ghci
101101
default: False
102102
manual: True
103103

104+
flag disable-lens
105+
description: Exclude the lens dependency and Raylib.Util.Lenses
106+
default: False
107+
manual: True
108+
104109
common example-options
105110
default-language: Haskell2010
106111

@@ -229,24 +234,34 @@ library
229234
Raylib.Util.Colors
230235
Raylib.Util.GUI
231236
Raylib.Util.GUI.Styles
232-
Raylib.Util.Lenses
233237
Raylib.Util.Math
234238
Raylib.Util.RLGL
235239

240+
if !flag(disable-lens)
241+
exposed-modules:
242+
Raylib.Util.Lenses
243+
236244
other-modules:
237245
Raylib.Internal.TH
238246
Raylib.Internal.Web.Native
239247
Raylib.Internal.Web.Processable
240248

249+
if !flag(disable-lens)
250+
other-modules:
251+
Raylib.Util.Lenses.TH
252+
241253
build-depends:
242254
, base >=4.0 && <4.22
243255
, bytestring >=0.11.0 && <0.13
244-
, containers >=0.6.0 && <0.7
245-
, exceptions >=0.10.4 && <0.11
246-
, lens >=4.0 && <5.4
247-
, linear >=1.22 && <1.24
248-
, template-haskell >=2.16.0.0 && <2.23.0.0
256+
, containers >=0.6.0 && <0.9
257+
, template-haskell >=2.16.0.0 && <2.24
249258
, text >=2.0 && <2.2
259+
260+
261+
if !flag(disable-lens)
262+
build-depends:
263+
, linear >=1.22 && <1.24
264+
, lens >=4.0 && <5.4
250265

251266
hs-source-dirs: src
252267
default-language: Haskell2010
@@ -363,3 +378,6 @@ library
363378

364379
if flag(ghci)
365380
cpp-options: -DGHCI
381+
382+
if flag(disable-lens)
383+
cpp-options: -DDISABLE_LENS

src/Raylib/Internal/Foreign.hs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,13 @@ import qualified Data.Text.Encoding as TE
4444
import Foreign (FunPtr, Ptr, Storable (peek, peekByteOff, poke, sizeOf), allocaBytes, castPtr, malloc, newArray, nullPtr, peekArray, plusPtr, pokeArray0, with, withArray, withArrayLen)
4545
import Foreign.C (CFloat, CInt, CString, CUChar, CUInt, peekCString, withCString)
4646
import Foreign.C.Types (CBool, CChar, CShort, CUShort)
47+
48+
#ifndef DISABLE_LENS
49+
4750
import Linear (V2, V3, V4)
4851

52+
#endif
53+
4954
-- Internal utility functions
5055

5156
#ifdef WEB_FFI
@@ -111,12 +116,16 @@ instance (Freeable a, Storable a) => Freeable [a] where
111116
let val = arr !! i in rlFreeDependents val (plusPtr ptr (i * sizeOf val))
112117
)
113118

119+
#ifndef DISABLE_LENS
120+
114121
instance Freeable (V2 a)
115122

116123
instance Freeable (V3 a)
117124

118125
instance Freeable (V4 a)
119126

127+
#endif
128+
120129
rlFreeMaybeArray :: (Freeable a, Storable a) => Maybe [a] -> Ptr a -> IO ()
121130
rlFreeMaybeArray Nothing _ = return ()
122131
rlFreeMaybeArray (Just arr) ptr = rlFree arr (castPtr ptr)

src/Raylib/Internal/TH.hs

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,59 +3,33 @@
33
{-# LANGUAGE TupleSections #-}
44

55
-- | Template Haskell functions used internally
6-
module Raylib.Internal.TH (genLenses, genNative) where
7-
8-
import Control.Lens (makeLensesFor)
9-
import Control.Monad (zipWithM)
6+
module Raylib.Internal.TH (genNative) where
107

118
#ifdef WEB_FFI
129

1310
import Language.Haskell.TH
1411
( Body (NormalB),
1512
Clause (Clause),
16-
Con (RecC),
17-
Dec (DataD, FunD, SigD),
13+
Dec (FunD, SigD),
1814
DecsQ,
1915
Exp (AppE, LitE, VarE),
20-
Info (TyConI),
2116
Lit (StringL),
22-
Name,
2317
TypeQ,
2418
mkName,
25-
nameBase,
26-
reify,
2719
)
2820
import Raylib.Internal.Web.Native (callRaylibFunction)
2921

3022
#else
3123

3224
import Language.Haskell.TH
33-
( Con (RecC),
34-
Dec (DataD, ForeignD),
25+
( Dec (ForeignD),
3526
DecsQ,
36-
Info (TyConI),
37-
Name,
3827
TypeQ,
39-
mkName,
40-
nameBase,
41-
reify, Foreign (ImportF), Callconv (CCall), Safety (Safe),
28+
mkName, Foreign (ImportF), Callconv (CCall), Safety (Safe),
4229
)
4330

4431
#endif
4532

46-
-- | Creates lenses with an underscore before field names; e.g. @vector2'x@
47-
-- becomes the lens @_vector2'x@
48-
genLenses :: [Name] -> DecsQ
49-
genLenses names = do
50-
infos <- mapM reify names
51-
concat <$> zipWithM genLensesForType names infos
52-
where
53-
genLensesForType name (TyConI (DataD _ _ _ _ [RecC _ ctors] _)) =
54-
makeLensesFor mapping name
55-
where
56-
mapping = map (\(a, _, _) -> let fName = nameBase a in (fName, '_' : fName)) ctors
57-
genLensesForType _ _ = error "(genLenses) Received a name that does not refer to a valid type!"
58-
5933
-- | Generates native code for the given functions. On non-web platforms, this
6034
-- means @foreign import@ statements. On web platforms, this means
6135
-- `callRaylibFunction` calls.

0 commit comments

Comments
 (0)