From patchwork Mon Oct 3 00:19:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Elsing X-Patchwork-Id: 6185 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 CDDF027BBEA; Mon, 3 Oct 2022 01:50:38 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 3B8B627BBEB for ; Mon, 3 Oct 2022 01:50:37 +0100 (BST) Received: from localhost ([::1]:57338 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1of9fH-0000aA-2r for patchwork@mira.cbaines.net; Sun, 02 Oct 2022 20:50:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49492) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1of9Ch-0007rU-GN for guix-patches@gnu.org; Sun, 02 Oct 2022 20:21:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:49311) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1of9Ch-0001xp-8M for guix-patches@gnu.org; Sun, 02 Oct 2022 20:21:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1of9Ch-000746-3a for guix-patches@gnu.org; Sun, 02 Oct 2022 20:21:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#58261] [PATCH 03/11] gnu: Add sajson. Resent-From: David Elsing Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 03 Oct 2022 00:21:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 58261 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 58261@debbugs.gnu.org Cc: David Elsing Received: via spool by 58261-submit@debbugs.gnu.org id=B58261.166475641526986 (code B ref 58261); Mon, 03 Oct 2022 00:21:03 +0000 Received: (at 58261) by debbugs.gnu.org; 3 Oct 2022 00:20:15 +0000 Received: from localhost ([127.0.0.1]:48361 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1of9Bu-00070z-4h for submit@debbugs.gnu.org; Sun, 02 Oct 2022 20:20:15 -0400 Received: from mout02.posteo.de ([185.67.36.66]:41257) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1of9Bq-000701-Nv for 58261@debbugs.gnu.org; Sun, 02 Oct 2022 20:20:11 -0400 Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 4041024010A for <58261@debbugs.gnu.org>; Mon, 3 Oct 2022 02:20:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1664756405; bh=pz3UNBUEOR2A/kAGkjDDR9+zVAKKXw/KuEG3w8IjnhU=; h=From:To:Cc:Subject:Date:From; b=Nav2pEWB6o/5hi4DgkINpgjV+b52udpYO42cOH+4g+2oTeV9T9B02EULpCJneWOuw RzYWhiFK663WjlGDeLB+PuEl19h86PPBdelYK3Hszj7RWiG0pDkigoj5NmySkp8onh R4ii0ORbPwPecsgIpOWidXXmz52390iNfZ3HtZa7hKlwLQdFFXggSkQme+dVQ0vS+6 z4L/QDDq6IYSCLRHIEafrTGA0vCKsVmPxK9Wf3iy40PRasdyipDetTpSpSDUruCkfu yDcCgL9YGFUXGehe1VnXXSmd4m/F5fE7Lrc+FAhS6IPu4+PNk3q2AygEMP7sp4jap/ 3wonzgTaxU8XA== Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4MghLD647Yz6tmX; Mon, 3 Oct 2022 02:20:04 +0200 (CEST) From: David Elsing Date: Mon, 3 Oct 2022 00:19:48 +0000 Message-Id: <58f8902b3b903cde3a1094fdb888e19ff1cd3ba5.1664725832.git.david.elsing@posteo.net> In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Mailman-Approved-At: Sun, 02 Oct 2022 20:50:23 -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" X-getmail-retrieved-from-mailbox: Patches * gnu/packages/cpp.scm (sajson): New variable. --- gnu/packages/cpp.scm | 63 +++++++++++++++++++ .../patches/sajson-parse_flags-linking.patch | 45 +++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 gnu/packages/patches/sajson-parse_flags-linking.patch diff --git a/gnu/packages/cpp.scm b/gnu/packages/cpp.scm index 65df317100..7bfa3d6cdf 100644 --- a/gnu/packages/cpp.scm +++ b/gnu/packages/cpp.scm @@ -57,6 +57,7 @@ (define-module (gnu packages cpp) #:use-module (guix build-system gnu) #:use-module (guix build-system meson) #:use-module (guix build-system python) + #:use-module (guix build-system scons) #:use-module (guix modules) #:use-module (guix gexp) #:use-module (gnu packages) @@ -1957,3 +1958,65 @@ (define-public pocketfft which is an reimplementation of FFTPack with several advantages, such as multidimensional algorithms, different datatypes and vector instructions.") (license license:bsd-3)))) + +(define-public sajson + (let ((commit "ec644013e34f9984a3cc9ba568cab97a391db9cd") (revision "0")) + (package + (name "sajson") + (version (git-version "0.0.0" revision commit)) + (source (origin + (method git-fetch) + (uri (git-reference + (url "https://github.com/chadaustin/sajson") + (commit commit))) + (file-name (git-file-name name version)) + (patches + (search-patches "sajson-parse_flags-linking.patch")) + (sha256 + (base32 + "0fjag27w7gvkc5pdhq3ad7yc09rabpzahndw1sgsg04ipznidmmq")) + (modules '((guix build utils))) + (snippet '(delete-file-recursively "third-party")))) + (build-system scons-build-system) + (arguments + (list + #:phases + #~(modify-phases %standard-phases + (add-after 'unpack 'disable-other-builds + (lambda _ + (substitute* "SConstruct" + (("for name, tools in builds:") + "for name, tools in [('opt', [gcc, opt])]:")) + #t)) + (add-after 'unpack 'use-external-unittest-cpp + (lambda* (#:key inputs #:allow-other-keys) + (substitute* "SConscript" + (("unittestpp_env\\.Library") "_dummy = ") + (("test_env = env.Clone\\(tools=\\[unittestpp, sajson\\]\\)") + (string-append + "test_env = env.Clone(tools=[sajson])\n" + "test_env.Append(CPPPATH='" + (search-input-directory inputs "/include/UnitTest++") + "', LIBPATH='" + (string-append #$(this-package-native-input "unittest-cpp") + "/lib") + "', LIBS=['UnitTest++'])"))) + #t)) + (replace 'check + (lambda* (#:key tests? #:allow-other-keys) + (when tests? + (invoke "build/opt/test") + (invoke "build/opt/test_unsorted")) + #t)) + (replace 'install + (lambda _ + (let ((out (string-append #$output "/include"))) + (install-file "include/sajson.h" out) + (install-file "include/sajson_ostream.h" out)) + #t))))) + (native-inputs (list unittest-cpp)) + (home-page "https://github.com/chadaustin/sajson") + (synopsis "Lightweight, extremely high-performance JSON parser for C++11") + (description "sajson is a high-performance, in-place JSON parser +header-only library.") + (license license:expat)))) diff --git a/gnu/packages/patches/sajson-parse_flags-linking.patch b/gnu/packages/patches/sajson-parse_flags-linking.patch new file mode 100644 index 0000000000..878706dc79 --- /dev/null +++ b/gnu/packages/patches/sajson-parse_flags-linking.patch @@ -0,0 +1,45 @@ +This patch is from the upstream pull request +https://github.com/chadaustin/sajson/pull/54. +It fixes linking with GCC. + +diff --git a/include/sajson.h b/include/sajson.h +index 8b4e05a..1bd045b 100644 +--- a/include/sajson.h ++++ b/include/sajson.h +@@ -138,12 +138,17 @@ constexpr inline size_t make_element(tag t, size_t value) { + // header. This trick courtesy of Rich Geldreich's Purple JSON parser. + template + struct globals_struct { ++ static const unsigned char parse_flags[256]; ++}; ++typedef globals_struct<> globals; ++ + // clang-format off + + // bit 0 (1) - set if: plain ASCII string character + // bit 1 (2) - set if: whitespace + // bit 4 (0x10) - set if: 0-9 e E . +- constexpr static const uint8_t parse_flags[256] = { ++ template ++ const unsigned char globals_struct::parse_flags[256] = { + // 0 1 2 3 4 5 6 7 8 9 A B C D E F + 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 2, 0, 0, // 0 + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1 +@@ -162,15 +167,13 @@ struct globals_struct { + }; + + // clang-format on +-}; +-typedef globals_struct<> globals; + +-constexpr inline bool is_plain_string_character(char c) { ++inline bool is_plain_string_character(char c) { + // return c >= 0x20 && c <= 0x7f && c != 0x22 && c != 0x5c; + return (globals::parse_flags[static_cast(c)] & 1) != 0; + } + +-constexpr inline bool is_whitespace(char c) { ++inline bool is_whitespace(char c) { + // return c == '\r' || c == '\n' || c == '\t' || c == ' '; + return (globals::parse_flags[static_cast(c)] & 2) != 0; + }