Skip to content

Enable building with the GHC Wasm backend #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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: 0 additions & 1 deletion cabal.config

This file was deleted.

28 changes: 27 additions & 1 deletion cabal.project
Original file line number Diff line number Diff line change
@@ -1,2 +1,28 @@
packages: ./.
./example

if arch(javascript)
packages: ./example

if arch(wasm32)
-- older versions of `time` don't build on WASM
-- https://github.com/haskellari/time-compat/issues/37
constraints: time installed
allow-newer: time

-- waiting for release
-- https://github.com/dmjio/miso/pull/752
source-repository-package
type: git
location: https://github.com/dmjio/miso
tag: e411f3e2872465f37eb53b6de4542010a105b53a

-- Wasm support
https://github.com/diagrams/diagrams-lib/pull/372
source-repository-package
type: git
location: https://github.com/georgefst/diagrams-lib
tag: 19d9ebeb22385a7674ea7bec6856dc130b73350f

-- default global Wasm config adds `:override` for `head.hackage` - often not what we want
-- https://gitlab.haskell.org/haskell-wasm/ghc-wasm-meta/-/issues/9#note_553150
active-repositories: hackage.haskell.org, head.hackage.ghc.haskell.org
12 changes: 6 additions & 6 deletions diagrams-miso.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ Library
Graphics.Rendering.Miso
Hs-source-dirs: src
Build-depends: aeson
, base >= 4.9 && < 4.10
, mtl >= 1 && < 2.3
, base >= 4.11 && < 4.21
, mtl >= 1 && < 2.4
, colour >= 2.3.2 && < 2.4
, diagrams-core >= 1.4 && < 1.5
, diagrams-core >= 1.4 && < 1.6
, diagrams-lib >= 1.4 && < 1.5
, monoid-extras >= 0.3 && < 0.5
, monoid-extras >= 0.3 && < 0.7
, miso >= 0.8
, containers >= 0.3 && < 0.6
, lens >= 4.15 && < 4.16
, containers >= 0.3 && < 0.8
, lens >= 4.15 && < 5.4

Ghc-options: -Wall

Expand Down
5 changes: 3 additions & 2 deletions src/Diagrams/Backend/Miso.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import Diagrams.Core.Types (Annotation (..))
import Diagrams.Prelude hiding (Attribute, size, view, local, text, query)
import Diagrams.TwoD.Adjust (adjustDia2D)
import Diagrams.TwoD.Text (Text(..))
import Miso hiding (Options, view, Result, onMouseDown, onMouseUp)
import Miso hiding (Options, view, Result, onMouseDown, onMouseUp, Node)
import Miso.String (MisoString, ms)

import Graphics.Rendering.Miso (RenderM)
Expand All @@ -78,9 +78,10 @@ type B = MisoSvg
type instance V MisoSvg = V2
type instance N MisoSvg = Double

instance Semigroup (Render MisoSvg V2 Double) where
Render r1 <> Render r2_ = Render $ mappend r1 r2_
instance Monoid (Render MisoSvg V2 Double) where
mempty = Render mempty
Render r1 `mappend` Render r2_ = Render $ mappend r1 r2_

instance Backend MisoSvg V2 Double where
newtype Render MisoSvg V2 Double = Render RenderM
Expand Down
3 changes: 2 additions & 1 deletion src/Graphics/Rendering/Miso.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ data Element = Element

type RenderM = Reader (Style V2 Double) [Element]

instance Semigroup RenderM where
a <> b = mappend <$> a <*> b
instance Monoid RenderM where
mempty = return []
mappend a b = mappend <$> a <*> b

type AttributeValue = String

Expand Down