mozilla / nixpkgs-mozilla

Mozilla overlay for Nixpkgs.
MIT License
517 stars 128 forks source link

gecko: build fails with clang7 #191

Open glasserc opened 5 years ago

glasserc commented 5 years ago

mach build fails with:

 0:15.74 checking for clang for bindgen...
 0:15.74 ERROR: --with-clang-path is not valid when the target compiler is clang
 0:15.80 *** Fix above errors and then restart with\
 0:15.80                "./mach build"
 0:15.80 make: *** [client.mk:115: configure] Error 1

After some investigation, it's something to do with the generated .mozconfig.nix-shell, which is:

mk_add_options AUTOCONF=/nix/store/s9q3jykannaf4b7p14vl77x2g1gb086r-autoconf-2.13/bin/autoconf
ac_add_options --with-libclang-path=/nix/store/mshvdcg7jzvlriw5pyygwdfla3x9b0k8-clang-5.0.2-lib/lib
ac_add_options --with-clang-path=/nix/store/g1jszd6w4cr41ayg8vfz4fjp1d62bqkn-clang-wrapper-5.0.2/bin/clang
export BINDGEN_CFLAGS="-cxx-isystem /nix/store/d4n93jn9fdq8fkmkm1q8f32lfagvibjk-gcc-7.4.0/include/c++/7.4.0 -isystem /nix/store/d4n93jn9fdq8fkmkm1q8f32lfagvibjk-gcc-7.4.0/include/c++/7.4.0/x86_64-unknown-linux-gnu"
export CC="/nix/store/bb8qpnh8f25x4bphbq48pnz8v5sxvvd4-clang-wrapper-7.0.1/bin/cc"
export CXX="/nix/store/bb8qpnh8f25x4bphbq48pnz8v5sxvvd4-clang-wrapper-7.0.1/bin/c++"

mach is unhappy because the argument to --with-clang-path doesn't correspond to the C++ compiler. I was eventually able to get it to work by hardcoding llvmPackages_7 in gecko/default.nix, and making some changes to the other paths, but I don't have a clean fix yet (and I'm not even sure this fix is correct -- the build is still happening).

nbp commented 5 years ago

hum … it sounds that when we are building with clang, we should use clang as much as possible for the libclang-path and the clang-path.

nbp commented 5 years ago

Fixing the first issue lead to another issue which made me to not investigate more in the first place, which is:

 0:18.27 make[4]: *** […/src/config/rules.mk:801: Unified_cpp_xpcom_threads0.o] Error 1
 0:18.27 make[4]: *** Waiting for unfinished jobs....
 0:19.60 In file included from …/bld/xpcom/threads/Unified_cpp_xpcom_threads1.cpp:83:
 0:19.60 In file included from …/src/xpcom/threads/nsThread.cpp:25:
 0:19.61 In file included from …/bld/dist/include/mozilla/BackgroundHangMonitor.h:10:
 0:19.61 In file included from …/bld/dist/include/mozilla/CPUUsageWatcher.h:12:
 0:19.61 In file included from …/bld/dist/include/mozilla/HangAnnotations.h:12:
 0:19.61 In file included from …/bld/ipc/ipdl/_ipdlheaders/mozilla/HangTypes.h:11:
 0:19.61 In file included from …/bld/dist/include/ipc/IPCMessageUtils.h:11:
 0:19.61 In file included from …/src/ipc/chromium/src/chrome/common/ipc_message_utils.h:14:
 0:19.61 In file included from …/src/ipc/chromium/src/base/file_path.h:74:
 0:19.61 In file included from …/src/ipc/chromium/src/base/hash_tables.h:70:
 0:19.61 /nix/store/wr5dlcw1asw8dwgm4bwjmga8f52m5lfx-gcc-7.4.0/include/c++/7.4.0/ext/hash_map:60:10: fatal error: 'backward_warning.h' file not found
 0:19.61 #include "backward_warning.h"
 0:19.61          ^~~~~~~~~~~~~~~~~~~~
 0:19.71 1 error generated.
glasserc commented 5 years ago

Ah yes. I posted a comment on the PR, but I also got this. I think what's happening is that (because of the cxxLib argument), clang is #includeing headers from GCC, which #include this backward_warning.h (which is a GCC implementation detail).

I hacked up my local version because I knew I only cared about clang7. I eventually got a successful build using this:

diff --git a/pkgs/gecko/default.nix b/pkgs/gecko/default.nix
index a9479d2..860605f 100644
--- a/pkgs/gecko/default.nix
+++ b/pkgs/gecko/default.nix
@@ -9,7 +9,7 @@
 , setuptools
 , rust # rust & cargo bundled. (otheriwse use pkgs.rust.{rustc,cargo})
 , buildFHSUserEnv # Build a FHS environment with all Gecko dependencies.
-, llvm, llvmPackages, nasm
+, llvm, llvmPackages_7, nasm
 , ccache

 , zlib, xorg
@@ -110,13 +110,14 @@ let
   ];

   genMozConfig = ''
-    cxxLib=$( echo -n ${gcc}/include/c++/* )
-    archLib=$cxxLib/$( ${gcc}/bin/gcc -dumpmachine )
+    cxxLib=$( echo -n ${llvmPackages_7.libcxx}/include/c++/* )
+    archLib=$cxxLib/$( ${llvmPackages_7.clang}/bin/clang -dumpmachine )

     cat - > $MOZCONFIG <<EOF
     mk_add_options AUTOCONF=${autoconf213}/bin/autoconf
-    ac_add_options --with-libclang-path=${llvmPackages.clang.cc.lib}/lib
-    ac_add_options --with-clang-path=${llvmPackages.clang}/bin/clang
+    ac_add_options --with-libclang-path=${llvmPackages_7.clang.cc.lib}/lib
+    ac_add_options --with-clang-path=${llvmPackages_7.clang}/bin/c++
+    #ac_add_options --enable-linker=${llvmPackages_7.lld}/bin/lld
     export BINDGEN_CFLAGS="-cxx-isystem $cxxLib -isystem $archLib"
     export CC="${stdenv.cc}/bin/cc"
     export CXX="${stdenv.cc}/bin/c++"
@@ -129,9 +130,9 @@ let
     export CC="${stdenv.cc}/bin/cc";
     export CXX="${stdenv.cc}/bin/c++";
     # To be used when building the JS Shell.
-    export NIX_EXTRA_CONFIGURE_ARGS="--with-libclang-path=${llvmPackages.clang.cc.lib}/lib --with-clang-path=${llvmPackages.clang}/bin/clang"
-    cxxLib=$( echo -n ${gcc}/include/c++/* )
-    archLib=$cxxLib/$( ${gcc}/bin/gcc -dumpmachine )
+    export NIX_EXTRA_CONFIGURE_ARGS="--with-libclang-path=${llvmPackages_7.clang.cc.lib}/lib --with-clang-path=${llvmPackages_7.clang}/bin/clang"
+    cxxLib=$( echo -n ${llvmPackages_7.libcxx}/include/c++/* )
+    archLib=$cxxLib/$( ${llvmPackages_7.clang}/bin/clang -dumpmachine )
     export BINDGEN_CFLAGS="-cxx-isystem $cxxLib -isystem $archLib"
     ${genMozConfig}
     ${builtins.getEnv "NIX_SHELL_HOOK"}
@@ -159,7 +160,7 @@ let
   };
 in

-stdenv.mkDerivation {
+llvmPackages_7.libcxxStdenv.mkDerivation {
   name = "gecko-dev-${version}";
   inherit src buildInputs shellHook;