diff mbox series

[bug#54560,01/47] gnu: Add go-google-golang-org-protobuf.

Message ID 20220325133211.5128-1-hello@lnikki.la
State New
Headers show
Series [bug#54560,01/47] gnu: Add go-google-golang-org-protobuf. | expand

Commit Message

Leo Nikkilä March 25, 2022, 1:31 p.m. UTC
* gnu/packages/golang.scm (go-google-golang-org-protobuf): New variable.
---
 gnu/packages/golang.scm | 43 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

Comments

M March 25, 2022, 7:09 p.m. UTC | #1
Leo Nikkilä schreef op vr 25-03-2022 om 15:31 [+0200]:
> +(define-public go-google-golang-org-protobuf

(A part of) this is already in Guix, see go-github-com-golang-protobuf-
proto.  Possibly relevant: <https://issues.guix.gnu.org/48259>.

Greetings,
Maxime.
M March 25, 2022, 7:15 p.m. UTC | #2
Leo Nikkilä schreef op vr 25-03-2022 om 15:31 [+0200]:
> +       (let ((glob-path "google.golang.org/protobuf/..."))
> +         (modify-phases %standard-phases
> +           (replace 'build
> +             (lambda args
> +               (apply (assoc-ref %standard-phases
> +                                 'build)
> +                      `(,@args #:import-path
> +                        ,glob-path))))

What are ‘glob paths’ here?  They don't appear to be used anywhere else
in Guix.  What's the problem with the default build phase?
Leo Nikkilä March 25, 2022, 10:55 p.m. UTC | #3
> see go-github-com-golang-protobuf-proto.

I clarified the difference between github.com/golang/protobuf and google.golang.org/protobuf under 03/47.

Should <https://issues.guix.gnu.org/48259> be applied, the separate `-proto` and `-ptypes` packages could certainly be replaced by the merged package.

> What are ‘glob paths’ here?  They don't appear to be used anywhere else
> in Guix.  What's the problem with the default build phase?

There's no top-level package in google.golang.org/protobuf, instead the repository consists of individual packages which depend on each other.

Looking at (gnu packages golang), I see two ways this has been dealt with before: splitting each one into multiple Guix packages, or building all of the packages together in one Guix package.

There are many of these packages in the repository [0], and another list of "internal" packages [1]. (This listing doesn't cover all of them, some are deeper within the tree.) In order to use this library you'll need most of them, and splitting each one into a separate Guix package feels unnecessary.

There are examples in (gnu packages golang) where a single Guix package contains many Golang packages, e.g. go-github-com-blanu-dust, redefining build phases to reduce a list of packages instead.

However, the number of these packages makes this approach difficult. The list of internal packages is not considered public nor stable; these are added and removed between releases. Maintaining a list of these within Guix seems prone to breaking during the update process.

`go build' and others support wildcards [2], which are also used within build scripts of the library [3]. Since the upstream build makes use of these, I thought they would be fair game to build it.

However, due to how go-build-system correlates these import paths with directory paths, supporting wildcards in `#:import-path` directly would require further changes to the build system.

Adapting how go-github-com-blanu-dust and others call these build phases directly, I found this to be the simplest way to use the wildcard capability, and avoid having to maintain a list of the packages within Guix directly.

Happy to try out other approaches, this is just what I came up with earlier.

I should've also specified `wildcard' instead of `glob' when naming this.

[0]: https://github.com/protocolbuffers/protobuf-go#package-ind
[1]: https://github.com/protocolbuffers/protobuf-go/tree/v1.27.1/internal
[2]: https://pkg.go.dev/cmd/go#hdr-Package_lists_and_patterns
[3]: https://github.com/protocolbuffers/protobuf-go/blob/v1.27.1/integration_test.go#L118-L120
M March 26, 2022, 9:31 a.m. UTC | #4
Leo Nikkilä schreef op vr 25-03-2022 om 22:55 [+0000]:
> However, due to how go-build-system correlates these import paths with directory paths, supporting wildcards in `#:import-path` directly would require further changes to the build system.

Looking at go-build-system.scm, it seems that 'unpack, 'install'
and 'install-licenses' need to be modified to drop the "/..." suffix,
if any?  If this is done in go-build-system, then more packages could
benefit and perhaps some existing package definitions could be
simplified.

;; See <https://pkg.go.dev/cmd/go#hdr-Package_lists_and_patterns>
;; for how wildcard paths work.
(define (unwildcard-import-path import-path
  (if (string-suffix? "/..." import-path)
      (string-drop-right import-path 4)
      import-path))

;; in 'unpack', change  
;; (when (string-null? unpack-path)
;;    (set! unpack-path import-path))
;; to
;; (when (string-null? unpack-path)
;;    (set! unpack-path (unwildcard-import-path unpack-path)))
;;
;; and likewise in 'install' and and 'install-license-files'.

Greetings,
Maxime.
diff mbox series

Patch

diff --git a/gnu/packages/golang.scm b/gnu/packages/golang.scm
index a8b845e301..455c4daf30 100644
--- a/gnu/packages/golang.scm
+++ b/gnu/packages/golang.scm
@@ -33,6 +33,7 @@ 
 ;;; Copyright © 2021 Chadwain Holness <chadwainholness@gmail.com>
 ;;; Copyright © 2021 Philip McGrath <philip@philipmcgrath.com>
 ;;; Copyright © 2021 Lu Hui <luhux76@gmail.com>
+;;; Copyright © 2022 Leo Nikkilä <hello@lnikki.la>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -9774,3 +9775,45 @@  (define-public go-github-com-go-chi-chi-v5
      "@code{go-github-com-go-chi-chi-v5} is an HTTP router that lets the user
 decompose request handling into many smaller layers.")
     (license license:expat)))
+
+(define-public go-google-golang-org-protobuf
+  (package
+    (name "go-google-golang-org-protobuf")
+    (version "1.27.1")
+    (source (origin
+              (method git-fetch)
+              (uri (git-reference
+                    (url "https://github.com/protocolbuffers/protobuf-go")
+                    (commit (string-append "v" version))))
+              (file-name (git-file-name name version))
+              (sha256
+               (base32
+                "0aszb7cv8fq1m8akgd4kjyg5q7g5z9fdqnry6057ygq9r8r2yif2"))))
+    (build-system go-build-system)
+    (arguments
+     '(#:import-path "google.golang.org/protobuf"
+       #:phases
+       (let ((glob-path "google.golang.org/protobuf/..."))
+         (modify-phases %standard-phases
+           (replace 'build
+             (lambda args
+               (apply (assoc-ref %standard-phases
+                                 'build)
+                      `(,@args #:import-path
+                        ,glob-path))))
+           (replace 'check
+             (lambda args
+               (apply (assoc-ref %standard-phases
+                                 'check)
+                      `(,@args #:import-path
+                        ,glob-path))))))))
+    (native-inputs (list go-github-com-google-go-cmp-cmp))
+    (synopsis "Go support for Google's protocol buffers")
+    (description
+     "Go implementation for protocol buffers, which is a
+language-neutral, platform-neutral, extensible mechanism for serializing
+structured data.  The protocol buffer language is a language for
+specifying the schema for structured data.  This schema is compiled into
+language specific bindings.")
+    (home-page "https://github.com/protocolbuffers/protobuf-go")
+    (license license:bsd-3)))