Unverified Commit a2fc9f41 authored by Maciej Krüger's avatar Maciej Krüger Committed by GitHub
Browse files

Merge pull request #262789 from hacker1024/feature/flutter-from-source

flutter: Construct SDK from Git repository + `flutter precache`
parents d17d1a37 9e046794
Loading
Loading
Loading
Loading
+10 −8
Original line number Diff line number Diff line
{ lib, stdenv, callPackage, fetchDartDeps, writeText, symlinkJoin, dartHooks, makeWrapper, dart, cacert, nodejs, darwin, jq }:
{ lib, stdenv, callPackage, fetchDartDeps, runCommand, symlinkJoin, writeText, dartHooks, makeWrapper, dart, cacert, nodejs, darwin, jq }:

{ sdkSetupScript ? ""
, pubGetScript ? "dart pub get"
@@ -37,13 +37,15 @@
let
  dartDeps = (fetchDartDeps.override {
    dart = symlinkJoin {
      name = "dart-fod";
      paths = [ dart ];
      nativeBuildInputs = [ makeWrapper ];
      postBuild = ''
        wrapProgram "$out/bin/dart" \
      name = "dart-sdk-fod";
      paths = [
        (runCommand "dart-fod" { nativeBuildInputs = [ makeWrapper ]; } ''
          mkdir -p "$out/bin"
          makeWrapper "${dart}/bin/dart" "$out/bin/dart" \
            --add-flags "--root-certs-file=${cacert}/etc/ssl/certs/ca-bundle.crt"
      '';
        '')
        dart
      ];
    };
  }) {
    buildDrvArgs = args;
+47 −6
Original line number Diff line number Diff line
@@ -154,15 +154,27 @@ let
      outputHash = if vendorHash != "" then vendorHash else lib.fakeSha256;
    } // (removeAttrs drvArgs [ "name" "pname" ]));

  depsListDrv = stdenvNoCC.mkDerivation ({
    name = "${name}-dart-deps-list.json";
    nativeBuildInputs = [ hook dart jq ];
  mkDepsDrv = args: stdenvNoCC.mkDerivation (args // {
    nativeBuildInputs = args.nativeBuildInputs or [ ] ++ [ hook dart ];

    configurePhase = ''
    configurePhase = args.configurePhase or ''
      runHook preConfigure
      doPubGet dart pub get --offline

      ${sdkSetupScript}

      _pub_get() {
        ${pubGetScript} --offline
      }
      doPubGet _pub_get

      runHook postConfigure
    '';
  } // (removeAttrs buildDrvInheritArgs [ "name" "pname" ]));

  depsListDrv = mkDepsDrv {
    name = "${name}-dart-deps-list.json";

    nativeBuildInputs = [ jq ];

    buildPhase = ''
      runHook preBuild
@@ -171,7 +183,34 @@ let
    '';

    dontInstall = true;
  } // (removeAttrs buildDrvInheritArgs [ "name" "pname" ]));
  };

  packageConfigDrv = mkDepsDrv {
    name = "${name}-package-config.json";

    nativeBuildInputs = [ jq ];

    buildPhase = ''
      runHook preBuild

      # Canonicalise the package_config.json, and replace references to the
      # reconstructed package cache with the original FOD.
      #
      # The reconstructed package cache is not reproducible. The intended
      # use-case of this derivation is for use with tools that use a
      # package_config.json to load assets from packages, and not for use with
      # Pub directly, which requires the setup performed by the hook before
      # usage.
      jq -S '
        .packages[] |= . + { rootUri: .rootUri | gsub("'"$PUB_CACHE"'"; "${hook.deps}/cache/.pub-cache") }
      | .generated |= "1970-01-01T00:00:00.000Z"
      ' .dart_tool/package_config.json > $out

      runHook postBuild
    '';

    dontInstall = true;
  };

  # As of Dart 3.0.0, Pub checks the revision of cached Git-sourced packages.
  # Git must be wrapped to return a positive result, as the real .git directory is wiped
@@ -195,8 +234,10 @@ let
    substitutions = { inherit gitSourceWrapper deps; };
    propagatedBuildInputs = [ dart git ];
    passthru = {
      inherit deps;
      files = deps.outPath;
      depsListFile = depsListDrv.outPath;
      packageConfig = packageConfigDrv;
    };
  }) ./setup-hook.sh;
in
+2 −0
Original line number Diff line number Diff line
@@ -48,6 +48,8 @@
    flutter config --enable-linux-desktop >/dev/null
  '';

  inherit pubGetScript;

  nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [ wrapGAppsHook ];
  buildInputs = (args.buildInputs or [ ]) ++ [ glib ];

+54 −0
Original line number Diff line number Diff line
{ lib
, runCommand
, xorg
, cacert
, unzip

, platform
, flutter
, hash
}:

let
  platforms = [
    "android"
    "ios"
    "web"
    "linux"
    "windows"
    "macos"
    "fuchsia"
    "universal"
  ];

  flutter' = flutter.override {
    # Use a version of Flutter with just enough capabilities to download
    # artifacts.
    supportedTargetPlatforms = [ ];
  };
in
runCommand "flutter-artifacts-${platform}"
{
  nativeBuildInputs = [ xorg.lndir flutter' unzip ];

  NIX_FLUTTER_TOOLS_VM_OPTIONS = "--root-certs-file=${cacert}/etc/ssl/certs/ca-bundle.crt";

  outputHash = hash;
  outputHashMode = "recursive";
  outputHashAlgo = "sha256";

  passthru = {
    inherit platform;
  };
} ''
  export FLUTTER_ROOT="$NIX_BUILD_TOP"
  lndir -silent '${flutter'}' "$FLUTTER_ROOT"
  rm -rf "$FLUTTER_ROOT/bin/cache"
  mkdir "$FLUTTER_ROOT/bin/cache"

  HOME="$(mktemp -d)" flutter precache -v '--${platform}' ${builtins.concatStringsSep " " (map (p: "'--no-${p}'") (lib.remove platform platforms))}
  rm -rf "$FLUTTER_ROOT/bin/cache/lockfile"
  find "$FLUTTER_ROOT" -type l -lname '${flutter'}/*' -delete

  cp -r bin/cache "$out"
''
+75 −0
Original line number Diff line number Diff line
# NOTICE: When updating these hashes, make sure that no additional platforms
# have been added to the `flutter precache` CLI. If any have, they may be
# included in every derivation, unless they are also added to the platform list
# in fetch-artifacts.nix.
#
# The known arguments are as follows:
# $ flutter precache --help --verbose
# Usage: flutter precache [arguments]
# -h, --help                              Print this usage information.
# -a, --all-platforms                     Precache artifacts for all host platforms.
# -f, --force                             Force re-downloading of artifacts.
#     --[no-]android                      Precache artifacts for Android development.
#     --[no-]android_gen_snapshot         Precache gen_snapshot for Android development.
#     --[no-]android_maven                Precache Gradle dependencies for Android development.
#     --[no-]android_internal_build       Precache dependencies for internal Android development.
#     --[no-]ios                          Precache artifacts for iOS development.
#     --[no-]web                          Precache artifacts for web development.
#     --[no-]linux                        Precache artifacts for Linux desktop development.
#     --[no-]windows                      Precache artifacts for Windows desktop development.
#     --[no-]macos                        Precache artifacts for macOS desktop development.
#     --[no-]fuchsia                      Precache artifacts for Fuchsia development.
#     --[no-]universal                    Precache artifacts required for any development platform.
#                                         (defaults to on)
#     --[no-]flutter_runner               Precache the flutter runner artifacts.
#     --[no-]use-unsigned-mac-binaries    Precache the unsigned macOS binaries when available.

# Schema:
# ${flutterVersion}.${targetPlatform}.${hostPlatform}
#
# aarch64-darwin as a host is not yet supported.
# https://github.com/flutter/flutter/issues/60118
{
  "3.13.8" = {
    android = {
      x86_64-linux = "sha256-Uc36aBq8wQo2aEvjAPOoixZElWOE/GNRm2GUfhbwT3Y=";
      aarch64-linux = "sha256-Uc36aBq8wQo2aEvjAPOoixZElWOE/GNRm2GUfhbwT3Y=";
      x86_64-darwin = "sha256-v/6/GTj7732fEOIgSaoM00yaw2qNwOMuvbuoCvii7vQ=";
    };
    fuchsia = {
      x86_64-linux = "sha256-eu0BERdz53CkSexbpu3KA7O6Q4g0s9SGD3t1Snsk3Fk=";
      aarch64-linux = "sha256-eu0BERdz53CkSexbpu3KA7O6Q4g0s9SGD3t1Snsk3Fk=";
      x86_64-darwin = "sha256-eu0BERdz53CkSexbpu3KA7O6Q4g0s9SGD3t1Snsk3Fk=";
    };
    ios = {
      x86_64-linux = "sha256-QwkeGnutTVsm682CqxRtEd9rKUvN7zlAJcqkvAQYwao=";
      aarch64-linux = "sha256-QwkeGnutTVsm682CqxRtEd9rKUvN7zlAJcqkvAQYwao=";
      x86_64-darwin = "sha256-QwkeGnutTVsm682CqxRtEd9rKUvN7zlAJcqkvAQYwao=";
    };
    linux = {
      x86_64-linux = "sha256-0gIOwux3YBdmcXgwICr8dpftj1CauaBUX8Rt5GG0WSs=";
      aarch64-linux = "sha256-drGHsuJoOCLqrhVrXczqJRCOtpeWVlqdWW0OSMS/l5M=";
      x86_64-darwin = "sha256-0gIOwux3YBdmcXgwICr8dpftj1CauaBUX8Rt5GG0WSs=";
    };
    macos = {
      x86_64-linux = "sha256-9WqCJQ37mcGc5tzfqQoY5CqHWHGTizjXf9p73bdnNWc=";
      aarch64-linux = "sha256-9WqCJQ37mcGc5tzfqQoY5CqHWHGTizjXf9p73bdnNWc=";
      x86_64-darwin = "sha256-9WqCJQ37mcGc5tzfqQoY5CqHWHGTizjXf9p73bdnNWc=";
    };
    universal = {
      x86_64-linux = "sha256-wATt1UPjo/fh7RFO1vvcUAdo0dMAaaOUIuzYodsM0v0=";
      aarch64-linux = "sha256-Z9bszNaIpCccG7OfvE5WFsw36dITiyCQAZ6p29+Yq68=";
      x86_64-darwin = "sha256-qN5bAXRfQ78TWF3FLBIxWzUB5y5OrZVQTEilY5J/+2k=";
    };
    web = {
      x86_64-linux = "sha256-DVXJOOFxv7tKt3d0NaYMexkphEcr7+gDFV67I6iAYa0=";
      aarch64-linux = "sha256-DVXJOOFxv7tKt3d0NaYMexkphEcr7+gDFV67I6iAYa0=";
      x86_64-darwin = "sha256-DVXJOOFxv7tKt3d0NaYMexkphEcr7+gDFV67I6iAYa0=";
    };
    windows = {
      x86_64-linux = "sha256-s8fJtwQkuZaGXr6vrPiKfpwP/NfewbETwyp9ERGqHYI=";
      aarch64-linux = "sha256-s8fJtwQkuZaGXr6vrPiKfpwP/NfewbETwyp9ERGqHYI=";
      x86_64-darwin = "sha256-s8fJtwQkuZaGXr6vrPiKfpwP/NfewbETwyp9ERGqHYI=";
    };
  };
}
Loading