Subject: Re: bug#43579: g++ does not provide std::fegetround

From: Miguel Ángel Arruga Vivas <[email-masked]>
Date: Fri, 13 Nov 2020 18:59:53 +0100

Hi!

Ludovic Courtès <[email-masked]> writes:
>[...]
> It’s the same story as <https://issues.guix.gnu.org/42392>.
>[...]
> So this is again #include_next not picking the right <fenv.h> due to
> search path ordering issues and/or duplicate entries.
>
> Thoughts anyone?
>
> I think we need a proper fix but the feedback we got from GCC folks last
> time didn’t give me much insight as to what we should do.

AFAIR, the issue comes from using XXX_INCLUDE_PATH instead of CPATH
because it includes gcc predefined paths:
  1. The order matters.
  2. The internal order may need duplicated paths.
  3. Even providing the right duplicated paths through these variables
  may not be supported may not work, it's an implementation detail after
  all.

This was changed because we wanted to avoid warnings on installed
libraries which could be raised to errors with -Werror.  I personally
don't like that approach, as the included headers are being compiled in
that moment so I think the -Werror should apply too, but indeed I
understand the reasons behind the compatibility with FHS.

The problem comes to generalizing this approach: there should be inputs
that must not enter the realm of these variables, mainly gcc and libc,
libc:static, libstdc++, and so on.

The attached WIP-patch would be a rough approach to that, but it will
take some time until I recompile the world to really test it.  Also this
isn't the best approach as the manifests shouldn't include these
neither, but I still don't find where and how to mark these inputs
cleanly.

WDYT?  Any idea is welcome. :-)

Happy hacking!
Miguel
From ad2e859589ccbd5e9310a921355ef5e7f4926d80 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miguel=20=C3=81ngel=20Arruga=20Vivas?=
 <[email-masked]>
Date: Fri, 13 Nov 2020 18:27:03 +0100
Subject: [PATCH] build-system/gnu: Remove libc, libstdc++ and gcc from include
 paths.

* guix/build/gnu-build-system.scm (set-paths)[include-input?]
[include-var?]: New predicates.
[inputs->directories, native-inputs->directories]: Extract code from ...
[input-directories, native-input-directories]: ... here.
[include-directories, native-include-directories]: New variables.
<body>: Select between input-directories, native-input-directories or
include-directories, native-include-directories depending on the
environment variable to set.
---
 guix/build/gnu-build-system.scm | 45 ++++++++++++++++++++++++---------
 1 file changed, 33 insertions(+), 12 deletions(-)

diff --git a/guix/build/gnu-build-system.scm b/guix/build/gnu-build-system.scm
index 2e7dff2034..2f8da33066 100644
--- a/guix/build/gnu-build-system.scm
+++ b/guix/build/gnu-build-system.scm
@@ -72,18 +72,35 @@ See https://reproducible-builds.org/specs/source-date-epoch/."
 (define* (set-paths #:key target inputs native-inputs
                     (search-paths '()) (native-search-paths '())
                     #:allow-other-keys)
-  (define input-directories
-    (match inputs
+  (define (include-input? input)
+    (let ((compiler-internals '("libc" "libc:static" "libstdc++" "gcc")))
+      (match input
+        ((name . _)
+         (not (member name compiler-internals))))))
+
+  (define (inputs->directories obj)
+    (match obj
       (((_ . dir) ...)
        dir)))
 
-  (define native-input-directories
-    (match native-inputs
+  (define (native-inputs->directories obj)
+    (match obj
       (((_ . dir) ...)
        dir)
       (#f                                         ; not cross compiling
        '())))
 
+  (define input-directories (inputs->directories inputs))
+  (define native-input-directories (native-inputs->directories native-inputs))
+
+  (define (include-var? var)
+    (string-suffix? var "_INCLUDE_PATH"))
+  (define include-directories
+    (inputs->directories (filter include-input? inputs)))
+  (define native-include-directories
+    (native-inputs->directories (filter include-input? native-inputs)))
+
+
   ;; Tell 'ld-wrapper' to disallow non-store libraries.
   (setenv "GUIX_LD_WRAPPER_ALLOW_IMPURITIES" "no")
 
@@ -98,10 +115,12 @@ See https://reproducible-builds.org/specs/source-date-epoch/."
   (for-each (match-lambda
              ((env-var (files ...) separator type pattern)
               (set-path-environment-variable env-var files
-                                             input-directories
-                                             #:separator separator
-                                             #:type type
-                                             #:pattern pattern)))
+                                             (if (include-var? env-var)
+                                                 include-directories
+                                                 input-directories)
+                                                 #:separator separator
+                                                 #:type type
+                                                 #:pattern pattern)))
             search-paths)
 
   (when native-search-paths
@@ -109,10 +128,12 @@ See https://reproducible-builds.org/specs/source-date-epoch/."
     (for-each (match-lambda
                ((env-var (files ...) separator type pattern)
                 (set-path-environment-variable env-var files
-                                               native-input-directories
-                                               #:separator separator
-                                               #:type type
-                                               #:pattern pattern)))
+                                             (if (include-var? env-var)
+                                                 native-include-directories
+                                                 native-input-directories)
+                                                 #:separator separator
+                                                 #:type type
+                                                 #:pattern pattern)))
               native-search-paths))
 
   #t)
-- 
2.29.2