From patchwork Mon Aug 2 15:01:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Vivien Kraus X-Patchwork-Id: 31723 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 622E327BC6B; Mon, 2 Aug 2021 16:06:52 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS, T_DKIM_INVALID,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 4BCC027BC78 for ; Mon, 2 Aug 2021 16:06:51 +0100 (BST) Received: from localhost ([::1]:49050 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mAZWk-0008Ne-60 for patchwork@mira.cbaines.net; Mon, 02 Aug 2021 11:06:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58636) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mAZS8-0005mw-6h for guix-patches@gnu.org; Mon, 02 Aug 2021 11:02:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:55589) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mAZS6-0003K6-H0 for guix-patches@gnu.org; Mon, 02 Aug 2021 11:02:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mAZS6-0003g1-El for guix-patches@gnu.org; Mon, 02 Aug 2021 11:02:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#49823] [PATCH] gnu: Add jsonnet. Resent-From: Vivien Kraus Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 02 Aug 2021 15:02:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 49823 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 49823@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.162791648214066 (code B ref -1); Mon, 02 Aug 2021 15:02:02 +0000 Received: (at submit) by debbugs.gnu.org; 2 Aug 2021 15:01:22 +0000 Received: from localhost ([127.0.0.1]:38896 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mAZRS-0003eo-0Y for submit@debbugs.gnu.org; Mon, 02 Aug 2021 11:01:22 -0400 Received: from lists.gnu.org ([209.51.188.17]:60804) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mAZRQ-0003eg-0O for submit@debbugs.gnu.org; Mon, 02 Aug 2021 11:01:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58366) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mAZRP-0005K1-J1 for guix-patches@gnu.org; Mon, 02 Aug 2021 11:01:19 -0400 Received: from planete-kraus.eu ([89.234.140.182]:50790) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_CHACHA20_POLY1305:256) (Exim 4.90_1) (envelope-from ) id 1mAZRM-0002eh-AA for guix-patches@gnu.org; Mon, 02 Aug 2021 11:01:19 -0400 Received: from planete-kraus.eu (localhost.lan [127.0.0.1]) by planete-kraus.eu (OpenSMTPD) with ESMTP id 73cd5b3d for ; Mon, 2 Aug 2021 15:01:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=planete-kraus.eu; h= message-id:subject:from:to:date:content-type:mime-version; s=*; bh=aF5GuyPI/5RsBB6jyZ673X9nHc0=; b=BYuIbZxs2M8dPhipft48cQ2l+V5P yB/Kz93QvvyckubZ2v7fn7nnwMR+RQcbDFttryvU/dAhB4HHHwxWPTaAgUxVkEIo Ibucjr6hx5Ds3SfsBV5nvX1/lmx/mnZ+tL09n0UKvs7A2V2l7cFpiWdNUJeiLjWv FjvGvikXbUTWbd8= Received: by planete-kraus.eu (OpenSMTPD) with ESMTPSA id b6753d7c (TLSv1.3:AEAD-CHACHA20-POLY1305-SHA256:256:NO) for ; Mon, 2 Aug 2021 15:01:09 +0000 (UTC) Message-ID: <71fbbaa57a2c1dba8f0d956ea162c2e15d332e0c.camel@planete-kraus.eu> Date: Mon, 02 Aug 2021 17:01:07 +0200 User-Agent: Evolution 3.34.2 MIME-Version: 1.0 Received-SPF: pass client-ip=89.234.140.182; envelope-from=vivien@planete-kraus.eu; helo=planete-kraus.eu X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Mailman-Approved-At: Mon, 02 Aug 2021 11:06:42 -0400 X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" Reply-to: Vivien Kraus X-ACL-Warn: , Vivien Kraus via Guix-patches X-Patchwork-Original-From: Vivien Kraus via Guix-patches via From: Vivien Kraus X-getmail-retrieved-from-mailbox: Patches 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 From 7cfbec67974d03c6e7dd56e4e2ade95f38faad6a Mon Sep 17 00:00:00 2001 From: Vivien Kraus 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 ")) + (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 + +// 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 +#include +#include +#include + +#define OUTPUT_LENGTH BASE16_ENCODE_LENGTH (MD5_DIGEST_SIZE) + +std::string +md5 (const std::string str) +{ + // Convert str to a byte array + std::vector 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 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