[PATCH 0/2] gnu: Add type-safe.

  • Open
  • quality assurance status badge
Details
3 participants
  • Liliana Marie Prikler
  • Paul A. Patience
  • Skyler Ferris
Owner
unassigned
Submitted by
Paul A. Patience
Severity
normal
P
P
Paul A. Patience wrote on 14 Feb 16:33 +0100
(address . guix-patches@gnu.org)(name . Paul A. Patience)(address . paul@apatience.com)
cover.1707924715.git.paul@apatience.com
Paul A. Patience (2):
gnu: Add debug-assert.
gnu: Add type-safe.

gnu/packages/cpp.scm | 81 +++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 80 insertions(+), 1 deletion(-)


base-commit: 570ef13a87bb54d3410c431700ba78316a2641e2
--
2.41.0
P
P
Paul A. Patience wrote on 14 Feb 16:36 +0100
[PATCH 1/2] gnu: Add debug-assert.
(address . 69126@debbugs.gnu.org)(name . Paul A. Patience)(address . paul@apatience.com)
0191a95edf076b5cd24326d49e54ce13f2bdb0d4.1707924715.git.paul@apatience.com
* gnu/packages/cpp.scm (debug-assert): New variable.

Change-Id: I4cee49ea2f5b761ab72bb7b063c2ea8fd99b991c
---
gnu/packages/cpp.scm | 28 +++++++++++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)

Toggle diff (45 lines)
diff --git a/gnu/packages/cpp.scm b/gnu/packages/cpp.scm
index 62a1923571..2456de5002 100644
--- a/gnu/packages/cpp.scm
+++ b/gnu/packages/cpp.scm
@@ -38,7 +38,7 @@
;;; Copyright © 2023 Liliana Marie Prikler <liliana.prikler@gmail.com>
;;; Copyright © 2023 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
;;; Copyright © 2023 Foundation Devices, Inc. <hello@foundationdevices.com>
-;;; Copyright © 2023 Paul A. Patience <paul@apatience.com>
+;;; Copyright © 2023-2024 Paul A. Patience <paul@apatience.com>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -3048,3 +3048,29 @@ (define-public tl-optional
the std::optional for C++11/14/17, with support for monadic operations added in
C++23.")
(license license:cc0)))
+
+(define-public debug-assert
+ ;; Newer version than last release, which was in 2018, is required for
+ ;; type_safe.
+ (let ((commit "d33781479baccf52a28e5c3c5a6da5ac59b09179")
+ (revision "0"))
+ (package
+ (name "debug-assert")
+ (version (git-version "1.3.3" revision commit))
+ (source
+ (origin
+ (method git-fetch)
+ (uri (git-reference
+ (url "https://github.com/foonathan/debug_assert")
+ (commit commit)))
+ (file-name (git-file-name name version))
+ (sha256
+ (base32 "0njbzx767pndpl8hq5falr4c8m0xsr6njh0943xf8xkcqq6splpz"))))
+ (build-system cmake-build-system)
+ (arguments (list #:tests? #f)) ; no tests
+ (home-page "https://github.com/foonathan/debug_assert")
+ (synopsis "Assertion macro for C++")
+ (description "debug_assert is a C++11 header-only library which provides the
+@code{DEBUG_ASSERT()} macro, which among other features can be selectively
+enabled in different parts of your code.")
+ (license license:zlib))))
--
2.41.0
P
P
Paul A. Patience wrote on 14 Feb 16:36 +0100
[PATCH 2/2] gnu: Add type-safe.
(address . 69126@debbugs.gnu.org)(name . Paul A. Patience)(address . paul@apatience.com)
b2d423449b6ce9964ea0ea8218528fd9fa12486e.1707924715.git.paul@apatience.com
* gnu/packages/cpp.scm (type-safe): New variable.

Change-Id: I96a690b41af78e331744daacba1cf5ee77f8257a
---
gnu/packages/cpp.scm | 53 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 53 insertions(+)

Toggle diff (63 lines)
diff --git a/gnu/packages/cpp.scm b/gnu/packages/cpp.scm
index 2456de5002..cf0771e470 100644
--- a/gnu/packages/cpp.scm
+++ b/gnu/packages/cpp.scm
@@ -3074,3 +3074,56 @@ (define-public debug-assert
@code{DEBUG_ASSERT()} macro, which among other features can be selectively
enabled in different parts of your code.")
(license license:zlib))))
+
+(define-public type-safe
+ (package
+ (name "type-safe")
+ (version "0.2.3")
+ (source
+ (origin
+ (method git-fetch)
+ (uri (git-reference
+ (url "https://github.com/foonathan/type_safe")
+ (commit (string-append "v" version))))
+ (file-name (git-file-name name version))
+ (sha256
+ (base32 "0ijd5grkbzfcmkqydka5ncl7ab4rc3307qr0ywwgzqsifr3ks0fd"))
+ (modules '((guix build utils)))
+ ;; Remove bundled debug_assert.
+ ;; Keep external/external.cmake because it enables
+ ;; TYPE_SAFE_HAS_IMPORTED_TARGETS, required for installing the CMake
+ ;; config files.
+ (snippet #~(delete-file-recursively "external/debug_assert"))))
+ (build-system cmake-build-system)
+ (arguments
+ (list #:configure-flags
+ #~(list "-DTYPE_SAFE_BUILD_TEST_EXAMPLE=ON"
+ "-DTYPE_SAFE_BUILD_DOC=OFF") ; needs standardese
+ #:phases
+ #~(modify-phases %standard-phases
+ (add-after 'unpack 'fix-dependencies
+ (lambda _
+ (substitute* "test/CMakeLists.txt"
+ (("^if\\(NOT EXISTS .*/catch\\.hpp\\)") "if(FALSE)")
+ (("^(target_include_directories\\(type_safe_test) .*"
+ all prefix)
+ (string-append all prefix " PRIVATE \""
+ #$(this-package-native-input "catch2")
+ "/include/catch2\")\n")))))
+ (add-after 'install 'fix-cmake-config
+ (lambda _
+ (substitute* (string-append
+ #$output
+ "/lib/cmake/type_safe/type_safe-config.cmake")
+ (("^(find_dependency\\(debug_assert)\\)" _ prefix)
+ (string-append prefix " PATHS \""
+ #$(this-package-input "debug-assert")
+ "/lib/cmake/debug_assert\")"))))))))
+ (native-inputs (list catch2))
+ (inputs (list debug-assert))
+ (home-page "https://github.com/foonathan/type_safe")
+ (synopsis "C++ abstractions for preventing bugs via the type system")
+ (description "type_safe is a C++ header-only library which provides
+abstractions for defining more appropriate types, thus allowing C++'s type
+system to prevent more bugs.")
+ (license license:expat)))
--
2.41.0
S
S
Skyler Ferris wrote on 14 Feb 22:27 +0100
Re: [bug#69126] [PATCH 0/2] gnu: Add type-safe.
965f1f2d-2112-4d40-b587-14b4f10c563f@protonmail.com
Hi Paul,

I am adding some review notes to this issue. To avoid any potential
confusion I want to be clear that I am not a committer, but I am adding
these notes in hopes that it will help a committer process these patches
more efficiently.

Regards,
Skyler
S
S
Skyler Ferris wrote on 14 Feb 22:29 +0100
Re: [bug#69126] [PATCH 1/2] gnu: Add debug-assert.
3bee2280-c098-4c23-9161-6d3c5a487768@protonmail.com
Things needing attention:

`guix lint` issues a warning that the beginning of the description
starts with a lowercase letter. IMO this is reasonable because the first
word is the name of the project, and it is a common convention for
project names to remain lowercased (the README in the project follows
this convention). However I am not sure how the Guix maintainers
consider this.

The arguments form is attached to a comment saying that there are no
tests, but it looks like the repository does contain a test in the
`test_package` directory with a separate CMakelists.txt file. I haven't
spent much time with the cmake build system in Guix, would it be
reasonable to replace the check phase with a procedure that uses the
file in this directory? If not then it might be helpful to replace the
comment with one explaining that, while tests exist, it is not feasible
to run them for some specific reason.

More details:

This diff applies cleanly to commit
ac470c516e19f194228edf9e348bdbc7fc10f97a.

The following paragraph contains notes about the confidence level of
source integrity. These notes are provided to indicate that due
attention has been given to this matter and to provide transparency into
the level of confidence in the source as well as the entities trusted
with maintaining integrity. The "optimal" level of confidence is
use-case dependent, as is the trustability of any given entity. These
notes are provided for transparency to the committer and any other
interested parties and should not be interpreted as criticism of the commit.

The commit used in the source form is signed by PGP key
5DE3E0509C47EA3CF04A42D34AEE18F83AFDEB23. The key is expired but NOT
revoked. It is available on the Ubuntu keyserver
with several other signatures, though none that are trusted by my
keyring. It is also available on the OpenPGP keyserver
but without a UID, meaning the email address was not verified. Note that
one of the UIDs listed in the Ubuntu server is "GitHub (web-flow
commit)", implying that the GitHub server is ultimately responsible for
maintaining integrity.

`./pre-inst-env guix build debug-assert` succeeded on my machine, an
x86_64 Xen guest. Additionally, the following program (based on the
example in the README) successfully compiled and produced the expected
output.

main.cpp
```
#include <debug_assert.hpp>

struct mymodule : debug_assert::default_handler,
debug_assert::set_level<static_cast<unsigned int>(-1)> {};

int main(void) {
    DEBUG_ASSERT(1 +1 == 3, my_module{}, debug_assert::level<2>{});
}
```

```
$ ./pre-inst-env guix shell gcc-toolchain debug-assert -C -- g++
-std=c++11 main.cpp
$ ./a.out
[debug assert] main.cpp:6: Assertion '1 +1 == 3' failed.
Aborted
```

The LICENSE file provided in the source repository matches the contents
S
S
Skyler Ferris wrote on 14 Feb 22:30 +0100
Re: [bug#69126] [PATCH 2/2] gnu: Add type-safe.
3463adf6-964b-4b52-a554-4575e5d8d237@protonmail.com
Things needing attention:

When I tried to compile a file which included `type_safe/integer.hpp`
from a container (see below for exact commands & source), I got an error
that the debug_assert header could not be found. I resolved this by
changing the debug-assert package from a normal input into a propagated
input, but there could be other ways to solve this.

main.cpp
```
#include <type_safe/integer.hpp>

int main(void) {
    type_safe::integer<int> tsi(1);
    return tsi.get();
}
```

```
$ ./pre-inst-env guix shell gcc-toolchain type-safe -C -- g++ -std=c++11
main.cpp
<error indicating that debug_assert.hpp was not found>
```

More details:

This diff applies cleanly to commit
ac470c516e19f194228edf9e348bdbc7fc10f97a, after applying the previous
commit in this series.

As with the review on the previous patch, notes about confidence in
source integrity are provided as an indication of attention and to
provide transparency. The commit tagged v0.2.3 does not have a signature
on it, but the commit 3 steps prior has a good signature. It uses the
same signing key as debug-assert, so all of the notes from there apply
here as well.

`./pre-inst-env guix build type-safe` succeeded on my machine, an x86_64
Xen guest. Additionally, after fixing the issue noted in the "Things
needing attention" section, the following test file produced an expected
compiler error indicating that the type_safe::integer needs an initial
value.

main.cpp
```
#include <type_safe/integer.hpp>

int main(void) {
    type_safe::integer<int> tsi;
    return tsi.get();
}
```

Once I added an initial value as shown in the "Things needing attention"
section, the file built successfully and the executable returned the
expected exit code.

```
$ ./pre-inst-env guix shell gcc-toolchain type-safe -C -- g++ -std=c++11
main.cpp
$ ./a.out
$ echo $?
1
```

The license file in the project matches the contents I see at
P
P
Paul A. Patience wrote on 15 Feb 15:02 +0100
Re: [bug#69126] [PATCH 1/2] gnu: Add debug-assert.
(name . Skyler Ferris)(address . skyvine@protonmail.com)(address . 69126@debbugs.gnu.org)
877cj5n7uq.fsf@apatience.com
Hello,

Thanks for reviewing my patches.

On 2024-02-14 16:29:05-05:00, Skyler Ferris wrote:
Toggle quote (7 lines)
> `guix lint` issues a warning that the beginning of the description
> starts with a lowercase letter. IMO this is reasonable because the first
> word is the name of the project, and it is a common convention for
> project names to remain lowercased (the README in the project follows
> this convention). However I am not sure how the Guix maintainers
> consider this.

I was aware of the issue, and I share your opinion.
Sometimes project authors write the project name lowercased but in a
fixed-width font, in which case I use either @samp{} or @code{}, which
guix lint does not raise an error for.
However, this author does not, so I left it as such.
For what it's worth, I counted a few hundred instances of a lowercased
project name without @samp{} or @code{} in the first line of the
description across the Guix codebase.
I will leave it to the discretion of the committer.

Toggle quote (9 lines)
> The arguments form is attached to a comment saying that there are no
> tests, but it looks like the repository does contain a test in the
> `test_package` directory with a separate CMakelists.txt file. I haven't
> spent much time with the cmake build system in Guix, would it be
> reasonable to replace the check phase with a procedure that uses the
> file in this directory? If not then it might be helpful to replace the
> comment with one explaining that, while tests exist, it is not feasible
> to run them for some specific reason.

The test_package directory seems to test the installation of
debug_assert with the Conan package manager, so there is nothing to do
here.

Best regards,
Paul
P
P
Paul A. Patience wrote on 15 Feb 15:23 +0100
Re: [bug#69126] [PATCH 2/2] gnu: Add type-safe.
(name . Skyler Ferris)(address . skyvine@protonmail.com)(address . 69126@debbugs.gnu.org)
8734ttn6vj.fsf@apatience.com
On 2024-02-14 16:30:57-05:00, Skyler Ferris wrote:
Toggle quote (6 lines)
> When I tried to compile a file which included `type_safe/integer.hpp`
> from a container (see below for exact commands & source), I got an error
> that the debug_assert header could not be found. I resolved this by
> changing the debug-assert package from a normal input into a propagated
> input, but there could be other ways to solve this.

Nice catch.
I have been using the type_safe library via CMake, which I made work in
the fix-cmake-config phase, but I forgot to consider the case you raised.
I've fixed the issue and will submit a patch presently.

Thanks for providing sample code and invocation, it made it quicker to
test.

Best regards,
Paul
P
P
Paul A. Patience wrote on 15 Feb 15:25 +0100
[PATCH v2] gnu: Add type-safe.
(address . 69126@debbugs.gnu.org)(name . Paul A. Patience)(address . paul@apatience.com)
6c2fafee4c064a64bc918781c106d4e67732d45d.1708006480.git.paul@apatience.com
* gnu/packages/cpp.scm (type-safe): New variable.

Change-Id: I96a690b41af78e331744daacba1cf5ee77f8257a
---
This patch addresses the issue raised by Skylar Ferris.

gnu/packages/cpp.scm | 60 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 60 insertions(+)

Toggle diff (72 lines)
diff --git a/gnu/packages/cpp.scm b/gnu/packages/cpp.scm
index 2456de5002..f7e502d1bf 100644
--- a/gnu/packages/cpp.scm
+++ b/gnu/packages/cpp.scm
@@ -3074,3 +3074,63 @@ (define-public debug-assert
@code{DEBUG_ASSERT()} macro, which among other features can be selectively
enabled in different parts of your code.")
(license license:zlib))))
+
+(define-public type-safe
+ (package
+ (name "type-safe")
+ (version "0.2.3")
+ (source
+ (origin
+ (method git-fetch)
+ (uri (git-reference
+ (url "https://github.com/foonathan/type_safe")
+ (commit (string-append "v" version))))
+ (file-name (git-file-name name version))
+ (sha256
+ (base32 "0ijd5grkbzfcmkqydka5ncl7ab4rc3307qr0ywwgzqsifr3ks0fd"))
+ (modules '((guix build utils)))
+ ;; Remove bundled debug_assert.
+ ;; Keep external/external.cmake because it enables
+ ;; TYPE_SAFE_HAS_IMPORTED_TARGETS, required for installing the CMake
+ ;; config files.
+ (snippet #~(delete-file-recursively "external/debug_assert"))))
+ (build-system cmake-build-system)
+ (arguments
+ (list #:configure-flags
+ #~(list "-DTYPE_SAFE_BUILD_TEST_EXAMPLE=ON"
+ "-DTYPE_SAFE_BUILD_DOC=OFF") ; needs standardese
+ #:phases
+ #~(modify-phases %standard-phases
+ (add-after 'unpack 'fix-dependencies
+ (lambda _
+ (substitute*
+ (list "include/type_safe/detail/assert.hpp"
+ "include/type_safe/detail/force_inline.hpp")
+ (("#include <debug_assert.hpp>")
+ (string-append "#include <"
+ #$(this-package-input "debug-assert")
+ "/include/debug_assert.hpp>")))
+ (substitute* "test/CMakeLists.txt"
+ (("^if\\(NOT EXISTS .*/catch\\.hpp\\)") "if(FALSE)")
+ (("^(target_include_directories\\(type_safe_test) .*"
+ all prefix)
+ (string-append all prefix " PRIVATE \""
+ #$(this-package-native-input "catch2")
+ "/include/catch2\")\n")))))
+ (add-after 'install 'fix-cmake-config
+ (lambda _
+ (substitute* (string-append
+ #$output
+ "/lib/cmake/type_safe/type_safe-config.cmake")
+ (("^(find_dependency\\(debug_assert)\\)" _ prefix)
+ (string-append prefix " PATHS \""
+ #$(this-package-input "debug-assert")
+ "/lib/cmake/debug_assert\")"))))))))
+ (native-inputs (list catch2))
+ (inputs (list debug-assert))
+ (home-page "https://github.com/foonathan/type_safe")
+ (synopsis "C++ abstractions for preventing bugs via the type system")
+ (description "type_safe is a C++ header-only library which provides
+abstractions for defining more appropriate types, thus allowing C++'s type
+system to prevent more bugs.")
+ (license license:expat)))

base-commit: 0191a95edf076b5cd24326d49e54ce13f2bdb0d4
--
2.41.0
L
L
Liliana Marie Prikler wrote on 17 Feb 09:43 +0100
543f0537937e104e9e030503ab880d19b070eb29.camel@gmail.com
Am Donnerstag, dem 15.02.2024 um 14:25 +0000 schrieb Paul A. Patience:
Toggle quote (5 lines)
> * gnu/packages/cpp.scm (type-safe): New variable.
>
> Change-Id: I96a690b41af78e331744daacba1cf5ee77f8257a
> ---
> This patch addresses the issue raised by Skylar Ferris.
Hi, the convention when renewing patches is to keep the order of the
old. Even if you don't resend all of them (which many for the record
do), it makes sense to still calls this v2 2/2 unless 1/2 is already
pushed.

Toggle quote (36 lines)
>  gnu/packages/cpp.scm | 60
> ++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 60 insertions(+)
>
> diff --git a/gnu/packages/cpp.scm b/gnu/packages/cpp.scm
> index 2456de5002..f7e502d1bf 100644
> --- a/gnu/packages/cpp.scm
> +++ b/gnu/packages/cpp.scm
> @@ -3074,3 +3074,63 @@ (define-public debug-assert
>  @code{DEBUG_ASSERT()} macro, which among other features can be
> selectively
>  enabled in different parts of your code.")
>        (license license:zlib))))
> +
> +(define-public type-safe
> +  (package
> +    (name "type-safe")
> +    (version "0.2.3")
> +    (source
> +     (origin
> +       (method git-fetch)
> +       (uri (git-reference
> +             (url "https://github.com/foonathan/type_safe")
> +             (commit (string-append "v" version))))
> +       (file-name (git-file-name name version))
> +       (sha256
> +        (base32
> "0ijd5grkbzfcmkqydka5ncl7ab4rc3307qr0ywwgzqsifr3ks0fd"))
> +       (modules '((guix build utils)))
> +       ;; Remove bundled debug_assert.
> +       ;; Keep external/external.cmake because it enables
> +       ;; TYPE_SAFE_HAS_IMPORTED_TARGETS, required for installing
> the CMake
> +       ;; config files.
> +       (snippet #~(delete-file-recursively
> "external/debug_assert"))))
You could also rewrite the top-level CMake file so that this is not an
issue. Alternatively, use the (let ((keep …)) …) pattern, so that the
code is self-explanatory.
Toggle quote (5 lines)
> +    (build-system cmake-build-system)
> +    (arguments
> +     (list #:configure-flags
> +           #~(list "-DTYPE_SAFE_BUILD_TEST_EXAMPLE=ON"
> +                   "-DTYPE_SAFE_BUILD_DOC=OFF") ; needs standardese
Can we package that or is there some bootstrapping issue?
Toggle quote (13 lines)
> +           #:phases
> +           #~(modify-phases %standard-phases
> +               (add-after 'unpack 'fix-dependencies
> +                 (lambda _
> +                   (substitute*
> +                       (list "include/type_safe/detail/assert.hpp"
> +                            
> "include/type_safe/detail/force_inline.hpp")
> +                     (("#include <debug_assert.hpp>")
> +                      (string-append "#include <"
> +                                     #$(this-package-input "debug-
> assert")
> +                                     "/include/debug_assert.hpp>")))
Use search-input-file.
Toggle quote (10 lines)
> +                   (substitute* "test/CMakeLists.txt"
> +                     (("^if\\(NOT EXISTS .*/catch\\.hpp\\)")
> "if(FALSE)")
> +                    
> (("^(target_include_directories\\(type_safe_test) .*"
> +                       all prefix)
> +                      (string-append all prefix " PRIVATE \""
> +                                     #$(this-package-native-input
> "catch2")
> +                                     "/include/catch2\")\n")))))
Use search-input-directory.
Toggle quote (13 lines)
> +               (add-after 'install 'fix-cmake-config
> +                 (lambda _
> +                   (substitute* (string-append
> +                                 #$output
> +                                 "/lib/cmake/type_safe/type_safe-
> config.cmake")
> +                     (("^(find_dependency\\(debug_assert)\\)" _
> prefix)
> +                      (string-append prefix " PATHS \""
> +                                     #$(this-package-input "debug-
> assert")
> +                                    
> "/lib/cmake/debug_assert\")"))))))))
In general, I'd encourage writing a patch to fix both this and the
issues pointed out above. Note, that CMake has its way of locating
packages per cmake files or pkgconfig, so hard-coding directories as
done here is typically *not* needed.
Toggle quote (12 lines)
> +    (native-inputs (list catch2))
> +    (inputs (list debug-assert))
> +    (home-page "https://github.com/foonathan/type_safe")
> +    (synopsis "C++ abstractions for preventing bugs via the type
> system")
> +    (description "type_safe is a C++ header-only library which
> provides
> +abstractions for defining more appropriate types, thus allowing
> C++'s type
> +system to prevent more bugs.")
> +    (license license:expat)))

Cheers
P
P
Paul A. Patience wrote on 20 Feb 20:33 +0100
[PATCH v3 0/2] gnu: Add type-safe.
(address . 69126@debbugs.gnu.org)(name . Paul A. Patience)(address . paul@apatience.com)
cover.1708457406.git.paul@apatience.com
Resubmitting the patch series as per Liliana Marie Prikler's suggestion.
No changes since the last.

Paul A. Patience (2):
gnu: Add debug-assert.
gnu: Add type-safe.

gnu/packages/cpp.scm | 88 +++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 87 insertions(+), 1 deletion(-)


base-commit: 570ef13a87bb54d3410c431700ba78316a2641e2
--
2.41.0
P
P
Paul A. Patience wrote on 20 Feb 20:33 +0100
[PATCH v3 1/2] gnu: Add debug-assert.
(address . 69126@debbugs.gnu.org)(name . Paul A. Patience)(address . paul@apatience.com)
0191a95edf076b5cd24326d49e54ce13f2bdb0d4.1708457406.git.paul@apatience.com
* gnu/packages/cpp.scm (debug-assert): New variable.

Change-Id: I4cee49ea2f5b761ab72bb7b063c2ea8fd99b991c
---
gnu/packages/cpp.scm | 28 +++++++++++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)

Toggle diff (45 lines)
diff --git a/gnu/packages/cpp.scm b/gnu/packages/cpp.scm
index 62a1923571..2456de5002 100644
--- a/gnu/packages/cpp.scm
+++ b/gnu/packages/cpp.scm
@@ -38,7 +38,7 @@
;;; Copyright © 2023 Liliana Marie Prikler <liliana.prikler@gmail.com>
;;; Copyright © 2023 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
;;; Copyright © 2023 Foundation Devices, Inc. <hello@foundationdevices.com>
-;;; Copyright © 2023 Paul A. Patience <paul@apatience.com>
+;;; Copyright © 2023-2024 Paul A. Patience <paul@apatience.com>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -3048,3 +3048,29 @@ (define-public tl-optional
the std::optional for C++11/14/17, with support for monadic operations added in
C++23.")
(license license:cc0)))
+
+(define-public debug-assert
+ ;; Newer version than last release, which was in 2018, is required for
+ ;; type_safe.
+ (let ((commit "d33781479baccf52a28e5c3c5a6da5ac59b09179")
+ (revision "0"))
+ (package
+ (name "debug-assert")
+ (version (git-version "1.3.3" revision commit))
+ (source
+ (origin
+ (method git-fetch)
+ (uri (git-reference
+ (url "https://github.com/foonathan/debug_assert")
+ (commit commit)))
+ (file-name (git-file-name name version))
+ (sha256
+ (base32 "0njbzx767pndpl8hq5falr4c8m0xsr6njh0943xf8xkcqq6splpz"))))
+ (build-system cmake-build-system)
+ (arguments (list #:tests? #f)) ; no tests
+ (home-page "https://github.com/foonathan/debug_assert")
+ (synopsis "Assertion macro for C++")
+ (description "debug_assert is a C++11 header-only library which provides the
+@code{DEBUG_ASSERT()} macro, which among other features can be selectively
+enabled in different parts of your code.")
+ (license license:zlib))))
--
2.41.0
P
P
Paul A. Patience wrote on 20 Feb 20:33 +0100
[PATCH v3 2/2] gnu: Add type-safe.
(address . 69126@debbugs.gnu.org)(name . Paul A. Patience)(address . paul@apatience.com)
6c2fafee4c064a64bc918781c106d4e67732d45d.1708457406.git.paul@apatience.com
* gnu/packages/cpp.scm (type-safe): New variable.

Change-Id: I96a690b41af78e331744daacba1cf5ee77f8257a
---
gnu/packages/cpp.scm | 60 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 60 insertions(+)

Toggle diff (70 lines)
diff --git a/gnu/packages/cpp.scm b/gnu/packages/cpp.scm
index 2456de5002..f7e502d1bf 100644
--- a/gnu/packages/cpp.scm
+++ b/gnu/packages/cpp.scm
@@ -3074,3 +3074,63 @@ (define-public debug-assert
@code{DEBUG_ASSERT()} macro, which among other features can be selectively
enabled in different parts of your code.")
(license license:zlib))))
+
+(define-public type-safe
+ (package
+ (name "type-safe")
+ (version "0.2.3")
+ (source
+ (origin
+ (method git-fetch)
+ (uri (git-reference
+ (url "https://github.com/foonathan/type_safe")
+ (commit (string-append "v" version))))
+ (file-name (git-file-name name version))
+ (sha256
+ (base32 "0ijd5grkbzfcmkqydka5ncl7ab4rc3307qr0ywwgzqsifr3ks0fd"))
+ (modules '((guix build utils)))
+ ;; Remove bundled debug_assert.
+ ;; Keep external/external.cmake because it enables
+ ;; TYPE_SAFE_HAS_IMPORTED_TARGETS, required for installing the CMake
+ ;; config files.
+ (snippet #~(delete-file-recursively "external/debug_assert"))))
+ (build-system cmake-build-system)
+ (arguments
+ (list #:configure-flags
+ #~(list "-DTYPE_SAFE_BUILD_TEST_EXAMPLE=ON"
+ "-DTYPE_SAFE_BUILD_DOC=OFF") ; needs standardese
+ #:phases
+ #~(modify-phases %standard-phases
+ (add-after 'unpack 'fix-dependencies
+ (lambda _
+ (substitute*
+ (list "include/type_safe/detail/assert.hpp"
+ "include/type_safe/detail/force_inline.hpp")
+ (("#include <debug_assert.hpp>")
+ (string-append "#include <"
+ #$(this-package-input "debug-assert")
+ "/include/debug_assert.hpp>")))
+ (substitute* "test/CMakeLists.txt"
+ (("^if\\(NOT EXISTS .*/catch\\.hpp\\)") "if(FALSE)")
+ (("^(target_include_directories\\(type_safe_test) .*"
+ all prefix)
+ (string-append all prefix " PRIVATE \""
+ #$(this-package-native-input "catch2")
+ "/include/catch2\")\n")))))
+ (add-after 'install 'fix-cmake-config
+ (lambda _
+ (substitute* (string-append
+ #$output
+ "/lib/cmake/type_safe/type_safe-config.cmake")
+ (("^(find_dependency\\(debug_assert)\\)" _ prefix)
+ (string-append prefix " PATHS \""
+ #$(this-package-input "debug-assert")
+ "/lib/cmake/debug_assert\")"))))))))
+ (native-inputs (list catch2))
+ (inputs (list debug-assert))
+ (home-page "https://github.com/foonathan/type_safe")
+ (synopsis "C++ abstractions for preventing bugs via the type system")
+ (description "type_safe is a C++ header-only library which provides
+abstractions for defining more appropriate types, thus allowing C++'s type
+system to prevent more bugs.")
+ (license license:expat)))
--
2.41.0
?