[bug#75778] gnu: Add microhs.

Message ID 20250123073630.11285-1-gay@disroot.org
State New
Headers
Series [bug#75778] gnu: Add microhs. |

Commit Message

Homo Jan. 23, 2025, 7:36 a.m. UTC
  Thanks to cooperative work with Lennart Augustsson, MicroHs is now bootstrappable with Hugs.

Skipping build of CPPHS because it depends on CPPHS, as well as skipping build of MicroCabal because its source lives in <https://github.com/augustss/MicroCabal>, so need to package it separately.

Depends on <https://issues.guix.gnu.org/75745>.

* gnu/packages/patches/microhs-Makefile.patch: New file.
* gnu/local.mk (dist_patch_DATA): Register it.
* gnu/packages/haskell.scm (microhs): New variable.

Change-Id: Iedbec3fef125044a36f7beed0d5db0d7ad123d5d
---
 gnu/local.mk                                |  1 +
 gnu/packages/haskell.scm                    | 42 ++++++++++++
 gnu/packages/patches/microhs-Makefile.patch | 76 +++++++++++++++++++++
 3 files changed, 119 insertions(+)
 create mode 100644 gnu/packages/patches/microhs-Makefile.patch
  

Patch

diff --git a/gnu/local.mk b/gnu/local.mk
index ecea6ae9c7..0a56634eb5 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1824,6 +1824,7 @@  dist_patch_DATA =						\
   %D%/packages/patches/mia-vtk9.patch				\
   %D%/packages/patches/mia-vtk92.patch				\
   %D%/packages/patches/mia-vtk-version.patch			\
+  %D%/packages/patches/microhs-Makefile.patch			\
   %D%/packages/patches/minisat-friend-declaration.patch		\
   %D%/packages/patches/minisat-install.patch			\
   %D%/packages/patches/miniz-for-pytorch.patch			\
diff --git a/gnu/packages/haskell.scm b/gnu/packages/haskell.scm
index 10803f5afe..43774dbc54 100644
--- a/gnu/packages/haskell.scm
+++ b/gnu/packages/haskell.scm
@@ -24,6 +24,7 @@ 
 ;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
 ;;; Copyright © 2021 Simon Tournier <zimon.toutoune@gmail.com>
 ;;; Copyright © 2023 Maxim Cournoyer <maxim.cournoyer@gmail.com>
+;;; Copyright © 2025 Homo <gay@disroot.org>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -54,6 +55,7 @@  (define-module (gnu packages haskell)
   #:use-module (gnu packages gawk)
   #:use-module (gnu packages gcc)
   #:use-module (gnu packages ghostscript)
+  #:use-module (gnu packages hugs)
   #:use-module (gnu packages libffi)
   #:use-module (gnu packages linux)
   #:use-module (gnu packages lisp)
@@ -113,6 +115,46 @@  (define-public cl-yale-haskell
 top of CLISP.")
       (license license:bsd-4))))
 
+(define-public microhs
+  ;; There are no tags, using latest commit from branch "hugs".
+  (let ((commit "c478ae10b84b722dc41b58d016fd28c8f7e97695")
+        (revision "0"))
+    (package
+      (name "microhs")
+      (version (git-version "0.11.2.4" revision commit))
+      (source (origin
+        (method git-fetch)
+        (uri (git-reference
+          (url "https://github.com/augustss/MicroHs")
+          (commit commit)))
+        (file-name (git-file-name name version))
+        (sha256
+          (base32 "09rx5zaygc0f3wx4pjxk58q7cfh9ac06194ha2gbqjdis71llfs4"))
+        (patches (search-patches "microhs-Makefile.patch"))
+        (modules '((guix build utils)))
+        ;; Remove pre-build binaries.
+        (snippet '(delete-file-recursively "generated"))))
+      (build-system gnu-build-system)
+      (arguments
+        (list
+          ;; TODO: CONF=unix-32 if CPU is 32-bit.
+          #:make-flags #~(list "CC=gcc" (string-append "PREFIX=" #$output))
+          ;; Some tests require GHC and CPPHS.
+          #:tests? #f
+          #:phases
+          #~(modify-phases %standard-phases
+            (delete 'configure))))
+      (inputs (list hugs))
+      (native-search-paths
+        (list (search-path-specification
+          (variable "MHSDIR")
+          (files '("lib/mhs")))))
+      (home-page "https://github.com/augustss/MicroHs")
+      (synopsis "A small compiler for Haskell")
+      (description "A compiler for an extended subset of Haskell-2010.
+The compiler translates to combinators and can compile itself.")
+      (license license:asl2.0))))
+
 ;; This package contains lots of generated .hc files containing C code to
 ;; bootstrap the compiler without a Haskell compiler.  The included .hc files
 ;; cover not just the compiler sources but also all Haskell libraries.
diff --git a/gnu/packages/patches/microhs-Makefile.patch b/gnu/packages/patches/microhs-Makefile.patch
new file mode 100644
index 0000000000..1f407a860d
--- /dev/null
+++ b/gnu/packages/patches/microhs-Makefile.patch
@@ -0,0 +1,76 @@ 
+Avoid verbosity in (arguments) in Guile code.
+
+diff --git a/Makefile b/Makefile
+index 2b98363b..86d2260e 100644
+--- a/Makefile
++++ b/Makefile
+@@ -34,7 +34,7 @@ MAINMODULE=src/MicroHs/Main.hs
+ #
+ .PHONY:	clean bootstrap install ghcgen newmhs newmhsz cachelib timecompile exampletest cachetest runtest runtestmhs everytest everytestmhs nfibtest info
+ 
+-all:	bin/mhs bin/cpphs bin/mcabal
++all:	bin/mhs
+ 
+ targets.conf:
+ 	echo [default]           > targets.conf
+@@ -56,11 +56,6 @@ newmhsz:	newmhs
+ sanitizemhs:	ghcgen targets.conf
+ 	$(CCEVAL) -fsanitize=undefined -fsanitize=address -fsanitize=pointer-compare -fsanitize=pointer-subtract generated/mhs.c -o bin/mhssane
+ 
+-# Compile mhs from distribution, with C compiler
+-bin/mhs:	src/runtime/*.c src/runtime/*.h targets.conf #generated/mhs.c
+-	@mkdir -p bin
+-	$(CCEVAL) generated/mhs.c -o bin/mhs
+-
+ # Compile cpphs from distribution, with C compiler
+ bin/cpphs:	src/runtime/*.c src/runtime/config*.h generated/cpphs.c
+ 	@mkdir -p bin
+@@ -108,16 +103,16 @@ mhs.js:	src/*/*.hs src/runtime/*.[ch] targets.conf
+ 	bin/mhs $(MHSINC) -temscripten $(MAINMODULE) -o mhs.js
+ 
+ # Make sure boottrapping works
+-bootstrap:	bin/mhs-stage2
++bin/mhs:	bin/mhs-stage2
+ 	@echo "*** copy stage2 to bin/mhs"
+ 	cp bin/mhs-stage2 bin/mhs
+ 	cp generated/mhs-stage2.c generated/mhs.c 
+ 
+ # Build stage1 compiler with existing compiler
+-bin/mhs-stage1:	bin/mhs src/*/*.hs
++bin/mhs-stage1:	bin/hmhs src/*/*.hs
+ 	@mkdir -p generated
+ 	@echo "*** Build stage1 compiler, using bin/mhs"
+-	bin/mhs -z $(MHSINC) $(MAINMODULE) -ogenerated/mhs-stage1.c
++	bin/hmhs -z $(MHSINC) $(MAINMODULE) -ogenerated/mhs-stage1.c
+ 	$(CCEVAL) generated/mhs-stage1.c -o bin/mhs-stage1
+ 
+ # Build stage2 compiler with stage1 compiler, and compare
+@@ -178,10 +173,9 @@ clean:
+ 	cd tests; make clean
+ 	-cabal clean
+ 
+-oldinstall:
++install:
+ 	mkdir -p $(PREFIX)/bin
+ 	cp bin/mhs $(PREFIX)/bin
+-	-cp bin/cpphs $(PREFIX)/bin
+ 	mkdir -p $(PREFIX)/lib/mhs/src/runtime
+ 	cp -r lib $(PREFIX)/lib/mhs
+ 	cp src/runtime/* $(PREFIX)/lib/mhs/src/runtime
+@@ -253,7 +247,7 @@ $(MCABALMHS)/packages/$(BASE).pkg: bin/mhs lib/*.hs lib/*/*.hs lib/*/*/*.hs
+ 	bin/mhs -Q $(BASE).pkg $(MCABALMHS)
+ 	@rm $(BASE).pkg
+ 
+-install: $(MCABALBIN)/mhs $(MCABALBIN)/cpphs $(MCABALBIN)/mcabal $(MCABALMHS)/packages/$(BASE).pkg
++newinstall: $(MCABALBIN)/mhs $(MCABALBIN)/cpphs $(MCABALBIN)/mcabal $(MCABALMHS)/packages/$(BASE).pkg
+ 	@echo $$PATH | tr ':' '\012' | grep -q $(MCABALBIN) || echo '***' Add $(MCABALBIN) to the PATH
+ 
+ # mkdir ~/.mcabal/packages/array-0.5.6.0
+@@ -277,6 +271,6 @@ generated/hmhs.c:
+ 	@mkdir -p generated
+ 	$(HUGS) $(HUGSINCS) $(MAINMODULE) $(MHSINC) $(MAINMODULE) -ogenerated/hmhs.c
+ 
+-bin/hmhs: generated/hmhs.c
++bin/hmhs: generated/hmhs.c src/runtime/*.c src/runtime/*.h targets.conf
+ 	@mkdir -p bin
+ 	$(CCEVAL) generated/hmhs.c -o bin/hmhs