Skip to content

Add MicroHs support. #864

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

Draft
wants to merge 18 commits into
base: master
Choose a base branch
from
Draft
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
6 changes: 6 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ jobs:
- name: (WASM) Miso examples
run: nix-build -A wasmExamples && ./result/bin/build.sh

- name: (x86) Example.hs (MicroHS 0.12.4.0)
run: cd micro/ && nix-shell --run 'mhs -temscripten Example -oout.js && qjs out.js'

- name: (JS) Example.hs (MicroHS 0.12.4.0)
run: cd micro/ && nix-shell --run 'mhs -r Example'

- name: Nix garbage collect
run: nix-collect-garbage -d

Expand Down
7 changes: 7 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,11 @@ with pkgs.haskell.lib;
# bun
inherit (pkgs)
bun;

# MicroHs-Miso
inherit (pkgs)
microhs
microhs-env
microhs-wrapper;

}
11 changes: 11 additions & 0 deletions micro/Example.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Example(fac, main) where

fac :: Int -> Int
fac 0 = 1
fac n = n * fac(n - 1)

main :: IO ()
main = do
let rs = map fac [1,2,3,10]
putStrLn "Some factorials"
print rs
81 changes: 81 additions & 0 deletions micro/miso.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
cabal-version: 3.0
name: miso
version: 1.9.0.0
synopsis: A tasty Haskell front-end framework
homepage: https://haskell-miso.org
license: BSD-3-Clause
license-file: LICENSE
author: dmjio
maintainer: [email protected]
copyright: Copyright (c) 2016-2025 @dmjio
category: Web
build-type: Simple
extra-doc-files: CHANGELOG.md

library
default-language:
Haskell2010
other-modules:
Miso.Concurrent
Miso.Delegate
Miso.Diff
Miso.Effect
Miso.Event
Miso.Event.Decoder
Miso.Event.Types
Miso.Exception
Miso.FFI
Miso.FFI.History
Miso.FFI.SSE
Miso.FFI.Storage
Miso.FFI.WebSocket
Miso.FFI.Internal
Miso.Html
Miso.Html.Element
Miso.Html.Event
Miso.Html.Property
Miso.Html.Types
Miso.Internal
Miso.Mathml
Miso.Mathml.Element
Miso.Render
Miso.Router
Miso.Run
Miso.Storage
Miso.Subscription
Miso.Subscription.History
Miso.Subscription.Keyboard
Miso.Subscription.Mouse
Miso.Subscription.WebSocket
Miso.Subscription.Window
Miso.Subscription.SSE
Miso.Svg.Attribute
Miso.Svg.Element
Miso.Svg.Event
Miso.Types
Miso.Util
Miso.WebSocket
exposed-modules:
Miso
Miso.Lens
Miso.Svg
Miso.String
ghc-options:
-Wall
hs-source-dirs:
../src, ../text-src
build-depends:
aeson < 2.3,
base < 5,
bytestring < 0.13,
containers < 0.9,
http-api-data < 0.9,
http-media < 0.9,
http-types < 0.13,
jsaddle < 0.10,
mtl < 2.4,
network-uri < 2.7,
servant < 0.21,
tagsoup < 0.15,
text < 2.2,
transformers < 0.7,
1 change: 1 addition & 0 deletions micro/shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(import ../default.nix {}).microhs-env
3 changes: 3 additions & 0 deletions nix/haskell/packages/ghc/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ self: super:
monad-logger = doJailbreak super.monad-logger;
string-interpolate = doJailbreak super.string-interpolate;
servant-server = doJailbreak super.servant-server;

/* microhs */
microhs = self.callCabal2nix "microhs" source.microhs {};
}
63 changes: 63 additions & 0 deletions nix/overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,69 @@ self: super: {
then import ./haskell/packages/ghcjs self
else import ./haskell/packages/ghc self;
};
ghc9101 = super.haskell.packages.ghc9101.override {
overrides = import ./haskell/packages/ghc self;
};
};
};

microhsTargetsConf =
super.writeTextFile {
name = "targets.conf";
text = ''
[default]
cc = "gcc"
ccflags = ""
conf = "unix-64"

[emscripten]
cc = "emcc"
ccflags = "-sALLOW_MEMORY_GROWTH -sTOTAL_STACK=5MB -sSINGLE_FILE -sENVIRONMENT=shell -sWASM=0"
conf = "unix-64"
'';
};

microhs =
super.stdenv.mkDerivation {
name = "MicroHs";
src = (import ../nix/source.nix super).microhs;
buildInputs = with super; [ emscripten ];
installPhase = ''
mkdir -p $out/{bin,share,lib/bin}

cp -v ./bin/mcabal $out/bin
cp -v ./bin/cpphs $out/bin
cp -v ./bin/mhs $out/bin
cp -rv ./lib $out

cp -rv ./generated $out
cp -rv ./boards $out
cp -rv ./paths $out
cp -rv ./doc $out
cp -rv ./src $out
cat ${self.microhsTargetsConf} > $out/targets.conf

cp README.md $out/share
'';
};

microhs-env = super.mkShell {
name = "microhs-env";
buildInputs = with self; [ microhs emscripten nodejs quickjs ];
# https://github.com/NixOS/nixpkgs/issues/139943#issuecomment-930432045
# dmj: Fix for using emcc in Darwin shell environment
#
# dmj: to compile /only/ JS, and work w/ QuickJS:
# $ emcc -sENVIRONMENT=shell -sWASM=0 main.c -oout.js && qjs out.js
shellHook = with super; ''
export MHSDIR=${self.microhs}
export CC=${super.emscripten}/bin/emcc
export PATH=$PATH:${self.microhs}/bin
mkdir -p ~/.emscripten_cache
chmod u+rwX -R ~/.emscripten_cache
cp -r ${super.emscripten}/share/emscripten/cache ~/.emscripten_cache
export EM_CACHE=~/.emscripten_cache
'';
};

}
8 changes: 8 additions & 0 deletions nix/source.nix
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,12 @@ in
rev = "d99f1965654568c0ced7bcd54c0d5083e08fce9c";
sha256 = "1fz4wac1if0lc54gvga640dybwlchi1ybzxw8yjz5836674mdkid";
};
microhs = fetchFromGitHub {
owner = "augustss";
repo = "microhs";
rev = "db0d3d12b0ee814441c6045bd680cc7d92a41375";
sha256 = "sha256-raTlZBQ5seYo/ez0Cg++nbQSLIKvSLLSqcCSL0svrLE=";
fetchSubmodules = true;
};

}
6 changes: 5 additions & 1 deletion shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ with (import ./default.nix {});

if pkg == "ghcjs"
then miso-ghcjs.env
else miso-ghc-9122.env.overrideAttrs (d: {
else
if pkg == "micro"
then pkgs.microhs-env
else
miso-ghc-9122.env.overrideAttrs (d: {
shellHook = ''
alias runner="${legacyPkgs.haskell.packages.ghc865.ghcid}/bin/ghcid -c 'cabal repl'"
'';
Expand Down
Loading