@@ -23,8 +23,7 @@
2323, ffmpegSupport ? true
2424, gtk3Support ? true, gtk2, gtk3, wrapGAppsHook
2525, waylandSupport ? true, libxkbcommon
26−# LTO is disabled since it caused segfaults on wayland see https://github.com/NixOS/nixpkgs/issues/101429
27−, ltoSupport ? false, overrideCC, buildPackages
26+, ltoSupport ? stdenv.isLinux, overrideCC, buildPackages
2827, gssSupport ? true, kerberos
2928, pipewireSupport ? waylandSupport && webrtcSupport, pipewire
3029
@@ -91,11 +90,19 @@ let
9190 then "/Applications/${binaryNameCapitalized}.app/Contents/MacOS"
9291 else "/bin";
9392
93+ # 78 ESR won't build with rustc 1.47
94+ inherit (if lib.versionAtLeast ffversion "82" then rustPackages else rustPackages_1_45)
95+ rustc cargo;
96+
9497 # Darwin's stdenv provides the default llvmPackages version, match that since
9598 # clang LTO on Darwin is broken so the stdenv is not being changed.
99+ # Target the LLVM version that rustc -Vv reports it is built with for LTO.
100+ # rustPackages_1_45 -> LLVM 10, rustPackages -> LLVM 11
96101 llvmPackages = if stdenv.isDarwin
97102 then buildPackages.llvmPackages
98− else buildPackages.llvmPackages_10;
103+ else if lib.versionAtLeast rustc.llvm.version "11"
104+ then buildPackages.llvmPackages_11
105+ else buildPackages.llvmPackages_10;
99106
100107 # When LTO for Darwin is fixed, the following will need updating as lld
101108 # doesn't work on it. For now it is fine since ltoSupport implies no Darwin.
@@ -103,10 +110,6 @@ let
103110 then overrideCC stdenv llvmPackages.lldClang
104111 else stdenv;
105112
106− # 78 ESR won't build with rustc 1.47
107− inherit (if lib.versionAtLeast ffversion "82" then rustPackages else rustPackages_1_45)
108− rustc cargo;
109−
110113 nss_pkg = if lib.versionOlder ffversion "83" then nss_3_53 else nss;
111114in
112115
@@ -121,13 +124,19 @@ buildStdenv.mkDerivation ({
121124 ] ++
122125 lib.optional (lib.versionOlder ffversion "83") ./no-buildconfig-ffx76.patch ++
123126 lib.optional (lib.versionAtLeast ffversion "84") ./no-buildconfig-ffx84.patch ++
127+ lib.optional (ltoSupport && lib.versionOlder ffversion "84") ./lto-dependentlibs-generation-ffx83.patch ++
128+ lib.optional (ltoSupport && lib.versionAtLeast ffversion "84" && lib.versionOlder ffversion "86")
129+ (fetchpatch {
130+ url = "https://hg.mozilla.org/mozilla-central/raw-rev/fdff20c37be3";
131+ sha256 = "135n9brliqy42lj3nqgb9d9if7x6x9nvvn0z4anbyf89bikixw48";
132+ })
124133
125134 # there are two flavors of pipewire support
126135 # The patches for the ESR release and the patches for the current stable
127136 # release.
128137 # Until firefox upstream stabilizes pipewire support we will have to continue
129138 # tracking multiple versions here.
130− lib.optional (pipewireSupport && lib.versionOlder ffversion "83")
139+ ++ lib.optional (pipewireSupport && lib.versionOlder ffversion "83")
131140 (fetchpatch {
132141 # https://src.fedoraproject.org/rpms/firefox/blob/master/f/firefox-pipewire-0-3.patch
133142 url = "https://src.fedoraproject.org/rpms/firefox/raw/e99b683a352cf5b2c9ff198756859bae408b5d9d/f/firefox-pipewire-0-3.patch";
@@ -316,6 +325,13 @@ buildStdenv.mkDerivation ({
316325 "MOZILLA_OFFICIAL=1"
317326 "BUILD_OFFICIAL=1"
318327 ]
328+ ++ lib.optionals ltoSupport [
329+ "AR=${llvmPackages.bintools}/bin/llvm-ar"
330+ "LLVM_OBJDUMP=${llvmPackages.bintools}/bin/llvm-objdump"
331+ "NM=${llvmPackages.bintools}/bin/llvm-nm"
332+ "RANLIB=${llvmPackages.bintools}/bin/llvm-ranlib"
333+ "STRIP=${llvmPackages.bintools}/bin/llvm-strip"
334+ ]
319335 ++ extraMakeFlags;
320336
321337 enableParallelBuilding = true;