all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Simon South <simon@simonsouth.net>
To: 51241@debbugs.gnu.org
Cc: ludo@gnu.org
Subject: [bug#51241] [PATCH 1/1] gnu: ragel: Fix build of knot on aarch64-linux.
Date: Wed, 29 Dec 2021 12:46:07 -0500	[thread overview]
Message-ID: <8d836816bdc6015fce6a8d4dba10cac38157364b.1640799363.git.simon@simonsouth.net> (raw)
In-Reply-To: <cover.1640799363.git.simon@simonsouth.net>

Apply a patch backported from Ragel's "ragel-6" branch that allows it to
reliably generate usable code on aarch64-linux where the C/C++ "char" type is
unsigned by default, fixing the build of Knot on this platform.

* gnu/packages/patches/ragel-char-signedness.patch: New file.
* gnu/local.mk (dist_patch_DATA): Add it.
* gnu/packages/ragel.scm (ragel)[arguments]: Add custom phase for AArch64 that
applies the patch.
[native-inputs]: Add "patch" and patch file on AArch64.
---
 gnu/local.mk                                  |  1 +
 .../patches/ragel-char-signedness.patch       | 42 +++++++++++++++++++
 gnu/packages/ragel.scm                        | 29 ++++++++++++-
 3 files changed, 71 insertions(+), 1 deletion(-)
 create mode 100644 gnu/packages/patches/ragel-char-signedness.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index 21e536a635..ebc5426e81 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1726,6 +1726,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/qtwebkit-fix-building-with-python-3.9.patch	\
   %D%/packages/patches/qtwebkit-fix-building-with-icu-68.patch	\
   %D%/packages/patches/qtwebkit-fix-building-with-glib-2.68.patch	\
+  %D%/packages/patches/ragel-char-signedness.patch		\
   %D%/packages/patches/randomjungle-disable-static-build.patch	\
   %D%/packages/patches/range-v3-build-with-gcc10.patch	\
   %D%/packages/patches/rapicorn-isnan.patch			\
diff --git a/gnu/packages/patches/ragel-char-signedness.patch b/gnu/packages/patches/ragel-char-signedness.patch
new file mode 100644
index 0000000000..b3b2bf958a
--- /dev/null
+++ b/gnu/packages/patches/ragel-char-signedness.patch
@@ -0,0 +1,42 @@
+From 2e638fccd81e96ce09841adc4b295b5ce694ea73 Mon Sep 17 00:00:00 2001
+From: Adrian Thurston <thurston@colm.net>
+Date: Sat, 6 Nov 2021 12:20:05 -0700
+Subject: [PATCH] C char type: decide signedness of char based on CHAR_MIN
+
+Previously had char fixed to signed char, this is not useful on ARM as it does
+not align with the host type. Instead, decide at runtime (or probably compile
+time) if char is signed or not.
+---
+ ragel/common.cpp | 16 ++++++++--------
+ 1 file changed, 8 insertions(+), 8 deletions(-)
+
+diff --git a/ragel/common.cpp b/ragel/common.cpp
+index 8e9f8ed0..55875c06 100644
+--- a/ragel/common.cpp
++++ b/ragel/common.cpp
+@@ -27,14 +27,14 @@
+ 
+ HostType hostTypesC[] =
+ {
+-	{ "char",     0,       "char",    true,   true,  false,  CHAR_MIN,  CHAR_MAX,   0, 0,              sizeof(char) },
+-	{ "unsigned", "char",  "uchar",   false,  true,  false,  0, 0,                  0,     UCHAR_MAX,  sizeof(unsigned char) },
+-	{ "short",    0,       "short",   true,   true,  false,  SHRT_MIN,  SHRT_MAX,   0, 0,              sizeof(short) },
+-	{ "unsigned", "short", "ushort",  false,  true,  false,  0, 0,                  0,     USHRT_MAX,  sizeof(unsigned short) },
+-	{ "int",      0,       "int",     true,   true,  false,  INT_MIN,   INT_MAX,    0, 0,              sizeof(int) },
+-	{ "unsigned", "int",   "uint",    false,  true,  false,  0, 0,                  0,     UINT_MAX,   sizeof(unsigned int) },
+-	{ "long",     0,       "long",    true,   true,  false,  LONG_MIN,  LONG_MAX,   0, 0,              sizeof(long) },
+-	{ "unsigned", "long",  "ulong",   false,  true,  false,  0, 0,                  0,     ULONG_MAX,  sizeof(unsigned long) }
++	{ "char",     0,       "char",    (CHAR_MIN != 0), true,  false,  SCHAR_MIN, SCHAR_MAX,  0, UCHAR_MAX, sizeof(char) },
++	{ "unsigned", "char",  "uchar",   false,           true,  false,  0, 0,                  0, UCHAR_MAX, sizeof(unsigned char) },
++	{ "short",    0,       "short",   true,            true,  false,  SHRT_MIN,  SHRT_MAX,   0, 0,         sizeof(short) },
++	{ "unsigned", "short", "ushort",  false,           true,  false,  0, 0,                  0, USHRT_MAX, sizeof(unsigned short) },
++	{ "int",      0,       "int",     true,            true,  false,  INT_MIN,   INT_MAX,    0, 0,         sizeof(int) },
++	{ "unsigned", "int",   "uint",    false,           true,  false,  0, 0,                  0, UINT_MAX,  sizeof(unsigned int) },
++	{ "long",     0,       "long",    true,            true,  false,  LONG_MIN,  LONG_MAX,   0, 0,         sizeof(long) },
++	{ "unsigned", "long",  "ulong",   false,           true,  false,  0, 0,                  0, ULONG_MAX, sizeof(unsigned long) }
+ };
+ 
+ #define S8BIT_MIN  -128
+-- 
+2.33.1
+
diff --git a/gnu/packages/ragel.scm b/gnu/packages/ragel.scm
index 1d9b67a6e0..d4016ed5ba 100644
--- a/gnu/packages/ragel.scm
+++ b/gnu/packages/ragel.scm
@@ -1,6 +1,7 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2015 Ricardo Wurmus <rekado@elephly.net>
 ;;; Copyright © 2019 Tobias Geerinckx-Rice <me@tobias.gr>
+;;; Copyright © 2021 Simon South <simon@simonsouth.net>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -22,7 +23,9 @@ (define-module (gnu packages ragel)
   #:use-module (guix packages)
   #:use-module (guix download)
   #:use-module (guix build-system gnu)
-  #:use-module (gnu packages))
+  #:use-module (guix utils)
+  #:use-module (gnu packages)
+  #:use-module (gnu packages base))
 
 (define-public ragel
   (package
@@ -36,6 +39,30 @@ (define-public ragel
                (base32
                 "0gvcsl62gh6sg73nwaxav4a5ja23zcnyxncdcdnqa2yjcpdnw5az"))))
     (build-system gnu-build-system)
+    (arguments
+     (if (target-aarch64?)
+         '(#:phases
+           (modify-phases %standard-phases
+             (add-after 'unpack 'apply-char-signedness-fix
+               ;; Apply a backported fix for aarch64-linux, where the C/C++
+               ;; "char" type is unsigned by default.
+               ;;
+               ;; The patch is applied in this custom phase and not via the
+               ;; "origin" object above to avoid rebuilding a large number of
+               ;; packages on other platforms.
+               (lambda _
+                 (let ((patch
+                        (search-input-file %build-inputs "/bin/patch"))
+                       (char-signedness-patch
+                        (assoc-ref %build-inputs "char-signedness-patch")))
+                   (invoke patch "-p1" "-i" char-signedness-patch))))))
+         '()))
+    (native-inputs
+     (if (target-aarch64?)
+         `(("char-signedness-patch"
+            ,(search-patch "ragel-char-signedness.patch"))
+           ("patch" ,patch))
+         '()))
     (home-page "https://www.colm.net/open-source/ragel/")
     (synopsis "State machine compiler")
     (description
-- 
2.34.0





  reply	other threads:[~2021-12-29 17:47 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-16 17:04 [bug#51241] [PATCH 0/1] gnu: ragel: Fix build of knot on aarch64-linux Simon South
2021-10-16 17:06 ` [bug#51241] [PATCH 1/1] " Simon South
2021-10-16 17:42 ` [bug#51241] [PATCH 0/1] " Tobias Geerinckx-Rice via Guix-patches via
2021-10-16 20:09   ` Simon South
2021-10-16 21:37     ` Tobias Geerinckx-Rice via Guix-patches via
2021-11-12 20:44 ` [bug#51241] [PATCH v2 " Simon South
2021-11-12 20:44   ` [bug#51241] [PATCH v2 1/1] " Simon South
2021-12-19 22:30     ` [bug#51241] [PATCH 0/1] " Ludovic Courtès
2021-12-20 22:57       ` Simon South
2021-12-21  9:12         ` Ludovic Courtès
2021-12-29 17:46           ` Simon South
2021-12-29 17:46             ` Simon South [this message]
2021-12-31 17:29               ` bug#51241: [PATCH 1/1] " Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8d836816bdc6015fce6a8d4dba10cac38157364b.1640799363.git.simon@simonsouth.net \
    --to=simon@simonsouth.net \
    --cc=51241@debbugs.gnu.org \
    --cc=ludo@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.