Subject: [PATCH rust-team 16/46] gnu: Add rust-prost-build-0.12.

From: Tomas Volf <[email-masked]>
Date: Thu, 15 Feb 2024 21:26:29 +0100

* gnu/packages/crates-io.scm (rust-prost-build-0.12): New variable.

Change-Id: I2a44bdae93d7db60cb7705a552f85205e99409a2
---
 gnu/packages/crates-io.scm | 59 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)

diff --git a/gnu/packages/crates-io.scm b/gnu/packages/crates-io.scm
index 6465099784..771e9939a7 100644
--- a/gnu/packages/crates-io.scm
+++ b/gnu/packages/crates-io.scm
@@ -103,6 +103,7 @@ (define-module (gnu packages crates-io)
   #:use-module (gnu packages pcre)
   #:use-module (gnu packages perl)
   #:use-module (gnu packages pkg-config)
+  #:use-module (gnu packages protobuf)
   #:use-module (gnu packages pulseaudio)
   #:use-module (gnu packages python)
   #:use-module (gnu packages rust)
@@ -49609,6 +49610,64 @@ (define-public rust-prost-0.12
 Language.")
     (license license:asl2.0)))
 
+(define-public rust-prost-build-0.12
+  (package
+    (name "rust-prost-build")
+    (version "0.12.3")
+    (source
+     (origin
+       (method url-fetch)
+       (uri (crate-uri "prost-build" version))
+       (file-name (string-append name "-" version ".tar.gz"))
+       (modules '((ice-9 string-fun)
+                  (ice-9 textual-ports)))
+       (snippet
+        #~(let* ((fname "src/lib.rs")
+                 (data-old (call-with-input-file fname get-string-all))
+                 (data-new (string-replace-substring
+                            data-old
+                            "env::var_os(\"PROTOC\")
+        .map(PathBuf::from)
+        .or_else(|| which::which(\"protoc\").ok())
+        .expect(&msg)"
+                            (string-append
+                             "PathBuf::from(\""
+                             #$protobuf
+                             "/bin/protoc\")"))))
+            (if (string=? data-old data-new)
+                (error "Nothing replaced, phase needs an update."))
+            (call-with-output-file fname
+              (lambda (port)
+                (display data-new port)))))
+       (sha256
+        (base32 "1lp2l1l65l163yggk9nw5mjb2fqwzz12693af5phn1v0abih4pn5"))))
+    (build-system cargo-build-system)
+    (arguments
+     `(#:skip-build? #t
+       #:cargo-inputs (("rust-bytes" ,rust-bytes-1)
+                       ("rust-heck" ,rust-heck-0.4)
+                       ("rust-itertools" ,rust-itertools-0.10)
+                       ("rust-log" ,rust-log-0.4)
+                       ("rust-multimap" ,rust-multimap-0.8)
+                       ("rust-once-cell" ,rust-once-cell-1)
+                       ("rust-petgraph" ,rust-petgraph-0.6)
+                       ("rust-prettyplease" ,rust-prettyplease-0.2)
+                       ("rust-prost" ,rust-prost-0.12)
+                       ("rust-prost-types" ,rust-prost-types-0.12)
+                       ("rust-pulldown-cmark" ,rust-pulldown-cmark-0.9)
+                       ("rust-pulldown-cmark-to-cmark" ,rust-pulldown-cmark-to-cmark-10)
+                       ("rust-regex" ,rust-regex-1)
+                       ("rust-syn" ,rust-syn-2)
+                       ("rust-tempfile" ,rust-tempfile-3)
+                       ("rust-which" ,rust-which-4))
+       #:cargo-native-inputs (("protobuf" ,protobuf))))
+    (home-page "https://github.com/tokio-rs/prost")
+    (synopsis "A Protocol Buffers implementation for the Rust Language")
+    (description
+     "@code{prost-build} makes it easy to generate Rust code from
+@code{.proto} files as part of a Cargo build.")
+    (license license:asl2.0)))
+
 (define-public rust-prost-0.9
   (package
     (name "rust-prost")
-- 
2.41.0