Unverified Commit bc927415 authored by Tristan Ross's avatar Tristan Ross Committed by GitHub
Browse files

Merge pull request #324717 from ExpidusOS/fix/flutter-engine

flutterPackages-source: disable old version sources, fix update hashes
parents a5084844 883f7160
Loading
Loading
Loading
Loading
+45 −38
Original line number Diff line number Diff line
{ lib, targetPlatform }:
rec {
{ lib, platform }:
let
  self = {
    os =
    if targetPlatform.isLinux then
      if platform.isLinux then
        "linux"
    else if targetPlatform.isDarwin then
      else if platform.isDarwin then
        "macos"
    else if targetPlatform.isWindows then
      else if platform.isWindows then
        "windows"
      else
      throw "Unsupported OS \"${targetPlatform.parsed.kernel.name}\"";
        throw "Unsupported OS \"${platform.parsed.kernel.name}\"";

    alt-os = if platform.isDarwin then "mac" else self.os;

    arch =
    if targetPlatform.isx86_64 then
      if platform.isx86_64 then
        "amd64"
    else if targetPlatform.isx86 && targetPlatform.is32bit then
      else if platform.isx86 && platform.is32bit then
        "386"
    else if targetPlatform.isAarch64 then
      else if platform.isAarch64 then
        "arm64"
    else if targetPlatform.isMips && targetPlatform.parsed.cpu.significantByte == "littleEndian" then
      else if platform.isMips && platform.parsed.cpu.significantByte == "littleEndian" then
        "mipsle"
    else if targetPlatform.isMips64 then
      "mips64${lib.optionalString (targetPlatform.parsed.cpu.significantByte == "littleEndian") "le"}"
    else if targetPlatform.isPower64 then
      "ppc64${lib.optionalString (targetPlatform.parsed.cpu.significantByte == "littleEndian") "le"}"
    else if targetPlatform.isS390x then
      else if platform.isMips64 then
        "mips64${lib.optionalString (platform.parsed.cpu.significantByte == "littleEndian") "le"}"
      else if platform.isPower64 then
        "ppc64${lib.optionalString (platform.parsed.cpu.significantByte == "littleEndian") "le"}"
      else if platform.isS390x then
        "s390x"
      else if platform.isRiscV64 then
        "riscv64"
      else
      throw "Unsupported CPU \"${targetPlatform.parsed.cpu.name}\"";
        throw "Unsupported CPU \"${platform.parsed.cpu.name}\"";

    alt-arch =
    if targetPlatform.isx86_64 then
      if platform.isx86_64 then
        "x64"
    else if targetPlatform.isAarch64 then
      else if platform.isAarch64 then
        "arm64"
      else
      targetPlatform.parsed.cpu.name;
        platform.parsed.cpu.name;

  platform = "${os}-${arch}";
  alt-platform = "${os}-${alt-arch}";
}
    platform = "${self.os}-${self.arch}";
    alt-platform = "${self.os}-${self.alt-arch}";
  };
in
self
+2 −2
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@
  url,
  patches,
  runtimeModes,
  isOptimized ? true,
  isOptimized ? null,
  lib,
  stdenv,
  dart,
@@ -33,8 +33,8 @@ let
        url
        patches
        runtimeMode
        isOptimized
        ;
      isOptimized = args.isOptimized or runtimeMode != "debug";
    }
  );
in
+37 −31
Original line number Diff line number Diff line
@@ -4,11 +4,11 @@
  writeText,
  symlinkJoin,
  targetPlatform,
  hostPlatform,
  buildPlatform,
  darwin,
  clang,
  llvm,
  tools ? callPackage ./tools.nix { inherit hostPlatform; },
  tools ? callPackage ./tools.nix { inherit buildPlatform; },
  stdenv,
  stdenvNoCC,
  dart,
@@ -33,7 +33,8 @@
  gtk3,
  pkg-config,
  ninja,
  python3,
  python312,
  python39,
  git,
  version,
  flutterVersion,
@@ -44,7 +45,7 @@
  patches,
  url,
  runtimeMode ? "release",
  isOptimized ? true,
  isOptimized ? runtimeMode != "debug",
}:
let
  expandSingleDep =
@@ -52,14 +53,19 @@ let

  expandDeps = deps: lib.flatten (map expandSingleDep deps);

  constants = callPackage ./constants.nix { inherit targetPlatform; };
  constants = callPackage ./constants.nix { platform = targetPlatform; };

  python3 = if lib.versionAtLeast flutterVersion "3.20" then python312 else python39;

  src = callPackage ./source.nix {
    inherit
      tools
      flutterVersion
      version
      hashes
      url
      targetPlatform
      buildPlatform
      ;
  };

@@ -81,9 +87,11 @@ let
    ];
  };

  outName = "host_${runtimeMode}${lib.optionalString (!isOptimized) "_unopt --unoptimized"}";
  outName = "host_${runtimeMode}${lib.optionalString (!isOptimized) "_unopt"}";

  dartPath = "${if (lib.versionAtLeast flutterVersion "3.23") then "flutter/third_party" else "third_party"}/dart";
  dartPath = "${
    if (lib.versionAtLeast flutterVersion "3.23") then "flutter/third_party" else "third_party"
  }/dart";
in
stdenv.mkDerivation (finalAttrs: {
  pname = "flutter-engine-${runtimeMode}${lib.optionalString (!isOptimized) "-unopt"}";
@@ -95,7 +103,11 @@ stdenv.mkDerivation (finalAttrs: {
    dartSdkVersion
    src
    outName
    swiftshader;
    swiftshader
    ;

  setOutputFlags = false;
  doStrip = isOptimized;

  toolchain = symlinkJoin {
    name = "flutter-engine-toolchain-${version}";
@@ -145,9 +157,14 @@ stdenv.mkDerivation (finalAttrs: {
    '';
  };

  NIX_CFLAGS_COMPILE = "-I${finalAttrs.toolchain}/include";
  NIX_CFLAGS_COMPILE = [
    "-I${finalAttrs.toolchain}/include"
  ] ++ lib.optional (!isOptimized) "-U_FORTIFY_SOURCE";

  nativeCheckInputs = lib.optionals stdenv.isLinux [ xorg.xorgserver openbox ];
  nativeCheckInputs = lib.optionals stdenv.isLinux [
    xorg.xorgserver
    openbox
  ];

  nativeBuildInputs =
    [
@@ -168,10 +185,7 @@ stdenv.mkDerivation (finalAttrs: {

  buildInputs = [ gtk3 ];

  patchtools = [
    "${dartPath}/tools/sdks/dart-sdk/bin/dart"
    "flutter/third_party/gn/gn"
  ];
  patchtools = [ "flutter/third_party/gn/gn" ];

  dontPatch = true;

@@ -194,6 +208,10 @@ stdenv.mkDerivation (finalAttrs: {
    mkdir -p src/flutter/buildtools/${constants.alt-platform}
    ln -s ${llvm} src/flutter/buildtools/${constants.alt-platform}/clang

    mkdir -p src/buildtools/${constants.alt-platform}
    ln -s ${llvm} src/buildtools/${constants.alt-platform}/clang

    mkdir -p src/${dartPath}/tools/sdks
    ln -s ${dart} src/${dartPath}/tools/sdks/dart-sdk

    ${lib.optionalString (stdenv.isLinux) ''
@@ -204,13 +222,12 @@ stdenv.mkDerivation (finalAttrs: {

    for dir in ''${patchgit[@]}; do
      pushd src/$dir
      rev=$(cat .git/HEAD)
      rm -rf .git
      git init
      git add .
      git config user.name "nobody"
      git config user.email "nobody@local.host"
      git commit -a -m "$rev" --quiet
      git commit -a -m "$dir" --quiet
      popd
    done

@@ -239,7 +256,9 @@ stdenv.mkDerivation (finalAttrs: {
    ++ lib.optionals (targetPlatform.isx86_64 == false) [
      "--linux"
      "--linux-cpu ${constants.alt-arch}"
    ];
    ]
    ++ lib.optional (!isOptimized) "--unoptimized"
    ++ lib.optional (runtimeMode == "debug") "--no-stripped";

  # NOTE: Once https://github.com/flutter/flutter/issues/127606 is fixed, use "--no-prebuilt-dart-sdk"
  configurePhase =
@@ -267,22 +286,9 @@ stdenv.mkDerivation (finalAttrs: {
    runHook preBuild

    export TERM=dumb
    for tool in flatc scenec gen_snapshot dart impellerc shader_archiver gen_snapshot_product; do
      ninja -C $out/out/$outName -j$NIX_BUILD_CORES $tool
      ${lib.optionalString (stdenv.isLinux) ''
        patchelf $out/out/$outName/$tool --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker)
      ''}
    done

    ninja -C $out/out/$outName -j$NIX_BUILD_CORES

    ${lib.optionalString (stdenv.isLinux) ''
      patchelf $out/out/$outName/dart-sdk/bin/dartaotruntime \
        --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker)

      find $out/out/$outName/exe.unstripped -executable -type f -exec patchelf --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) {} \;
    ''}

    runHook postBuild
  '';

@@ -323,5 +329,5 @@ stdenv.mkDerivation (finalAttrs: {
      "x86_64-darwin"
      "aarch64-darwin"
    ];
  };
  } // lib.optionalAttrs (lib.versionOlder flutterVersion "3.22") { hydraPlatforms = [ ]; };
})
+32 −12
Original line number Diff line number Diff line
{
  lib,
  callPackage,
  hostPlatform,
  buildPlatform,
  targetPlatform,
  hostPlatform,
  fetchgit,
  tools ? callPackage ./tools.nix { inherit hostPlatform; },
  tools ? null,
  curl,
  pkg-config,
  git,
@@ -11,15 +13,19 @@
  runCommand,
  writeText,
  cacert,
  flutterVersion,
  version,
  hashes,
  url,
}:
}@pkgs:
let
  constants = callPackage ./constants.nix { inherit targetPlatform; };
  target-constants = callPackage ./constants.nix { platform = targetPlatform; };
  build-constants = callPackage ./constants.nix { platform = buildPlatform; };
  tools = pkgs.tools or (callPackage ./tools.nix { inherit hostPlatform buildPlatform; });

  boolOption = value: if value then "True" else "False";
in
runCommand "flutter-engine-source-${version}-${targetPlatform.system}"
runCommand "flutter-engine-source-${version}-${buildPlatform.system}-${targetPlatform.system}"
  {
    pname = "flutter-engine-source";
    inherit version;
@@ -51,8 +57,20 @@ runCommand "flutter-engine-source-${version}-${targetPlatform.system}"
          "setup_githooks": False,
          "download_esbuild": False,
          "download_dart_sdk": False,
          "host_cpu": "${build-constants.alt-arch}",
          "host_os": "${build-constants.alt-os}",
        },
      }]

      target_os_only = True
      target_os = [
        "${target-constants.alt-os}"
      ]

      target_cpu_only = True
      target_cpu = [
        "${target-constants.alt-arch}"
      ]
    '';

    NIX_SSL_CERT_FILE = "${cacert}/etc/ssl/certs/ca-bundle.crt";
@@ -64,7 +82,9 @@ runCommand "flutter-engine-source-${version}-${targetPlatform.system}"

    outputHashAlgo = "sha256";
    outputHashMode = "recursive";
    outputHash = hashes.${targetPlatform.system} or (throw "Hash not set for ${targetPlatform.system}");
    outputHash =
      (hashes."${buildPlatform.system}" or { })."${targetPlatform.system}"
        or (throw "Hash not set for ${targetPlatform.system} on ${buildPlatform.system}");
  }
  ''
    source ${../../../../build-support/fetchgit/deterministic-git}
@@ -76,13 +96,13 @@ runCommand "flutter-engine-source-${version}-${targetPlatform.system}"
    cd $out

    export PATH=$PATH:$depot_tools
    python3 $depot_tools/gclient.py sync --no-history --shallow --nohooks 2>&1 >/dev/null
    find $out -name '.git' -exec dirname {} \; | xargs bash -c 'make_deterministic_repo $@' _
    find $out -path '*/.git/*' ! -name 'HEAD' -prune -exec rm -rf {} \;
    find $out -name '.git' -exec mkdir {}/logs \;
    find $out -name '.git' -exec cp {}/HEAD {}/logs/HEAD \;
    python3 $depot_tools/gclient.py sync --no-history --shallow --nohooks -j $NIX_BUILD_CORES
    find $out -name '.git' -exec rm -rf {} \; || true

    rm -rf $out/src/flutter/{buildtools,prebuilts,third_party/swiftshader}
    rm -rf $out/src/buildtools/
    rm -rf $out/src/flutter/{buildtools,prebuilts,third_party/swiftshader,third_party/gn/.versions}
    rm -rf $out/src/flutter/{third_party/dart/tools/sdks/dart-sdk,third_party/ninja/ninja}
    rm -rf $out/src/third_party/{dart/tools/sdks/dart-sdk,libcxx/test}

    rm -rf $out/.cipd $out/.gclient $out/.gclient_entries $out/.gclient_previous_custom_vars $out/.gclient_previous_sync_commits
  ''
+44 −13
Original line number Diff line number Diff line
{
  stdenv,
  callPackage,
  fetchgit,
  fetchurl,
  writeText,
  runCommand,
  buildPlatform,
  hostPlatform,
  darwin,
  writeShellScriptBin,
@@ -29,7 +31,9 @@
  },
}:
let
  constants = callPackage ./constants.nix { targetPlatform = hostPlatform; };
  constants = callPackage ./constants.nix { platform = buildPlatform; };
  host-constants = callPackage ./constants.nix { platform = hostPlatform; };
  stdenv-constants = callPackage ./constants.nix { platform = stdenv.hostPlatform; };
in
{
  depot_tools = fetchgit {
@@ -39,17 +43,44 @@ in
  };

  cipd =
    let
      unwrapped =
        runCommand "cipd-${cipdCommit}"
          {
        unwrapped = fetchurl {
            src = fetchurl {
              name = "cipd-${cipdCommit}-unwrapped";
          url = "https://chrome-infra-packages.appspot.com/client?platform=${constants.platform}&version=git_revision:${cipdCommit}";
          sha256 = cipdHashes.${constants.platform};
              url = "https://chrome-infra-packages.appspot.com/client?platform=${stdenv-constants.platform}&version=git_revision:${cipdCommit}";
              sha256 = cipdHashes.${stdenv-constants.platform};
            };
          }
          ''
            mkdir -p $out/bin
        install -m755 $unwrapped $out/bin/cipd
            install -m755 $src $out/bin/cipd
          '';
    in
    writeShellScriptBin "cipd" ''
      params=$@

      if [[ "$1" == "ensure" ]]; then
        shift 1
        params="ensure"

        while [ "$#" -ne 0 ]; do
          if [[ "$1" == "-ensure-file" ]]; then
            ensureFile="$2"
            shift 2
            params="$params -ensure-file $ensureFile"

            sed -i 's/''${platform}/${host-constants.platform}/g' "$ensureFile"
            sed -i 's/gn\/gn\/${stdenv-constants.platform}/gn\/gn\/${constants.platform}/g' "$ensureFile"
          else
            params="$params $1"
            shift 1
          fi
        done
      fi

      exec ${unwrapped}/bin/cipd $params
    '';

  vpython =
Loading