about summary refs log tree commit diff
path: root/pkgs/build-support
diff options
context:
space:
mode:
authorTheodore Ni <3806110+tjni@users.noreply.github.com>2022-09-19 11:08:15 -0700
committertoonn <toonn@toonn.io>2022-09-20 12:14:51 +0200
commitc319d8ae3b7522656f74085281672f61c7112a98 (patch)
tree5a0da7d66b64646cd93c623e8d275a3140fab886 /pkgs/build-support
parentac6d052fd9c611821d34e8e41b550fb7530f8fbe (diff)
downloadnixlib-c319d8ae3b7522656f74085281672f61c7112a98.tar
nixlib-c319d8ae3b7522656f74085281672f61c7112a98.tar.gz
nixlib-c319d8ae3b7522656f74085281672f61c7112a98.tar.bz2
nixlib-c319d8ae3b7522656f74085281672f61c7112a98.tar.lz
nixlib-c319d8ae3b7522656f74085281672f61c7112a98.tar.xz
nixlib-c319d8ae3b7522656f74085281672f61c7112a98.tar.zst
nixlib-c319d8ae3b7522656f74085281672f61c7112a98.zip
cc-wrapper: comment explaining C++ stdlib order
There is context here that I needed when resolving an issue in which
libc was added to NIX_CFLAGS_COMPILE before the C++ stdlib that took
me awhile to understand.

It was suggested to me that this context be included as a comment,
since it is not obvious and could help others in the future.
Diffstat (limited to 'pkgs/build-support')
-rw-r--r--pkgs/build-support/cc-wrapper/cc-wrapper.sh25
1 files changed, 25 insertions, 0 deletions
diff --git a/pkgs/build-support/cc-wrapper/cc-wrapper.sh b/pkgs/build-support/cc-wrapper/cc-wrapper.sh
index 83b6817798f2..78759f2cfbbc 100644
--- a/pkgs/build-support/cc-wrapper/cc-wrapper.sh
+++ b/pkgs/build-support/cc-wrapper/cc-wrapper.sh
@@ -122,6 +122,31 @@ fi
 
 if [[ "$isCxx" = 1 ]]; then
     if [[ "$cxxInclude" = 1 ]]; then
+        #
+        # The motivation for this comment is to explain the reason for appending
+        # the C++ stdlib to NIX_CFLAGS_COMPILE, which I initially thought should
+        # change and later realized it shouldn't in:
+        #
+        #   https://github.com/NixOS/nixpkgs/pull/185569#issuecomment-1234959249
+        #
+        # NIX_CFLAGS_COMPILE contains dependencies added using "-isystem", and
+        # NIX_CXXSTDLIB_COMPILE adds the C++ stdlib using "-isystem". Appending
+        # NIX_CXXSTDLIB_COMPILE to NIX_CLAGS_COMPILE emulates this part of the
+        # include lookup order from GCC/Clang:
+        #
+        # > 4. Directories specified with -isystem options are scanned in
+        # >    left-to-right order.
+        # > 5. Standard system directories are scanned.
+        # > 6. Directories specified with -idirafter options are scanned
+        # >    in left-to-right order.
+        #
+        # NIX_CXX_STDLIB_COMPILE acts as the "standard system directories" that
+        # are otherwise missing from CC in nixpkgs, so should be added last.
+        #
+        # This means that the C standard library should never be present inside
+        # NIX_CFLAGS_COMPILE, because it MUST come after the C++ stdlib. It is
+        # added automatically by cc-wrapper later using "-idirafter".
+        #
         NIX_CFLAGS_COMPILE_@suffixSalt@+=" $NIX_CXXSTDLIB_COMPILE_@suffixSalt@"
     fi
     if [[ "$cxxLibrary" = 1 ]]; then