Merge pull request #229265 from amjoseph-nixpkgs/pr/chromium/cross/all

authored by Artturi and committed by GitHub 4055d18c 51606bc8

+133 -10
+1 -1
pkgs/applications/networking/browsers/chromium/browser.nix
··· 6 6 mkChromiumDerivation (base: rec { 7 7 name = "chromium-browser"; 8 8 packageName = "chromium"; 9 - buildTargets = [ "mksnapshot" "chrome_sandbox" "chrome" ]; 9 + buildTargets = [ "run_mksnapshot_default" "chrome_sandbox" "chrome" ]; 10 10 11 11 outputs = ["out" "sandbox"]; 12 12
+84 -5
pkgs/applications/networking/browsers/chromium/common.nix
··· 1 1 { stdenv, lib, fetchurl, fetchpatch 2 + , buildPackages 3 + , pkgsBuildBuild 4 + , pkgsBuildTarget 2 5 # Channel data: 3 6 , channel, upstream-info 4 7 # Helper functions: ··· 8 11 , ninja, pkg-config 9 12 , python3, perl 10 13 , which 11 - , llvmPackages 14 + , llvmPackages_attrName 12 15 , rustc 16 + , libuuid 17 + , overrideCC 13 18 # postPatch: 14 19 , pkgsBuildHost 15 20 # configurePhase: ··· 116 121 inherit (upstream-info.deps.ungoogled-patches) rev sha256; 117 122 }; 118 123 124 + # There currently isn't a (much) more concise way to get a stdenv 125 + # that uses lld as its linker without bootstrapping pkgsLLVM; see 126 + # https://github.com/NixOS/nixpkgs/issues/142901 127 + buildPlatformLlvmStdenv = 128 + let 129 + llvmPackages = pkgsBuildBuild.${llvmPackages_attrName}; 130 + in 131 + overrideCC llvmPackages.stdenv 132 + (llvmPackages.stdenv.cc.override { 133 + inherit (llvmPackages) bintools; 134 + }); 135 + 136 + chromiumRosettaStone = { 137 + cpu = platform: 138 + let name = platform.parsed.cpu.name; 139 + in ({ "x86_64" = "x64"; 140 + "i686" = "x86"; 141 + "arm" = "arm"; 142 + "aarch64" = "arm64"; 143 + }.${platform.parsed.cpu.name} 144 + or (throw "no chromium Rosetta Stone entry for cpu: ${name}")); 145 + os = platform: 146 + if platform.isLinux 147 + then "linux" 148 + else throw "no chromium Rosetta Stone entry for os: ${platform.config}"; 149 + }; 150 + 119 151 base = rec { 120 152 pname = "${packageName}-unwrapped"; 121 153 inherit (upstream-info) version; ··· 130 162 ninja pkg-config 131 163 python3WithPackages perl 132 164 which 133 - llvmPackages.bintools 165 + buildPackages.${llvmPackages_attrName}.bintools 134 166 bison gperf 135 167 ]; 136 168 169 + depsBuildBuild = [ 170 + buildPlatformLlvmStdenv 171 + buildPlatformLlvmStdenv.cc 172 + pkg-config 173 + libuuid 174 + libpng # needed for "host/generate_colors_info" 175 + ] 176 + # When cross-compiling, chromium builds a huge proportion of its 177 + # components for both the `buildPlatform` (which it calls 178 + # `host`) as well as for the `hostPlatform` -- easily more than 179 + # half of the dependencies are needed here. To avoid having to 180 + # maintain a separate list of buildPlatform-dependencies, we 181 + # simply throw in the kitchen sink. 182 + ++ buildInputs 183 + ; 184 + 137 185 buildInputs = [ 138 186 (libpng.override { apngSupport = false; }) # https://bugs.chromium.org/p/chromium/issues/detail?id=752403 139 187 bzip2 flac speex opusWithCustomModes 140 188 libevent expat libjpeg snappy 141 189 libcap 142 - xdg-utils minizip libwebp 190 + ] ++ lib.optionals (!xdg-utils.meta.broken) [ 191 + xdg-utils 192 + ] ++ [ 193 + minizip libwebp 143 194 libusb1 re2 144 195 ffmpeg libxslt libxml2 145 196 nasm ··· 162 213 ++ lib.optional pulseSupport libpulseaudio; 163 214 164 215 patches = [ 216 + ./cross-compile.patch 165 217 # Optional patch to use SOURCE_DATE_EPOCH in compute_build_timestamp.py (should be upstreamed): 166 218 ./patches/no-build-timestamps.patch 167 219 # For bundling Widevine (DRM), might be replaceable via bundle_widevine_cdm=true in gnFlags: ··· 225 277 '/usr/share/locale/' \ 226 278 '${glibc}/share/locale/' 227 279 280 + '' + lib.optionalString (!xdg-utils.meta.broken) '' 228 281 sed -i -e 's@"\(#!\)\?.*xdg-@"\1${xdg-utils}/bin/xdg-@' \ 229 282 chrome/browser/shell_integration_linux.cc 230 283 ··· 268 321 # weaken or disable security measures like sandboxing or ASLR): 269 322 is_official_build = true; 270 323 disable_fieldtrial_testing_config = true; 324 + 325 + # note: chromium calls buildPlatform "host" and calls hostPlatform "target" 326 + host_cpu = chromiumRosettaStone.cpu stdenv.buildPlatform; 327 + host_os = chromiumRosettaStone.os stdenv.buildPlatform; 328 + target_cpu = chromiumRosettaStone.cpu stdenv.hostPlatform; 329 + v8_target_cpu = chromiumRosettaStone.cpu stdenv.hostPlatform; 330 + target_os = chromiumRosettaStone.os stdenv.hostPlatform; 331 + 271 332 # Build Chromium using the system toolchain (for Linux distributions): 333 + # 334 + # What you would expect to be caled "target_toolchain" is 335 + # actually called either "default_toolchain" or "custom_toolchain", 336 + # depending on which part of the codebase you are in; see: 337 + # https://github.com/chromium/chromium/blob/d36462cc9279464395aea5e65d0893d76444a296/build/config/BUILDCONFIG.gn#L17-L44 272 338 custom_toolchain = "//build/toolchain/linux/unbundle:default"; 273 - host_toolchain = "//build/toolchain/linux/unbundle:default"; 339 + host_toolchain = "//build/toolchain/linux/unbundle:host"; 340 + v8_snapshot_toolchain = "//build/toolchain/linux/unbundle:host"; 341 + 342 + host_pkg_config = "${pkgsBuildBuild.pkg-config}/bin/pkg-config"; 343 + pkg_config = "${pkgsBuildHost.pkg-config}/bin/${stdenv.cc.targetPrefix}pkg-config"; 344 + 274 345 # Don't build against a sysroot image downloaded from Cloud Storage: 275 346 use_sysroot = false; 276 347 # Because we use a different toolchain / compiler version: ··· 304 375 rtc_use_pipewire = true; 305 376 # Disable PGO because the profile data requires a newer compiler version (LLVM 14 isn't sufficient): 306 377 chrome_pgo_phase = 0; 307 - clang_base_path = "${llvmPackages.stdenv.cc}"; 378 + clang_base_path = "${pkgsBuildTarget.${llvmPackages_attrName}.stdenv.cc}"; 308 379 use_qt = false; 309 380 # To fix the build as we don't provide libffi_pic.a 310 381 # (ld.lld: error: unable to find library -l:libffi_pic.a): ··· 313 384 # We do intentionally not set rustc_version as nixpkgs will never do incremental 314 385 # rebuilds, thus leaving this empty is fine. 315 386 rust_sysroot_absolute = "${rustc}"; 387 + } // lib.optionalAttrs (!(stdenv.buildPlatform.canExecute stdenv.hostPlatform)) { 388 + # https://www.mail-archive.com/v8-users@googlegroups.com/msg14528.html 389 + arm_control_flow_integrity = "none"; 316 390 } // lib.optionalAttrs proprietaryCodecs { 317 391 # enable support for the H.264 codec 318 392 proprietary_codecs = true; ··· 342 416 # our Clang is always older than Chromium's and the build logs have a size 343 417 # of approx. 25 MB without this option (and this saves e.g. 66 %). 344 418 env.NIX_CFLAGS_COMPILE = "-Wno-unknown-warning-option"; 419 + env.BUILD_CC = "$CC_FOR_BUILD"; 420 + env.BUILD_CXX = "$CXX_FOR_BUILD"; 421 + env.BUILD_AR = "$AR_FOR_BUILD"; 422 + env.BUILD_NM = "$NM_FOR_BUILD"; 423 + env.BUILD_READELF = "$READELF_FOR_BUILD"; 345 424 346 425 buildPhase = let 347 426 buildCommand = target: ''
+31
pkgs/applications/networking/browsers/chromium/cross-compile.patch
··· 1 + diff --git a/build/toolchain/linux/unbundle/BUILD.gn b/build/toolchain/linux/unbundle/BUILD.gn 2 + index a091491236bb1..d36fd4e652fbf 100644 3 + --- a/build/toolchain/linux/unbundle/BUILD.gn 4 + +++ b/build/toolchain/linux/unbundle/BUILD.gn 5 + @@ -9,6 +9,7 @@ gcc_toolchain("default") { 6 + cxx = getenv("CXX") 7 + ar = getenv("AR") 8 + nm = getenv("NM") 9 + + readelf = getenv("READELF") 10 + ld = cxx 11 + 12 + extra_cflags = getenv("CFLAGS") 13 + @@ -27,6 +28,7 @@ gcc_toolchain("host") { 14 + cxx = getenv("BUILD_CXX") 15 + ar = getenv("BUILD_AR") 16 + nm = getenv("BUILD_NM") 17 + + readelf = getenv("BUILD_READELF") 18 + ld = cxx 19 + 20 + extra_cflags = getenv("BUILD_CFLAGS") 21 + @@ -35,7 +37,8 @@ gcc_toolchain("host") { 22 + extra_ldflags = getenv("BUILD_LDFLAGS") 23 + 24 + toolchain_args = { 25 + - current_cpu = current_cpu 26 + - current_os = current_os 27 + + current_cpu = host_cpu 28 + + current_os = host_os 29 + + v8_current_cpu = target_cpu 30 + } 31 + }
+17 -4
pkgs/applications/networking/browsers/chromium/default.nix
··· 16 16 , cupsSupport ? true 17 17 , pulseSupport ? config.pulseaudio or stdenv.isLinux 18 18 , commandLineArgs ? "" 19 + , pkgsBuildTarget 20 + , pkgsBuildBuild 21 + , pkgs 19 22 }: 20 23 21 24 let 22 - llvmPackages = llvmPackages_16; 23 - stdenv = llvmPackages.stdenv; 25 + # Sometimes we access `llvmPackages` via `pkgs`, and other times 26 + # via `pkgsFooBar`, so a string (attrname) is the only way to have 27 + # a single point of control over the LLVM version used. 28 + llvmPackages_attrName = "llvmPackages_16"; 29 + stdenv = pkgs.${llvmPackages_attrName}.stdenv; 24 30 25 31 upstream-info = (import ./upstream-info.nix).${channel}; 26 32 ··· 42 48 callPackage = newScope chromium; 43 49 44 50 chromium = rec { 45 - inherit stdenv llvmPackages upstream-info; 51 + inherit stdenv llvmPackages_attrName upstream-info; 46 52 47 53 mkChromiumDerivation = callPackage ./common.nix ({ 48 54 inherit channel chromiumVersionAtLeast versionRange; ··· 60 66 inherit channel chromiumVersionAtLeast enableWideVine ungoogled; 61 67 }; 62 68 63 - ungoogled-chromium = callPackage ./ungoogled.nix {}; 69 + # ungoogled-chromium is, contrary to its name, not a build of 70 + # chromium. It is a patched copy of chromium's *source code*. 71 + # Therefore, it needs to come from buildPackages, because it 72 + # contains python scripts which get /nix/store/.../bin/python3 73 + # patched into their shebangs. 74 + ungoogled-chromium = pkgsBuildBuild.callPackage ./ungoogled.nix {}; 64 75 }; 65 76 66 77 pkgSuffix = if channel == "dev" then "unstable" else ··· 209 220 210 221 export XDG_DATA_DIRS=$XDG_ICON_DIRS:$GSETTINGS_SCHEMAS_PATH\''${XDG_DATA_DIRS:+:}\$XDG_DATA_DIRS 211 222 223 + '' + lib.optionalString (!xdg-utils.meta.broken) '' 212 224 # Mainly for xdg-open but also other xdg-* tools (this is only a fallback; \$PATH is suffixed so that other implementations can be used): 213 225 export PATH="\$PATH\''${PATH:+:}${xdg-utils}/bin" 226 + '' + '' 214 227 215 228 . 216 229 w