Re: [PATCH v6 01/10] gnu: cross: Use CROSS_*_INCLUDE_PATH for system headers.

2016-04-29 Thread Jan Nieuwenhuizen
Andy Wingo writes:

 +   ,(if (mingw-target?)
 +"cmd.exe"
 +`(if bash
 + (string-append bash "/bin/bash")
 + "bash"))
  %standard-phases)))
>
> Note that this patch has an extra level of quoting for the not-mingw
> case.

Oops, changed it to (see below)

  (let ((bash (assoc-ref inputs "bash")))
(substitute* "module/ice-9/popen.scm"
  (("/bin/sh")
   (if bash
   (string-append bash "/bin/bash")
   "bash")
%standard-phases)))

>> I can imagine that if I somehow installed a version of bash.exe
>> (msys/cygwin) in PATH, I would expect open-pipe to use that rather than
>> cmd.
>>
>> I'm not sure if you have a suggestion for change here, or if we should
>> get more input first?
>
> 3 options:
>
>  1. Run cmd.exe from path.  Disadvantage: incompatible interface.
>
>  2. Build bash in mingw for Guix; no special cases.  The Right Thing.
> However I'm OK with accepting a patch that doesn't do this, in the
> interests of moving things forward.
>
>  3. Run bash from path.  Disadvantage: bash probably not in the path and
> the invocation would fail.  Arguably an early failure is the right
> thing, though!
>
> I think I'd go with (3) rather than (1).  WDYT?  From a Guile
> perspective you can always use `open-pipe*' which doesn't trampoline
> through a shell at all.

Thank you, that's a helpful observation.  Seeing this, yes 3) would be
my choice too.

Thinking about it 2) The Right Thing I had another puzzle-area: why is
it that we have /bin/sh and not /bin/guile in GuixSD; and wouldn't we
want the shell to be schemy-er or, how hard would it be for guile to
parse shell?

Anyway, while testing 3) I realised that whatever we put here is moot, at
least for now, seeing that...

#ifdef HAVE_FORK
static void
scm_init_popen (void)
{
  scm_c_define_gsubr ("open-process", 2, 0, 1, scm_open_process);
}
#endif

Sorry for being so dull...there isn't a any of such goodness [yet] in
Windows/MinGW.

>> Below is a first attempt that I didn't want to send as a proper patch
>> yet.  I could do with some input, especially from Manolis.
>
> It's really helpful to me, thank you!

Okay, thanks.  I'll work on this a bit and present a patch later.

I'm building and will have a v7 patch set rsn.

Greetings,
Jan

-- 
Jan Nieuwenhuizen  | GNU LilyPond http://lilypond.org
Freelance IT http://JoyofSource.com | Avatar®  http://AvatarAcademy.nl  



Re: [PATCH v6 01/10] gnu: cross: Use CROSS_*_INCLUDE_PATH for system headers.

2016-04-29 Thread Andy Wingo
Hi :)

On Thu 28 Apr 2016 22:16, Jan Nieuwenhuizen  writes:

>>> @@ -167,7 +172,11 @@ without requiring the source code to be rewritten.")
>>>(let ((bash (assoc-ref inputs "bash")))
>>>  (substitute* "module/ice-9/popen.scm"
>>>(("/bin/sh")
>>> -   (string-append bash "/bin/bash")
>>> +   ,(if (mingw-target?)
>>> +"cmd.exe"
>>> +`(if bash
>>> + (string-append bash "/bin/bash")
>>> + "bash"))
>>>  %standard-phases)))

Note that this patch has an extra level of quoting for the not-mingw
case.

>>
>> I guess the thing is, cmd.exe is part of the system, so it should be
>> linked "dynamically" (i.e. via the PATH); but is cmd.exe really a bash
>> replacement?  Is this the right way for open-pipe in Guile to work?
>
> Good question.  I don't really know.  Probably it's not; but then, even
> if we have bash would't you expect some utils like cat/grep/sed?  FWIW,
> I spent two nights trying to port bash before I decided to give up, err
> re-prioritise.  I'd love to provide that all, and I'd also love to get
> some help with that ;-)
>
> I can imagine that if I somehow installed a version of bash.exe
> (msys/cygwin) in PATH, I would expect open-pipe to use that rather than
> cmd.
>
> I'm not sure if you have a suggestion for change here, or if we should
> get more input first?

3 options:

 1. Run cmd.exe from path.  Disadvantage: incompatible interface.

 2. Build bash in mingw for Guix; no special cases.  The Right Thing.
However I'm OK with accepting a patch that doesn't do this, in the
interests of moving things forward.

 3. Run bash from path.  Disadvantage: bash probably not in the path and
the invocation would fail.  Arguably an early failure is the right
thing, though!

I think I'd go with (3) rather than (1).  WDYT?  From a Guile
perspective you can always use `open-pipe*' which doesn't trampoline
through a shell at all.

> So, most of the difficulties I had should be fixed now; not sure what
> difficulties the next person will have.  So, what to write exactly?
>
> Below is a first attempt that I didn't want to send as a proper patch
> yet.  I could do with some input, especially from Manolis.

It's really helpful to me, thank you!

Andy



Re: [PATCH v6 01/10] gnu: cross: Use CROSS_*_INCLUDE_PATH for system headers.

2016-04-28 Thread Jan Nieuwenhuizen
Jan Nieuwenhuizen writes:

>* any change made to cross-gcc / cross-libc triggers a rebuild of
>  both worlds

this is not true, as Manolis pointed out on irc; I'm probably mistaking
changes to ncurses or somesuch.

> Because Guix uses pseudo cross-compilation in the bootstrap process
> @ref{Bootstrapping}, changes to @var{cross-gcc} may rebuild our native
> world

also, not true; forget this bit.  Sorry ;-)

Greetings,
Jan.

-- 
Jan Nieuwenhuizen  | GNU LilyPond http://lilypond.org
Freelance IT http://JoyofSource.com | Avatar®  http://AvatarAcademy.nl  



Re: [PATCH v6 01/10] gnu: cross: Use CROSS_*_INCLUDE_PATH for system headers.

2016-04-28 Thread Jan Nieuwenhuizen
Andy Wingo writes:

Hi!

[Manolis: I've written a bit about the cross setup below, do you want
 to have a look?]

> Mostly formatting nits, only a couple substantial comments.  Looking
> great.

Oh that's super, thanks for all your help!

It seems I have picked-up the convention of doing

   (if condition 
   ))

now that I think of it, could be lispy with optionally longer else
branch.  I have wondered why scheme/guile does not have that.  Possibly
it's an artifact of more imperative days?

>> + (if libc
>> + (setenv "CROSS_LIBRARY_PATH"
>> + (string-append
>> +  libc "/lib"
>> +  ":" libc "/i686-w64-mingw32/lib")))
>
> Use "when" please

Yes, done.

>> +(define (native-libc target)
>> +  (if (mingw-target? target) mingw-w64
>> +  glibc))
>
> The if should be either all on one line, or on three lines

Changed to three lines; I expect this to get longer in time.

>> Subject: [PATCH 07/10] gnu: ncurses: support mingw.
>> +  (cond ((mingw-target? target)
>> +  (with-directory-excursion (string-append out "/bin")
>> +(for-each
>> + (lambda (lib)
>
> Because the consequent is so large, please indent the condition on the
> line after "cond", i.e.
>
>   (cond
>((mingw-target? target)
> ...))

Ok.

>
>> +++ b/gnu/packages/patches/readline-6.3-mingw.patch
>> @@ -0,0 +1,128 @@
>> +Mingw lacks some SIG*.  Taken from
>> +
>> + wget
>> https://raw.githubusercontent.com/Alexpux/MINGW-packages/master/mingw-w64-readline/readline-6.3-mingw.patch
>> +
>> +some updates to make it apply.
>> +
>> +Upstream status: Not presented to upstream.
>
> Probably needs to go upstream I think, and we should clarify the
> licensing on it or rewrite it.

Yes.  I have sent the owner of the github archive a mail for
clarification.

>> +,(if (mingw-target?) "/bin"
>> + "/lib"))
>
> One line or three lines please

Sure, one line.

>> Subject: [PATCH 10/10] gnu: guile-2.0: support mingw.
>> +,@(if (mingw-target?)
>> +  `(("bash" ,bash)
>> +("guile" ,guile-2.0))
>> +  '(
>
> Would we not need Guile always when cross-compiling?

Hmm.  I'm adding bash here and removing it below for mingw; which makes
some sense.  Guile should be included via self-native-input? -- ah, I
prolly unset self-native-input? while experimenting with a cross-guile
package and /there/ I needed this.  Retried without guile, removed,
changed to one line.

>> + ,@(if (mingw-target?) '()
>> +   `(("bash" ,bash)
>
> One line please.

Ok.

>> @@ -167,7 +172,11 @@ without requiring the source code to be rewritten.")
>>(let ((bash (assoc-ref inputs "bash")))
>>  (substitute* "module/ice-9/popen.scm"
>>(("/bin/sh")
>> -   (string-append bash "/bin/bash")
>> +   ,(if (mingw-target?)
>> +"cmd.exe"
>> +`(if bash
>> + (string-append bash "/bin/bash")
>> + "bash"))
>>  %standard-phases)))
>
> I guess the thing is, cmd.exe is part of the system, so it should be
> linked "dynamically" (i.e. via the PATH); but is cmd.exe really a bash
> replacement?  Is this the right way for open-pipe in Guile to work?

Good question.  I don't really know.  Probably it's not; but then, even
if we have bash would't you expect some utils like cat/grep/sed?  FWIW,
I spent two nights trying to port bash before I decided to give up, err
re-prioritise.  I'd love to provide that all, and I'd also love to get
some help with that ;-)

I can imagine that if I somehow installed a version of bash.exe
(msys/cygwin) in PATH, I would expect open-pipe to use that rather than
cmd.

I'm not sure if you have a suggestion for change here, or if we should
get more input first?

> Finally at the very end of all of this I think it would be great to have
> some kind of document, "how to compile software for windows using
> Guix".   WDYT?  That document could include any relevant details about
> the internal structure of a cross-compile -- how Guix links things
> together.  I know that for me, this information is vey easily paged
> out to long-term storage; takes a while to pull it back in :)

I think that's a good idea.  I spent quite some time figuring-out how
things work in Guix.  Most is just great; the biggest problems I
encountered were

   * any change made to cross-gcc / cross-libc triggers a rebuild of
 both worlds

and most changes I made were small, wrong and terribly difficult to
inspect.  I tried to work around that creating separate 

Re: [PATCH v6 01/10] gnu: cross: Use CROSS_*_INCLUDE_PATH for system headers.

2016-04-28 Thread Andy Wingo
Hi :)

Mostly formatting nits, only a couple substantial comments.  Looking
great.

On Wed 27 Apr 2016 21:27, Jan Nieuwenhuizen  writes:

> From d81bd3a288f3298d11983da6050958af99780dfe Mon Sep 17 00:00:00 2001
> From: Jan Nieuwenhuizen 
> Date: Sun, 17 Apr 2016 18:42:43 +0200
> Subject: [PATCH 04/10] gnu: cross-build: i686-w64-mingw32: new cross target.
>
> + (if libc
> + (setenv "CROSS_LIBRARY_PATH"
> + (string-append
> +  libc "/lib"
> +  ":" libc "/i686-w64-mingw32/lib")))

Use "when" please

> +(define (native-libc target)
> +  (if (mingw-target? target) mingw-w64
> +  glibc))

The if should be either all on one line, or on three lines

> From aacfb151046372046446e083bb6056e086f3cf68 Mon Sep 17 00:00:00 2001
> From: Jan Nieuwenhuizen 
> Date: Tue, 12 Apr 2016 15:47:54 +0200
> Subject: [PATCH 07/10] gnu: ncurses: support mingw.
>
> +  (cond ((mingw-target? target)
> +  (with-directory-excursion (string-append out "/bin")
> +(for-each
> + (lambda (lib)

Because the consequent is so large, please indent the condition on the
line after "cond", i.e.

  (cond
   ((mingw-target? target)
...))

> +++ b/gnu/packages/patches/readline-6.3-mingw.patch
> @@ -0,0 +1,128 @@
> +Mingw lacks some SIG*.  Taken from
> +
> +wget 
> https://raw.githubusercontent.com/Alexpux/MINGW-packages/master/mingw-w64-readline/readline-6.3-mingw.patch
> +
> +some updates to make it apply.
> +
> +Upstream status: Not presented to upstream.

Probably needs to go upstream I think, and we should clarify the
licensing on it or rewrite it.

> +,(if (mingw-target?) "/bin"
> + "/lib"))

One line or three lines please

> From 5d77ef604ba7c89cfb14275ae9dc0d9b792517ee Mon Sep 17 00:00:00 2001
> From: Jan Nieuwenhuizen 
> Date: Sun, 24 Apr 2016 14:06:56 +0200
> Subject: [PATCH 10/10] gnu: guile-2.0: support mingw.
>
> * gnu/packages/guile.scm (guile-2.0): Support mingw.
> ---
>  gnu/packages/guile.scm | 17 +
>  1 file changed, 13 insertions(+), 4 deletions(-)
>
> diff --git a/gnu/packages/guile.scm b/gnu/packages/guile.scm
> index fe043cb..82e2cfc 100644
> --- a/gnu/packages/guile.scm
> +++ b/gnu/packages/guile.scm
> @@ -134,11 +134,16 @@ without requiring the source code to be rewritten.")
>"1qh3j7308qvsjgwf7h94yqgckpbgz2k3yqdkzsyhqcafvfka9l5f"))
>  (patches (list (search-patch "guile-arm-fixes.patch")
> (build-system gnu-build-system)
> -   (native-inputs `(("pkgconfig" ,pkg-config)))
> +   (native-inputs `(("pkgconfig" ,pkg-config)
> +,@(if (mingw-target?)
> +  `(("bash" ,bash)
> +("guile" ,guile-2.0))
> +  '(

Would we not need Guile always when cross-compiling?

> (inputs `(("libffi" ,libffi)
>   ("readline" ,readline)
> - ("bash" ,bash)))
> -
> + ,@(libiconv-if-needed)
> + ,@(if (mingw-target?) '()
> +   `(("bash" ,bash)

One line please.

> @@ -167,7 +172,11 @@ without requiring the source code to be rewritten.")
>(let ((bash (assoc-ref inputs "bash")))
>  (substitute* "module/ice-9/popen.scm"
>(("/bin/sh")
> -   (string-append bash "/bin/bash")
> +   ,(if (mingw-target?)
> +"cmd.exe"
> +`(if bash
> + (string-append bash "/bin/bash")
> + "bash"))
>  %standard-phases)))

I guess the thing is, cmd.exe is part of the system, so it should be
linked "dynamically" (i.e. via the PATH); but is cmd.exe really a bash
replacement?  Is this the right way for open-pipe in Guile to work?

Finally at the very end of all of this I think it would be great to have
some kind of document, "how to compile software for windows using
Guix".   WDYT?  That document could include any relevant details about
the internal structure of a cross-compile -- how Guix links things
together.  I know that for me, this information is vey easily paged
out to long-term storage; takes a while to pull it back in :)

Andy



[PATCH v6 01/10] gnu: cross: Use CROSS_*_INCLUDE_PATH for system headers.

2016-04-27 Thread Jan Nieuwenhuizen
Hi!

Highlights in this iteration

   * removed indentation from commit messages
   * replaced and-let* with and=>
   * have added #:phases return #t
   * removed extra cross-gcc mingw configure flags
   * removed custom cross-gcc-mingw install phase
   * use name "libc" instead of "mingw-w64", allowing a clean-up
   * add some comments
   * document gcc-cross-environment-variables.patch harder

Usage
./pre-inst-env guix build --target=i686-w64-mingw32 guile

Greetings,
Jan

>From b9b3059fee137152b1155c1aff590659ddb3c7f9 Mon Sep 17 00:00:00 2001
From: Jan Nieuwenhuizen 
Date: Tue, 26 Apr 2016 10:51:52 +0200
Subject: [PATCH 01/10] gnu: cross: Use CROSS_*_INCLUDE_PATH for system
 headers.

* gnu/packages/patches/gcc-cross-environment-variables.patch: Also use CROSS_
variants: CROSS_C_INCLUDE_PATH, CROSS_CPLUS_INCLUDE_PATH,
CROSS_OBJC_INCLUDE_PATH, CROSS_OBJCPLUS_INCLUDE_PATH to be used for system
libraries, see
https://lists.gnu.org/archive/html/guix-devel/2016-04/msg00620.html.
* gnu/packages/cross-base.scm (cross-gcc, cross-gcc-arguments, cross-libc):
Use CROSS_*_INCLUDE_PATH (WAS: CPATH).
---
 gnu/packages/cross-base.scm| 70 +++---
 .../patches/gcc-cross-environment-variables.patch  | 82 +-
 2 files changed, 107 insertions(+), 45 deletions(-)

diff --git a/gnu/packages/cross-base.scm b/gnu/packages/cross-base.scm
index 8bd599c..60cc1e4 100644
--- a/gnu/packages/cross-base.scm
+++ b/gnu/packages/cross-base.scm
@@ -1,6 +1,7 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2013, 2014, 2015, 2016 Ludovic Courtès 
 ;;; Copyright © 2014, 2015 Mark H Weaver 
+;;; Copyright © 2016 Jan Nieuwenhuizen 
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -166,36 +167,40 @@ may be either a libc package or #f.)"
   `(alist-cons-before
 'configure 'set-cross-path
 (lambda* (#:key inputs #:allow-other-keys)
-  ;; Add the cross Linux headers to CROSS_CPATH, and remove them
-  ;; from CPATH.
+  ;; Add the cross Linux headers to CROSS_C_*_INCLUDE_PATH,
+  ;; and remove them from C_*INCLUDE_PATH.
   (let ((libc  (assoc-ref inputs "libc"))
 (linux (assoc-ref inputs "xlinux-headers")))
 (define (cross? x)
   ;; Return #t if X is a cross-libc or cross Linux.
   (or (string-prefix? libc x)
   (string-prefix? linux x)))
-
-(setenv "CROSS_CPATH"
-(string-append libc "/include:"
-   linux "/include"))
+(let ((cpath (string-append
+  libc "/include"
+  ":" linux "/include")))
+  (for-each (cut setenv <> cpath)
+'("CROSS_C_INCLUDE_PATH"
+  "CROSS_CPLUS_INCLUDE_PATH"
+  "CROSS_OBJC_INCLUDE_PATH"
+  "CROSS_OBJCPLUS_INCLUDE_PATH")))
 (setenv "CROSS_LIBRARY_PATH"
 (string-append libc "/lib"))
-
-(let ((cpath   (search-path-as-string->list
-(getenv "C_INCLUDE_PATH")))
-  (libpath (search-path-as-string->list
-(getenv "LIBRARY_PATH"
-  (setenv "CPATH"
-  (list->search-path-as-string
-   (remove cross? cpath) ":"))
-  (for-each unsetenv
-'("C_INCLUDE_PATH" "CPLUS_INCLUDE_PATH"))
-  (setenv "LIBRARY_PATH"
-  (list->search-path-as-string
-   (remove cross? libpath) ":"))
-  #t)))
-,phases)
-  phases)))
+(for-each
+ (lambda (var)
+   (and=> (getenv var)
+  (lambda (value)
+(let* ((path (search-path-as-string->list value))
+   (native-path (list->search-path-as-string
+ (remove cross? path) ":")))
+  (setenv var native-path)
+  '("C_INCLUDE_PATH"
+"CPLUS_INCLUDE_PATH"
+"OBJC_INCLUDE_PATH"
+"OBJCPLUS_INCLUDE_PATH"
+"LIBRARY_PATH"))
+#t))
+,phases))
+  (else phases)))
 
 (define (cross-gcc-patches target)
   "Return GCC patches needed for TARGET."
@@ -261,7 +266,16 @@