miso icon indicating copy to clipboard operation
miso copied to clipboard

Add MicroHs support.

Open dmjio opened this issue 10 months ago • 2 comments

We'd like to add support for @augustss's MicroHs project as a first class citizen, to explore its cross-compilation capabilities (w/ emscripten, and other platforms).

This PR fetches MicroHs at master and builds using the recommended Makefile workflow. We make install into /nix/store during the installPhase, along with other tools. This PR introduces 3 derivations to facilitate the process of getting a miso MicroHS build into miso's CI.

  1. The microhs nix package places cpphs, mhs and mcabal inside of $out/bin. We also copy lib, generated, src, boards, docs, into $out (aka /nix/store/).

  2. We now acquire mcabal, mhs and cpphs through the make C bootstrapping install, and have a derivation for mhs built w/ GHC (separately).

  3. We have created a targets.conf file that lives in the /nix/store that mhs now uses to set CC and CC-FLAGS correctly.

  4. microhs-env is a shell environment (cd miso/micro && nix-shell) 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), edit: adds nodejs and emscripten too
  • [x] Ensure MicroHs works on Darwin OSX
  • [x] Ensure emscripten builds C files on Darwin (https://github.com/NixOS/nixpkgs/issues/139943#issuecomment-930432045)
  • [x] Compile and run fibs Example.hs in CI for x86
  • [x] Ensure emscripten JS payloads run in QuickJS
  • [x] Compile and run fibs Example.hs in CI for JS (even w/ -temscripten gcc is still chosen (and targets.conf has both).
  • [ ] Use mcabal install to fetch and build all of miso's dependencies (WIP)
  • [x] Explore adding support for a JS FFI (foreign import javascript& js-sources:) via emscripten (this might require modifications to mhs and mcabal). https://github.com/augustss/MicroHs/issues/217
  • [ ] Add js-sources to mcabal
  • [ ] Add JSVal to MicroHS (https://github.com/dmjio/miso/issues/1100)
  • [ ] Place miso's MicroHS build under CI using both emscripten and native
  • [ ] Consider upstreaming MicroHs into nixpkgs proper (with pkgsCross support) -- using the traditional haskell nixpkgs workflow

For JSFFI support (for browser targets) w/ emscripten research the following

  • https://emscripten.org/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html#calling-javascript-from-c-c

dmjio avatar Apr 10 '25 02:04 dmjio

There is a stack overflow in the latest emscripten

https://github.com/dmjio/miso/actions/runs/15972581883/job/45046966990#step:26:679

dmjio avatar Jul 12 '25 04:07 dmjio

https://github.com/NixOS/nixpkgs/pull/460845

dmjio avatar Nov 12 '25 16:11 dmjio