Subject: Re: [RFC PATCH v2] gnu: racket: Backport fix for powerpc64le.

From: Thiago Jung Bauermann <[email-masked]>
Date: Thu, 18 Aug 2022 21:51:31 -0300

Hello Philip,

Philip McGrath <[email-masked]> writes:

> Hi Thiago,
>
>> > Nice! thanks for the quick fix. I tested guix-issue-57050-v2 and now
>> > chez-scheme-for-racket-bootstrap-bootfiles builds successfully!  >
>> > Unfortunately there's still a holdup: the install phase of
>> > racket-vm-cs-8.6 > fails:
>> >
>> > [...]
>> >
>> > Apparently some part of the racket-vm-cs build system thinks that it's
>> > cross-compiling when it's not. I'm still trying to figure out where this >
>> > “--cross-compiler” argument is being added but thought I'd provide an
>> > early > report.  >
>>
>> Thanks for trying this! I think I've found what's going wrong in the
>> 'configure' script is going wrong, but I'm not sure yet what's the right way
>> to fix it.
>>
>
> Matthew Flatt fixed our use-case in 'configure' upstream, and I've
> cherry-picked it for Guix in the patch below. Can you try this instead?

Great!

> I've updated the 'zuo' branch at https://gitlab.com/philip1/guix-patches to
> point to this (commit ddc94a778b196e9425f0057cbd21404e7ecf6605) and tagged it
> as guix-issue-57050-v2-rfc2; I also tagged the previous attempt as
> guix-issue-57050-v2-rfc1.

I tried it but ran into two problems:

1. For some reason I didn't understand, the problem I first reported
about rktboot/main.rkt failing during the build of
chez-scheme-for-racket-bootstrap-bootfiles came back. I had to increase
STACK_SAFETY_MARGIN again. I simply increased it 10x to make sure it
would work. If you want I can experiment with different values to find
an appropriate one.

2. I could be wrong, but I don't think Guix supports having more than
one patch per file. After I moved the new patch to its own file, the
racket packet was built!

> I will send a clean v3 of this series once this and other remaining questions
> are resolved.

Nice. Below are the changes are made on top of guix-issue-57050-v2-rfc2.

-- 
Thanks
Thiago

Fix cross-install patches and increase STACK_SAFETY_MARGIN.
Also, add the patches to gnu/local.mk.
---
 gnu/local.mk                                  |  2 +
 .../racket-backport-8.6-cross-install-2.patch | 92 ++++++++++++++++++
 .../racket-backport-8.6-cross-install.patch   | 93 -------------------
 gnu/packages/racket.scm                       |  3 +-
 4 files changed, 96 insertions(+), 94 deletions(-)
 create mode 100644 gnu/packages/patches/racket-backport-8.6-cross-install-2.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index 4a873803506a..412968ef3066 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1774,6 +1774,8 @@ dist_patch_DATA =						\
   %D%/packages/patches/ripperx-missing-file.patch		\
   %D%/packages/patches/rpcbind-CVE-2017-8779.patch		\
   %D%/packages/patches/rtags-separate-rct.patch			\
+  %D%/packages/patches/racket-backport-8.6-cross-install.patch	\
+  %D%/packages/patches/racket-backport-8.6-cross-install-2.patch	\
   %D%/packages/patches/racket-backport-8.6-zuo.patch		\
   %D%/packages/patches/racket-chez-scheme-bin-sh.patch		\
   %D%/packages/patches/racket-rktio-bin-sh.patch		\
diff --git a/gnu/packages/patches/racket-backport-8.6-cross-install-2.patch b/gnu/packages/patches/racket-backport-8.6-cross-install-2.patch
new file mode 100644
index 000000000000..f3317e39b10c
--- /dev/null
+++ b/gnu/packages/patches/racket-backport-8.6-cross-install-2.patch
@@ -0,0 +1,92 @@
+From 85802f4d515e310e657928707800ad709a676e2a Mon Sep 17 00:00:00 2001
+From: Matthew Flatt <[email-masked]>
+Date: Mon, 15 Aug 2022 10:37:01 +0800
+Subject: [PATCH 2/2] configure: adjust cross-build assumption for a pb build
+
+Don't assume a cross build for a pb target on a platform that's only
+supported via pb.
+
+(cherry picked from commit 70e484e885637c495be5481983dae2207fdd67bb)
+
+(Edited to remove unrelated tweak to comments in
+"racket/src/expander/expand/require+provide.rkt".)
+---
+ racket/src/cs/c/configure    | 15 +++++++++++----
+ racket/src/cs/c/configure.ac | 15 +++++++++++----
+ 2 files changed, 22 insertions(+), 8 deletions(-)
+
+diff --git a/racket/src/cs/c/configure b/racket/src/cs/c/configure
+index 454d79e11a..7e0fa5600d 100755
+--- a/racket/src/cs/c/configure
++++ b/racket/src/cs/c/configure
+@@ -4679,6 +4679,11 @@ case "$MACH_HOST_CPU" in
+     ;;
+ esac
+ 
++if test "${MACH}" = "" ; then
++  default_mach_was_empty=yes
++else
++  default_mach_was_empty=no
++fi
+ 
+ if test "${enable_mach}" != "" ; then
+   MACH="${enable_mach}"
+@@ -4701,13 +4706,15 @@ elif test "$MACH" = "" -o "$MACH_OS" = "" ; then
+    exit 1
+ fi
+ 
+-# For a pb build where Racket is supplied, force cross-build
+-# mode on the assumption that the host is not a pb build
+-# (because it should be created with default configure options)
++# For a pb build where Racket is supplied and MACH was not originally
++# empty, force cross-build mode on the assumption that the host is not
++# a pb build (because it should be created with default configure options)
+ if test "${enable_pb}" = "yes" ; then
+   if test "${enable_racket}" != "" ; then
+     if test "${enable_target}" = "" ; then
+-      enable_target="${MACH}"
++      if test "${default_mach_was_empty}" = "no" ; then
++        enable_target="${MACH}"
++      fi
+     fi
+   fi
+ fi
+diff --git a/racket/src/cs/c/configure.ac b/racket/src/cs/c/configure.ac
+index 5bce979c92..734c1e8feb 100644
+--- a/racket/src/cs/c/configure.ac
++++ b/racket/src/cs/c/configure.ac
+@@ -415,6 +415,11 @@ case "$MACH_HOST_CPU" in
+     ;;
+ esac
+ 
++if test "${MACH}" = "" ; then
++  default_mach_was_empty=yes
++else
++  default_mach_was_empty=no
++fi
+ 
+ if test "${enable_mach}" != "" ; then
+   MACH="${enable_mach}"
+@@ -437,13 +442,15 @@ elif test "$MACH" = "" -o "$MACH_OS" = "" ; then
+    exit 1
+ fi
+ 
+-# For a pb build where Racket is supplied, force cross-build
+-# mode on the assumption that the host is not a pb build
+-# (because it should be created with default configure options)
++# For a pb build where Racket is supplied and MACH was not originally
++# empty, force cross-build mode on the assumption that the host is not
++# a pb build (because it should be created with default configure options)
+ if test "${enable_pb}" = "yes" ; then
+   if test "${enable_racket}" != "" ; then
+     if test "${enable_target}" = "" ; then
+-      enable_target="${MACH}"
++      if test "${default_mach_was_empty}" = "no" ; then
++        enable_target="${MACH}"
++      fi
+     fi
+   fi
+ fi
+-- 
+2.32.0
+
diff --git a/gnu/packages/patches/racket-backport-8.6-cross-install.patch b/gnu/packages/patches/racket-backport-8.6-cross-install.patch
index 2c4d8924ed5b..81cd4d2b225f 100644
--- a/gnu/packages/patches/racket-backport-8.6-cross-install.patch
+++ b/gnu/packages/patches/racket-backport-8.6-cross-install.patch
@@ -31,96 +31,3 @@ index 8d3950bb27..d8b74c509d 100644
 -- 
 2.32.0
 
-
-From 85802f4d515e310e657928707800ad709a676e2a Mon Sep 17 00:00:00 2001
-From: Matthew Flatt <[email-masked]>
-Date: Mon, 15 Aug 2022 10:37:01 +0800
-Subject: [PATCH 2/2] configure: adjust cross-build assumption for a pb build
-
-Don't assume a cross build for a pb target on a platform that's only
-supported via pb.
-
-(cherry picked from commit 70e484e885637c495be5481983dae2207fdd67bb)
-
-(Edited to remove unrelated tweak to comments in
-"racket/src/expander/expand/require+provide.rkt".)
----
- racket/src/cs/c/configure    | 15 +++++++++++----
- racket/src/cs/c/configure.ac | 15 +++++++++++----
- 2 files changed, 22 insertions(+), 8 deletions(-)
-
-diff --git a/racket/src/cs/c/configure b/racket/src/cs/c/configure
-index 454d79e11a..7e0fa5600d 100755
---- a/racket/src/cs/c/configure
-+++ b/racket/src/cs/c/configure
-@@ -4679,6 +4679,11 @@ case "$MACH_HOST_CPU" in
-     ;;
- esac
- 
-+if test "${MACH}" = "" ; then
-+  default_mach_was_empty=yes
-+else
-+  default_mach_was_empty=no
-+fi
- 
- if test "${enable_mach}" != "" ; then
-   MACH="${enable_mach}"
-@@ -4701,13 +4706,15 @@ elif test "$MACH" = "" -o "$MACH_OS" = "" ; then
-    exit 1
- fi
- 
--# For a pb build where Racket is supplied, force cross-build
--# mode on the assumption that the host is not a pb build
--# (because it should be created with default configure options)
-+# For a pb build where Racket is supplied and MACH was not originally
-+# empty, force cross-build mode on the assumption that the host is not
-+# a pb build (because it should be created with default configure options)
- if test "${enable_pb}" = "yes" ; then
-   if test "${enable_racket}" != "" ; then
-     if test "${enable_target}" = "" ; then
--      enable_target="${MACH}"
-+      if test "${default_mach_was_empty}" = "no" ; then
-+        enable_target="${MACH}"
-+      fi
-     fi
-   fi
- fi
-diff --git a/racket/src/cs/c/configure.ac b/racket/src/cs/c/configure.ac
-index 5bce979c92..734c1e8feb 100644
---- a/racket/src/cs/c/configure.ac
-+++ b/racket/src/cs/c/configure.ac
-@@ -415,6 +415,11 @@ case "$MACH_HOST_CPU" in
-     ;;
- esac
- 
-+if test "${MACH}" = "" ; then
-+  default_mach_was_empty=yes
-+else
-+  default_mach_was_empty=no
-+fi
- 
- if test "${enable_mach}" != "" ; then
-   MACH="${enable_mach}"
-@@ -437,13 +442,15 @@ elif test "$MACH" = "" -o "$MACH_OS" = "" ; then
-    exit 1
- fi
- 
--# For a pb build where Racket is supplied, force cross-build
--# mode on the assumption that the host is not a pb build
--# (because it should be created with default configure options)
-+# For a pb build where Racket is supplied and MACH was not originally
-+# empty, force cross-build mode on the assumption that the host is not
-+# a pb build (because it should be created with default configure options)
- if test "${enable_pb}" = "yes" ; then
-   if test "${enable_racket}" != "" ; then
-     if test "${enable_target}" = "" ; then
--      enable_target="${MACH}"
-+      if test "${default_mach_was_empty}" = "no" ; then
-+        enable_target="${MACH}"
-+      fi
-     fi
-   fi
- fi
--- 
-2.32.0
-
diff --git a/gnu/packages/racket.scm b/gnu/packages/racket.scm
index b1de6cf88519..a38aeb08b503 100644
--- a/gnu/packages/racket.scm
+++ b/gnu/packages/racket.scm
@@ -206,6 +206,7 @@ (define %racket-origin
      (base32 "1yi36nr7zrdwrnvpmliirxxjz4pyfyhkar6yvk3rapvmg4q2vmnk"))
     (file-name (git-file-name "racket" %racket-version))
     (patches (search-patches "racket-backport-8.6-cross-install.patch"
+                             "racket-backport-8.6-cross-install-2.patch"
                              "racket-backport-8.6-docindex-write.patch"
                              "racket-backport-8.6-hurd.patch"
                              "racket-backport-8.6-zuo.patch"
@@ -429,7 +430,7 @@ (define-public racket-vm-bc
                        (lambda (flag)
                          (if (string-prefix? "CPPFLAGS=" flag)
                              (string-append flag
-                                            " -DSTACK_SAFETY_MARGIN=200000")
+                                            " -DSTACK_SAFETY_MARGIN=2000000")
                              flag))
                        #$(racket-vm-common-configure-flags)))
                    (else