diff mbox series

[bug#63527,v2,1/3] gnu: Add rumpkernel.

Message ID 8b12244dab33c893860c6247d96a595e0fb9a345.1684244425.git.janneke@gnu.org
State New
Headers show
Series Initial attempt at rumpdisk support for the Hurd. | expand

Commit Message

Janneke Nieuwenhuizen May 16, 2023, 1:48 p.m. UTC
This uses Debian Salsa package management as upstream as that is where
delopment happens.  Once things have stabalized upstream may change to the
NetBSD git from where Debian takes their snapshots.

* gnu/packages/patches/rumpkernel-cross-build.patch: New file.
* gnu/local.mk (dist_patch_DATA): Add it.
* gnu/packages/hurd.scm (rumpkernel): Use it in new variable.
---
 gnu/local.mk                                  |   1 +
 gnu/packages/hurd.scm                         | 208 +++++++++++++++++-
 .../patches/rumpkernel-cross-build.patch      | 153 +++++++++++++
 3 files changed, 361 insertions(+), 1 deletion(-)
 create mode 100644 gnu/packages/patches/rumpkernel-cross-build.patch
diff mbox series

Patch

diff --git a/gnu/local.mk b/gnu/local.mk
index 012ce84d2d..0e394e5c36 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1860,6 +1860,7 @@  dist_patch_DATA =						\
   %D%/packages/patches/rocm-opencl-runtime-4.3-noclinfo.patch 	\
   %D%/packages/patches/rocm-opencl-runtime-4.3-noopencl.patch 	\
   %D%/packages/patches/rottlog-direntry.patch 			\
+  %D%/packages/patches/rumpkernel-cross-build.patch		\
   %D%/packages/patches/ruby-hiredis-use-system-hiredis.patch	\
   %D%/packages/patches/ruby-hydra-minimal-no-byebug.patch	\
   %D%/packages/patches/ruby-anystyle-data-immutable-install.patch	\
diff --git a/gnu/packages/hurd.scm b/gnu/packages/hurd.scm
index 34c7c00f2d..8edf5d91c6 100644
--- a/gnu/packages/hurd.scm
+++ b/gnu/packages/hurd.scm
@@ -3,7 +3,7 @@ 
 ;;; Copyright © 2018, 2020-2023 Ludovic Courtès <ludo@gnu.org>
 ;;; Copyright © 2020 Efraim Flashner <efraim@flashner.co.il>
 ;;; Copyright © 2020 Marius Bakke <mbakke@fastmail.com>
-;;; Copyright © 2020, 2022 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
+;;; Copyright © 2020, 2022, 2023 Janneke Nieuwenhuizen <janneke@gnu.org>
 ;;; Copyright © 2020 Ricardo Wurmus <rekado@elephly.net>
 ;;; Copyright © 2020 Rene Saavedra <pacoon@protonmail.com>
 ;;;
@@ -662,3 +662,209 @@  (define-public netdde
       ;; Some drivers are dually licensed with the options being GPLv2 or one
       ;; of MPL/Expat/BSD-3 (dependent on the driver).
       (license gpl2))))
+
+(define-public rumpkernel
+  (let ((commit "ec2ab9612be4dc48a316a21a0c96d3388478a064")
+        (revision "2"))
+    (package
+      (name "rumpkernel")
+      (version (git-version "0-20211031" revision commit))
+      (source (origin
+                (method git-fetch)
+                (uri (git-reference
+                      (url "https://salsa.debian.org/hurd-team/rumpkernel.git")
+                      (commit commit)))
+                (sha256
+                 (base32
+                  "1ypjg3jyzhh3gnanmk6fh76dwl5ml78n311nbi0hw7f7hygzn7vk"))
+                (file-name (git-file-name name commit))))
+      (build-system gnu-build-system)
+      (arguments
+       (list
+        #:tests? #f
+        #:modules '((srfi srfi-26)
+                    (ice-9 match)
+                    (ice-9 rdelim)
+                    (guix build utils)
+                    (guix build gnu-build-system))
+        #:phases
+        #~(modify-phases %standard-phases
+            (add-after 'unpack 'apply-patches
+              (lambda* (#:key target #:allow-other-keys)
+                (let* ((patch-directory "debian/patches/")
+                       (series (string-append patch-directory "series"))
+                       (text (with-input-from-file series read-string))
+                       (lines (string-split (string-trim-right text) #\newline))
+                       (patches (filter (negate (cute string-prefix? "#" <>))
+                                        lines))
+                       (patch-files (map
+                                     (cute string-append patch-directory <>)
+                                     patches)))
+                  (for-each
+                   (cute invoke "patch" "--force" "-p1" "-i" <>)
+                   patch-files)
+                  ;; Somewhere in the build.sh/make process MIG is not being
+                  ;; exported, apparently.
+                  (when target
+                    (substitute* "pci-userspace/src-gnu/Makefile.inc"
+                      (("MIG=mig")
+                       (string-append "MIG=" target "-mig")))))))
+            (add-before 'configure 'setenv
+              (lambda* (#:key build target #:allow-other-keys)
+                (define (noisy-setenv name value)
+                  (setenv name value)
+                  (format (current-error-port) "set ~a=~s\n" name value))
+                (noisy-setenv "HOST_CC" "gcc")
+                (when target
+                  (noisy-setenv "MIG" (string-append target "-mig")))
+                (let ((target (or target build)))
+                  (noisy-setenv "TARGET_AR" (string-append target "-ar"))
+                  (noisy-setenv "TARGET_CC" (string-append target "-gcc"))
+                  (noisy-setenv "TARGET_CXX" (string-append target "-g++"))
+                  (noisy-setenv "TARGET_LD" (string-append target "-ld"))
+                  (noisy-setenv "TARGET_MIG" (string-append target "-mig"))
+                  (noisy-setenv "TARGET_NM" (string-append target "-nm")))
+                (setenv "PAWD" "pwd")
+                (for-each
+                 (cute noisy-setenv <> "")
+                 '("_GCC_CRTENDS"
+                   "_GCC_CRTEND"
+                   "_GCC_CRTBEGINS"
+                   "_GCC_CRTBEGIN"
+                   "_GCC_CRTI"
+                   "_GCC_CRTN"))
+                (noisy-setenv "BSDOBJDIR=" (string-append (getcwd) "/obj"))))
+            (replace 'configure
+              (lambda args
+                (let ((configure (assoc-ref %standard-phases 'configure)))
+                  (with-directory-excursion "buildrump.sh/src/lib/librumpuser"
+                    (apply configure args)))))
+            (replace 'build
+              (lambda* (#:key parallel-build? #:allow-other-keys)
+                (let* ((jobs (if parallel-build? (parallel-job-count) 1))
+                       (host-cpu (match #$(or (%current-target-system
+                                               (%current-system)))
+                                   ("i586-pc-gnu" "i386")
+                                   ("i686-linux" "i386")
+                                   ("x86_64-linux" "amd64")))
+                       (toprump (string-append
+                                 (getcwd)
+                                 "/buildrump.sh/src/sys/rump"))
+                       (rump-make (string-append
+                                   (getcwd)
+                                   "/buildrump.sh/src/obj/tooldir/bin/nbmake-"
+                                   host-cpu)))
+                  (mkdir "obj")
+                  (with-directory-excursion "buildrump.sh/src"
+                    (invoke
+                     "sh" "build.sh"
+                     "-V" "TOOLS_BUILDRUMP=yes"
+                     "-V" "MKBINUTILS=no" 
+                     "-V" "MKGDB=no" 
+                     "-V" "MKGROFF=no" 
+                     "-V" (string-append "TOPRUMP=" toprump)
+                     "-V" "BUILDRUMP_CPPFLAGS=-Wno-error=stringop-overread"
+                     "-V" "RUMPUSER_EXTERNAL_DPLIBS=pthread" 
+		     "-V" (string-append
+                           "CPPFLAGS="
+                           " -I../../obj/destdir." host-cpu "/usr/include"
+                           " -D_FILE_OFFSET_BITS=64"
+                           " -DRUMP_REGISTER_T=int"
+                           " -DRUMPUSER_CONFIG=yes"
+                           " -DNO_PCI_MSI_MSIX=yes"
+                           " -DNUSB_DMA=1")
+                     "-V" (string-append
+                           "CWARNFLAGS="
+                           " -Wno-error=maybe-uninitialized"
+                           " -Wno-error=address-of-packed-member"
+                           " -Wno-error=unused-variable"
+                           " -Wno-error=stack-protector"
+                           " -Wno-error=array-parameter"
+                           " -Wno-error=array-bounds"
+                           " -Wno-error=stringop-overflow")
+                     "-V" "LIBCRTBEGIN="
+                     "-V" "LIBCRTEND="
+                     "-V" "LIBCRT0="
+                     "-V" "LIBCRTI="
+                     "-V" "_GCC_CRTENDS="
+                     "-V" "_GCC_CRTEND="
+                     "-V" "_GCC_CRTBEGINS="
+                     "-V" "_GCC_CRTBEGIN="
+                     "-V" "_GCC_CRTI="
+                     "-V" "_GCC_CRTN="
+                     "-U"
+                     "-u"
+                     "-T" "./obj/tooldir"
+                     "-m" host-cpu
+                     "-j" (number->string jobs)
+                     "tools"
+                     "rump"))
+                  (with-directory-excursion "buildrump.sh/src/lib/librumpuser"
+                    (setenv "RUMPRUN" "true")
+                    (invoke rump-make "dependall"))
+                  (with-directory-excursion "pci-userspace/src-gnu"
+                    (invoke rump-make "dependall")))))
+            (replace 'install
+              (lambda _
+                (define (install-file file target)
+                  (let ((dest (string-append target (basename file))))
+                    (format (current-output-port) "`~a' -> `~a'~%" file dest)
+                    (mkdir-p (dirname dest))
+                    (if (file-exists? dest)
+                        (format (current-error-port)
+                                "warning: skipping: ~a\n" file)
+                        (let ((stat (lstat file)))
+                          (case (stat:type stat)
+                            ((symlink)
+                             (let ((target (readlink file)))
+                               (symlink target dest)))
+                            (else
+                             (copy-file file dest)))))))
+                (let ((header (string-append #$output "/include/rump"))
+                      (lib (string-append #$output "/lib/")))
+                  (mkdir-p header)
+                  (copy-recursively "buildrump.sh/src/sys/rump/include/rump"
+                                    header)
+                  (mkdir-p lib)
+                  (for-each
+                   (cute install-file <> lib)
+                   (append (find-files "buildrump.sh/src" "librump.*[.](a|so.*)")
+                           (find-files "obj" "librump.*[.](a|so.*)")))))))))
+      (inputs
+       (list gnumach-headers libpciaccess))
+      (native-inputs
+       (list
+        autoconf
+        automake
+        libgcrypt
+        (if (%current-target-system)
+            (let* ((cross-base (resolve-interface '(gnu packages cross-base)))
+                   (cross-mig (module-ref cross-base 'cross-mig)))
+              (cross-mig (%current-target-system)))
+            mig)
+        zlib))
+      (supported-systems %hurd-systems)
+      (home-page "https://wiki.netbsd.org/rumpkernel")
+      (synopsis "NetBSD as rumpkernel for the GNU/Hurd")
+      (description
+       "This package provides NetBSD as rumpkernel for the GNU/Hurd, so that
+the Hurd may be installed on iron.  Using this rumpkernel package, the hurd
+package's rumpdisk can be built which provides the pci.arbiter and rumpdisk
+servers.")
+      (license (list
+                asl2.0
+                boost1.0
+                bsd-2
+                bsd-3
+                bsd-4
+                cddl1.0
+                expat
+                gpl1
+                gpl2+
+                gpl3+
+                isc
+                lgpl2.0+
+                public-domain
+                (@ (guix licenses) zlib)
+                (non-copyleft "file://src/lib/libc/hash/hashhl.c"
+                              "See debian/copyright in the distribution."))))))
diff --git a/gnu/packages/patches/rumpkernel-cross-build.patch b/gnu/packages/patches/rumpkernel-cross-build.patch
new file mode 100644
index 0000000000..a8c7d93e20
--- /dev/null
+++ b/gnu/packages/patches/rumpkernel-cross-build.patch
@@ -0,0 +1,153 @@ 
+This patch fixes cross-building the rumpkernel:
+
+  * Fixes for non-multiarch toolchains,
+  * Support cross-mig,
+  * Cater for non-FHS .../bin/sh.
+
+Upstream status: not presented upstream.
+
+From 3e080e8a43f8b2f7a107849dd2e7e38ee2732d20 Mon Sep 17 00:00:00 2001
+From: Janneke Nieuwenhuizen <janneke@gnu.org>
+Date: Tue, 16 May 2023 07:29:23 +0200
+Subject: [PATCH 1/3] squash! patch: debian/patches/crossbuild
+
+---
+ buildrump.sh/src/build.sh          | 10 ++++++++--
+ pci-userspace/src-gnu/Makefile.inc |  3 ++-
+ 2 files changed, 10 insertions(+), 3 deletions(-)
+
+diff --git a/buildrump.sh/src/build.sh b/buildrump.sh/src/build.sh
+index 60375f5f4..0e80813c1 100755
+--- a/buildrump.sh/src/build.sh
++++ b/buildrump.sh/src/build.sh
+@@ -2230,12 +2230,18 @@ maketoolwrapper ()
+ 	musthave=$1
+ 	tool=$2
+ 
+-	if [ "${tool}" = "CC" ]; then
++	if [ "${tool}" = "AR" ]; then
++		lctool=${TARGET_AR-ar}
++	elif [ "${tool}" = "CC" ]; then
+ 		lctool=${TARGET_CC-gcc}
+ 	elif [ "${tool}" = "CXX" ]; then
+ 		lctool=${TARGET_CXX-g++}
+ 	elif [ "${tool}" = "LD" ]; then
+ 		lctool=${TARGET_LD-ld}
++	elif [ "${tool}" = "MIG" ]; then
++		lctool=${TARGET_MIG-mig}
++	elif [ "${tool}" = "NM" ]; then
++		lctool=${TARGET_NM-nm}
+ 	else
+ 		lctool=$(echo ${tool} | tr '[A-Z]' '[a-z]')
+ 	fi
+@@ -2302,7 +2308,7 @@ makerumptools ()
+ 	for x in CC AR NM OBJCOPY; do
+ 		maketoolwrapper true $x
+ 	done
+-	for x in AS LD OBJDUMP RANLIB READELF SIZE STRINGS STRIP CXX; do
++	for x in AS LD OBJDUMP RANLIB READELF SIZE STRINGS STRIP CXX MIG; do
+ 		maketoolwrapper false $x
+ 	done
+ 
+diff --git a/pci-userspace/src-gnu/Makefile.inc b/pci-userspace/src-gnu/Makefile.inc
+index 6f8db357e..ef25bac3a 100644
+--- a/pci-userspace/src-gnu/Makefile.inc
++++ b/pci-userspace/src-gnu/Makefile.inc
+@@ -8,11 +8,12 @@ RUMPCOMP_USER_CPPFLAGS+=-I${PCIDIR} -I${DESTDIR}/usr/include
+ RUMPCOMP_CPPFLAGS+=	-I${PCIDIR} -I${DESTDIR}/usr/include
+ CPPFLAGS+=		-I${PCIDIR}
+ LDFLAGS+= -lmachuser -Wl,--no-as-needed -lpciaccess -Wl,--as-needed
++MIG=mig
+ 
+ mach_debugUser.c:
+ 	echo '#include <mach_debug/mach_debug.defs>' \
+ 		| ${CC} -E -x c - -o - \
+-		| mig -cc cat - /dev/null -subrprefix __ \
++		| $(MIG) -cc cat - /dev/null -subrprefix __ \
+ 			-user mach_debugUser.c \
+ 			-server /dev/null \
+ 			-header mach_debug_U.h
+-- 
+2.39.2
+
+From af67549b7c5da5970a9330d281bd8305e1f6e8ed Mon Sep 17 00:00:00 2001
+From: Janneke Nieuwenhuizen <janneke@gnu.org>
+Date: Tue, 16 May 2023 07:39:54 +0200
+Subject: [PATCH 2/3] crossbuild: Cater for non-FHS shell.
+
+---
+ buildrump.sh/src/tools/genassym/Makefile | 2 +-
+ buildrump.sh/src/tools/lorder/Makefile   | 2 +-
+ 2 files changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/buildrump.sh/src/tools/genassym/Makefile b/buildrump.sh/src/tools/genassym/Makefile
+index e597c522b..96ca4ac21 100644
+--- a/buildrump.sh/src/tools/genassym/Makefile
++++ b/buildrump.sh/src/tools/genassym/Makefile
+@@ -17,7 +17,7 @@ ${TIMESTAMP}: genassym
+ 	${HOST_INSTALL_FILE} -m ${BINMODE} ${.ALLSRC} ${.TARGET}
+ 
+ genassym: genassym.sh
+-	${TOOL_SED} -e "s,/bin/sh,${HOST_BSHELL},g" \
++	${TOOL_SED} -e "s,\([ \!]\)/bin/sh,\1${HOST_BSHELL},g" \
+ 	    -e "s,{AWK:=.*},{AWK:="${TOOL_AWK:Q}"}," \
+ 		< ${.ALLSRC} > ${.TARGET}
+ 
+diff --git a/buildrump.sh/src/tools/lorder/Makefile b/buildrump.sh/src/tools/lorder/Makefile
+index f3c599e12..92af83d51 100644
+--- a/buildrump.sh/src/tools/lorder/Makefile
++++ b/buildrump.sh/src/tools/lorder/Makefile
+@@ -17,7 +17,7 @@ ${TIMESTAMP}: lorder
+ 	${HOST_INSTALL_FILE} -m ${BINMODE} ${.ALLSRC} ${.TARGET}
+ 
+ lorder: lorder.sh
+-	${TOOL_SED} -e "s,/bin/sh,"${HOST_BSHELL:Q}",g" \
++	${TOOL_SED} -e "s,\([ \!]\)/bin/sh,\1"${HOST_BSHELL:Q}",g" \
+ 	    -e "s,{JOIN:=.*},{JOIN:="${TOOL_JOIN:Q}"}," \
+ 	    -e "s,{MKTEMP:=.*},{MKTEMP:="${TOOL_MKTEMP:Q}"}," \
+ 	    -e "s,{NM:=.*},{NM:="${NM:Q}"}," \
+-- 
+2.39.2
+
+From 9c8c93485e688bcc3db129bb56da03b18daae52c Mon Sep 17 00:00:00 2001
+From: Janneke Nieuwenhuizen <janneke@gnu.org>
+Date: Tue, 16 May 2023 08:55:51 +0200
+Subject: [PATCH 3/3] squash! pci-userspace: Add acpi lookup of irqs with
+ fallback
+
+---
+ debian/patches/acpi.diff | 5 +++--
+ 1 file changed, 3 insertions(+), 2 deletions(-)
+
+diff --git a/debian/patches/acpi.diff b/debian/patches/acpi.diff
+index 8015a6e63..8e359b2c0 100644
+--- a/debian/patches/acpi.diff
++++ b/debian/patches/acpi.diff
+@@ -1,6 +1,6 @@
+ --- a/pci-userspace/src-gnu/Makefile.inc
+ +++ b/pci-userspace/src-gnu/Makefile.inc
+-@@ -3,7 +3,7 @@
++@@ -3,8 +3,8 @@
+  PCIDIR:=	${.PARSEDIR}
+  .PATH:		${PCIDIR}
+ 
+@@ -9,6 +9,7 @@
+  RUMPCOMP_USER_CPPFLAGS+=-I${PCIDIR} -I${DESTDIR}/usr/include
+  RUMPCOMP_CPPFLAGS+=	-I${PCIDIR} -I${DESTDIR}/usr/include
+  CPPFLAGS+=		-I${PCIDIR}
++ MIG=mig
+ @@ -16,3 +16,11 @@
+  			-user mach_debugUser.c \
+  			-server /dev/null \
+@@ -17,7 +18,7 @@
+ +acpiUser.c:
+ +	echo '#include <hurd/acpi.defs>' \
+ +		| ${CC} -E -x c - -o - \
+-+		| mig -cc cat - /dev/null -subrprefix __ \
+++		| $(MIG) -cc cat - /dev/null -subrprefix __ \
+ +			-user acpiUser.c \
+ +			-server /dev/null \
+ +			-header acpi_U.h
+-- 
+2.39.2
+