[PATCH] Mingw support for zlib

  • Done
  • quality assurance status badge
Details
4 participants
  • Liliana Marie Prikler
  • Liliana Marie Prikler
  • Ludovic Courtès
  • Vivien Kraus
Owner
unassigned
Submitted by
Vivien Kraus
Severity
normal

Debbugs page

Vivien Kraus wrote 3 years ago
(address . guix-patches@gnu.org)
9418154f0a4f8c2b06b1b5bbce8df570ec4028de.camel@planete-kraus.eu
Dear guix,

zlib can be cross-compiled to mingw. It can be done by not running
configure, but instead using the win32/Makefile.gcc makefile, with some
tweaks for guix.

I think it should not rebuild anything, but I’m not sure. What do you
think?

Best regards,

Vivien
From 956c0491ea489ceaafe951f40f49efe8733b2563 Mon Sep 17 00:00:00 2001
From: Vivien Kraus <vivien@planete-kraus.eu>
Date: Sat, 25 Jun 2022 16:33:44 +0200
Subject: [PATCH] gnu: zlib: Support mingw cross-compilation.

* gnu/packages/compression.scm (zlib): Only run configure if not mingw.
---
gnu/packages/compression.scm | 25 +++++++++++++++++++++++--
1 file changed, 23 insertions(+), 2 deletions(-)

Toggle diff (68 lines)
diff --git a/gnu/packages/compression.scm b/gnu/packages/compression.scm
index d5bd3abf0f..5bce852523 100644
--- a/gnu/packages/compression.scm
+++ b/gnu/packages/compression.scm
@@ -125,8 +125,29 @@ (define-public zlib
,@(if (%current-target-system)
`((setenv "CHOST" ,(%current-target-system)))
'())
- (invoke "./configure"
- (string-append "--prefix=" out)))))
+ ,@(if (and (%current-target-system)
+ (string-suffix? "-w64-mingw32" (%current-target-system)))
+ `((substitute* "win32/Makefile.gcc"
+ (("PREFIX =")
+ (string-append "PREFIX = " ,(%current-target-system) "-"))
+ (("prefix \\?= /usr/local")
+ (string-append "prefix ?= " out))
+ (("# BINARY_PATH, INCLUDE_PATH and LIBRARY_PATH must be set.")
+ "\
+BINARY_PATH = $(prefix)/bin
+INCLUDE_PATH = $(prefix)/include
+LIBRARY_PATH = $(prefix)/lib"))
+ (rename-file "win32/Makefile.gcc" "Makefile"))
+ `((invoke "./configure"
+ (string-append "--prefix=" out)))))))
+ ,@(if (and (%current-target-system)
+ (string-suffix? "-mingw32" (%current-target-system)))
+ `(add-after 'install 'install-mingw-shared
+ (lambda* (#:key make-flags #:allow-other-keys)
+ (apply invoke "make"
+ (append make-flags
+ '("install" "SHARED_MODE=1")))))
+ '())
(add-after 'install 'move-static-library
(lambda* (#:key outputs #:allow-other-keys)
(let ((out (assoc-ref outputs "out"))

base-commit: 6ffb3ef4d61e47c39b9ee4d1dceeaeb9360094c0
prerequisite-patch-id: cb331cf7152091377b37baa313ba3a5a87b3143f
prerequisite-patch-id: 92209f66b90c79d7bf060944906c869625b407dd
prerequisite-patch-id: 5e408465a1d766662ee1c33a4b807a779a4c664b
prerequisite-patch-id: eb8a798c6dc097419cb5bdf51641e3169e681e2e
prerequisite-patch-id: ea2b7638049e23e80fe2716e78900ea14cf922cd
prerequisite-patch-id: ca6164abf3d0287d49f726b3ae92b75ef94a8103
prerequisite-patch-id: 3265f90d5769feeed4b62de20c4f69c5a5e7a81d
prerequisite-patch-id: f85ec750b9f798b9e41bb00d7edb82d421353b33
prerequisite-patch-id: 6b60605cbf22b6ad4eff2f0da74a74c30fe2a9c8
prerequisite-patch-id: d6051ad60e172c8f11ef40772e502d86f4333acb
prerequisite-patch-id: 1dbff988e2360cb1ee029f64f300ce44c11d76e9
prerequisite-patch-id: 66ad9148ea45252dbef3037bd7a50a4ec32e2b5b
prerequisite-patch-id: 0c3aa04452a6a1d3f56951aa177a174a032ff299
prerequisite-patch-id: 42948a36a16f9824c17b8e7b7294ea33e81eb238
prerequisite-patch-id: b1b2b2215d1a71bfac6239766067c34cfbb70ebb
prerequisite-patch-id: 91f834615aed988f8f2d9b1655721debd65e0cdf
prerequisite-patch-id: 4a5b6330f14470cc7688ba1ffabd38414d3d9860
prerequisite-patch-id: 86c9604f41fa8d1e0a02fdd1a0ac3fbed3ac37e2
prerequisite-patch-id: 4551ff825ddc78669180eaa1826e8b581e2726f7
prerequisite-patch-id: 0c89c6e62602aded309ea47143fea68aed8c1617
prerequisite-patch-id: 4ad64d116fb8674505d7411a296137046096c60c
prerequisite-patch-id: 9939453dfc6bcac6f98aafdf60812b2bf884fb3a
prerequisite-patch-id: 8c206238029371a28c49cd914d7aae780114b10c
prerequisite-patch-id: f95b376c7e13855b8d3784a6cefc4800b945d502
prerequisite-patch-id: b39addb89db4cb5f5727a492411eae5ace52ad8b
prerequisite-patch-id: d9bc7451845593d839c8921801d3db8ab58f14ad
prerequisite-patch-id: 836dc57a4ee4aa788d05eed45b3804c139e4f995
prerequisite-patch-id: 0b4c563142f8f5ae6ca10e34b814266310be2686
--
2.36.1
Liliana Marie Prikler wrote 3 years ago
d5b4227a233f0efffde3e1f02923c22f61454671.camel@ist.tugraz.at
Am Dienstag, dem 12.07.2022 um 01:53 +0200 schrieb Vivien Kraus:

Toggle quote (3 lines)
> + ,@(if (and (%current-target-system)
> + (string-suffix? "-w64-mingw32" (%current-
> target-system)))
I'm pretty sure there's an abbreviation for this like target-mingw?
Toggle quote (14 lines)
> + `((substitute* "win32/Makefile.gcc"
> + (("PREFIX =")
> + (string-append "PREFIX = " ,(%current-
> target-system) "-"))
> + (("prefix \\?= /usr/local")
> + (string-append "prefix ?= " out))
> + (("# BINARY_PATH, INCLUDE_PATH and
> LIBRARY_PATH must be set.")
> + "\
> +BINARY_PATH = $(prefix)/bin
> +INCLUDE_PATH = $(prefix)/include
> +LIBRARY_PATH = $(prefix)/lib"))
> + (rename-file "win32/Makefile.gcc"
> "Makefile"))
I think these can be conditionally added to #:make-flags
Toggle quote (11 lines)
> + `((invoke "./configure"
> + (string-append "--prefix=" out)))))))

> + ,@(if (and (%current-target-system)
> + (string-suffix? "-mingw32" (%current-target-
> system)))
> + `(add-after 'install 'install-mingw-shared
> + (lambda* (#:key make-flags #:allow-other-keys)
> + (apply invoke "make"
> + (append make-flags
> + '("install" "SHARED_MODE=1")))))
SHARED_MODE might likewise be conditionally added to #:make-flags.

Cheers
Vivien Kraus wrote 3 years ago
29fa1e573d51f351796ba22d7344d9738d71c9be.camel@planete-kraus.eu
Le mardi 12 juillet 2022 à 08:07 +0200, Liliana Marie Prikler a écrit :
Toggle quote (7 lines)
> Am Dienstag, dem 12.07.2022 um 01:53 +0200 schrieb Vivien Kraus:
>
> > +               ,@(if (and (%current-target-system)
> > +                          (string-suffix? "-w64-mingw32"
> > (%current-
> > target-system)))
> I'm pretty sure there's an abbreviation for this like target-mingw?
Precisely! Fixed it, thank you.

Toggle quote (15 lines)
> > +                     `((substitute* "win32/Makefile.gcc"
> > +                         (("PREFIX =")
> > +                          (string-append "PREFIX = " ,(%current-
> > target-system) "-"))
> > +                         (("prefix \\?= /usr/local")
> > +                          (string-append "prefix ?= " out))
> > +                         (("# BINARY_PATH, INCLUDE_PATH and
> > LIBRARY_PATH must be set.")
> > +                          "\
> > +BINARY_PATH = $(prefix)/bin
> > +INCLUDE_PATH = $(prefix)/include
> > +LIBRARY_PATH = $(prefix)/lib"))
> > +                       (rename-file "win32/Makefile.gcc"
> > "Makefile"))
> I think these can be conditionally added to #:make-flags
I did it for all but prefix, because I have to have the output path. Is
there a way to get it from within the make-flags?

Toggle quote (14 lines)
> > +                     `((invoke "./configure"
> > +                               (string-append "--prefix="
> > out)))))))
>
> > +         ,@(if (and (%current-target-system)
> > +                    (string-suffix? "-mingw32" (%current-target-
> > system)))
> > +               `(add-after 'install 'install-mingw-shared
> > +                  (lambda* (#:key make-flags #:allow-other-keys)
> > +                    (apply invoke "make"
> > +                           (append make-flags
> > +                                   '("install"
> > "SHARED_MODE=1")))))
> SHARED_MODE might likewise be conditionally added to #:make-flags.
I get both the DLL loader and the DLL in the default output, and the
static lib in the static output, so it works.

Thank you for your review!

Vivien
From 1ddb567f30f565e951321b80921f27ed7f10f604 Mon Sep 17 00:00:00 2001
From: Vivien Kraus <vivien@planete-kraus.eu>
Date: Sat, 25 Jun 2022 16:33:44 +0200
Subject: [PATCH v2] gnu: zlib: Support mingw cross-compilation.

* gnu/packages/compression.scm (zlib): Only run configure if not mingw.
---
gnu/packages/compression.scm | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)

Toggle diff (41 lines)
diff --git a/gnu/packages/compression.scm b/gnu/packages/compression.scm
index d5bd3abf0f..ea1bc2a03f 100644
--- a/gnu/packages/compression.scm
+++ b/gnu/packages/compression.scm
@@ -113,7 +113,15 @@ (define-public zlib
(build-system gnu-build-system)
(outputs '("out" "static"))
(arguments
- `(#:phases
+ `(#:make-flags
+ ,(if (target-mingw?)
+ `(list ,(string-append "PREFIX=" (%current-target-system) "-")
+ "BINARY_PATH = $(prefix)/bin"
+ "INCLUDE_PATH = $(prefix)/include"
+ "LIBRARY_PATH = $(prefix)/lib"
+ "SHARED_MODE = 1")
+ ''())
+ #:phases
(modify-phases %standard-phases
(replace 'configure
(lambda* (#:key outputs #:allow-other-keys)
@@ -125,8 +133,13 @@ (define-public zlib
,@(if (%current-target-system)
`((setenv "CHOST" ,(%current-target-system)))
'())
- (invoke "./configure"
- (string-append "--prefix=" out)))))
+ ,@(if (target-mingw?)
+ `((substitute* "win32/Makefile.gcc"
+ (("prefix \\?= /usr/local")
+ (string-append "prefix ?= " out)))
+ (rename-file "win32/Makefile.gcc" "Makefile"))
+ `((invoke "./configure"
+ (string-append "--prefix=" out)))))))
(add-after 'install 'move-static-library
(lambda* (#:key outputs #:allow-other-keys)
(let ((out (assoc-ref outputs "out"))

base-commit: f0c8abe85787a0018c0adeb0bc4a6672d46686e4
--
2.36.1
Liliana Marie Prikler wrote 3 years ago
c8697df7788f2ad06ed07296f627b59b939cdc01.camel@ist.tugraz.at
Am Dienstag, dem 12.07.2022 um 18:45 +0200 schrieb Vivien Kraus:
Toggle quote (28 lines)
> Le mardi 12 juillet 2022 à 08:07 +0200, Liliana Marie Prikler a
> écrit :
> > Am Dienstag, dem 12.07.2022 um 01:53 +0200 schrieb Vivien Kraus:
> >
> > > +               ,@(if (and (%current-target-system)
> > > +                          (string-suffix? "-w64-mingw32"
> > > (%current-
> > > target-system)))
> > I'm pretty sure there's an abbreviation for this like target-mingw?
> Precisely! Fixed it, thank you.
>
> > > +                     `((substitute* "win32/Makefile.gcc"
> > > +                         (("PREFIX =")
> > > +                          (string-append "PREFIX = " ,(%current-
> > > target-system) "-"))
> > > +                         (("prefix \\?= /usr/local")
> > > +                          (string-append "prefix ?= " out))
> > > +                         (("# BINARY_PATH, INCLUDE_PATH and
> > > LIBRARY_PATH must be set.")
> > > +                          "\
> > > +BINARY_PATH = $(prefix)/bin
> > > +INCLUDE_PATH = $(prefix)/include
> > > +LIBRARY_PATH = $(prefix)/lib"))
> > > +                       (rename-file "win32/Makefile.gcc"
> > > "Makefile"))
> > I think these can be conditionally added to #:make-flags
> I did it for all but prefix, because I have to have the output path.
> Is there a way to get it from within the make-flags?
With the gexp-style you'd write #$output, otherwise ,(assoc-ref %build-
outputs "out").

Toggle quote (16 lines)
> > > +                     `((invoke "./configure"
> > > +                               (string-append "--prefix="
> > > out)))))))
> >
> > > +         ,@(if (and (%current-target-system)
> > > +                    (string-suffix? "-mingw32" (%current-target-
> > > system)))
> > > +               `(add-after 'install 'install-mingw-shared
> > > +                  (lambda* (#:key make-flags #:allow-other-keys)
> > > +                    (apply invoke "make"
> > > +                           (append make-flags
> > > +                                   '("install"
> > > "SHARED_MODE=1")))))
> > SHARED_MODE might likewise be conditionally added to #:make-flags.
> I get both the DLL loader and the DLL in the default output, and the
> static lib in the static output, so it works.
Oh, so you mean the static output should be built without SHARED_MODE?


Cheers
Vivien Kraus wrote 3 years ago
d9ac8a144f4a442d4f9d0d6d996dd8962b0c3a8a.camel@planete-kraus.eu
Le mercredi 13 juillet 2022 à 07:49 +0200, Liliana Marie Prikler a
écrit :
Toggle quote (26 lines)
> Am Dienstag, dem 12.07.2022 um 18:45 +0200 schrieb Vivien Kraus:
> > Le mardi 12 juillet 2022 à 08:07 +0200, Liliana Marie Prikler a
> > écrit :
> > > Am Dienstag, dem 12.07.2022 um 01:53 +0200 schrieb Vivien Kraus:
> > > > +                     `((substitute* "win32/Makefile.gcc"
> > > > +                         (("PREFIX =")
> > > > +                          (string-append "PREFIX = "
> > > > ,(%current-
> > > > target-system) "-"))
> > > > +                         (("prefix \\?= /usr/local")
> > > > +                          (string-append "prefix ?= " out))
> > > > +                         (("# BINARY_PATH, INCLUDE_PATH and
> > > > LIBRARY_PATH must be set.")
> > > > +                          "\
> > > > +BINARY_PATH = $(prefix)/bin
> > > > +INCLUDE_PATH = $(prefix)/include
> > > > +LIBRARY_PATH = $(prefix)/lib"))
> > > > +                       (rename-file "win32/Makefile.gcc"
> > > > "Makefile"))
> > > I think these can be conditionally added to #:make-flags
> > I did it for all but prefix, because I have to have the output
> > path.
> > Is there a way to get it from within the make-flags?
> With the gexp-style you'd write #$output, otherwise ,(assoc-ref
> %build-
> outputs "out").
Looking at the "-builder" scheme file that is generated for the
derivation, it looks like what I want is simply %outputs, not %build-
outputs.

Toggle quote (23 lines)
>
> > > > +                     `((invoke "./configure"
> > > > +                               (string-append "--prefix="
> > > > out)))))))
> > >
> > > > +         ,@(if (and (%current-target-system)
> > > > +                    (string-suffix? "-mingw32" (%current-
> > > > target-
> > > > system)))
> > > > +               `(add-after 'install 'install-mingw-shared
> > > > +                  (lambda* (#:key make-flags #:allow-other-
> > > > keys)
> > > > +                    (apply invoke "make"
> > > > +                           (append make-flags
> > > > +                                   '("install"
> > > > "SHARED_MODE=1")))))
> > > SHARED_MODE might likewise be conditionally added to #:make-
> > > flags.
> > I get both the DLL loader and the DLL in the default output, and
> > the
> > static lib in the static output, so it works.
> Oh, so you mean the static output should be built without
> SHARED_MODE?
No, SHARED_MODE=1 means "please also install the DLL" and SHARED_MODE=0
means "please do not install the DLL". Reading the win32/Makefile.gcc,
nothing special is done if SHARED_MODE=0. It is only used in the
install and uninstall targets. I don’t really understand why you would
want to set SHARED_MODE=0 (even weirder to set it as a default) but I
guess it happens.
From 6991416907cb2b3e8be639c18cecb6bf519da904 Mon Sep 17 00:00:00 2001
From: Vivien Kraus <vivien@planete-kraus.eu>
Date: Sat, 25 Jun 2022 16:33:44 +0200
Subject: [PATCH v3] gnu: zlib: Support mingw cross-compilation.

* gnu/packages/compression.scm (zlib): Only run configure if not mingw.
---
gnu/packages/compression.scm | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)

Toggle diff (39 lines)
diff --git a/gnu/packages/compression.scm b/gnu/packages/compression.scm
index d5bd3abf0f..871f90656c 100644
--- a/gnu/packages/compression.scm
+++ b/gnu/packages/compression.scm
@@ -113,7 +113,16 @@ (define-public zlib
(build-system gnu-build-system)
(outputs '("out" "static"))
(arguments
- `(#:phases
+ `(#:make-flags
+ ,(if (target-mingw?)
+ `(list ,(string-append "PREFIX=" (%current-target-system) "-")
+ "BINARY_PATH = $(prefix)/bin"
+ "INCLUDE_PATH = $(prefix)/include"
+ "LIBRARY_PATH = $(prefix)/lib"
+ "SHARED_MODE = 1"
+ (string-append "prefix = " (assoc-ref %outputs "out")))
+ ''())
+ #:phases
(modify-phases %standard-phases
(replace 'configure
(lambda* (#:key outputs #:allow-other-keys)
@@ -125,8 +134,10 @@ (define-public zlib
,@(if (%current-target-system)
`((setenv "CHOST" ,(%current-target-system)))
'())
- (invoke "./configure"
- (string-append "--prefix=" out)))))
+ ,@(if (target-mingw?)
+ `((rename-file "win32/Makefile.gcc" "Makefile"))
+ `((invoke "./configure"
+ (string-append "--prefix=" out)))))))
(add-after 'install 'move-static-library
(lambda* (#:key outputs #:allow-other-keys)
(let ((out (assoc-ref outputs "out"))

base-commit: dcf133587ac7d73ba306a314e1a496a7efb9960b
--
2.36.1
Liliana Marie Prikler wrote 3 years ago
b97100e6044e6cb20f35130d799c157dd68b36a1.camel@ist.tugraz.at
Am Mittwoch, dem 13.07.2022 um 17:19 +0200 schrieb Vivien Kraus:
Toggle quote (4 lines)
> [...]
> Looking at the "-builder" scheme file that is generated for the
> derivation, it looks like what I want is simply %outputs, not %build-
> outputs.
Yeah, my bad, it's %build-inputs and %outputs respectively.

Toggle quote (6 lines)
>
> > Oh, so you mean the static output should be built without
> > SHARED_MODE?
> No, SHARED_MODE=1 means "please also install the DLL" and
> SHARED_MODE=0 means "please do not install the DLL". Reading the
> win32/Makefile.gcc, nothing special is done if SHARED_MODE=0. 
In that case we could set it via #:make-flags, right?

Toggle quote (3 lines)
> It is only used in the install and uninstall targets. I don’t really
> understand why you would want to set SHARED_MODE=0 (even weirder to
> set it as a default) but I guess it happens.
Perhaps the rationale is that users might not actually want the shared
libraries for some bespoke reasons (not that those reasons would apply
to Guix users).

Cheers
Vivien Kraus wrote 3 years ago
e3f6acc0787965c15e57644d3dec4003f20d8dd9.camel@planete-kraus.eu
Le jeudi 14 juillet 2022 à 08:01 +0200, Liliana Marie Prikler a écrit :
Toggle quote (6 lines)
> > > Oh, so you mean the static output should be built without
> > > SHARED_MODE?
> > No, SHARED_MODE=1 means "please also install the DLL" and
> > SHARED_MODE=0 means "please do not install the DLL". Reading the
> > win32/Makefile.gcc, nothing special is done if SHARED_MODE=0. 
> In that case we could set it via #:make-flags, right?
I’m not sure I understand. I think that’s what I did, and obviously it
works since the dll is installed in the default output. Could you
explain a bit more the phrase "we could set it"?

Vivien
Liliana Marie Prikler wrote 3 years ago
973e2566abcd13f7612f1d69a59188220b67b337.camel@ist.tugraz.at
Am Freitag, dem 15.07.2022 um 16:28 +0200 schrieb Vivien Kraus:
Toggle quote (14 lines)
> Le jeudi 14 juillet 2022 à 08:01 +0200, Liliana Marie Prikler a
> écrit :
> > > > Oh, so you mean the static output should be built without
> > > > SHARED_MODE?
> > > No, SHARED_MODE=1 means "please also install the DLL" and
> > > SHARED_MODE=0 means "please do not install the DLL". Reading the
> > > win32/Makefile.gcc, nothing special is done if SHARED_MODE=0. 
> > In that case we could set it via #:make-flags, right?
> I’m not sure I understand. I think that’s what I did, and obviously
> it
> works since the dll is installed in the default output. Could you
> explain a bit more the phrase "we could set it"?
>
> Vivien
My bad; I didn't notice the attachments. LGTM
Ludovic Courtès wrote 3 years ago
Re: bug#56504: [PATCH] Mingw support for zlib
(name . Liliana Marie Prikler)(address . liliana.prikler@ist.tugraz.at)
871qugreuo.fsf_-_@gnu.org
Hey Liliana,

Liliana Marie Prikler <liliana.prikler@ist.tugraz.at> skribis:

Toggle quote (17 lines)
> Am Freitag, dem 15.07.2022 um 16:28 +0200 schrieb Vivien Kraus:
>> Le jeudi 14 juillet 2022 à 08:01 +0200, Liliana Marie Prikler a
>> écrit :
>> > > > Oh, so you mean the static output should be built without
>> > > > SHARED_MODE?
>> > > No, SHARED_MODE=1 means "please also install the DLL" and
>> > > SHARED_MODE=0 means "please do not install the DLL". Reading the
>> > > win32/Makefile.gcc, nothing special is done if SHARED_MODE=0. 
>> > In that case we could set it via #:make-flags, right?
>> I’m not sure I understand. I think that’s what I did, and obviously
>> it
>> works since the dll is installed in the default output. Could you
>> explain a bit more the phrase "we could set it"?
>>
>> Vivien
> My bad; I didn't notice the attachments. LGTM

Please do apply what LGTY, thanks!

Ludo’.
Liliana Marie Prikler wrote 3 years ago
(name . Ludovic Courtès)(address . ludo@gnu.org)
1bf73703e734bf040eb3eebc9eb1a0fdb9e781a1.camel@gmail.com
Am Dienstag, dem 19.07.2022 um 23:07 +0200 schrieb Ludovic Courtès:
Toggle quote (1 lines)
> Please do apply what LGTY, thanks!
Pardon the delays, zlib for mingw is pushed now.
Closed
?
Your comment

This issue is archived.

To comment on this conversation send an email to 56504@debbugs.gnu.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 56504
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch
You may also tag this issue. See list of standard tags. For example, to set the confirmed and easy tags
mumi command -t +confirmed -t +easy
Or, remove the moreinfo tag and set the help tag
mumi command -t -moreinfo -t +help