flutter: Download engine artifacts individually

This brings the following benefits:
- Artifacts missing in the SDK tarball (such as prebuilts for linux-aarch64) can be obtained
- Artifacts can be patched more granularly (e.g. libflutter_linux_gtk is patchelf-ed for GTK3, and the linux-aarch64 assets have a postPatch to add some missing files)
- Minimal Flutter packages can be generated (e.g. mkFlutterApp only needs prebuilts for desktop Linux, and developers that don't care for desktop Linux can exclude the artifacts and dependencies)

It also paves the way for including manually built engine facts.
This commit is contained in:
hacker1024 2023-04-15 01:59:31 +10:00
parent c3797393b7
commit 62e50080f3
3 changed files with 350 additions and 20 deletions

View File

@ -0,0 +1,127 @@
{ lib
, stdenv
, hostPlatform
, engineVersion
, fetchzip
, autoPatchelfHook
, gtk3
}:
let
hashes = (import ./hashes.nix).${engineVersion};
artifacts =
{
common = {
flutter_patched_sdk = { archive = "flutter_patched_sdk.zip"; };
flutter_patched_sdk_product = { archive = "flutter_patched_sdk_product.zip"; };
};
platform = {
android =
(lib.genAttrs
[ "arm" "arm64" "x64" ]
(arch:
{
base = [
{ archive = "artifacts.zip"; }
];
variants = lib.genAttrs [ "profile" "release" ]
(variant: [
{ archive = "artifacts.zip"; }
{ archive = "${lib.toLower hostPlatform.uname.system}-x64.zip"; }
]);
})) //
{
"x86" = {
base = [
{ archive = "artifacts.zip"; }
];
variants.jit-release = [
{ archive = "artifacts.zip"; }
];
};
};
linux = lib.genAttrs
[ "arm64" "x64" ]
(arch:
let
linux-flutter-gtk = {
archive = "linux-${arch}-flutter-gtk.zip";
buildInputs = [ gtk3 ];
};
in
{
base = [
({ archive = "artifacts.zip"; } // lib.optionalAttrs (arch == "arm64") {
# For some reason, the arm64 artifacts are missing shader code.
postPatch = ''
if [ -d shader_lib ]; then
The shader_lib directory has been included in the artifact archive.
This patch should be removed.
fi
ln -s ${lib.findSingle
(pkg: lib.getName pkg == "flutter-artifact-linux-x64-artifacts")
(throw "Could not find the x64 artifact archive.")
(throw "Could not find the correct x64 artifact archive.")
artifactDerivations.platform.linux.x64.base
}/shader_lib .
'';
})
{ archive = "font-subset.zip"; }
linux-flutter-gtk
];
variants = lib.genAttrs [ "debug" "profile" "release" ] (variant: [
linux-flutter-gtk
]);
});
};
};
mkArtifactDerivation = { platform ? null, variant ? null, archive, ... }@args:
let
artifactDirectory = if platform == null then null else "${platform}${lib.optionalString (variant != null) "-${variant}"}";
archiveBasename = lib.removeSuffix ".${(lib.last (lib.splitString "." archive))}" archive;
in
stdenv.mkDerivation ({
pname = "flutter-artifact${lib.optionalString (platform != null) "-${artifactDirectory}"}-${archiveBasename}";
version = engineVersion;
src = fetchzip {
url = "https://storage.googleapis.com/flutter_infra_release/flutter/${engineVersion}${lib.optionalString (platform != null) "/${artifactDirectory}"}/${archive}";
stripRoot = false;
hash = (if artifactDirectory == null then hashes else hashes.${artifactDirectory}).${archive};
};
nativeBuildInputs = [ autoPatchelfHook ];
installPhase = "cp -r . $out";
} // args);
artifactDerivations = {
common = builtins.mapAttrs (name: mkArtifactDerivation) artifacts.common;
platform =
builtins.mapAttrs
(os: architectures:
builtins.mapAttrs
(architecture: variants: {
base = map
(args: mkArtifactDerivation ({
platform = "${os}-${architecture}";
} // args))
variants.base;
variants = builtins.mapAttrs
(variant: variantArtifacts: map
(args: mkArtifactDerivation ({
platform = "${os}-${architecture}";
inherit variant;
} // args))
variantArtifacts)
variants.variants;
})
architectures)
artifacts.platform;
};
in
artifactDerivations

View File

@ -0,0 +1,144 @@
{
"1a65d409c7a1438a34d21b60bf30a6fd5db59314" = {
"flutter_patched_sdk.zip" = "sha256-Pvsjttm5OwpJ/pW4UQXvvEiJYCM5CoZZfVXz5jef37k=";
"flutter_patched_sdk_product.zip" = "sha256-fhj2uUOrLwrzHrM6RNVpPNize5Qu6mLQDcSzLT2TbRA=";
"android-arm" = {
"artifacts.zip" = "sha256-KDMiI6SQoZHfFV5LJJZ7VOGyEKC4UxzRc777j4BbXgM=";
};
"android-arm-profile" = {
"artifacts.zip" = "sha256-MErLoGJWXg4yJ6b6c5bqP8Nat6O7eYSfM71mMNAAQf4=";
"linux-x64.zip" = "sha256-0TZQ05HR7NRqHzeoHZ/sOrjKiSvCpMUH85YXXzV4URg=";
};
"android-arm-release" = {
"artifacts.zip" = "sha256-hU4S4FOqUGokByZ47nzOqQ4A9QFshruqrpJvJUBHUho=";
"linux-x64.zip" = "sha256-AqNlqjOht+c2sdW5ReoF66ZJWJl1W4vGKbQ3YyderRY=";
};
"android-arm64" = {
"artifacts.zip" = "sha256-ApNg3Uu9gyGNsx7sdpTCz1yADVAI5ZuNHgvgiuH9IpQ=";
};
"android-arm64-profile" = {
"artifacts.zip" = "sha256-D/8+WKPIkOaV3PwkCHiJROFlokm4lWWmtPQb93Yqwr0=";
"linux-x64.zip" = "sha256-S0RHLov6/C22VvGdvZV87Ybaxun8YBrw1gTgNklRcM0=";
};
"android-arm64-release" = {
"artifacts.zip" = "sha256-OoYqHtwmT+VWJ+G+sMXM5+ux3h1Fnyo9Vj2za9cm5eE=";
"linux-x64.zip" = "sha256-NuXclg1a+Ofw5AWJ1tajpn2jYEZw6DluWxrFVL8rPfg=";
};
"android-x86" = {
"artifacts.zip" = "sha256-nN66nIrcbJHq2S4oIT5e2NCv7mS5Kw+HBv3ReHs+d3Y=";
};
"android-x86-jit-release" = {
"artifacts.zip" = "sha256-A8F6K78Ykp1rMsUmjD7B9nFFPAubZnqAqgWSzbNCRwk=";
};
"android-x64" = {
"artifacts.zip" = "sha256-hrBvnzCj/24h5kat96avlgXi6WhMsos5aPlkgxOYo8Q=";
};
"android-x64-profile" = {
"artifacts.zip" = "sha256-xzSj/2ah9aQoosaNGkSWFP3bMNJqRSFc0+78XEBHwzM=";
"linux-x64.zip" = "sha256-HfBiz1JWlBQ8KEfmf8uDlVzFlDt3+VF2VeY82tsMjHs=";
};
"android-x64-release" = {
"artifacts.zip" = "sha256-TcfMeA+8Uf9yRrYdEIsjip0cKmSUm2Ow1tkoE9803XY=";
"linux-x64.zip" = "sha256-D6efb6pj9+xjPnJu3O+ZCmwfatBzasuFZEFRntAiU9U=";
};
"linux-arm64" = {
"artifacts.zip" = "sha256-xyKVaEFb5gVkVrPzDrOql5BmXGO0FnCSeXOoQ10ZFrw=";
"font-subset.zip" = "sha256-Ulwb6q2SzB4suMJhAM3zAwWOzlEImlu9Ha+w5u4QqIU=";
"linux-arm64-flutter-gtk.zip" = "sha256-SiYOH++py4zeoD3BkNayqy/C9Zz9OiYQ5+u+pDLIpWg=";
};
"linux-arm64-debug" = {
"linux-arm64-flutter-gtk.zip" = "sha256-SiYOH++py4zeoD3BkNayqy/C9Zz9OiYQ5+u+pDLIpWg=";
};
"linux-arm64-profile" = {
"linux-arm64-flutter-gtk.zip" = "sha256-xB0eqrBYD7vhOwYUgJwNaBftNZJgdwxA9AUpEfX0iFs=";
};
"linux-arm64-release" = {
"linux-arm64-flutter-gtk.zip" = "sha256-aHLKV129WIRsLUG6xTMwCKB4eXD3jonqinjI8KSsOus=";
};
"linux-x64" = {
"artifacts.zip" = "sha256-+zIABFXUpiqn3OMoLcU4NDLxZ1y9z0r46iCTNRHAkz8=";
"font-subset.zip" = "sha256-W4SRPvA4rraVqN1ehbY6MFL7ZIWDHVJhjlLtxyUJJKY=";
"linux-x64-flutter-gtk.zip" = "sha256-boICnuJF4zqGb7kaN5haO/df9hC9KeJidt3uIK06S7M=";
};
"linux-x64-debug" = {
"linux-x64-flutter-gtk.zip" = "sha256-boICnuJF4zqGb7kaN5haO/df9hC9KeJidt3uIK06S7M=";
};
"linux-x64-profile" = {
"linux-x64-flutter-gtk.zip" = "sha256-RAsgupVF18IxLaP8tJ7XRQ8y/um46nlpA8fDITPwLqY=";
};
"linux-x64-release" = {
"linux-x64-flutter-gtk.zip" = "sha256-RAsgupVF18IxLaP8tJ7XRQ8y/um46nlpA8fDITPwLqY=";
};
};
"57d3bac3dd5cb5b0e464ab70e7bc8a0d8cf083ab" = {
"flutter_patched_sdk.zip" = "sha256-A/y5Y+Aw0CUhXABbdyQcGCSnSbO7Ask+71m8LZDSjH4=";
"flutter_patched_sdk_product.zip" = "sha256-VPxF4NrTUhFbpztyPnLEiC9Cy0kDDbYvy21kA5ES4HM=";
"android-arm" = {
"artifacts.zip" = "sha256-3igOO+rgFh0fNTIIiiucqSmqC+NKFPG5H1CnIa9bDcM=";
};
"android-arm-profile" = {
"artifacts.zip" = "sha256-qai254LNrQXJBsaoQgXao6mBpzzcYHh4sUESurSyxNA=";
"linux-x64.zip" = "sha256-hBkntf1fX5w752ly6lVUHm6wEM/4ep9guJGma3SKjxU=";
};
"android-arm-release" = {
"artifacts.zip" = "sha256-7yuXIJyErb1PZyk56+TtlJY0o1EOwmdAvpVfGGAteuA=";
"linux-x64.zip" = "sha256-v/jBnE662XOX/fOhYbve7ZiQwVu0haIMOD532Vdj9Yw=";
};
"android-arm64" = {
"artifacts.zip" = "sha256-Llxu8+SkYEtnoiMf01rffPpF/AjrlV+QPuAW850oMzo=";
};
"android-arm64-profile" = {
"artifacts.zip" = "sha256-su4U80supv8Q+2kE/5FTybiA5NFbKNMHqdB0NHCqrVI=";
"linux-x64.zip" = "sha256-yGt0SztNxYHDwZ1DwzLg5REE8rmMRKNn7GfCQ+GEHBw=";
};
"android-arm64-release" = {
"artifacts.zip" = "sha256-+p1+SXSEglR3jqWc/jKgmtR9nOGgMRGC+anoTs1kRc8=";
"linux-x64.zip" = "sha256-5UiG5gxOso8NO+7nkb6bjxW8e/Tr7mlvPRUagSRTCNs=";
};
"android-x86" = {
"artifacts.zip" = "sha256-Cbo17VYWaclyO1RLHkwjbqoFVZ283IgGdN0uDdiWvQs=";
};
"android-x86-jit-release" = {
"artifacts.zip" = "sha256-gSPm2tClTj2vEYtGKgobD/mebWLNlDp8nEoFX0rhEOk=";
};
"android-x64" = {
"artifacts.zip" = "sha256-PVb1aKMMTlDT41O2MZRAUjCq8h+m/s2h5qOnEFPd77w=";
};
"android-x64-profile" = {
"artifacts.zip" = "sha256-gZSSRCDy42AMLMiu/KH7YsDuFVaxRcoyXzUgV8V025Y=";
"linux-x64.zip" = "sha256-9+LCjeI18u/GlPDMIl6Jx6b++lc90fJ5tVBlDR+ctDs=";
};
"android-x64-release" = {
"artifacts.zip" = "sha256-rsS08VP86/b2S0TEYusCEJBvS4BuevsmV9REAxRgJIc=";
"linux-x64.zip" = "sha256-H4nFCJ+iCUzIwHogYzS+h33eDMaFnz71dcDLSQW1aPg=";
};
"linux-arm64" = {
"artifacts.zip" = "sha256-kCxsKQQQX6wzhD46bfoflKdz3AYYkoSyavhfyTDuHLU=";
"font-subset.zip" = "sha256-Yk6JsNWe7ftEQU/TsjDUZSFeLzeIbcS63lhl8fsWsdk=";
"linux-arm64-flutter-gtk.zip" = "sha256-girVdkXrTO5tssoi+eKwG9ykstCR/VOx8zWtcAz8AKM=";
};
"linux-arm64-debug" = {
"linux-arm64-flutter-gtk.zip" = "sha256-girVdkXrTO5tssoi+eKwG9ykstCR/VOx8zWtcAz8AKM=";
};
"linux-arm64-profile" = {
"linux-arm64-flutter-gtk.zip" = "sha256-VL5cwYaZ1FOJ3TwJzbgvHDQwkU9NrHGnf/tQhZ/dAGg=";
};
"linux-arm64-release" = {
"linux-arm64-flutter-gtk.zip" = "sha256-27hy7mLFCLkqJbn+5p5eJdYnfBKTyfFe98iUMmKyz4g=";
};
"linux-x64" = {
"artifacts.zip" = "sha256-JgEX+rKxdcWBBaxyR42eC7qOAvaawF9M2+rfaD4IgeA=";
"font-subset.zip" = "sha256-5EoxBrxSjaLLd+rKrxVYNoUZaejk0qcQ5LVsmqtKc2g=";
"linux-x64-flutter-gtk.zip" = "sha256-MH5HDPoXXi/KpQLQ0U1tQzZ0sbZx1RVhZtQ7L+WhZgk=";
};
"linux-x64-debug" = {
"linux-x64-flutter-gtk.zip" = "sha256-MH5HDPoXXi/KpQLQ0U1tQzZ0sbZx1RVhZtQ7L+WhZgk=";
};
"linux-x64-profile" = {
"linux-x64-flutter-gtk.zip" = "sha256-r2hB/AKrB5vNga2fve4tTM4j+Zp9KDqNlTjKQhQvbaI=";
};
"linux-x64-release" = {
"linux-x64-flutter-gtk.zip" = "sha256-muREs2iUiHCZM+SGN5q3HRRGnejJapKN582Aeog49MI=";
};
};
}

View File

@ -2,27 +2,75 @@
, patches
, dart
, src
, includedEngineArtifacts ? {
common = [
"flutter_patched_sdk"
"flutter_patched_sdk_product"
];
platform = {
android = lib.optionalAttrs stdenv.hostPlatform.isx86_64
((lib.genAttrs [ "arm" "arm64" "x64" ] (architecture: [ "profile" "release" ])) // { x86 = [ "jit-release" ]; });
linux = lib.optionals stdenv.hostPlatform.isLinux
(lib.genAttrs ((lib.optional stdenv.hostPlatform.isx86_64 "x64") ++ (lib.optional stdenv.hostPlatform.isAarch64 "arm64"))
(architecture: [ "debug" "profile" "release" ]));
};
}
, lib
, callPackage
, stdenv
, autoPatchelfHook
, runCommandLocal
, symlinkJoin
, lndir
, git
, which
, atk
, glib
, gtk3
, libepoxy
}:
}@args:
let
# Libraries that Flutter artifacts depend on at runtime.
artifactRuntimeDeps = [
atk
glib
gtk3
libepoxy
];
engineArtifactDirectory =
let
engineArtifacts = callPackage ./engine-artifacts {
engineVersion = lib.removeSuffix "\n" (builtins.readFile (src + /bin/internal/engine.version));
};
in
runCommandLocal "flutter-engine-artifacts-${version}" { }
(
let
mkCommonArtifactLinkCommand = { artifact }:
''
mkdir -p $out/common
${lndir}/bin/lndir -silent ${artifact} $out/common
'';
mkPlatformArtifactLinkCommand = { artifact, os, architecture, variant ? null }:
let
artifactDirectory = "${os}-${architecture}${lib.optionalString (variant != null) "-${variant}"}";
in
''
mkdir -p $out/${artifactDirectory}
${lndir}/bin/lndir -silent ${artifact} $out/${artifactDirectory}
'';
in
''
${
builtins.concatStringsSep "\n"
((map (name: mkCommonArtifactLinkCommand {
artifact = engineArtifacts.common.${name};
}) (if includedEngineArtifacts ? common then includedEngineArtifacts.common else [ ])) ++
(builtins.foldl' (commands: os: commands ++
(builtins.foldl' (commands: architecture: commands ++
(builtins.foldl' (commands: variant: commands ++
(map (artifact: mkPlatformArtifactLinkCommand {
inherit artifact os architecture variant;
}) engineArtifacts.platform.${os}.${architecture}.variants.${variant}))
(map (artifact: mkPlatformArtifactLinkCommand {
inherit artifact os architecture;
}) engineArtifacts.platform.${os}.${architecture}.base)
includedEngineArtifacts.platform.${os}.${architecture}))
[] (builtins.attrNames includedEngineArtifacts.platform.${os})))
[] (builtins.attrNames (if includedEngineArtifacts ? platform then includedEngineArtifacts.platform else { }))))
}
''
);
unwrapped =
stdenv.mkDerivation {
@ -31,8 +79,7 @@ let
outputs = [ "out" "cache" ];
nativeBuildInputs = [ autoPatchelfHook ];
buildInputs = [ git ] ++ artifactRuntimeDeps;
buildInputs = [ git ];
postPatch = ''
patchShebangs --build ./bin/
@ -75,7 +122,10 @@ let
echo "$revision" > "$STAMP_PATH"
echo -n "${version}" > version
rm -r bin/cache/dart-sdk
# Certain prebuilts should be replaced with Nix-built (or at least Nix-patched) equivalents.
rm -r \
bin/cache/dart-sdk \
bin/cache/artifacts/engine
'';
installPhase = ''
@ -83,8 +133,8 @@ let
mkdir -p $out
cp -r . $out
mkdir -p $out/bin/cache/
ln -sf ${dart} $out/bin/cache/dart-sdk
ln -sf ${engineArtifactDirectory} $out/bin/cache/artifacts/engine
runHook postInstall
'';
@ -110,7 +160,17 @@ let
# found here should be included as-is, for tooling compatibility.
sdk = unwrapped;
mkFlutterApp = callPackage ../../../build-support/flutter {
flutter = callPackage ./wrapper.nix { flutter = unwrapped; };
# Package a minimal version of Flutter that only uses Linux desktop release artifacts.
flutter = callPackage ./wrapper.nix {
flutter = callPackage ./flutter.nix (args // {
includedEngineArtifacts = {
common = [ "flutter_patched_sdk_product" ];
platform.linux = lib.optionals stdenv.hostPlatform.isLinux
(lib.genAttrs ((lib.optional stdenv.hostPlatform.isx86_64 "x64") ++ (lib.optional stdenv.hostPlatform.isAarch64 "arm64"))
(architecture: [ "release" ]));
};
});
};
};
};
@ -125,7 +185,6 @@ let
platforms = [ "x86_64-linux" "aarch64-linux" ];
maintainers = with maintainers; [ babariviere ericdallo FlafyDev gilice hacker1024 ];
};
}
;
};
in
unwrapped