Re: gnu: Add Go build system.

2016-12-16 Thread Petter

On 2016-12-16 03:05, Leo Famulari wrote:

On Sun, Dec 11, 2016 at 01:17:48AM +0100, Petter wrote:

+(define* (build #:key import-path #:allow-other-keys)
+  (system* "go" "install" import-path))
+
+(define* (install #:key inputs outputs #:allow-other-keys)
+  (copy-recursively "bin" (string-append (assoc-ref outputs "out") 
"/bin"))
+  (copy-recursively "pkg" (string-append (assoc-ref outputs "out") 
"/pkg"))
+  (copy-recursively "src" (string-append (assoc-ref outputs "out") 
"/src")))


It looks like `go install` knows "where" to install the files, but
installs them in the wrong place, and then we copy them into place in
the install phase. I think it's inefficient to move the files twice.

Can the build phase use something like `go build`, followed by the
install phase using `go install` to move the files directly to the
package's output directory in /gnu/store?


The differences between `go install` and `go build` here is that `go
install` compiles and moves the result to $GOPATH/bin (unless GOBIN is
set to somewhere else).

`go build` compiles (always from source I believe) and leaves the
resulting binary in current directory.

`go install` compiles and also creates package objects in pkg/ which I
believe is a compiled object that is compiled once and then reused,
unless source is changed. Not sure if timestamps are used to determine
whether source has changed, and how that works on Guix.

Optimizations could be made for sure, I will look at this at
convenience.

On 2016-12-16 05:49, Leo Famulari wrote:

On Sun, Dec 11, 2016 at 01:17:48AM +0100, Petter wrote:

From 4c0597a95ae3cd111ef12d675edf501c559458ba Mon Sep 17 00:00:00 2001
From: Petter <pet...@mykolab.ch>
Date: Sun, 11 Dec 2016 01:10:09 +0100
Subject: [PATCH] gnu: Add Go build system.

* guix/build-system/go.scm: New file
* guix/build/go-build-system.scm: New file.


Another question: does this build system try to run tests? In my own
Syncthing packaging I used `go run build.go test`, but I noticed that
your Syncthing package built with this build system doesn't seem to run
the tests.


No. It only builds/installs at the moment. Tests, docs,
cross-compilation and other things (if there are more things), are not
dealt with at this point.

Note that Syncthing uses their own build program (build.go). This is
atypical. There will be a test phase, and Syncthing will override this
with their way of running tests.

Regarding cross-compilation. Go supports: 386, amd64, amd64p32, arm,
arm64, mips64, mips64le, ppc64, ppc64le and s390x as far as I can
tell. With mips32 being added in February. I have yet to discover how
the build system should deal with cross-compilations. The Go part is
easy, just set the GOARCH environment variable before compiling.
`GOARCH=mips64 go install ...`



Re: gnu: Add Go build system.

2016-12-15 Thread Leo Famulari
On Sun, Dec 11, 2016 at 01:17:48AM +0100, Petter wrote:
> From 4c0597a95ae3cd111ef12d675edf501c559458ba Mon Sep 17 00:00:00 2001
> From: Petter <pet...@mykolab.ch>
> Date: Sun, 11 Dec 2016 01:10:09 +0100
> Subject: [PATCH] gnu: Add Go build system.
> 
> * guix/build-system/go.scm: New file
> * guix/build/go-build-system.scm: New file.

Another question: does this build system try to run tests? In my own
Syncthing packaging I used `go run build.go test`, but I noticed that
your Syncthing package built with this build system doesn't seem to run
the tests.



Re: gnu: Add Go build system.

2016-12-15 Thread Leo Famulari
On Sun, Dec 11, 2016 at 01:17:48AM +0100, Petter wrote:
> I've made an attempt at making a build system for Go. It seems to
> work, but it's not pretty. My Guix/Guile skills are bad, so keep your
> expectations to a minimum. Consider it something where there was
> nothing.

Thank you for working on this!

> I started with a copy of the GNU build system, removed code I felt
> wasn't necessary, then adapted to Go's needs. Note, comments and those
> first text string after a (define) have not been updated. Unnecessary
> #:use-modules have not been removed. In short, it's bad and there's a
> lot to do make it ok-ish. That's where you come in :)

I haven't contributed or carefully studied the other build systems yet,
so my feedback will be rather superficial. I hope somebody with some
more knowledge will jump in :)

> Subject: [PATCH] gnu: Add Go build system.
> 
> * guix/build-system/go.scm: New file
> * guix/build/go-build-system.scm: New file.

> diff --git a/guix/build/go-build-system.scm b/guix/build/go-build-system.scm

> +(define* (build #:key import-path #:allow-other-keys)
> +  (system* "go" "install" import-path))
> +
> +(define* (install #:key inputs outputs #:allow-other-keys)
> +  (copy-recursively "bin" (string-append (assoc-ref outputs "out") "/bin"))
> +  (copy-recursively "pkg" (string-append (assoc-ref outputs "out") "/pkg"))
> +  (copy-recursively "src" (string-append (assoc-ref outputs "out") "/src")))

It looks like `go install` knows "where" to install the files, but
installs them in the wrong place, and then we copy them into place in
the install phase. I think it's inefficient to move the files twice.

Can the build phase use something like `go build`, followed by the
install phase using `go install` to move the files directly to the
package's output directory in /gnu/store?



gnu: Add Go build system.

2016-12-10 Thread Petter

Hi,

I've made an attempt at making a build system for Go. It seems to
work, but it's not pretty. My Guix/Guile skills are bad, so keep your
expectations to a minimum. Consider it something where there was
nothing.

I started with a copy of the GNU build system, removed code I felt
wasn't necessary, then adapted to Go's needs. Note, comments and those
first text string after a (define) have not been updated. Unnecessary
#:use-modules have not been removed. In short, it's bad and there's a
lot to do make it ok-ish. That's where you come in :)

I'll add Syncthing, a sizeable Go project, and its dependencies in a
later e-mail. These recipes uses this Go build system, and my primary
goal has been to make these nice, while functional. Now we can
hopefully work on the build system with a minimum of modifications to
the recipes.


Happy hacking!
PetterFrom 4c0597a95ae3cd111ef12d675edf501c559458ba Mon Sep 17 00:00:00 2001
From: Petter <pet...@mykolab.ch>
Date: Sun, 11 Dec 2016 01:10:09 +0100
Subject: [PATCH] gnu: Add Go build system.

* guix/build-system/go.scm: New file
* guix/build/go-build-system.scm: New file.
---
 guix/build-system/go.scm   | 193 +
 guix/build/go-build-system.scm | 186 +++
 2 files changed, 379 insertions(+)
 create mode 100644 guix/build-system/go.scm
 create mode 100644 guix/build/go-build-system.scm

diff --git a/guix/build-system/go.scm b/guix/build-system/go.scm
new file mode 100644
index 000..f336f20
--- /dev/null
+++ b/guix/build-system/go.scm
@@ -0,0 +1,193 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2016 Petter <pet...@mykolab.ch>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (guix build-system go)
+  #:use-module (guix store)
+  #:use-module (guix utils)
+  #:use-module (guix combinators)
+  #:use-module (guix derivations)
+  #:use-module (guix search-paths)
+  #:use-module (guix build-system)
+  #:use-module (guix packages)
+  #:use-module (gnu packages base)
+  #:use-module (gnu packages golang)
+  #:use-module (srfi srfi-1)
+  #:use-module (ice-9 match)
+  #:export (%go-build-system-modules
+go-build
+go-build-system
+sourcestuff
+standard-packages))
+
+;; Commentary:
+;;
+;; Standard build procedure for packages using the GNU Build System or
+;; something compatible ("./configure && make && make install").
+;;
+;; Code:
+
+(define %go-build-system-modules
+  ;; Build-side modules imported and used by default.
+  '((guix build go-build-system)
+(guix build utils)
+(guix build gremlin)
+(guix elf)))
+
+(define %default-modules
+  ;; Modules in scope in the build-side environment.
+  '((guix build go-build-system)
+(guix build utils)))
+
+(define* (lower name
+#:key source inputs native-inputs outputs target
+(implicit-inputs? #t) (implicit-cross-inputs? #t)
+(strip-binaries? #t) system
+#:allow-other-keys
+#:rest arguments)
+  "Return a bag for NAME from the given arguments."
+  (define private-keywords
+`(#:source #:inputs #:native-inputs #:outputs
+  #:implicit-inputs? #:implicit-cross-inputs?
+  ,@(if target '() '(#:target
+
+  (bag
+(name name)
+(system system) (target target)
+(build-inputs `(,@(if source
+  `(("source" ,source)))
+("go" ,go)
+,@native-inputs))
+(host-inputs inputs)
+
+(build (if target gnu-cross-build go-build))
+(arguments (strip-keyword-arguments private-keywords arguments
+
+(define* (go-build store name input-drvs
+#:key (guile #f)
+(outputs '("out"))
+(search-paths '())
+(configure-flags ''())
+(make-flags ''())
+(out-of-source? #f)
+(tests? #t)
+(import-path "")
+(unpack-path "")
+(test-target "check")
+(parallel-build? #t)
+(parallel-tests? #t)
+(