about summary refs log tree commit diff
path: root/pkgs/applications/networking/browsers
diff options
context:
space:
mode:
authoremilylange <git@emilylange.de>2024-01-31 18:54:16 +0100
committeremilylange <git@emilylange.de>2024-02-01 00:35:57 +0100
commitaf35dbbf8c5fa08e38e21694b91cdf8c59677abf (patch)
treee9fd0ef8ab821824f66d8eb79bee628900fb974b /pkgs/applications/networking/browsers
parent3ab52f06cf7b413fcdc3db1c78b386a34e139d92 (diff)
downloadnixlib-af35dbbf8c5fa08e38e21694b91cdf8c59677abf.tar
nixlib-af35dbbf8c5fa08e38e21694b91cdf8c59677abf.tar.gz
nixlib-af35dbbf8c5fa08e38e21694b91cdf8c59677abf.tar.bz2
nixlib-af35dbbf8c5fa08e38e21694b91cdf8c59677abf.tar.lz
nixlib-af35dbbf8c5fa08e38e21694b91cdf8c59677abf.tar.xz
nixlib-af35dbbf8c5fa08e38e21694b91cdf8c59677abf.tar.zst
nixlib-af35dbbf8c5fa08e38e21694b91cdf8c59677abf.zip
chromium: fix rust toolchain and remove M121 workaround
The rust toolchain is required for chromium since M121.

In the last major bump (M120 -> M121) we had to work around this
requirement because we hadn't had our that part of our toolchain ready.

Until now :)

So this fixes and enables the toolchain for any chromium/electron >= 121
and removes the workaround from the last major bump.
Diffstat (limited to 'pkgs/applications/networking/browsers')
-rw-r--r--pkgs/applications/networking/browsers/chromium/common.nix30
-rw-r--r--pkgs/applications/networking/browsers/chromium/patches/chromium-121-rust.patch19
2 files changed, 36 insertions, 13 deletions
diff --git a/pkgs/applications/networking/browsers/chromium/common.nix b/pkgs/applications/networking/browsers/chromium/common.nix
index f860edc93a36..45fc2054c103 100644
--- a/pkgs/applications/networking/browsers/chromium/common.nix
+++ b/pkgs/applications/networking/browsers/chromium/common.nix
@@ -238,16 +238,9 @@ let
       })
     ] ++ lib.optionals (chromiumVersionAtLeast "121") [
       # M121 is the first version to require the new rust toolchain.
-      # But we don't have that ready yet.
-      # So we have to revert the singular commit that requires rust toolchain.
-      # This works, because the code in question, the QR code generator, is present in
-      # two variants: c++ and rust. This workaround will not last.
-      # The c++ variant in question is deemed to be removed in a month (give or take).
-      (githubPatch {
-        revert = true;
-        commit = "bcf739b95713071687ff25010683248de0092f6a";
-        hash = "sha256-1ZPe45cc2bjnErcF3prbLMlYpU7kpuwDVcjewINQr+Q=";
-      })
+      # Partial revert of https://github.com/chromium/chromium/commit/3687976b0c6d36cf4157419a24a39f6770098d61
+      # allowing us to use our rustc and our clang.
+      ./patches/chromium-121-rust.patch
     ];
 
     postPatch = ''
@@ -412,11 +405,15 @@ let
       # (ld.lld: error: unable to find library -l:libffi_pic.a):
       use_system_libffi = true;
       # Use nixpkgs Rust compiler instead of the one shipped by Chromium.
-      # We do intentionally not set rustc_version as nixpkgs will never do incremental
-      # rebuilds, thus leaving this empty is fine.
       rust_sysroot_absolute = "${buildPackages.rustc}";
-      # Building with rust is disabled for now - this matches the flags in other major distributions.
+      # Rust is enabled for M121+, see next section:
       enable_rust = false;
+    } // lib.optionalAttrs (chromiumVersionAtLeast "121") {
+      # M121 the first version to actually require a functioning rust toolchain
+      enable_rust = true;
+      # While we technically don't need the cache-invalidation rustc_version provides, rustc_version
+      # is still used in some scripts (e.g. build/rust/std/find_std_rlibs.py).
+      rustc_version = buildPackages.rustc.version;
     } // lib.optionalAttrs (!(stdenv.buildPlatform.canExecute stdenv.hostPlatform)) {
       # https://www.mail-archive.com/v8-users@googlegroups.com/msg14528.html
       arm_control_flow_integrity = "none";
@@ -431,6 +428,13 @@ let
     } // lib.optionalAttrs ungoogled (lib.importTOML ./ungoogled-flags.toml)
     // (extraAttrs.gnFlags or {}));
 
+    # We cannot use chromiumVersionAtLeast in mkDerivation's env attrset due
+    # to infinite recursion when chromium.override is used (e.g. electron).
+    # To work aroud this, we use export in the preConfigure phase.
+    preConfigure = lib.optionalString (chromiumVersionAtLeast "121") ''
+      export RUSTC_BOOTSTRAP=1
+    '';
+
     configurePhase = ''
       runHook preConfigure
 
diff --git a/pkgs/applications/networking/browsers/chromium/patches/chromium-121-rust.patch b/pkgs/applications/networking/browsers/chromium/patches/chromium-121-rust.patch
new file mode 100644
index 000000000000..b5292c80858b
--- /dev/null
+++ b/pkgs/applications/networking/browsers/chromium/patches/chromium-121-rust.patch
@@ -0,0 +1,19 @@
+--- a/build/config/compiler/BUILD.gn
++++ b/build/config/compiler/BUILD.gn
+@@ -1629,16 +1629,6 @@
+     configs += [ "//build/config/c++:runtime_library" ]
+   }
+
+-  # Rust and C++ both provide intrinsics for LLVM to call for math operations. We
+-  # want to use the C++ intrinsics, not the ones in the Rust compiler_builtins
+-  # library. The Rust symbols are marked as weak, so that they can be replaced by
+-  # the C++ symbols. This config ensures the C++ symbols exist and are strong in
+-  # order to cause that replacement to occur by explicitly linking in clang's
+-  # compiler-rt library.
+-  if (is_clang && toolchain_has_rust) {
+-    configs += [ "//build/config/clang:compiler_builtins" ]
+-  }
+-
+   # TODO(crbug.com/830987): Come up with a better name for is POSIX + Fuchsia
+   # configuration.
+   if (is_posix || is_fuchsia) {