* [bug#49823] [PATCH] gnu: Add jsonnet.
@ 2021-08-02 15:01 Vivien Kraus via Guix-patches via
2021-08-02 16:15 ` [bug#49823] Using texinfo for the description Vivien Kraus via Guix-patches via
2021-08-10 12:58 ` [bug#49823] [PATCH] gnu: Add jsonnet Ludovic Courtès
0 siblings, 2 replies; 11+ messages in thread
From: Vivien Kraus via Guix-patches via @ 2021-08-02 15:01 UTC (permalink / raw)
To: 49823
[-- Attachment #1: Type: text/plain, Size: 547 bytes --]
Hello,
Here is jsonnet. I don’t fully understand what it does, but thanks to
leoprikler, I know it is a dependency to package GraalJS, an
interpreter for JavaScript on the Java Virtual Machine.
For the sake of having "no dependencies", it bundles a custom
implementation of MD5. According to a comment in the associated
license, it is taken from the implementation of bzflag, but it does not
seem to use the same as of today.
I decided to use nettle, and add a few lines of C++ to shape it into
the required interface.
Best regards,
Vivien
[-- Attachment #2: 0001-gnu-Add-jsonnet.patch --]
[-- Type: text/x-patch, Size: 4280 bytes --]
From 7cfbec67974d03c6e7dd56e4e2ade95f38faad6a Mon Sep 17 00:00:00 2001
From: Vivien Kraus <vivien@planete-kraus.eu>
Date: Mon, 2 Aug 2021 16:07:08 +0200
Subject: [PATCH] gnu: Add jsonnet.
* gnu/packages/cpp.scm (jsonnet): New variable.
---
gnu/packages/cpp.scm | 103 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 103 insertions(+)
diff --git a/gnu/packages/cpp.scm b/gnu/packages/cpp.scm
index 42e9d50687..4e51c4a0cc 100644
--- a/gnu/packages/cpp.scm
+++ b/gnu/packages/cpp.scm
@@ -63,6 +63,7 @@
#:use-module (gnu packages llvm)
#:use-module (gnu packages logging)
#:use-module (gnu packages maths)
+ #:use-module (gnu packages nettle)
#:use-module (gnu packages onc-rpc)
#:use-module (gnu packages perl)
#:use-module (gnu packages pkg-config)
@@ -1211,3 +1212,105 @@ of reading and writing XML.")
;; incompatible with the GPL v2. Refer to the file named FLOSSE for the
;; details.
(license license:gpl2+)))
+
+(define-public jsonnet
+ (package
+ (name "jsonnet")
+ (version "0.17.0")
+ (source
+ (origin
+ (method git-fetch)
+ (uri (git-reference
+ (url "https://github.com/google/jsonnet")
+ (commit (string-append "v" version))))
+ (file-name (git-file-name name version))
+ (sha256
+ (base32 "1ddz14699v5lqx3dh0mb7hfffr6fk5zhmzn3z8yxkqqvriqnciim"))
+ (modules '((guix build utils)))
+ (snippet
+ '(begin
+ (delete-file-recursively "third_party")
+ (delete-file-recursively "doc/third_party")
+ (substitute*
+ '("core/vm.cpp")
+ (("#include \"json.hpp\"") "#include <nlohmann/json.hpp>"))
+ (mkdir-p "third_party/md5")
+ (call-with-output-file "third_party/md5/CMakeLists.txt"
+ (lambda (port)
+ (format port "add_library(md5 STATIC md5.cpp md5.h)
+find_package(PkgConfig REQUIRED)
+pkg_check_modules(NETTLE REQUIRED nettle)
+target_link_libraries(md5 ${NETTLE_LIBRARIES})
+target_include_directories(md5 PUBLIC ${NETTLE_INCLUDE_DIRS})
+")))
+ (call-with-output-file "third_party/md5/md5.h"
+ (lambda (port)
+ (format port "#ifndef BZF_MD5_H
+#define BZF_MD5_H
+#include <string>
+
+// Return the hexadecimal digest.
+std::string md5 (const std::string str);
+
+#endif
+")))
+ (call-with-output-file "third_party/md5/md5.cpp"
+ (lambda (port)
+ (format port "#include \"md5.h\"
+#include <nettle/md5.h>
+#include <nettle/base16.h>
+#include <string>
+#include <vector>
+
+#define OUTPUT_LENGTH BASE16_ENCODE_LENGTH (MD5_DIGEST_SIZE)
+
+std::string
+md5 (const std::string str)
+{
+ // Convert str to a byte array
+ std::vector<uint8_t> input (str.begin (), str.end ());
+
+ // Compute the digest
+ struct md5_ctx nettle_ctx;
+ md5_init (&nettle_ctx);
+ md5_update (&nettle_ctx, input.size (), input.data ());
+ uint8_t digest[MD5_DIGEST_SIZE];
+ md5_digest (&nettle_ctx, MD5_DIGEST_SIZE, digest);
+
+ // Encode it to base16
+ std::vector<char> encoded (BASE16_ENCODE_LENGTH (MD5_DIGEST_SIZE));
+ base16_encode_update (encoded.data (), MD5_DIGEST_SIZE, digest);
+ std::string final_digest (encoded.begin (), encoded.end ());
+ return final_digest;
+}
+")))))))
+ (build-system cmake-build-system)
+ (arguments
+ `(#:configure-flags '("-DUSE_SYSTEM_GTEST=ON" "-DUSE_SYSTEM_JSON=ON")))
+ (propagated-inputs
+ '())
+ (native-inputs
+ `(("googletest" ,googletest)
+ ("pkg-config" ,pkg-config)))
+ (inputs
+ `(("json-modern-cxx" ,json-modern-cxx)
+ ;; jsonnet uses a md5 implementation claiming to be from
+ ;; https://www.bzflag.org/, but they don’t use it anymore. We
+ ;; replace it with md5 from nettle.
+ ("nettle" ,nettle)))
+ (home-page "https://jsonnet.org/")
+ (synopsis "The data templating language")
+ (description "A data templating language for app and tool developers:
+- Generate config data
+- Side-effect free
+- Organize, simplify, unify
+- Manage sprawling config
+
+A simple extension of JSON
+- Open source (Apache 2.0)
+- Familiar syntax
+- Reformatter, linter
+- Editor & IDE integrations
+- Formally specified
+")
+ (license license:asl2.0)))
--
2.32.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [bug#49823] Using texinfo for the description
2021-08-02 15:01 [bug#49823] [PATCH] gnu: Add jsonnet Vivien Kraus via Guix-patches via
@ 2021-08-02 16:15 ` Vivien Kraus via Guix-patches via
2021-08-02 16:35 ` Maxime Devos
2021-08-10 12:58 ` [bug#49823] [PATCH] gnu: Add jsonnet Ludovic Courtès
1 sibling, 1 reply; 11+ messages in thread
From: Vivien Kraus via Guix-patches via @ 2021-08-02 16:15 UTC (permalink / raw)
To: 49823
[-- Attachment #1: Type: text/plain, Size: 459 bytes --]
maximed told me I could use texinfo in the description.
(I also removed a couple of lines in the C++ source because the
constant was not used.)
Also, I was advised to put the added source code in a local-file such
as what is done by gnuzilla, but I could not figure out how it was done
for gnuzilla (the package is quite large). If I go with a patch, there
are a lot of things that get deleted, so it makes a rather large patch.
What do you think?
Vivien
[-- Attachment #2: 0001-gnu-Add-jsonnet.patch --]
[-- Type: text/x-patch, Size: 4301 bytes --]
From 7fb706951904f58cb3dd8963885024f7d9383c0b Mon Sep 17 00:00:00 2001
From: Vivien Kraus <vivien@planete-kraus.eu>
Date: Mon, 2 Aug 2021 16:07:08 +0200
Subject: [PATCH] gnu: Add jsonnet.
* gnu/packages/cpp.scm (jsonnet): New variable.
---
gnu/packages/cpp.scm | 105 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 105 insertions(+)
diff --git a/gnu/packages/cpp.scm b/gnu/packages/cpp.scm
index 42e9d50687..318e387069 100644
--- a/gnu/packages/cpp.scm
+++ b/gnu/packages/cpp.scm
@@ -63,6 +63,7 @@
#:use-module (gnu packages llvm)
#:use-module (gnu packages logging)
#:use-module (gnu packages maths)
+ #:use-module (gnu packages nettle)
#:use-module (gnu packages onc-rpc)
#:use-module (gnu packages perl)
#:use-module (gnu packages pkg-config)
@@ -1211,3 +1212,107 @@ of reading and writing XML.")
;; incompatible with the GPL v2. Refer to the file named FLOSSE for the
;; details.
(license license:gpl2+)))
+
+(define-public jsonnet
+ (package
+ (name "jsonnet")
+ (version "0.17.0")
+ (source
+ (origin
+ (method git-fetch)
+ (uri (git-reference
+ (url "https://github.com/google/jsonnet")
+ (commit (string-append "v" version))))
+ (file-name (git-file-name name version))
+ (sha256
+ (base32 "1ddz14699v5lqx3dh0mb7hfffr6fk5zhmzn3z8yxkqqvriqnciim"))
+ (modules '((guix build utils)))
+ (snippet
+ '(begin
+ (delete-file-recursively "third_party")
+ (delete-file-recursively "doc/third_party")
+ (substitute*
+ '("core/vm.cpp")
+ (("#include \"json.hpp\"") "#include <nlohmann/json.hpp>"))
+ (mkdir-p "third_party/md5")
+ (call-with-output-file "third_party/md5/CMakeLists.txt"
+ (lambda (port)
+ (format port "add_library(md5 STATIC md5.cpp md5.h)
+find_package(PkgConfig REQUIRED)
+pkg_check_modules(NETTLE REQUIRED nettle)
+target_link_libraries(md5 ${NETTLE_LIBRARIES})
+target_include_directories(md5 PUBLIC ${NETTLE_INCLUDE_DIRS})
+")))
+ (call-with-output-file "third_party/md5/md5.h"
+ (lambda (port)
+ (format port "#ifndef BZF_MD5_H
+#define BZF_MD5_H
+#include <string>
+
+// Return the hexadecimal digest.
+std::string md5 (const std::string str);
+
+#endif
+")))
+ (call-with-output-file "third_party/md5/md5.cpp"
+ (lambda (port)
+ (format port "#include \"md5.h\"
+#include <nettle/md5.h>
+#include <nettle/base16.h>
+#include <string>
+#include <vector>
+
+std::string
+md5 (const std::string str)
+{
+ // Convert str to a byte array
+ std::vector<uint8_t> input (str.begin (), str.end ());
+
+ // Compute the digest
+ struct md5_ctx nettle_ctx;
+ md5_init (&nettle_ctx);
+ md5_update (&nettle_ctx, input.size (), input.data ());
+ uint8_t digest[MD5_DIGEST_SIZE];
+ md5_digest (&nettle_ctx, MD5_DIGEST_SIZE, digest);
+
+ // Encode it to base16
+ std::vector<char> encoded (BASE16_ENCODE_LENGTH (MD5_DIGEST_SIZE));
+ base16_encode_update (encoded.data (), MD5_DIGEST_SIZE, digest);
+ std::string final_digest (encoded.begin (), encoded.end ());
+ return final_digest;
+}
+")))))))
+ (build-system cmake-build-system)
+ (arguments
+ `(#:configure-flags '("-DUSE_SYSTEM_GTEST=ON" "-DUSE_SYSTEM_JSON=ON")))
+ (propagated-inputs
+ '())
+ (native-inputs
+ `(("googletest" ,googletest)
+ ("pkg-config" ,pkg-config)))
+ (inputs
+ `(("json-modern-cxx" ,json-modern-cxx)
+ ;; jsonnet uses a md5 implementation claiming to be from
+ ;; https://www.bzflag.org/, but they don’t use it anymore. We
+ ;; replace it with md5 from nettle.
+ ("nettle" ,nettle)))
+ (home-page "https://jsonnet.org/")
+ (synopsis "The data templating language")
+ (description "A data templating language for app and tool developers:
+@itemize
+@item Generate config data
+@item Side-effect free
+@item Organize, simplify, unify
+@item Manage sprawling config
+@end itemize
+
+A simple extension of JSON:
+@itemize
+@item Open source (Apache 2.0)
+@item Familiar syntax
+@item Reformatter, linter
+@item Editor & IDE integrations
+@item Formally specified
+@end itemize
+")
+ (license license:asl2.0)))
--
2.32.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [bug#49823] Using texinfo for the description
2021-08-02 16:15 ` [bug#49823] Using texinfo for the description Vivien Kraus via Guix-patches via
@ 2021-08-02 16:35 ` Maxime Devos
2021-08-02 17:09 ` Vivien Kraus via Guix-patches via
0 siblings, 1 reply; 11+ messages in thread
From: Maxime Devos @ 2021-08-02 16:35 UTC (permalink / raw)
To: Vivien Kraus, 49823
[-- Attachment #1: Type: text/plain, Size: 1107 bytes --]
Vivien Kraus via Guix-patches via schreef op ma 02-08-2021 om 18:15 [+0200]:
> maximed told me I could use texinfo in the description.
>
> (I also removed a couple of lines in the C++ source because the
> constant was not used.)
>
> Also, I was advised to put the added source code in a local-file such
> as what is done by gnuzilla, but I could not figure out how it was done
> for gnuzilla (the package is quite large).
Something like this should work (untested):
(package
(origin
[...]
(snippet
#~(begin
[...]
(delete-file "third_party/md5/md5.cpp") ; maybe not necessary?
(copy-file #+(search-auxiliary-file "jsonnet-md5.cpp")
"third_party/md5/md5.cpp")
[...])))
[...])
> If I go with a patch, there
> are a lot of things that get deleted, so it makes a rather large patch.
"git diff" has an option "--irreversible-deletes" and "--break-rewrites"
which should reduce the size of the patch, by not including the previous
version.
> What do you think?
>
> Vivien
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 260 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* [bug#49823] Using texinfo for the description
2021-08-02 16:35 ` Maxime Devos
@ 2021-08-02 17:09 ` Vivien Kraus via Guix-patches via
2021-08-02 17:52 ` Leo Prikler
0 siblings, 1 reply; 11+ messages in thread
From: Vivien Kraus via Guix-patches via @ 2021-08-02 17:09 UTC (permalink / raw)
To: Maxime Devos, 49823
[-- Attachment #1: Type: text/plain, Size: 242 bytes --]
Le lundi 02 août 2021 à 18:35 +0200, Maxime Devos a écrit :
> Something like this should work (untested):
>
> (package
> (origin
> [...]
> (snippet
> #~(begin
I didn’t know snippets could be Gexps. Thank you.
[-- Attachment #2: 0001-gnu-Add-jsonnet.patch --]
[-- Type: text/x-patch, Size: 6449 bytes --]
From a13f36497aebb37c4d68c9d0a88eb522eb7afff0 Mon Sep 17 00:00:00 2001
From: Vivien Kraus <vivien@planete-kraus.eu>
Date: Mon, 2 Aug 2021 16:07:08 +0200
Subject: [PATCH] gnu: Add jsonnet.
* gnu/packages/cpp.scm (jsonnet): New variable.
---
Makefile.am | 5 +-
.../aux-files/jsonnet-md5/CMakeLists.txt | 5 ++
gnu/packages/aux-files/jsonnet-md5/md5.cpp | 25 +++++++
gnu/packages/aux-files/jsonnet-md5/md5.h | 8 +++
gnu/packages/cpp.scm | 68 +++++++++++++++++++
5 files changed, 110 insertions(+), 1 deletion(-)
create mode 100644 gnu/packages/aux-files/jsonnet-md5/CMakeLists.txt
create mode 100644 gnu/packages/aux-files/jsonnet-md5/md5.cpp
create mode 100644 gnu/packages/aux-files/jsonnet-md5/md5.h
diff --git a/Makefile.am b/Makefile.am
index d5ec909213..5cac270104 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -390,7 +390,10 @@ AUX_FILES = \
gnu/packages/aux-files/linux-libre/4.4-i686.conf \
gnu/packages/aux-files/linux-libre/4.4-x86_64.conf \
gnu/packages/aux-files/pack-audit.c \
- gnu/packages/aux-files/run-in-namespace.c
+ gnu/packages/aux-files/run-in-namespace.c \
+ gnu/packages/aux-files/jsonnet-md5/CMakeLists.txt \
+ gnu/packages/aux-files/jsonnet-md5/md5.cpp \
+ gnu/packages/aux-files/jsonnet-md5/md5.h
# Templates, examples.
EXAMPLES = \
diff --git a/gnu/packages/aux-files/jsonnet-md5/CMakeLists.txt b/gnu/packages/aux-files/jsonnet-md5/CMakeLists.txt
new file mode 100644
index 0000000000..498ad514e9
--- /dev/null
+++ b/gnu/packages/aux-files/jsonnet-md5/CMakeLists.txt
@@ -0,0 +1,5 @@
+add_library(md5 STATIC md5.cpp md5.h)
+find_package(PkgConfig REQUIRED)
+pkg_check_modules(NETTLE REQUIRED nettle)
+target_link_libraries(md5 ${NETTLE_LIBRARIES})
+target_include_directories(md5 PUBLIC ${NETTLE_INCLUDE_DIRS})
diff --git a/gnu/packages/aux-files/jsonnet-md5/md5.cpp b/gnu/packages/aux-files/jsonnet-md5/md5.cpp
new file mode 100644
index 0000000000..b8fcb536dd
--- /dev/null
+++ b/gnu/packages/aux-files/jsonnet-md5/md5.cpp
@@ -0,0 +1,25 @@
+#include "md5.h"
+#include <nettle/md5.h>
+#include <nettle/base16.h>
+#include <string>
+#include <vector>
+
+std::string
+md5 (const std::string str)
+{
+ // Convert str to a byte array
+ std::vector<uint8_t> input (str.begin (), str.end ());
+
+ // Compute the digest
+ struct md5_ctx nettle_ctx;
+ md5_init (&nettle_ctx);
+ md5_update (&nettle_ctx, input.size (), input.data ());
+ uint8_t digest[MD5_DIGEST_SIZE];
+ md5_digest (&nettle_ctx, MD5_DIGEST_SIZE, digest);
+
+ // Encode it to base16
+ std::vector<char> encoded (BASE16_ENCODE_LENGTH (MD5_DIGEST_SIZE));
+ base16_encode_update (encoded.data (), MD5_DIGEST_SIZE, digest);
+ std::string final_digest (encoded.begin (), encoded.end ());
+ return final_digest;
+}
diff --git a/gnu/packages/aux-files/jsonnet-md5/md5.h b/gnu/packages/aux-files/jsonnet-md5/md5.h
new file mode 100644
index 0000000000..0c8a826e04
--- /dev/null
+++ b/gnu/packages/aux-files/jsonnet-md5/md5.h
@@ -0,0 +1,8 @@
+#ifndef BZF_MD5_H
+#define BZF_MD5_H
+#include <string>
+
+// Return the hexadecimal digest.
+std::string md5 (const std::string str);
+
+#endif
diff --git a/gnu/packages/cpp.scm b/gnu/packages/cpp.scm
index 42e9d50687..f37a9bc219 100644
--- a/gnu/packages/cpp.scm
+++ b/gnu/packages/cpp.scm
@@ -45,6 +45,7 @@
#:use-module (guix build-system gnu)
#:use-module (guix build-system python)
#:use-module (guix modules)
+ #:use-module (guix gexp)
#:use-module (gnu packages)
#:use-module (gnu packages autotools)
#:use-module (gnu packages boost)
@@ -63,6 +64,7 @@
#:use-module (gnu packages llvm)
#:use-module (gnu packages logging)
#:use-module (gnu packages maths)
+ #:use-module (gnu packages nettle)
#:use-module (gnu packages onc-rpc)
#:use-module (gnu packages perl)
#:use-module (gnu packages pkg-config)
@@ -1211,3 +1213,69 @@ of reading and writing XML.")
;; incompatible with the GPL v2. Refer to the file named FLOSSE for the
;; details.
(license license:gpl2+)))
+
+(define-public jsonnet
+ (package
+ (name "jsonnet")
+ (version "0.17.0")
+ (source
+ (origin
+ (method git-fetch)
+ (uri (git-reference
+ (url "https://github.com/google/jsonnet")
+ (commit (string-append "v" version))))
+ (file-name (git-file-name name version))
+ (sha256
+ (base32 "1ddz14699v5lqx3dh0mb7hfffr6fk5zhmzn3z8yxkqqvriqnciim"))
+ (modules '((guix build utils)))
+ (snippet
+ #~(begin
+ (delete-file-recursively "third_party")
+ (delete-file-recursively "doc/third_party")
+ (substitute*
+ '("core/vm.cpp")
+ (("#include \"json.hpp\"") "#include <nlohmann/json.hpp>"))
+ (mkdir-p "third_party/md5")
+ (copy-file #+(local-file
+ (search-auxiliary-file "jsonnet-md5/CMakeLists.txt"))
+ "third_party/md5/CMakeLists.txt")
+ (copy-file #+(local-file
+ (search-auxiliary-file "jsonnet-md5/md5.h"))
+ "third_party/md5/md5.h")
+ (copy-file #+(local-file
+ (search-auxiliary-file "jsonnet-md5/md5.cpp"))
+ "third_party/md5/md5.cpp")))))
+ (build-system cmake-build-system)
+ (arguments
+ `(#:configure-flags '("-DUSE_SYSTEM_GTEST=ON" "-DUSE_SYSTEM_JSON=ON")))
+ (propagated-inputs
+ '())
+ (native-inputs
+ `(("googletest" ,googletest)
+ ("pkg-config" ,pkg-config)))
+ (inputs
+ `(("json-modern-cxx" ,json-modern-cxx)
+ ;; jsonnet uses a md5 implementation claiming to be from
+ ;; https://www.bzflag.org/, but they don’t use it anymore. We
+ ;; replace it with md5 from nettle.
+ ("nettle" ,nettle)))
+ (home-page "https://jsonnet.org/")
+ (synopsis "The data templating language")
+ (description "A data templating language for app and tool developers:
+@itemize
+@item Generate config data
+@item Side-effect free
+@item Organize, simplify, unify
+@item Manage sprawling config
+@end itemize
+
+A simple extension of JSON:
+@itemize
+@item Open source (Apache 2.0)
+@item Familiar syntax
+@item Reformatter, linter
+@item Editor & IDE integrations
+@item Formally specified
+@end itemize
+")
+ (license license:asl2.0)))
--
2.32.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [bug#49823] Using texinfo for the description
2021-08-02 17:09 ` Vivien Kraus via Guix-patches via
@ 2021-08-02 17:52 ` Leo Prikler
2021-08-02 23:21 ` Vivien Kraus via Guix-patches via
0 siblings, 1 reply; 11+ messages in thread
From: Leo Prikler @ 2021-08-02 17:52 UTC (permalink / raw)
To: Vivien Kraus, Maxime Devos, 49823
Hi Vivien,
sorry for coaxing you into packaging this thing, I merely noticed
graaljs using jsonnet and I'm pretty sure those paths will at some
point of the build need to get parsed. ^^"
Am Montag, den 02.08.2021, 19:09 +0200 schrieb Vivien Kraus:
> + (synopsis "The data templating language")
Should just be "Data templating language"
> + (description "A data templating language for app and tool
> developers:
> +@itemize
> +@item Generate config data
> +@item Side-effect free
> +@item Organize, simplify, unify
> +@item Manage sprawling config
> +@end itemize
> +
> +A simple extension of JSON:
> +@itemize
> +@item Open source (Apache 2.0)
> +@item Familiar syntax
> +@item Reformatter, linter
> +@item Editor & IDE integrations
> +@item Formally specified
> +@end itemize
> +")
Sorry, but that's a little too much keyword soup. Perhaps "Jsonnet is
a templating language extending JSON syntax with variables, conditions,
functions and more."
> + (license license:asl2.0)))
> + `(("json-modern-cxx" ,json-modern-cxx)
On a related note, we should imo rename this to nlohmann-json and patch
dependants accordingly. What do others think?
^ permalink raw reply [flat|nested] 11+ messages in thread
* [bug#49823] Using texinfo for the description
2021-08-02 17:52 ` Leo Prikler
@ 2021-08-02 23:21 ` Vivien Kraus via Guix-patches via
0 siblings, 0 replies; 11+ messages in thread
From: Vivien Kraus via Guix-patches via @ 2021-08-02 23:21 UTC (permalink / raw)
To: Leo Prikler, Maxime Devos, 49823
[-- Attachment #1: Type: text/plain, Size: 221 bytes --]
Here it is with the new wording.
Le lundi 02 août 2021 à 19:52 +0200, Leo Prikler a écrit :
> On a related note, we should imo rename this to nlohmann-json and
> patch
> dependants accordingly. What do others think?
[-- Attachment #2: 0001-gnu-Add-jsonnet.patch --]
[-- Type: text/x-patch, Size: 6156 bytes --]
From 88d24816aa57e084be090303fda1e5840b703aa1 Mon Sep 17 00:00:00 2001
From: Vivien Kraus <vivien@planete-kraus.eu>
Date: Mon, 2 Aug 2021 16:07:08 +0200
Subject: [PATCH] gnu: Add jsonnet.
* gnu/packages/cpp.scm (jsonnet): New variable.
---
Makefile.am | 5 +-
.../aux-files/jsonnet-md5/CMakeLists.txt | 5 ++
gnu/packages/aux-files/jsonnet-md5/md5.cpp | 25 +++++++++
gnu/packages/aux-files/jsonnet-md5/md5.h | 8 +++
gnu/packages/cpp.scm | 53 +++++++++++++++++++
5 files changed, 95 insertions(+), 1 deletion(-)
create mode 100644 gnu/packages/aux-files/jsonnet-md5/CMakeLists.txt
create mode 100644 gnu/packages/aux-files/jsonnet-md5/md5.cpp
create mode 100644 gnu/packages/aux-files/jsonnet-md5/md5.h
diff --git a/Makefile.am b/Makefile.am
index d5ec909213..5cac270104 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -390,7 +390,10 @@ AUX_FILES = \
gnu/packages/aux-files/linux-libre/4.4-i686.conf \
gnu/packages/aux-files/linux-libre/4.4-x86_64.conf \
gnu/packages/aux-files/pack-audit.c \
- gnu/packages/aux-files/run-in-namespace.c
+ gnu/packages/aux-files/run-in-namespace.c \
+ gnu/packages/aux-files/jsonnet-md5/CMakeLists.txt \
+ gnu/packages/aux-files/jsonnet-md5/md5.cpp \
+ gnu/packages/aux-files/jsonnet-md5/md5.h
# Templates, examples.
EXAMPLES = \
diff --git a/gnu/packages/aux-files/jsonnet-md5/CMakeLists.txt b/gnu/packages/aux-files/jsonnet-md5/CMakeLists.txt
new file mode 100644
index 0000000000..498ad514e9
--- /dev/null
+++ b/gnu/packages/aux-files/jsonnet-md5/CMakeLists.txt
@@ -0,0 +1,5 @@
+add_library(md5 STATIC md5.cpp md5.h)
+find_package(PkgConfig REQUIRED)
+pkg_check_modules(NETTLE REQUIRED nettle)
+target_link_libraries(md5 ${NETTLE_LIBRARIES})
+target_include_directories(md5 PUBLIC ${NETTLE_INCLUDE_DIRS})
diff --git a/gnu/packages/aux-files/jsonnet-md5/md5.cpp b/gnu/packages/aux-files/jsonnet-md5/md5.cpp
new file mode 100644
index 0000000000..b8fcb536dd
--- /dev/null
+++ b/gnu/packages/aux-files/jsonnet-md5/md5.cpp
@@ -0,0 +1,25 @@
+#include "md5.h"
+#include <nettle/md5.h>
+#include <nettle/base16.h>
+#include <string>
+#include <vector>
+
+std::string
+md5 (const std::string str)
+{
+ // Convert str to a byte array
+ std::vector<uint8_t> input (str.begin (), str.end ());
+
+ // Compute the digest
+ struct md5_ctx nettle_ctx;
+ md5_init (&nettle_ctx);
+ md5_update (&nettle_ctx, input.size (), input.data ());
+ uint8_t digest[MD5_DIGEST_SIZE];
+ md5_digest (&nettle_ctx, MD5_DIGEST_SIZE, digest);
+
+ // Encode it to base16
+ std::vector<char> encoded (BASE16_ENCODE_LENGTH (MD5_DIGEST_SIZE));
+ base16_encode_update (encoded.data (), MD5_DIGEST_SIZE, digest);
+ std::string final_digest (encoded.begin (), encoded.end ());
+ return final_digest;
+}
diff --git a/gnu/packages/aux-files/jsonnet-md5/md5.h b/gnu/packages/aux-files/jsonnet-md5/md5.h
new file mode 100644
index 0000000000..0c8a826e04
--- /dev/null
+++ b/gnu/packages/aux-files/jsonnet-md5/md5.h
@@ -0,0 +1,8 @@
+#ifndef BZF_MD5_H
+#define BZF_MD5_H
+#include <string>
+
+// Return the hexadecimal digest.
+std::string md5 (const std::string str);
+
+#endif
diff --git a/gnu/packages/cpp.scm b/gnu/packages/cpp.scm
index 42e9d50687..c4ce820eaf 100644
--- a/gnu/packages/cpp.scm
+++ b/gnu/packages/cpp.scm
@@ -45,6 +45,7 @@
#:use-module (guix build-system gnu)
#:use-module (guix build-system python)
#:use-module (guix modules)
+ #:use-module (guix gexp)
#:use-module (gnu packages)
#:use-module (gnu packages autotools)
#:use-module (gnu packages boost)
@@ -63,6 +64,7 @@
#:use-module (gnu packages llvm)
#:use-module (gnu packages logging)
#:use-module (gnu packages maths)
+ #:use-module (gnu packages nettle)
#:use-module (gnu packages onc-rpc)
#:use-module (gnu packages perl)
#:use-module (gnu packages pkg-config)
@@ -1211,3 +1213,54 @@ of reading and writing XML.")
;; incompatible with the GPL v2. Refer to the file named FLOSSE for the
;; details.
(license license:gpl2+)))
+
+(define-public jsonnet
+ (package
+ (name "jsonnet")
+ (version "0.17.0")
+ (source
+ (origin
+ (method git-fetch)
+ (uri (git-reference
+ (url "https://github.com/google/jsonnet")
+ (commit (string-append "v" version))))
+ (file-name (git-file-name name version))
+ (sha256
+ (base32 "1ddz14699v5lqx3dh0mb7hfffr6fk5zhmzn3z8yxkqqvriqnciim"))
+ (modules '((guix build utils)))
+ (snippet
+ #~(begin
+ (delete-file-recursively "third_party")
+ (delete-file-recursively "doc/third_party")
+ (substitute*
+ '("core/vm.cpp")
+ (("#include \"json.hpp\"") "#include <nlohmann/json.hpp>"))
+ (mkdir-p "third_party/md5")
+ (copy-file #+(local-file
+ (search-auxiliary-file "jsonnet-md5/CMakeLists.txt"))
+ "third_party/md5/CMakeLists.txt")
+ (copy-file #+(local-file
+ (search-auxiliary-file "jsonnet-md5/md5.h"))
+ "third_party/md5/md5.h")
+ (copy-file #+(local-file
+ (search-auxiliary-file "jsonnet-md5/md5.cpp"))
+ "third_party/md5/md5.cpp")))))
+ (build-system cmake-build-system)
+ (arguments
+ `(#:configure-flags '("-DUSE_SYSTEM_GTEST=ON" "-DUSE_SYSTEM_JSON=ON")))
+ (propagated-inputs
+ '())
+ (native-inputs
+ `(("googletest" ,googletest)
+ ("pkg-config" ,pkg-config)))
+ (inputs
+ `(("json-modern-cxx" ,json-modern-cxx)
+ ;; jsonnet uses a md5 implementation claiming to be from
+ ;; https://www.bzflag.org/, but they don’t use it anymore. We
+ ;; replace it with md5 from nettle.
+ ("nettle" ,nettle)))
+ (home-page "https://jsonnet.org/")
+ (synopsis "Data templating language")
+ (description "Jsonnet is a templating language extending JSON
+syntax with variables, conditions, functions and more.")
+ (license license:asl2.0)))
--
2.32.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [bug#49823] [PATCH] gnu: Add jsonnet.
2021-08-02 15:01 [bug#49823] [PATCH] gnu: Add jsonnet Vivien Kraus via Guix-patches via
2021-08-02 16:15 ` [bug#49823] Using texinfo for the description Vivien Kraus via Guix-patches via
@ 2021-08-10 12:58 ` Ludovic Courtès
2021-08-10 14:28 ` Vivien Kraus via Guix-patches via
1 sibling, 1 reply; 11+ messages in thread
From: Ludovic Courtès @ 2021-08-10 12:58 UTC (permalink / raw)
To: Vivien Kraus; +Cc: 49823, Leo Prikler, Maxime Devos
Hi Vivien,
Vivien Kraus <vivien@planete-kraus.eu> skribis:
> Here is jsonnet. I don’t fully understand what it does, but thanks to
> leoprikler, I know it is a dependency to package GraalJS, an
> interpreter for JavaScript on the Java Virtual Machine.
>
> For the sake of having "no dependencies", it bundles a custom
> implementation of MD5. According to a comment in the associated
> license, it is taken from the implementation of bzflag, but it does not
> seem to use the same as of today.
>
> I decided to use nettle, and add a few lines of C++ to shape it into
> the required interface.
I think using Nettle is a wise decision; however, it’s a decision for
upstream to make IMO. I’m not comfortable with shipping custom
md5.{cpp,h} and CMakeLists.txt; to me, we’d be taking a bit too much of
upstream’s burden and delivering something that’s quite different.
Apart from that, the last patch you sent LGTM.
Thoughts?
Thanks,
Ludo’.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [bug#49823] [PATCH] gnu: Add jsonnet.
2021-08-10 12:58 ` [bug#49823] [PATCH] gnu: Add jsonnet Ludovic Courtès
@ 2021-08-10 14:28 ` Vivien Kraus via Guix-patches via
2021-08-11 9:56 ` Ludovic Courtès
0 siblings, 1 reply; 11+ messages in thread
From: Vivien Kraus via Guix-patches via @ 2021-08-10 14:28 UTC (permalink / raw)
To: Ludovic Courtès; +Cc: 49823, Leo Prikler, Maxime Devos
Hi!
Ludovic Courtès writes:
>> For the sake of having "no dependencies", it bundles a custom
>> implementation of MD5. According to a comment in the associated
>> license, it is taken from the implementation of bzflag, but it does not
>> seem to use the same as of today.
>>
>> I decided to use nettle, and add a few lines of C++ to shape it into
>> the required interface.
>
> I think using Nettle is a wise decision; however, it’s a decision for
> upstream to make IMO. I’m not comfortable with shipping custom
> md5.{cpp,h} and CMakeLists.txt; to me, we’d be taking a bit too much of
> upstream’s burden and delivering something that’s quite different.
OK. Should I keep the bundled MD5 implementation then?
Vivien
^ permalink raw reply [flat|nested] 11+ messages in thread
* [bug#49823] [PATCH] gnu: Add jsonnet.
2021-08-10 14:28 ` Vivien Kraus via Guix-patches via
@ 2021-08-11 9:56 ` Ludovic Courtès
2021-08-11 10:12 ` Vivien Kraus via Guix-patches via
0 siblings, 1 reply; 11+ messages in thread
From: Ludovic Courtès @ 2021-08-11 9:56 UTC (permalink / raw)
To: Vivien Kraus; +Cc: 49823, Leo Prikler, Maxime Devos
Hi,
Vivien Kraus <vivien@planete-kraus.eu> skribis:
> Ludovic Courtès writes:
>>> For the sake of having "no dependencies", it bundles a custom
>>> implementation of MD5. According to a comment in the associated
>>> license, it is taken from the implementation of bzflag, but it does not
>>> seem to use the same as of today.
>>>
>>> I decided to use nettle, and add a few lines of C++ to shape it into
>>> the required interface.
>>
>> I think using Nettle is a wise decision; however, it’s a decision for
>> upstream to make IMO. I’m not comfortable with shipping custom
>> md5.{cpp,h} and CMakeLists.txt; to me, we’d be taking a bit too much of
>> upstream’s burden and delivering something that’s quite different.
>
> OK. Should I keep the bundled MD5 implementation then?
Yeah, I think so. Clearly it’s a gray area, there are pros and cons,
but I’d lean towards minimal changes to upstream source.
Thanks,
Ludo’.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [bug#49823] [PATCH] gnu: Add jsonnet.
2021-08-11 9:56 ` Ludovic Courtès
@ 2021-08-11 10:12 ` Vivien Kraus via Guix-patches via
2021-08-12 7:53 ` bug#49823: " Ludovic Courtès
0 siblings, 1 reply; 11+ messages in thread
From: Vivien Kraus via Guix-patches via @ 2021-08-11 10:12 UTC (permalink / raw)
To: Ludovic Courtès; +Cc: 49823, Leo Prikler, Maxime Devos
[-- Attachment #1: Type: text/plain, Size: 247 bytes --]
Ludovic Courtès writes:
>> OK. Should I keep the bundled MD5 implementation then?
>
> Yeah, I think so. Clearly it’s a gray area, there are pros and cons,
> but I’d lean towards minimal changes to upstream source.
Here you go :)
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: jsonnet with the bundled md5 code --]
[-- Type: text/x-patch, Size: 2389 bytes --]
From 8ce461001ed14c3267d839334e4853feaed69b50 Mon Sep 17 00:00:00 2001
From: Vivien Kraus <vivien@planete-kraus.eu>
Date: Mon, 2 Aug 2021 16:07:08 +0200
Subject: [PATCH] gnu: Add jsonnet.
* gnu/packages/cpp.scm (jsonnet): New variable.
---
gnu/packages/cpp.scm | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/gnu/packages/cpp.scm b/gnu/packages/cpp.scm
index 42e9d50687..870c02dac3 100644
--- a/gnu/packages/cpp.scm
+++ b/gnu/packages/cpp.scm
@@ -45,6 +45,7 @@
#:use-module (guix build-system gnu)
#:use-module (guix build-system python)
#:use-module (guix modules)
+ #:use-module (guix gexp)
#:use-module (gnu packages)
#:use-module (gnu packages autotools)
#:use-module (gnu packages boost)
@@ -1211,3 +1212,43 @@ of reading and writing XML.")
;; incompatible with the GPL v2. Refer to the file named FLOSSE for the
;; details.
(license license:gpl2+)))
+
+(define-public jsonnet
+ (package
+ (name "jsonnet")
+ (version "0.17.0")
+ (source
+ (origin
+ (method git-fetch)
+ (uri (git-reference
+ (url "https://github.com/google/jsonnet")
+ (commit (string-append "v" version))))
+ (file-name (git-file-name name version))
+ (sha256
+ (base32 "1ddz14699v5lqx3dh0mb7hfffr6fk5zhmzn3z8yxkqqvriqnciim"))
+ (modules '((guix build utils)))
+ (snippet
+ #~(begin
+ (rename-file "third_party/md5" ".md5")
+ (delete-file-recursively "third_party")
+ (delete-file-recursively "doc/third_party")
+ (substitute*
+ '("core/vm.cpp")
+ (("#include \"json.hpp\"") "#include <nlohmann/json.hpp>"))
+ (mkdir "third_party")
+ (rename-file ".md5" "third_party/md5")))))
+ (build-system cmake-build-system)
+ (arguments
+ `(#:configure-flags '("-DUSE_SYSTEM_GTEST=ON" "-DUSE_SYSTEM_JSON=ON")))
+ (propagated-inputs
+ '())
+ (native-inputs
+ `(("googletest" ,googletest)
+ ("pkg-config" ,pkg-config)))
+ (inputs
+ `(("json-modern-cxx" ,json-modern-cxx)))
+ (home-page "https://jsonnet.org/")
+ (synopsis "Data templating language")
+ (description "Jsonnet is a templating language extending JSON
+syntax with variables, conditions, functions and more.")
+ (license license:asl2.0)))
--
2.32.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* bug#49823: [PATCH] gnu: Add jsonnet.
2021-08-11 10:12 ` Vivien Kraus via Guix-patches via
@ 2021-08-12 7:53 ` Ludovic Courtès
0 siblings, 0 replies; 11+ messages in thread
From: Ludovic Courtès @ 2021-08-12 7:53 UTC (permalink / raw)
To: Vivien Kraus; +Cc: 49823-done, Maxime Devos, Leo Prikler
[-- Attachment #1: Type: text/plain, Size: 431 bytes --]
Hi Vivien,
Vivien Kraus <vivien@planete-kraus.eu> skribis:
> From 8ce461001ed14c3267d839334e4853feaed69b50 Mon Sep 17 00:00:00 2001
> From: Vivien Kraus <vivien@planete-kraus.eu>
> Date: Mon, 2 Aug 2021 16:07:08 +0200
> Subject: [PATCH] gnu: Add jsonnet.
>
> * gnu/packages/cpp.scm (jsonnet): New variable.
Applied with the tweak below.
Thank you, and thanks for taking the time for the extra work!
Ludo’.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 892 bytes --]
diff --git a/gnu/packages/cpp.scm b/gnu/packages/cpp.scm
index 870c02dac3..8c8109fb83 100644
--- a/gnu/packages/cpp.scm
+++ b/gnu/packages/cpp.scm
@@ -1232,16 +1232,13 @@ of reading and writing XML.")
(rename-file "third_party/md5" ".md5")
(delete-file-recursively "third_party")
(delete-file-recursively "doc/third_party")
- (substitute*
- '("core/vm.cpp")
+ (substitute* '("core/vm.cpp")
(("#include \"json.hpp\"") "#include <nlohmann/json.hpp>"))
(mkdir "third_party")
(rename-file ".md5" "third_party/md5")))))
(build-system cmake-build-system)
(arguments
`(#:configure-flags '("-DUSE_SYSTEM_GTEST=ON" "-DUSE_SYSTEM_JSON=ON")))
- (propagated-inputs
- '())
(native-inputs
`(("googletest" ,googletest)
("pkg-config" ,pkg-config)))
^ permalink raw reply related [flat|nested] 11+ messages in thread
end of thread, other threads:[~2021-08-12 7:55 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-08-02 15:01 [bug#49823] [PATCH] gnu: Add jsonnet Vivien Kraus via Guix-patches via
2021-08-02 16:15 ` [bug#49823] Using texinfo for the description Vivien Kraus via Guix-patches via
2021-08-02 16:35 ` Maxime Devos
2021-08-02 17:09 ` Vivien Kraus via Guix-patches via
2021-08-02 17:52 ` Leo Prikler
2021-08-02 23:21 ` Vivien Kraus via Guix-patches via
2021-08-10 12:58 ` [bug#49823] [PATCH] gnu: Add jsonnet Ludovic Courtès
2021-08-10 14:28 ` Vivien Kraus via Guix-patches via
2021-08-11 9:56 ` Ludovic Courtès
2021-08-11 10:12 ` Vivien Kraus via Guix-patches via
2021-08-12 7:53 ` bug#49823: " Ludovic Courtès
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/guix.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.