diff mbox series

[bug#46725] gnu: guile-lib: Fix cross compilation.

Message ID 20210224083709.9342-1-mail@cbaines.net
State Accepted
Headers show
Series [bug#46725] gnu: guile-lib: Fix cross compilation. | expand

Checks

Context Check Description
cbaines/submitting builds success
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/issue success View issue

Commit Message

Christopher Baines Feb. 24, 2021, 8:37 a.m. UTC
These changes were sent upstream as
https://lists.gnu.org/archive/html/guile-devel/2021-02/msg00004.html

Without this change, the .go files are built for the host architecture, rather
than the target. I noticed this when cross building the
guix-build-coordinator (for which guile-lib is an input) to the Hurd.

* gnu/packages/guile-xyz.scm (guile-lib)[arguments]: Add
'patch-for-cross-compilation phase.
[native-inputs]: Add autoconf, automake and gettext.
(guile2.0-lib): Adjust to use alist-replace.
(guile2.2-lib): Adjust to use alist-replace.
---
 gnu/packages/guile-xyz.scm | 37 ++++++++++++++++++++++++++++++++-----
 1 file changed, 32 insertions(+), 5 deletions(-)

Comments

Ludovic Courtès March 2, 2021, 7:20 p.m. UTC | #1
Hi!

Christopher Baines <mail@cbaines.net> skribis:

> These changes were sent upstream as
> https://lists.gnu.org/archive/html/guile-devel/2021-02/msg00004.html
>
> Without this change, the .go files are built for the host architecture, rather
> than the target. I noticed this when cross building the
> guix-build-coordinator (for which guile-lib is an input) to the Hurd.
>
> * gnu/packages/guile-xyz.scm (guile-lib)[arguments]: Add
> 'patch-for-cross-compilation phase.
> [native-inputs]: Add autoconf, automake and gettext.
> (guile2.0-lib): Adjust to use alist-replace.
> (guile2.2-lib): Adjust to use alist-replace.

[...]

> +             (substitute* "configure.ac"
> +               (("GUILE_FLAGS")
> +                "GUILE_FLAGS
> +if test \"$cross_compiling\" != no; then
> +   GUILE_TARGET=\"--target=$host_alias\"
> +   AC_SUBST([GUILE_TARGET])
> +fi

You could even set ‘GUILE_TARGET’ unconditionally.

Otherwise LGTM.

Thanks,
Ludo’.
Maxim Cournoyer March 4, 2021, 1:16 p.m. UTC | #2
Hi Ludovic,

Ludovic Courtès <ludo@gnu.org> writes:

> Hi!
>
> Christopher Baines <mail@cbaines.net> skribis:
>
>> These changes were sent upstream as
>> https://lists.gnu.org/archive/html/guile-devel/2021-02/msg00004.html
>>
>> Without this change, the .go files are built for the host architecture, rather
>> than the target. I noticed this when cross building the
>> guix-build-coordinator (for which guile-lib is an input) to the Hurd.
>>
>> * gnu/packages/guile-xyz.scm (guile-lib)[arguments]: Add
>> 'patch-for-cross-compilation phase.
>> [native-inputs]: Add autoconf, automake and gettext.
>> (guile2.0-lib): Adjust to use alist-replace.
>> (guile2.2-lib): Adjust to use alist-replace.
>
> [...]
>
>> +             (substitute* "configure.ac"
>> +               (("GUILE_FLAGS")
>> +                "GUILE_FLAGS
>> +if test \"$cross_compiling\" != no; then
>> +   GUILE_TARGET=\"--target=$host_alias\"
>> +   AC_SUBST([GUILE_TARGET])
>> +fi
>
> You could even set ‘GUILE_TARGET’ unconditionally.

It seems a conditional is needed, because info
'(autoconf)Canonicalizing' says:

    The variables ‘build_alias’, ‘host_alias’, and ‘target_alias’ are
    always exactly the arguments of ‘--build’, ‘--host’, and ‘--target’; in
    particular, they are left empty if the user did not use them, even if
    the corresponding ‘AC_CANONICAL’ macro was run.

I.e. without the condition '--target=' could be passed to guild, which
probably wouldn't work.

But in another part of the autoconf manual (Hosts and
Cross-Compilation), it says:

      The relationship between build, host, and target have been cleaned
    up: the chain of default is now simply: target defaults to host, host to
    build, and build to the result of ‘config.guess’.  Nevertheless, in
    order to ease the transition from 2.13 to 2.50, the following transition
    scheme is implemented.  _Do not rely on it_, as it will be completely
    disabled in a couple of releases (we cannot keep it, as it proves to
    cause more problems than it cures).

       They all default to the result of running ‘config.guess’, unless you
    specify either ‘--build’ or ‘--host’.  In this case, the default becomes
    the system type you specified.  If you specify both, and they’re
    different, ‘configure’ enters cross compilation mode, so it doesn’t run
    any tests that require execution.

       Hint: if you mean to override the result of ‘config.guess’, prefer
    ‘--build’ over ‘--host’.

So it seems that nowadays the build, host, and target would take default
values as guessed by config.guess, and that the earlier section of the
manual should be updated?

Maxim
Ludovic Courtès March 8, 2021, 2:22 p.m. UTC | #3
Hi,

Maxim Cournoyer <maxim.cournoyer@gmail.com> skribis:

> Ludovic Courtès <ludo@gnu.org> writes:
>
>> Hi!
>>
>> Christopher Baines <mail@cbaines.net> skribis:
>>
>>> These changes were sent upstream as
>>> https://lists.gnu.org/archive/html/guile-devel/2021-02/msg00004.html
>>>
>>> Without this change, the .go files are built for the host architecture, rather
>>> than the target. I noticed this when cross building the
>>> guix-build-coordinator (for which guile-lib is an input) to the Hurd.
>>>
>>> * gnu/packages/guile-xyz.scm (guile-lib)[arguments]: Add
>>> 'patch-for-cross-compilation phase.
>>> [native-inputs]: Add autoconf, automake and gettext.
>>> (guile2.0-lib): Adjust to use alist-replace.
>>> (guile2.2-lib): Adjust to use alist-replace.
>>
>> [...]
>>
>>> +             (substitute* "configure.ac"
>>> +               (("GUILE_FLAGS")
>>> +                "GUILE_FLAGS
>>> +if test \"$cross_compiling\" != no; then
>>> +   GUILE_TARGET=\"--target=$host_alias\"
>>> +   AC_SUBST([GUILE_TARGET])
>>> +fi
>>
>> You could even set ‘GUILE_TARGET’ unconditionally.
>
> It seems a conditional is needed, because info
> '(autoconf)Canonicalizing' says:
>
>     The variables ‘build_alias’, ‘host_alias’, and ‘target_alias’ are
>     always exactly the arguments of ‘--build’, ‘--host’, and ‘--target’; in
>     particular, they are left empty if the user did not use them, even if
>     the corresponding ‘AC_CANONICAL’ macro was run.
>
> I.e. without the condition '--target=' could be passed to guild, which
> probably wouldn't work.

Ah true.  In Guile-{Gcrypt,zlib,…}, ‘--target’ is passed conditionally.
Apologies for the confusion!

> So it seems that nowadays the build, host, and target would take default
> values as guessed by config.guess, and that the earlier section of the
> manual should be updated?

Dunno; but in hindsight, what Chris did seemed right.

Thanks,
Ludo’.
Christopher Baines March 8, 2021, 10:11 p.m. UTC | #4
Ludovic Courtès <ludo@gnu.org> writes:

> Hi,
>
> Maxim Cournoyer <maxim.cournoyer@gmail.com> skribis:
>
>> Ludovic Courtès <ludo@gnu.org> writes:
>>
>>> Hi!
>>>
>>> Christopher Baines <mail@cbaines.net> skribis:
>>>
>>>> These changes were sent upstream as
>>>> https://lists.gnu.org/archive/html/guile-devel/2021-02/msg00004.html
>>>>
>>>> Without this change, the .go files are built for the host architecture, rather
>>>> than the target. I noticed this when cross building the
>>>> guix-build-coordinator (for which guile-lib is an input) to the Hurd.
>>>>
>>>> * gnu/packages/guile-xyz.scm (guile-lib)[arguments]: Add
>>>> 'patch-for-cross-compilation phase.
>>>> [native-inputs]: Add autoconf, automake and gettext.
>>>> (guile2.0-lib): Adjust to use alist-replace.
>>>> (guile2.2-lib): Adjust to use alist-replace.
>>>
>>> [...]
>>>
>>>> +             (substitute* "configure.ac"
>>>> +               (("GUILE_FLAGS")
>>>> +                "GUILE_FLAGS
>>>> +if test \"$cross_compiling\" != no; then
>>>> +   GUILE_TARGET=\"--target=$host_alias\"
>>>> +   AC_SUBST([GUILE_TARGET])
>>>> +fi
>>>
>>> You could even set ‘GUILE_TARGET’ unconditionally.
>>
>> It seems a conditional is needed, because info
>> '(autoconf)Canonicalizing' says:
>>
>>     The variables ‘build_alias’, ‘host_alias’, and ‘target_alias’ are
>>     always exactly the arguments of ‘--build’, ‘--host’, and ‘--target’; in
>>     particular, they are left empty if the user did not use them, even if
>>     the corresponding ‘AC_CANONICAL’ macro was run.
>>
>> I.e. without the condition '--target=' could be passed to guild, which
>> probably wouldn't work.
>
> Ah true.  In Guile-{Gcrypt,zlib,…}, ‘--target’ is passed conditionally.
> Apologies for the confusion!
>
>> So it seems that nowadays the build, host, and target would take default
>> values as guessed by config.guess, and that the earlier section of the
>> manual should be updated?
>
> Dunno; but in hindsight, what Chris did seemed right.

I don't really get the change I'm making, but I'm confident it has the
desired effect, I just copied it other Guile libraries. Anyway, I think
this is still useful, so I've gone ahead and pushed as
a0b24d5f8c5813329986b1bd690ed50b5308cc78.

If there are better ways to get the cross compiling to work, then that
can be put in place upstream, and then these changes removed.

Thanks,

Chris
Maxim Cournoyer March 11, 2021, 9:01 p.m. UTC | #5
Hi Chris,

Christopher Baines <mail@cbaines.net> writes:

> Ludovic Courtès <ludo@gnu.org> writes:
>
>> Hi,
>>
>> Maxim Cournoyer <maxim.cournoyer@gmail.com> skribis:
>>
>>> Ludovic Courtès <ludo@gnu.org> writes:
>>>
>>>> Hi!
>>>>
>>>> Christopher Baines <mail@cbaines.net> skribis:
>>>>
>>>>> These changes were sent upstream as
>>>>> https://lists.gnu.org/archive/html/guile-devel/2021-02/msg00004.html
>>>>>
>>>>> Without this change, the .go files are built for the host architecture, rather
>>>>> than the target. I noticed this when cross building the
>>>>> guix-build-coordinator (for which guile-lib is an input) to the Hurd.
>>>>>
>>>>> * gnu/packages/guile-xyz.scm (guile-lib)[arguments]: Add
>>>>> 'patch-for-cross-compilation phase.
>>>>> [native-inputs]: Add autoconf, automake and gettext.
>>>>> (guile2.0-lib): Adjust to use alist-replace.
>>>>> (guile2.2-lib): Adjust to use alist-replace.
>>>>
>>>> [...]
>>>>
>>>>> +             (substitute* "configure.ac"
>>>>> +               (("GUILE_FLAGS")
>>>>> +                "GUILE_FLAGS
>>>>> +if test \"$cross_compiling\" != no; then
>>>>> +   GUILE_TARGET=\"--target=$host_alias\"
>>>>> +   AC_SUBST([GUILE_TARGET])
>>>>> +fi
>>>>
>>>> You could even set ‘GUILE_TARGET’ unconditionally.
>>>
>>> It seems a conditional is needed, because info
>>> '(autoconf)Canonicalizing' says:
>>>
>>>     The variables ‘build_alias’, ‘host_alias’, and ‘target_alias’ are
>>>     always exactly the arguments of ‘--build’, ‘--host’, and ‘--target’; in
>>>     particular, they are left empty if the user did not use them, even if
>>>     the corresponding ‘AC_CANONICAL’ macro was run.
>>>
>>> I.e. without the condition '--target=' could be passed to guild, which
>>> probably wouldn't work.
>>
>> Ah true.  In Guile-{Gcrypt,zlib,…}, ‘--target’ is passed conditionally.
>> Apologies for the confusion!
>>
>>> So it seems that nowadays the build, host, and target would take default
>>> values as guessed by config.guess, and that the earlier section of the
>>> manual should be updated?
>>
>> Dunno; but in hindsight, what Chris did seemed right.
>
> I don't really get the change I'm making, but I'm confident it has the
> desired effect, I just copied it other Guile libraries. Anyway, I think
> this is still useful, so I've gone ahead and pushed as
> a0b24d5f8c5813329986b1bd690ed50b5308cc78.
>
> If there are better ways to get the cross compiling to work, then that
> can be put in place upstream, and then these changes removed.
>
> Thanks,
>
> Chris

FYI, I have sent to the Guile patches tracker commits (keeping original
authorship) of all the Guix-specific changes to guile-lib; the version
of your patch is slightly modified to test the value about to be used,
but otherwise it behaves the same.

Maxim
diff mbox series

Patch

diff --git a/gnu/packages/guile-xyz.scm b/gnu/packages/guile-xyz.scm
index ce5aad8ec7..07f81bcc1b 100644
--- a/gnu/packages/guile-xyz.scm
+++ b/gnu/packages/guile-xyz.scm
@@ -116,6 +116,7 @@ 
   #:use-module (guix build-system gnu)
   #:use-module (guix build-system guile)
   #:use-module (guix utils)
+  #:use-module ((guix build utils) #:select (alist-replace))
   #:use-module (ice-9 match)
   #:use-module ((srfi srfi-1) #:select (alist-delete)))
 
@@ -2194,6 +2195,21 @@  library.")
        '("GUILE_AUTO_COMPILE=0")        ; to prevent guild errors
        #:phases
        (modify-phases %standard-phases
+         (add-after 'unpack 'patch-for-cross-compilation
+           (lambda _
+             (substitute* "configure.ac"
+               (("GUILE_FLAGS")
+                "GUILE_FLAGS
+if test \"$cross_compiling\" != no; then
+   GUILE_TARGET=\"--target=$host_alias\"
+   AC_SUBST([GUILE_TARGET])
+fi
+"))
+             (substitute* "am/guile.mk"
+               (("guild compile") "guild compile $(GUILE_TARGET)"))
+             (delete-file "configure")  ; trigger the bootstrap phase to run
+                                        ; autoreconf
+             #t))
          (add-before 'configure 'patch-module-dir
            (lambda _
              (substitute* "src/Makefile.in"
@@ -2204,7 +2220,10 @@  library.")
 $(libdir)/guile/@GUILE_EFFECTIVE_VERSION@/site-ccache\n"))
              #t)))))
     (native-inputs
-     `(("guile" ,guile-3.0)
+     `(("autoconf" ,autoconf)
+       ("automake" ,automake)
+       ("gettext" ,gettext-minimal)
+       ("guile" ,guile-3.0)
        ("pkg-config" ,pkg-config)))
     (inputs
      `(("guile" ,guile-3.0)))
@@ -2225,15 +2244,23 @@  for Guile\".")
   (package
     (inherit guile-lib)
     (name "guile2.0-lib")
-    (native-inputs `(("pkg-config" ,pkg-config)))
-    (inputs `(("guile" ,guile-2.0)))))
+    (native-inputs
+     (alist-replace "guile" (list guile-2.0)
+                    (package-native-inputs guile-lib)))
+    (inputs
+     (alist-replace "guile" (list guile-2.0)
+                    (package-inputs guile-lib)))))
 
 (define-public guile2.2-lib
   (package
     (inherit guile-lib)
     (name "guile2.2-lib")
-    (native-inputs `(("pkg-config" ,pkg-config)))
-    (inputs `(("guile" ,guile-2.2)))))
+    (native-inputs
+     (alist-replace "guile" (list guile-2.2)
+                    (package-native-inputs guile-lib)))
+    (inputs
+     (alist-replace "guile" (list guile-2.2)
+                    (package-inputs guile-lib)))))
 
 (define-public guile3.0-lib
   (deprecated-package "guile3.0-lib" guile-lib))