From e98f9e77481f4b83186f8f17e2eb955374e9f038 Mon Sep 17 00:00:00 2001 From: dmjio Date: Wed, 9 Apr 2025 20:24:59 -0500 Subject: [PATCH 01/24] Add MicroHs support. We'd like to add support for the [MicroHs project](https://github.com/augustss/MicroHs) as a first class citizen, to explore its cross-compilation capabilities (w/ emscripten, and other platforms). This PR fetches MicroHs at master and builds (with ghc910) using the recommended Makefile workflow. We "make install" into /nix/store during the installPhase. 1) The 'microhs' package that places cpphs, mcabal inside of $out/bin, mhs is placed inside of $out/lib/bin. We also copy lib, generated, boards, docs, into $out (aka /nix/store/). 2) 'microhs-wrapper' package. This is a shell script that ensure `mhs` is present on PATH, also ensures the $MSHDIR variable points to the MicroHs /lib that exists in the /nix/store. "export MHSDIR=${self.microhs}" 3) 'microhs-env' shell environment that includes both of the above packages. Using `nix-shell` we can now enter an environment where `mhs` is present on PATH and points to the correct $MHSDIR, along with all the other build tools present (cpphs, mcabal). To test, clone miso and call "nix-shell --argstr pkg micro --run 'mhs --version'" - [x] Build MicroHS into miso's nixpkgs (mcabal,mhs,cpphs) - [x] Create 3 derivations for microhs (microhs,microhs-env,microhs-wrapper) - [x] Introduce micro/ subdirectory with a new 'miso.cabal' that MicroHS supports - [x] Add MicroHs shell environment to shell.nix (command above) - [ ] Use 'mcabal install' to fetch and build all of miso's dependencies (TODO) - [ ] Explore adding support for a JS FFI via emscripten (this might require modifications to mcabal or mhs to support "foreign import javascript" syntax) - [ ] Create install script with nix that uses mcabal to install all deps. and builds miso. Place miso's MicroHS build under CI using both emscripten and native - [ ] Consider upstreaming MicroHs into nixpkgs proper (with pkgsCross support) For JSFFI support (for browser targets) w/ emscripten consider the following docs - https://emscripten.org/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html#calling-javascript-from-c-c --- default.nix | 6 ++++ micro/miso.cabal | 81 ++++++++++++++++++++++++++++++++++++++++++++++ micro/shell.nix | 1 + micro/targets.conf | 3 ++ nix/overlay.nix | 29 +++++++++++++++++ nix/source.nix | 8 +++++ shell.nix | 11 ++++++- 7 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 micro/miso.cabal create mode 100644 micro/shell.nix create mode 100644 micro/targets.conf diff --git a/default.nix b/default.nix index cfa1db3d5..4070f6674 100644 --- a/default.nix +++ b/default.nix @@ -129,4 +129,10 @@ with pkgs.haskell.lib; ''; }; + # MicroHs-Miso + inherit (pkgs) + microhs + microhs-env + microhs-wrapper; + } diff --git a/micro/miso.cabal b/micro/miso.cabal new file mode 100644 index 000000000..ec8779f05 --- /dev/null +++ b/micro/miso.cabal @@ -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: code@dmj.io +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, diff --git a/micro/shell.nix b/micro/shell.nix new file mode 100644 index 000000000..d4c5e4d8c --- /dev/null +++ b/micro/shell.nix @@ -0,0 +1 @@ +(import ../default.nix {}).microhs-env diff --git a/micro/targets.conf b/micro/targets.conf new file mode 100644 index 000000000..597f423d1 --- /dev/null +++ b/micro/targets.conf @@ -0,0 +1,3 @@ +[default] +cc = "cc" +conf = "unix-64" diff --git a/nix/overlay.nix b/nix/overlay.nix index b09c7dbf0..cd816ccf9 100644 --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -37,4 +37,33 @@ self: super: { }; }; }; + + microhs-wrapper = super.writeShellScriptBin "mhs" '' + export MHSDIR=${self.microhs} + exec "${self.microhs}/lib/bin/mhs" "$@" + ''; + + microhs = + super.stdenv.mkDerivation { + name = "MicroHs"; + src = (import ../nix/source.nix super).microhs; + installPhase = '' + mkdir -p $out/{bin,lib/bin,paths,share,doc,boards,mhs/bin} + cp -v ./bin/mcabal $out/bin + cp -v ./bin/cpphs $out/bin + cp -rv ./lib $out + cp -rv ./generated $out + cp -v ./bin/mhs $out/lib/bin/mhs + cp -rv ./boards $out + cp -rv ./paths $out + cp -rv ./doc $out + cp README.md $out/share + ''; + }; + + microhs-env = super.mkShell { + name = "microhs-env"; + buildInputs = with self; [ microhs microhs-wrapper ]; + }; + } diff --git a/nix/source.nix b/nix/source.nix index a4bea5401..9e4deecce 100644 --- a/nix/source.nix +++ b/nix/source.nix @@ -67,4 +67,12 @@ in rev = "1da7afa"; hash = "sha256-bAfIlnd3PRn9wqGn38R3+6ok1dxRR3Jeb+UUIYJZ7/M="; }; + microhs = fetchFromGitHub { + owner = "augustss"; + repo = "microhs"; + rev = "db0d3d12b0ee814441c6045bd680cc7d92a41375"; + sha256 = "sha256-raTlZBQ5seYo/ez0Cg++nbQSLIKvSLLSqcCSL0svrLE="; + fetchSubmodules = true; + }; + } diff --git a/shell.nix b/shell.nix index 001662af8..a2259ac3c 100644 --- a/shell.nix +++ b/shell.nix @@ -4,4 +4,13 @@ with (import ./default.nix {}); if pkg == "ghcjs" then miso-ghcjs.env -else miso-ghc-9122.env \ No newline at end of file +else miso-ghc-9122.env +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'" + ''; +}) From 649ba526ba2479da046f397c0dcb21c27452a046 Mon Sep 17 00:00:00 2001 From: dmjio Date: Wed, 9 Apr 2025 23:20:10 -0500 Subject: [PATCH 02/24] Add emscripten and nodejs to the shell environment --- nix/overlay.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nix/overlay.nix b/nix/overlay.nix index cd816ccf9..0d983e744 100644 --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -63,7 +63,9 @@ self: super: { microhs-env = super.mkShell { name = "microhs-env"; - buildInputs = with self; [ microhs microhs-wrapper ]; + buildInputs = with self; + [ microhs microhs-wrapper emscripten nodejs + ]; }; } From d7dc24fd98dbfe3bd14dd34498a8516f98bc9a42 Mon Sep 17 00:00:00 2001 From: dmjio Date: Wed, 9 Apr 2025 23:33:17 -0500 Subject: [PATCH 03/24] Include src/ in derivation. - Add src/ because the RTS gets compiled during compilation. - Clean-up bash --- nix/overlay.nix | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/nix/overlay.nix b/nix/overlay.nix index 0d983e744..2b234d49f 100644 --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -48,15 +48,19 @@ self: super: { name = "MicroHs"; src = (import ../nix/source.nix super).microhs; installPhase = '' - mkdir -p $out/{bin,lib/bin,paths,share,doc,boards,mhs/bin} + mkdir -p $out/{bin,share,lib/bin} + cp -v ./bin/mcabal $out/bin cp -v ./bin/cpphs $out/bin cp -rv ./lib $out - cp -rv ./generated $out cp -v ./bin/mhs $out/lib/bin/mhs + + cp -rv ./generated $out cp -rv ./boards $out cp -rv ./paths $out cp -rv ./doc $out + cp -rv ./src $out + cp README.md $out/share ''; }; From e8bb60904d190930d8df267dd0773829b806eba7 Mon Sep 17 00:00:00 2001 From: dmjio Date: Wed, 9 Apr 2025 23:34:18 -0500 Subject: [PATCH 04/24] Add micro/Example.hs Use this for CI testing (for now, until miso builds). --- micro/Example.hs | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 micro/Example.hs diff --git a/micro/Example.hs b/micro/Example.hs new file mode 100644 index 000000000..aec85687a --- /dev/null +++ b/micro/Example.hs @@ -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 From 916cdc8e3cd01a437f9717bf18ea81d9fe41a74d Mon Sep 17 00:00:00 2001 From: dmjio Date: Wed, 9 Apr 2025 23:46:24 -0500 Subject: [PATCH 05/24] Add js target (uses emcc from nix-shell) --- micro/targets.conf | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/micro/targets.conf b/micro/targets.conf index 597f423d1..e07a8e0ce 100644 --- a/micro/targets.conf +++ b/micro/targets.conf @@ -1,3 +1,7 @@ [default] cc = "cc" conf = "unix-64" + +[js] +cc = "emcc" +conf = "unix-32" \ No newline at end of file From e429464609ca47677ad646536eff59aeaf1badab Mon Sep 17 00:00:00 2001 From: dmjio Date: Wed, 9 Apr 2025 23:51:42 -0500 Subject: [PATCH 06/24] Add MicroHs to CI github workflows --- .github/workflows/main.yml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8264d3ad7..9ed03f4fe 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -84,7 +84,19 @@ jobs: - name: (x86) Miso sample app jsaddle (GHC 8.6.5) run: nix-build -A sample-app - - name: (x86) Nix garbage collect +# - name: (JS) Miso sample app (GHCJS 9.12.2) +# run: nix-build -A sample-app-js + +# - name: (x86) Miso sample app jsaddle (GHC 9.12.2) +# run: nix-build -A sample-app + + - 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 -r Example' + + - name: Nix garbage collect run: nix-collect-garbage -d - name: (WASM) Miso examples (GHC 9.12.2) From 6f384c60bd6dacd927bf68ed24132ac8c150b9a1 Mon Sep 17 00:00:00 2001 From: dmjio Date: Thu, 10 Apr 2025 00:08:39 -0500 Subject: [PATCH 07/24] Update targets.conf, add emscripten to buildDeps - Use compiler generated targets from Makefile --- micro/targets.conf | 9 +++++---- nix/overlay.nix | 2 ++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/micro/targets.conf b/micro/targets.conf index e07a8e0ce..82740cc56 100644 --- a/micro/targets.conf +++ b/micro/targets.conf @@ -1,7 +1,8 @@ [default] -cc = "cc" +cc = "gcc" +ccflags = "" conf = "unix-64" -[js] -cc = "emcc" -conf = "unix-32" \ No newline at end of file +[emscripten] +cc = "emcc -sALLOW_MEMORY_GROWTH -sTOTAL_STACK=5MB -sNODERAWFS -sSINGLE_FILE -DUSE_SYSTEM_RAW" +conf = "unix-64" diff --git a/nix/overlay.nix b/nix/overlay.nix index 2b234d49f..2a62bd8b2 100644 --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -47,6 +47,7 @@ self: super: { super.stdenv.mkDerivation { name = "MicroHs"; src = (import ../nix/source.nix super).microhs; + buildInputs = with super; [ emscripten ]; installPhase = '' mkdir -p $out/{bin,share,lib/bin} @@ -60,6 +61,7 @@ self: super: { cp -rv ./paths $out cp -rv ./doc $out cp -rv ./src $out + cat ./targets.conf cp README.md $out/share ''; From 77abc75750be9a2afe6aa2d0b785a25c94d806fa Mon Sep 17 00:00:00 2001 From: "code@dmj.io" Date: Fri, 11 Apr 2025 22:26:04 -0500 Subject: [PATCH 08/24] Add QuickJS to shell environment. We need to ensure we support QuickJS on Darwin/OSX --- nix/overlay.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nix/overlay.nix b/nix/overlay.nix index 2a62bd8b2..94a855dde 100644 --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -70,7 +70,7 @@ self: super: { microhs-env = super.mkShell { name = "microhs-env"; buildInputs = with self; - [ microhs microhs-wrapper emscripten nodejs + [ microhs microhs-wrapper emscripten nodejs quickjs ]; }; From b82cd50bd75009044f619858b374cf77c3ecd74a Mon Sep 17 00:00:00 2001 From: "code@dmj.io" Date: Sat, 12 Apr 2025 11:35:53 -0500 Subject: [PATCH 09/24] Add Darwin fixes for emscripten shell env. https://github.com/NixOS/nixpkgs/issues/139943#issuecomment-930432045 We need to ensure that ~/.emscripten_cache is created, populated and EM_CACHE is set. --- nix/overlay.nix | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/nix/overlay.nix b/nix/overlay.nix index 94a855dde..b7c09f19a 100644 --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -72,6 +72,15 @@ self: super: { buildInputs = with self; [ microhs microhs-wrapper emscripten nodejs quickjs ]; + # https://github.com/NixOS/nixpkgs/issues/139943#issuecomment-930432045 + # dmj: Fix for using emcc in Darwin shell environment + shellHook = with super; + lib.optionalString stdenv.isDarwin '' + mkdir -p ~/.emscripten_cache + chmod u+rwX -R ~/.emscripten_cache + cp -r ${super.emscripten}/share/emscripten/cache ~/.emscripten_cache + export EM_CACHE=~/.emscripten_cache + ''; }; } From a3e2c0b6485d379e9afc1a932e301814e62a5e7b Mon Sep 17 00:00:00 2001 From: dmjio Date: Sat, 12 Apr 2025 13:02:42 -0500 Subject: [PATCH 10/24] Linux has the same problem, drop Darwin only shellHook. --- nix/overlay.nix | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/nix/overlay.nix b/nix/overlay.nix index b7c09f19a..594b7b02a 100644 --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -74,8 +74,7 @@ self: super: { ]; # https://github.com/NixOS/nixpkgs/issues/139943#issuecomment-930432045 # dmj: Fix for using emcc in Darwin shell environment - shellHook = with super; - lib.optionalString stdenv.isDarwin '' + shellHook = with super; '' mkdir -p ~/.emscripten_cache chmod u+rwX -R ~/.emscripten_cache cp -r ${super.emscripten}/share/emscripten/cache ~/.emscripten_cache From fdbd8cd0fb8fcdb76433723ae4ce63da2126569c Mon Sep 17 00:00:00 2001 From: dmjio Date: Mon, 14 Apr 2025 13:51:55 -0500 Subject: [PATCH 11/24] Add note on QuickJS and Emscripten --- nix/overlay.nix | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/nix/overlay.nix b/nix/overlay.nix index 594b7b02a..8531b106b 100644 --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -74,12 +74,15 @@ self: super: { ]; # 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; '' - mkdir -p ~/.emscripten_cache - chmod u+rwX -R ~/.emscripten_cache - cp -r ${super.emscripten}/share/emscripten/cache ~/.emscripten_cache - export EM_CACHE=~/.emscripten_cache - ''; + mkdir -p ~/.emscripten_cache + chmod u+rwX -R ~/.emscripten_cache + cp -r ${super.emscripten}/share/emscripten/cache ~/.emscripten_cache + export EM_CACHE=~/.emscripten_cache + ''; }; } From 57cde3af37936a9e9fead7e37c8ba9fbce7b0335 Mon Sep 17 00:00:00 2001 From: dmjio Date: Mon, 14 Apr 2025 21:48:39 -0500 Subject: [PATCH 12/24] Add a GHC build for MicroHs. --- nix/haskell/packages/ghc/default.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nix/haskell/packages/ghc/default.nix b/nix/haskell/packages/ghc/default.nix index 02b180f88..ea1538582 100644 --- a/nix/haskell/packages/ghc/default.nix +++ b/nix/haskell/packages/ghc/default.nix @@ -26,4 +26,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 {}; } From 87915e1d149d17be39a6d27874b61c4bc38f6161 Mon Sep 17 00:00:00 2001 From: dmjio Date: Mon, 14 Apr 2025 22:36:53 -0500 Subject: [PATCH 13/24] Drop microhs-wrapper, make microhsTargetsConf, add GHC build of MicroHs. - Export CC - Put GHC compiled mhs on $PATH - set $MHSDIR --- micro/targets.conf | 3 ++- nix/overlay.nix | 30 +++++++++++++++++++++--------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/micro/targets.conf b/micro/targets.conf index 82740cc56..c8dd07c9e 100644 --- a/micro/targets.conf +++ b/micro/targets.conf @@ -4,5 +4,6 @@ ccflags = "" conf = "unix-64" [emscripten] -cc = "emcc -sALLOW_MEMORY_GROWTH -sTOTAL_STACK=5MB -sNODERAWFS -sSINGLE_FILE -DUSE_SYSTEM_RAW" +cc = "emcc" +ccflags = "-sALLOW_MEMORY_GROWTH -sTOTAL_STACK=5MB -sNODERAWFS -sSINGLE_FILE -DUSE_SYSTEM_RAW -sENVIRONMENT=web -sWASM=0" conf = "unix-64" diff --git a/nix/overlay.nix b/nix/overlay.nix index 8531b106b..1e6ab2f3c 100644 --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -38,10 +38,21 @@ self: super: { }; }; - microhs-wrapper = super.writeShellScriptBin "mhs" '' - export MHSDIR=${self.microhs} - exec "${self.microhs}/lib/bin/mhs" "$@" - ''; + 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 { @@ -54,14 +65,14 @@ self: super: { cp -v ./bin/mcabal $out/bin cp -v ./bin/cpphs $out/bin cp -rv ./lib $out - cp -v ./bin/mhs $out/lib/bin/mhs + cp -v ${self.haskell.packages.ghc9122.microhs}/bin/mhs $out/bin/mhs cp -rv ./generated $out cp -rv ./boards $out cp -rv ./paths $out cp -rv ./doc $out cp -rv ./src $out - cat ./targets.conf + cat ${self.microhsTargetsConf} > $out/targets.conf cp README.md $out/share ''; @@ -69,15 +80,16 @@ self: super: { microhs-env = super.mkShell { name = "microhs-env"; - buildInputs = with self; - [ microhs microhs-wrapper emscripten nodejs quickjs - ]; + 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 From b44ead3aa381ecbd1c0b43f3894c4f9e56c80c06 Mon Sep 17 00:00:00 2001 From: dmjio Date: Mon, 14 Apr 2025 22:39:48 -0500 Subject: [PATCH 14/24] Drop targets.conf (uses the nix-built one) --- micro/targets.conf | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 micro/targets.conf diff --git a/micro/targets.conf b/micro/targets.conf deleted file mode 100644 index c8dd07c9e..000000000 --- a/micro/targets.conf +++ /dev/null @@ -1,9 +0,0 @@ -[default] -cc = "gcc" -ccflags = "" -conf = "unix-64" - -[emscripten] -cc = "emcc" -ccflags = "-sALLOW_MEMORY_GROWTH -sTOTAL_STACK=5MB -sNODERAWFS -sSINGLE_FILE -DUSE_SYSTEM_RAW -sENVIRONMENT=web -sWASM=0" -conf = "unix-64" From 06fe960bd0866d4b2806d80f0bec7c09c341721e Mon Sep 17 00:00:00 2001 From: dmjio Date: Mon, 14 Apr 2025 22:40:07 -0500 Subject: [PATCH 15/24] Put MicroHs fibonacci example under CI, eval in qjs. --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9ed03f4fe..0d54079ee 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -94,7 +94,7 @@ jobs: 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 -r Example' + run: cd micro/ && nix-shell --run 'mhs -temscripten Example -oout.js && qjs out.js' - name: Nix garbage collect run: nix-collect-garbage -d From f4417484ae49608cfc43fb5eadb6cac9a04c3b22 Mon Sep 17 00:00:00 2001 From: dmjio Date: Mon, 14 Apr 2025 23:18:16 -0500 Subject: [PATCH 16/24] Use bootstrapped mhs in CI. --- nix/overlay.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nix/overlay.nix b/nix/overlay.nix index 1e6ab2f3c..c7d610295 100644 --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -64,8 +64,8 @@ self: super: { cp -v ./bin/mcabal $out/bin cp -v ./bin/cpphs $out/bin + cp -v ./bin/mhs $out/bin cp -rv ./lib $out - cp -v ${self.haskell.packages.ghc9122.microhs}/bin/mhs $out/bin/mhs cp -rv ./generated $out cp -rv ./boards $out From 2a4dbda32be8ede8e70e4b4cbe71462e23bee422 Mon Sep 17 00:00:00 2001 From: dmjio Date: Mon, 14 Apr 2025 23:18:30 -0500 Subject: [PATCH 17/24] Add two sections, one for JS and x86. --- .github/workflows/main.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0d54079ee..e9197f44c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -96,6 +96,9 @@ jobs: - 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 From 4025b0f5f269eeff60e5619646604b9cb6bb1e2d Mon Sep 17 00:00:00 2001 From: dmjio Date: Tue, 15 Apr 2025 14:27:47 -0500 Subject: [PATCH 18/24] Add ghc9101 for microhs dev --- nix/overlay.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nix/overlay.nix b/nix/overlay.nix index c7d610295..72eb2b9ea 100644 --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -35,6 +35,9 @@ 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; + }; }; }; From cad908a9e89bc8842a178dda9a46e7bbfd2da782 Mon Sep 17 00:00:00 2001 From: dmjio Date: Sun, 29 Jun 2025 13:19:41 -0500 Subject: [PATCH 19/24] Bump MicroHs hash --- nix/source.nix | 7 +++---- shell.nix | 3 --- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/nix/source.nix b/nix/source.nix index 9e4deecce..a66de29fa 100644 --- a/nix/source.nix +++ b/nix/source.nix @@ -69,10 +69,9 @@ in }; microhs = fetchFromGitHub { owner = "augustss"; - repo = "microhs"; - rev = "db0d3d12b0ee814441c6045bd680cc7d92a41375"; - sha256 = "sha256-raTlZBQ5seYo/ez0Cg++nbQSLIKvSLLSqcCSL0svrLE="; + repo = "MicroHs"; + rev = "0fc720779cfcae7b7ef1aa001a9859b7247eb211"; + hash = "sha256-cnz0rG3fkwjjIGLtyUCuGYSXYXCDS0T4qbVmGvCjwmg="; fetchSubmodules = true; }; - } diff --git a/shell.nix b/shell.nix index a2259ac3c..ccab57271 100644 --- a/shell.nix +++ b/shell.nix @@ -1,10 +1,7 @@ { pkg ? "ghc" }: - with (import ./default.nix {}); - if pkg == "ghcjs" then miso-ghcjs.env -else miso-ghc-9122.env else if pkg == "micro" then pkgs.microhs-env From 7a0d16672d6ff053f9baaf29dd8a06112c3f4de8 Mon Sep 17 00:00:00 2001 From: dmjio Date: Sun, 29 Jun 2025 17:02:49 -0500 Subject: [PATCH 20/24] Drop extra WASM build in CI --- .github/workflows/main.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e9197f44c..09f3db408 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -90,9 +90,6 @@ jobs: # - name: (x86) Miso sample app jsaddle (GHC 9.12.2) # run: nix-build -A sample-app - - 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' From b3ac8c4577e4e3b669cf69bd2c31fd53f561d972 Mon Sep 17 00:00:00 2001 From: dmjio Date: Mon, 30 Jun 2025 07:13:21 -0500 Subject: [PATCH 21/24] Don't fetch submodules --- nix/source.nix | 1 - 1 file changed, 1 deletion(-) diff --git a/nix/source.nix b/nix/source.nix index a66de29fa..f29ab9c4d 100644 --- a/nix/source.nix +++ b/nix/source.nix @@ -72,6 +72,5 @@ in repo = "MicroHs"; rev = "0fc720779cfcae7b7ef1aa001a9859b7247eb211"; hash = "sha256-cnz0rG3fkwjjIGLtyUCuGYSXYXCDS0T4qbVmGvCjwmg="; - fetchSubmodules = true; }; } From 55da34f267703082b8698b6daea99a90320b3630 Mon Sep 17 00:00:00 2001 From: dmjio Date: Sat, 12 Jul 2025 15:24:59 -0500 Subject: [PATCH 22/24] Add microhs hook --- flake.nix | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/flake.nix b/flake.nix index 038ed6f5b..25d2e7e5d 100644 --- a/flake.nix +++ b/flake.nix @@ -95,6 +95,37 @@ ]; }); + # MicroHS shell + microhs = + pkgs.mkShell { + name = "The micro miso ${system} shell"; + buildInputs = with pkgs; + [ pkgs.microhs nodejs quickjs + # inputs.ghc-wasm-meta.packages.${system}.all_9_12 + ]; + # 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 inputs.ghc-wasm-meta.packages.${system}.all_9_12; + '' + export MHSDIR=${pkgs.microhs} + export CC=${inputs.ghc-wasm-meta.packages.${system}.all_9_12}/bin/emcc + export PATH=$PATH:${pkgs.microhs}/bin + mkdir -p ~/.emscripten_cache + chmod u+rwX -R ~/.emscripten_cache + # cp -r ${emscripten}/share/emscripten/cache ~/.emscripten_cache + export EM_CACHE=~/.emscripten_cache + + function build () { + mhs -temscripten Example -oout.js && qjs out.js + } + + ''; + }; + # WASM shell wasm = pkgs.mkShell { From e13801c6d1ef422fcc3b7a3c0376cab22d6c1c6e Mon Sep 17 00:00:00 2001 From: dmjio Date: Sun, 17 Aug 2025 21:21:23 -0500 Subject: [PATCH 23/24] Update flake --- flake.nix | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/flake.nix b/flake.nix index 2cf24559b..96a130f19 100644 --- a/flake.nix +++ b/flake.nix @@ -91,9 +91,9 @@ pkgs.mkShell { name = "The micro miso ${system} shell"; buildInputs = with pkgs; - [ pkgs.microhs nodejs quickjs - # inputs.ghc-wasm-meta.packages.${system}.all_9_12 + [ pkgs.microhs nodejs quickjs emscripten ]; + # https://github.com/NixOS/nixpkgs/issues/139943#issuecomment-930432045 # dmj: Fix for using emcc in Darwin shell environment # @@ -103,11 +103,11 @@ # with inputs.ghc-wasm-meta.packages.${system}.all_9_12; '' export MHSDIR=${pkgs.microhs} - export CC=${inputs.ghc-wasm-meta.packages.${system}.all_9_12}/bin/emcc + export CC=${pkgs.emscripten}/bin/emcc export PATH=$PATH:${pkgs.microhs}/bin mkdir -p ~/.emscripten_cache chmod u+rwX -R ~/.emscripten_cache - # cp -r ${emscripten}/share/emscripten/cache ~/.emscripten_cache + # cp -r ${pkgs.emscripten}/share/emscripten/cache ~/.emscripten_cache export EM_CACHE=~/.emscripten_cache function build () { @@ -115,6 +115,8 @@ } ''; + }; + # Shell for JavaScript / TypeScript development typescript = pkgs.mkShell { From 5c78d4e9a837b65cd8a4a032d187e84294d4b8b3 Mon Sep 17 00:00:00 2001 From: dmjio Date: Sun, 17 Aug 2025 22:02:32 -0500 Subject: [PATCH 24/24] Update targets --- nix/overlay.nix | 48 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/nix/overlay.nix b/nix/overlay.nix index a8730d980..786511342 100644 --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -21,16 +21,44 @@ self: super: { super.writeTextFile { name = "targets.conf"; text = '' - [default] - cc = "gcc" - ccflags = "" - conf = "unix-64" + [default] + cc = "cc" + ccflags = "-w -Wall -O3" + cclibs = "-lm" + conf = "unix" - [emscripten] - cc = "emcc" - ccflags = "-sALLOW_MEMORY_GROWTH -sTOTAL_STACK=5MB -sSINGLE_FILE -sENVIRONMENT=shell -sWASM=0" - conf = "unix-64" - ''; + [debug] + cc = "cc" + ccflags = "-w -Wall -g" + cclibs = "-lm" + conf = "unix" + + [emscripten] + cc = "emcc" + ccflags = "-O3 -sEXPORTED_RUNTIME_METHODS=stringToNewUTF8 -sALLOW_MEMORY_GROWTH -sTOTAL_STACK=5MB -sNODERAWFS -sSINGLE_FILE -DUSE_SYSTEM_RAW -sEXIT_RUNTIME -Wno-address-of-packed-member -sERROR_ON_UNDEFINED_SYMBOLS=0 -sWASM=0" + cclibs = "-lm" + conf = "unix" + + [tcc] + cc = "tcc" + ccflags = "-D__TCC__=1" + cclibs = "-lm" + conf = "unix" + + [windows] + cc = "cl" + ccflags = "-O2" + cclibs = "" + conf = "windows" + cout = "-Fe" + + [environment] + -- Get all values from the environment + cc = "$CC" + ccflags = "$MHSCCFLAGS" + cclibs = "$MHSCCLIBS" + conf = "$MHSCONF" + ''; }; microhs = @@ -54,6 +82,8 @@ self: super: { cat ${self.microhsTargetsConf} > $out/targets.conf cp README.md $out/share + ls -lah + ls -lah $out/ ''; };