diff mbox series

[bug#69126,2/2] gnu: Add type-safe.

Message ID b2d423449b6ce9964ea0ea8218528fd9fa12486e.1707924715.git.paul@apatience.com
State New
Headers show
Series gnu: Add type-safe. | expand

Commit Message

Paul A. Patience Feb. 14, 2024, 3:36 p.m. UTC
* gnu/packages/cpp.scm (type-safe): New variable.

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

Comments

Skyler Ferris Feb. 14, 2024, 9:30 p.m. UTC | #1
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 
https://directory.fsf.org/wiki/License:Expat.
Paul A. Patience Feb. 15, 2024, 2:23 p.m. UTC | #2
On 2024-02-14 16:30:57-05:00, Skyler Ferris wrote:
> 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
diff mbox series

Patch

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)))