git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #99922 from S-NA/wip/firefox-lto

firefox: add ltoSupport and enable it by default

commitb6b09ac7ae3c3fbe7dd3d45625abe2fd650af025 authorAndreas Rammhold <andreas@rammhold.de> dateTue 20 Oct 2020, 16:23 (6 years ago) parent038afc6aecd9ab
1 file changed+45−17
pkgs/applications/networking/browsers/firefox/common.nix+45−17
pkgs/applications/networking/browsers/firefox/common.nix+45−17
@@ -9,7 +9,7 @@
99, hunspell, libXdamage, libevent, libstartup_notification
1010, libvpx_1_8
1111, icu67, libpng, jemalloc, glib
12−, autoconf213, which, gnused, cargo, rustc, llvmPackages
12+, autoconf213, which, gnused, cargo, rustc
1313, rust-cbindgen, nodejs, nasm, fetchpatch
1414, debugBuild ? false
1515
@@ -22,6 +22,7 @@
2222, ffmpegSupport ? true
2323, gtk3Support ? true, gtk2, gtk3, wrapGAppsHook
2424, waylandSupport ? true, libxkbcommon
25+, ltoSupport ? stdenv.isLinux, overrideCC, buildPackages
2526, gssSupport ? true, kerberos
2627, pipewireSupport ? waylandSupport && webrtcSupport, pipewire
2728
@@ -71,6 +72,7 @@
7172
7273assert stdenv.cc.libc or null != null;
7374assert pipewireSupport -> !waylandSupport || !webrtcSupport -> throw "pipewireSupport requires both wayland and webrtc support.";
75+assert ltoSupport -> stdenv.isDarwin -> throw "LTO is broken on Darwin (see PR#19312).";
7476
7577let
7678 flag = tf: x: [(if tf then "--enable-${x}" else "--disable-${x}")];
@@ -87,9 +89,20 @@ let
8789 then "/Applications/${binaryNameCapitalized}.app/Contents/MacOS"
8890 else "/bin";
8991
92+ # Darwin's stdenv provides the default llvmPackages version, match that since
93+ # clang LTO on Darwin is broken so the stdenv is not being changed.
94+ llvmPackages = if stdenv.isDarwin
95+ then buildPackages.llvmPackages
96+ else buildPackages.llvmPackages_10;
97+
98+ # When LTO for Darwin is fixed, the following will need updating as lld
99+ # doesn't work on it. For now it is fine since ltoSupport implies no Darwin.
100+ buildStdenv = if ltoSupport
101+ then overrideCC stdenv llvmPackages.lldClang
102+ else stdenv;
90103in
91104
92−stdenv.mkDerivation ({
105+buildStdenv.mkDerivation ({
93106 name = "${pname}-unwrapped-${ffversion}";
94107 version = ffversion;
95108
@@ -131,11 +144,17 @@ stdenv.mkDerivation ({
131144 ++ lib.optional pulseaudioSupport libpulseaudio # only headers are needed
132145 ++ lib.optional gtk3Support gtk3
133146 ++ lib.optional gssSupport kerberos
147+ ++ lib.optional ltoSupport llvmPackages.libunwind
134148 ++ lib.optionals waylandSupport [ libxkbcommon ]
135149 ++ lib.optionals pipewireSupport [ pipewire ]
136− ++ lib.optionals stdenv.isDarwin [ CoreMedia ExceptionHandling Kerberos
137− AVFoundation MediaToolbox CoreLocation
138− Foundation libobjc AddressBook cups ];
150+ ++ lib.optionals buildStdenv.isDarwin [ CoreMedia ExceptionHandling Kerberos
151+ AVFoundation MediaToolbox CoreLocation
152+ Foundation libobjc AddressBook cups ];
153+
154+ NIX_LDFLAGS = lib.optionalString ltoSupport ''
155+ -rpath ${placeholder "out"}/lib/${binaryName}
156+ -rpath ${llvmPackages.libunwind.out}/lib
157+ '';
139158
140159 NIX_CFLAGS_COMPILE = toString [
141160 "-I${glib.dev}/include/gio-unix-2.0"
@@ -179,7 +198,7 @@ stdenv.mkDerivation ({
179198 which
180199 ]
181200 ++ lib.optional gtk3Support wrapGAppsHook
182− ++ lib.optionals stdenv.isDarwin [ xcbuild rsync ]
201+ ++ lib.optionals buildStdenv.isDarwin [ xcbuild rsync ]
183202 ++ extraNativeBuildInputs;
184203
185204 preConfigure = ''
@@ -197,12 +216,12 @@ stdenv.mkDerivation ({
197216 # included we need to look in a few places.
198217 # TODO: generalize this process for other use-cases.
199218
200− BINDGEN_CFLAGS="$(< ${stdenv.cc}/nix-support/libc-crt1-cflags) \
201− $(< ${stdenv.cc}/nix-support/libc-cflags) \
202− $(< ${stdenv.cc}/nix-support/cc-cflags) \
203− $(< ${stdenv.cc}/nix-support/libcxx-cxxflags) \
204− ${lib.optionalString stdenv.cc.isClang "-idirafter ${stdenv.cc.cc}/lib/clang/${lib.getVersion stdenv.cc.cc}/include"} \
205− ${lib.optionalString stdenv.cc.isGNU "-isystem ${stdenv.cc.cc}/include/c++/${lib.getVersion stdenv.cc.cc} -isystem ${stdenv.cc.cc}/include/c++/${lib.getVersion stdenv.cc.cc}/${stdenv.hostPlatform.config}"} \
219+ BINDGEN_CFLAGS="$(< ${buildStdenv.cc}/nix-support/libc-crt1-cflags) \
220+ $(< ${buildStdenv.cc}/nix-support/libc-cflags) \
221+ $(< ${buildStdenv.cc}/nix-support/cc-cflags) \
222+ $(< ${buildStdenv.cc}/nix-support/libcxx-cxxflags) \
223+ ${lib.optionalString buildStdenv.cc.isClang "-idirafter ${buildStdenv.cc.cc}/lib/clang/${lib.getVersion buildStdenv.cc.cc}/include"} \
224+ ${lib.optionalString buildStdenv.cc.isGNU "-isystem ${buildStdenv.cc.cc}/include/c++/${lib.getVersion buildStdenv.cc.cc} -isystem ${buildStdenv.cc.cc}/include/c++/${lib.getVersion buildStdenv.cc.cc}/${buildStdenv.hostPlatform.config}"} \
206225 $NIX_CFLAGS_COMPILE"
207226
208227 echo "ac_add_options BINDGEN_CFLAGS='$BINDGEN_CFLAGS'" >> $MOZCONFIG
@@ -236,11 +255,20 @@ stdenv.mkDerivation ({
236255 "--enable-jemalloc"
237256 "--enable-default-toolkit=${default-toolkit}"
238257 "--with-libclang-path=${llvmPackages.libclang}/lib"
239− "--with-clang-path=${llvmPackages.clang}/bin/clang"
240258 "--with-system-nspr"
241259 "--with-system-nss"
242260 ]
243− ++ lib.optional (stdenv.isDarwin) "--disable-xcode-checks"
261+ ++ lib.optional (buildStdenv.isDarwin) "--disable-xcode-checks"
262+ ++ lib.optional (!ltoSupport) "--with-clang-path=${llvmPackages.clang}/bin/clang"
263+ # LTO is done using clang and lld on Linux.
264+ # Darwin needs to use the default linker as lld is not supported (yet?):
265+ # https://bugzilla.mozilla.org/show_bug.cgi?id=1538724
266+ # elf-hack is broken when using clang+lld:
267+ # https://bugzilla.mozilla.org/show_bug.cgi?id=1482204
268+ ++ lib.optionals ltoSupport [
269+ "--enable-lto"
270+ "--disable-elf-hack"
271+ ] ++ lib.optional (ltoSupport && !buildStdenv.isDarwin) "--enable-linker=lld"
244272
245273 ++ flag alsaSupport "alsa"
246274 ++ flag pulseaudioSupport "pulseaudio"
@@ -270,12 +298,12 @@ stdenv.mkDerivation ({
270298 enableParallelBuilding = true;
271299 doCheck = false; # "--disable-tests" above
272300
273− installPhase = if stdenv.isDarwin then ''
301+ installPhase = if buildStdenv.isDarwin then ''
274302 mkdir -p $out/Applications
275303 cp -LR dist/${binaryNameCapitalized}.app $out/Applications
276304 '' else null;
277305
278− postInstall = lib.optionalString stdenv.isLinux ''
306+ postInstall = lib.optionalString buildStdenv.isLinux ''
279307 # Remove SDK cruft. FIXME: move to a separate output?
280308 rm -rf $out/share/idl $out/include $out/lib/${binaryName}-devel-*
281309
@@ -283,7 +311,7 @@ stdenv.mkDerivation ({
283311 gappsWrapperArgs+=(--argv0 "$out/bin/.${binaryName}-wrapped")
284312 '';
285313
286− postFixup = lib.optionalString stdenv.isLinux ''
314+ postFixup = lib.optionalString buildStdenv.isLinux ''
287315 # Fix notifications. LibXUL uses dlopen for this, unfortunately; see #18712.
288316 patchelf --set-rpath "${lib.getLib libnotify
289317 }/lib:$(patchelf --print-rpath "$out"/lib/${binaryName}*/libxul.so)" \