Subject: [bug#75778] [PATCH] gnu: Add microhs.

From: Lars-Dominik Braun <[email-masked]>
Date: Sun, 26 Jan 2025 08:07:52 +0100

Hi,

> Need help to change CONF=unix-64 to CONF=unix-32 on all 32-bit 
> architectures, MicroHs should work on every architecture without any 
> other modifications, provided Hugs itself is available for bootstrap.

the attached patch should work and also enables tests.

Lars

>From 30612fd4a49d73a9c9747b68d98ce94c1993ee08 Mon Sep 17 00:00:00 2001
Message-ID: <[email-masked]>
From: Homo <[email-masked]>
Date: Thu, 23 Jan 2025 09:36:26 +0200
Subject: [PATCH] gnu: Add microhs.

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.

* 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
Signed-off-by: Lars-Dominik Braun <[email-masked]>
---
 gnu/local.mk                                |  1 +
 gnu/packages/haskell.scm                    | 43 ++++++++++++
 gnu/packages/patches/microhs-Makefile.patch | 76 +++++++++++++++++++++
 3 files changed, 120 insertions(+)
 create mode 100644 gnu/packages/patches/microhs-Makefile.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index 5091f93eb8..9a44bdfc02 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1835,6 +1835,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..05d2de878a 100644
--- a/gnu/packages/haskell.scm
+++ b/gnu/packages/haskell.scm
@@ -24,6 +24,7 @@
 ;;; Copyright © 2021 Xinglu Chen <[email-masked]>
 ;;; Copyright © 2021 Simon Tournier <[email-masked]>
 ;;; Copyright © 2023 Maxim Cournoyer <[email-masked]>
+;;; Copyright © 2025 Homo <[email-masked]>
 ;;;
 ;;; 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,47 @@ (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
+          #:make-flags #~(list "CC=gcc"
+                               (string-append "PREFIX=" #$output)
+                               (string-append "CONF=unix-"
+                                 #$(if (target-64bit?) "64" "32")))
+          #:test-target "runtestmhs"
+          #: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

base-commit: b226a1007a9111adacb05984b8d74def24257dce
-- 
2.45.3