flutter338: init at 3.38.0-0.2.pre

This commit is contained in:
qzylinra
2025-11-03 07:14:56 +00:00
committed by qzylinra
parent a84b0a7c50
commit e61e676f4b
26 changed files with 1861 additions and 590 deletions
@@ -71,7 +71,7 @@ runCommand "flutter-artifacts-${flutterPlatform}-${systemPlatform}"
''
export FLUTTER_ROOT="$NIX_BUILD_TOP"
lndir -silent '${flutter'}' "$FLUTTER_ROOT"
rm -rf "$FLUTTER_ROOT/bin/cache"
rm --recursive --force "$FLUTTER_ROOT/bin/cache"
mkdir "$FLUTTER_ROOT/bin/cache"
''
+ lib.optionalString (lib.versionAtLeast flutter'.version "3.26") ''
@@ -89,18 +89,18 @@ runCommand "flutter-artifacts-${flutterPlatform}-${systemPlatform}"
flutter ? engine && flutter.engine.meta.available
) "--local-engine ${flutter.engine.outName}"
} \
-v '--${flutterPlatform}' ${
--verbose '--${flutterPlatform}' ${
builtins.concatStringsSep " " (map (p: "'--no-${p}'") (lib.remove flutterPlatform flutterPlatforms))
}
rm -rf "$FLUTTER_ROOT/bin/cache/lockfile"
rm --recursive --force "$FLUTTER_ROOT/bin/cache/lockfile"
''
+ lib.optionalString (lib.versionAtLeast flutter'.version "3.26") ''
rm -rf "$FLUTTER_ROOT/bin/cache/dart-sdk"
rm --recursive --force "$FLUTTER_ROOT/bin/cache/dart-sdk"
''
+ ''
find "$FLUTTER_ROOT" -type l -lname '${flutter'}/*' -delete
cp -r bin/cache "$out"
cp --recursive bin/cache "$out"
''
)
@@ -4,9 +4,9 @@
...
}:
{
# Use arm64 instead of arm64e.
postPatch = ''
if [ "$pname" == "flutter-tools" ]; then
# Use arm64 instead of arm64e.
substituteInPlace lib/src/ios/xcodeproj.dart \
--replace-fail arm64e arm64
fi
@@ -15,9 +15,9 @@
installPhase = ''
runHook preInstall
mkdir -p "$out/bin"
cp -r . "$out/bin/cache"
rm -f "$out/bin/cache/flutter.version.json"
mkdir --parents "$out/bin"
cp --recursive . "$out/bin/cache"
rm --force "$out/bin/cache/flutter.version.json"
runHook postInstall
'';
@@ -54,19 +54,19 @@ let
sources = {
"${dartVersion}-x86_64-linux" = fetchzip {
url = "https://storage.googleapis.com/dart-archive/channels/${channel}/release/${dartVersion}/sdk/dartsdk-linux-x64-release.zip";
sha256 = dartHash.x86_64-linux;
hash = dartHash.x86_64-linux;
};
"${dartVersion}-aarch64-linux" = fetchzip {
url = "https://storage.googleapis.com/dart-archive/channels/${channel}/release/${dartVersion}/sdk/dartsdk-linux-arm64-release.zip";
sha256 = dartHash.aarch64-linux;
hash = dartHash.aarch64-linux;
};
"${dartVersion}-x86_64-darwin" = fetchzip {
url = "https://storage.googleapis.com/dart-archive/channels/${channel}/release/${dartVersion}/sdk/dartsdk-macos-x64-release.zip";
sha256 = dartHash.x86_64-darwin;
hash = dartHash.x86_64-darwin;
};
"${dartVersion}-aarch64-darwin" = fetchzip {
url = "https://storage.googleapis.com/dart-archive/channels/${channel}/release/${dartVersion}/sdk/dartsdk-macos-arm64-release.zip";
sha256 = dartHash.aarch64-darwin;
hash = dartHash.aarch64-darwin;
};
};
};
@@ -75,7 +75,7 @@ let
source = fetchFromGitHub {
owner = "flutter";
repo = "flutter";
rev = version;
tag = version;
hash = flutterHash;
};
in
@@ -83,7 +83,7 @@ let
if lib.versionAtLeast version "3.32" then
# # Could not determine engine revision
(runCommand source.name { } ''
cp -r ${source} $out
cp --recursive ${source} $out
chmod +w $out/bin
mkdir $out/bin/cache
cp $out/bin/internal/engine.version $out/bin/cache/engine.stamp
@@ -3,13 +3,10 @@ runCommand "flutter-engine-${engine.version}-dart"
{
version = engine.dartSdkVersion;
inherit engine;
inherit (engine) outName;
meta = engine.meta // {
description = "Dart SDK compiled from the Flutter Engine";
};
}
''
ln -s ${engine}/out/$outName/dart-sdk $out
ln --symbolic ${engine}/out/${engine.outName}/dart-sdk $out
''
@@ -9,12 +9,9 @@
url,
patches,
runtimeModes,
isOptimized ? null,
lib,
stdenv,
dart,
mainRuntimeMode ? null,
altRuntimeMode ? null,
...
}@args:
let
mainRuntimeMode = args.mainRuntimeMode or builtins.elemAt runtimeModes 0;
@@ -41,25 +38,16 @@ in
stdenv.mkDerivation (
{
pname = "flutter-engine";
inherit url runtimeModes;
inherit (runtimeModesBuilds.${mainRuntimeMode})
meta
src
version
dartSdkVersion
isOptimized
runtimeMode
outName
dart
swiftshader
;
inherit altRuntimeMode;
inherit url runtimeModes altRuntimeMode;
inherit (runtimeModesBuilds.${mainRuntimeMode}) version src meta;
dontUnpack = true;
dontBuild = true;
installPhase = ''
mkdir -p $out/out
runHook preInstall
mkdir --parents $out/out
''
+ lib.concatMapStrings (
runtimeMode:
@@ -68,9 +56,23 @@ stdenv.mkDerivation (
runtimeModeOut = runtimeModeBuild.outName;
in
''
ln -sf ${runtimeModeBuild}/out/${runtimeModeOut} $out/out/${runtimeModeOut}
ln --symbolic --force ${runtimeModeBuild}/out/${runtimeModeOut} $out/out/${runtimeModeOut}
''
) runtimeModes;
) runtimeModes
+ ''
runHook postInstall
'';
passthru = {
inherit (runtimeModesBuilds.${mainRuntimeMode})
dartSdkVersion
isOptimized
runtimeMode
outName
dart
swiftshader
;
};
}
// runtimeModesBuilds
)
@@ -1,11 +1,12 @@
{
lib,
callPackage,
writeText,
fetchurl,
bash,
bintools,
symlinkJoin,
darwin,
clang,
llvm,
tools ? callPackage ./tools.nix {
inherit (stdenv)
hostPlatform
@@ -13,10 +14,8 @@
;
},
stdenv,
stdenvNoCC,
dart,
fetchgit,
runCommand,
llvmPackages,
patchelf,
openbox,
@@ -49,18 +48,12 @@
isOptimized ? runtimeMode != "debug",
}:
let
expandSingleDep =
dep: lib.optionals (lib.isDerivation dep) ([ dep ] ++ map (output: dep.${output}) dep.outputs);
expandDeps = deps: lib.flatten (map expandSingleDep deps);
constants = callPackage ./constants.nix { platform = stdenv.targetPlatform; };
python3 = python312;
src = callPackage ./source.nix {
inherit
tools
flutterVersion
version
hashes
@@ -93,22 +86,11 @@ let
outName = "host_${runtimeMode}${lib.optionalString (!isOptimized) "_unopt"}";
dartPath = "${
if (lib.versionAtLeast flutterVersion "3.23") then "flutter/third_party" else "third_party"
}/dart";
dartPath = "flutter/third_party/dart";
in
stdenv.mkDerivation (finalAttrs: {
pname = "flutter-engine-${runtimeMode}${lib.optionalString (!isOptimized) "-unopt"}";
inherit
version
runtimeMode
patches
isOptimized
dartSdkVersion
src
outName
swiftshader
;
inherit version src patches;
setOutputFlags = false;
doStrip = isOptimized;
@@ -117,36 +99,39 @@ stdenv.mkDerivation (finalAttrs: {
name = "flutter-engine-toolchain-${version}";
paths =
expandDeps (
lib.optionals (stdenv.hostPlatform.isLinux) [
gtk3
wayland
libepoxy
libglvnd
freetype
at-spi2-atk
glib
gdk-pixbuf
harfbuzz
pango
cairo
xorg.libxcb
xorg.libX11
xorg.libXcursor
xorg.libXrandr
xorg.libXrender
xorg.libXinerama
xorg.libXi
xorg.libXext
xorg.libXfixes
xorg.libXxf86vm
xorg.xorgproto
zlib
]
++ lib.optionals (stdenv.hostPlatform.isDarwin) [
clang
llvm
]
lib.flatten (
map (dep: lib.optionals (lib.isDerivation dep) ([ dep ] ++ map (output: dep.${output}) dep.outputs))
(
lib.optionals (stdenv.hostPlatform.isLinux) [
gtk3
wayland
libepoxy
libglvnd
freetype
at-spi2-atk
glib
gdk-pixbuf
harfbuzz
pango
cairo
xorg.libxcb
xorg.libX11
xorg.libXcursor
xorg.libXrandr
xorg.libXrender
xorg.libXinerama
xorg.libXi
xorg.libXext
xorg.libXfixes
xorg.libXxf86vm
xorg.xorgproto
zlib
]
++ lib.optionals (stdenv.hostPlatform.isDarwin) [
clang
llvm
]
)
)
++ [
stdenv.cc.libc_dev
@@ -156,19 +141,16 @@ stdenv.mkDerivation (finalAttrs: {
# Needed due to Flutter expecting everything to be relative to $out
# and not true absolute path (ie relative to "/").
postBuild = ''
mkdir -p $(dirname $(dirname "$out/$out"))
ln -s $(dirname "$out") $out/$(dirname "$out")
mkdir --parents $(dirname $(dirname "$out/$out"))
ln --symbolic $(dirname "$out") $out/$(dirname "$out")
'';
};
NIX_CFLAGS_COMPILE = [
"-I${finalAttrs.toolchain}/include"
"-Wno-error"
]
++ lib.optional (!isOptimized) "-U_FORTIFY_SOURCE"
++ lib.optionals (lib.versionAtLeast flutterVersion "3.35") [
"-Wno-macro-redefined"
"-Wno-error=macro-redefined"
];
++ lib.optional (!isOptimized) "-U_FORTIFY_SOURCE";
nativeCheckInputs = lib.optionals stdenv.hostPlatform.isLinux [
xorg.xorgserver
@@ -195,77 +177,93 @@ stdenv.mkDerivation (finalAttrs: {
]
++ lib.optionals (stdenv.cc.libc ? bin) [ stdenv.cc.libc.bin ];
buildInputs = [ gtk3 ];
buildInputs = [
gtk3
libepoxy
];
patchtools = [ "flutter/third_party/gn/gn" ];
dontPatch = true;
patchgit = [
env.patchgit = toString [
dartPath
"flutter"
"."
]
++ lib.optional (lib.versionAtLeast flutterVersion "3.21") "flutter/third_party/skia";
"flutter/third_party/skia"
];
postUnpack = ''
pushd ${src.name}
sourceRoot = if lib.versionAtLeast flutterVersion "3.38" then "${src.name}/engine" else src.name;
cp ${./pkg-config.py} src/build/config/linux/pkg-config.py
postUnpack =
lib.optionalString (lib.versionAtLeast flutterVersion "3.38") ''
chmod --recursive +w ${src.name}
echo '#!${lib.getExe bash}' > ${src.name}/bin/internal/content_aware_hash.sh
echo 'echo 1111111111111111111111111111111111111111' >> ${src.name}/bin/internal/content_aware_hash.sh
''
+ ''
pushd ${finalAttrs.sourceRoot}
cp -pr --reflink=auto $swiftshader src/flutter/third_party/swiftshader
chmod -R u+w -- src/flutter/third_party/swiftshader
cp ${
fetchurl {
url = "https://raw.githubusercontent.com/chromium/chromium/631a813125b886a52274653144019fd1681a0e97/build/config/linux/pkg-config.py";
hash = "sha256-9coRpgCewlkFXSGrMVkudaZUll0IFc9jDRBP+2PloOI=";
}
} src/build/config/linux/pkg-config.py
ln -s ${llvmPackages.llvm.monorepoSrc} src/flutter/third_party/swiftshader/third_party/llvm-project
cp --preserve=mode,ownership,timestamps --recursive --reflink=auto ${swiftshader} src/flutter/third_party/swiftshader
chmod --recursive u+w -- src/flutter/third_party/swiftshader
mkdir -p src/flutter/buildtools/${constants.alt-platform}
ln -s ${llvm} src/flutter/buildtools/${constants.alt-platform}/clang
ln --symbolic ${llvmPackages.llvm.monorepoSrc} src/flutter/third_party/swiftshader/third_party/llvm-project
mkdir -p src/buildtools/${constants.alt-platform}
ln -s ${llvm} src/buildtools/${constants.alt-platform}/clang
mkdir --parents src/flutter/buildtools/${constants.alt-platform}
ln --symbolic ${llvm} src/flutter/buildtools/${constants.alt-platform}/clang
mkdir -p src/${dartPath}/tools/sdks
ln -s ${dart} src/${dartPath}/tools/sdks/dart-sdk
mkdir --parents src/buildtools/${constants.alt-platform}
ln --symbolic ${llvm} src/buildtools/${constants.alt-platform}/clang
${lib.optionalString (stdenv.hostPlatform.isLinux) ''
for patchtool in ''${patchtools[@]}; do
patchelf src/$patchtool --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker)
mkdir --parents src/${dartPath}/tools/sdks
ln --symbolic ${dart} src/${dartPath}/tools/sdks/dart-sdk
${lib.optionalString (stdenv.hostPlatform.isLinux) ''
for patchtool in ''${patchtools[@]}; do
patchelf src/$patchtool --set-interpreter ${bintools.dynamicLinker}
done
''}
for dir in ''${patchgit[@]}; do
pushd src/$dir
rm --recursive --force .git
git init
git add .
git config user.name "nobody"
git config user.email "nobody@local.host"
git commit --all --message="$dir" --quiet
popd
done
dart src/${dartPath}/tools/generate_package_config.dart
echo "${dartSdkVersion}" >src/${dartPath}/sdk/version
rm --recursive --force src/third_party/angle/.git
python3 src/flutter/tools/pub_get_offline.py
pushd src/flutter
for p in ''${patches[@]}; do
patch -p1 -i $p
done
''}
for dir in ''${patchgit[@]}; do
pushd src/$dir
rm -rf .git
git init
git add .
git config user.name "nobody"
git config user.email "nobody@local.host"
git commit -a -m "$dir" --quiet
popd
done
dart src/${dartPath}/tools/generate_package_config.dart
echo "${dartSdkVersion}" >src/${dartPath}/sdk/version
rm -rf src/third_party/angle/.git
python3 src/flutter/tools/pub_get_offline.py
pushd src/flutter
for p in ''${patches[@]}; do
patch -p1 -i $p
done
popd
''
# error: 'close_range' is missing exception specification 'noexcept(true)'
+ lib.optionalString (lib.versionAtLeast flutterVersion "3.35") ''
substituteInPlace src/flutter/third_party/dart/runtime/bin/process_linux.cc \
--replace-fail "(unsigned int first, unsigned int last, int flags)" "(unsigned int first, unsigned int last, int flags) noexcept(true)"
''
+ ''
popd
'';
''
# error: 'close_range' is missing exception specification 'noexcept(true)'
+ lib.optionalString (lib.versionAtLeast flutterVersion "3.35") ''
substituteInPlace src/flutter/third_party/dart/runtime/bin/process_linux.cc \
--replace-fail "(unsigned int first, unsigned int last, int flags)" "(unsigned int first, unsigned int last, int flags) noexcept(true)"
''
+ ''
popd
'';
configureFlags = [
"--no-prebuilt-dart-sdk"
@@ -281,7 +279,6 @@ stdenv.mkDerivation (finalAttrs: {
++ lib.optional finalAttrs.finalPackage.doCheck "--enable-unittests"
++ lib.optional (!finalAttrs.finalPackage.doCheck) "--no-enable-unittests";
# NOTE: Once https://github.com/flutter/flutter/issues/127606 is fixed, use "--no-prebuilt-dart-sdk"
configurePhase = ''
runHook preConfigure
@@ -292,12 +289,13 @@ stdenv.mkDerivation (finalAttrs: {
''
+ ''
python3 ./src/flutter/tools/gn $configureFlags \
--runtime-mode $runtimeMode \
--runtime-mode ${runtimeMode} \
--out-dir $out \
--target-sysroot $toolchain \
--target-dir $outName \
--target-sysroot ${finalAttrs.toolchain} \
--target-dir ${outName} \
--target-triple ${stdenv.targetPlatform.config} \
--enable-fontconfig
--enable-fontconfig \
--no-prebuilt-dart-sdk
runHook postConfigure
'';
@@ -306,14 +304,14 @@ stdenv.mkDerivation (finalAttrs: {
runHook preBuild
export TERM=dumb
${lib.optionalString (lib.versionAtLeast flutterVersion "3.29") ''
# ValueError: ZIP does not support timestamps before 1980
substituteInPlace src/flutter/build/zip.py \
--replace-fail "zipfile.ZipFile(args.output, 'w', zipfile.ZIP_DEFLATED)" "zipfile.ZipFile(args.output, 'w', zipfile.ZIP_DEFLATED, strict_timestamps=False)"
''}
ninja -C $out/out/$outName -j$NIX_BUILD_CORES
''
# ValueError: ZIP does not support timestamps before 1980
+ lib.optionalString (lib.versionAtLeast flutterVersion "3.29") ''
substituteInPlace src/flutter/build/zip.py \
--replace-fail "zipfile.ZipFile(args.output, 'w', zipfile.ZIP_DEFLATED)" "zipfile.ZipFile(args.output, 'w', zipfile.ZIP_DEFLATED, strict_timestamps=False)"
''
+ ''
ninja -C $out/out/${outName} -j$NIX_BUILD_CORES
runHook postBuild
'';
@@ -321,28 +319,39 @@ stdenv.mkDerivation (finalAttrs: {
# Tests are broken
doCheck = false;
checkPhase = ''
ln -s $out/out src/out
runHook preCheck
ln --symbolic $out/out src/out
touch src/out/run_tests.log
sh src/flutter/testing/run_tests.sh $outName
sh src/flutter/testing/run_tests.sh ${outName}
rm src/out/run_tests.log
runHook postCheck
'';
installPhase = ''
runHook preInstall
rm -rf $out/out/$outName/{obj,exe.unstripped,lib.unstripped,zip_archives}
rm $out/out/$outName/{args.gn,build.ninja,build.ninja.d,compile_commands.json,toolchain.ninja}
find $out/out/$outName -name '*_unittests' -delete
find $out/out/$outName -name '*_benchmarks' -delete
rm -rf $out/out/${outName}/{obj,exe.unstripped,lib.unstripped,zip_archives}
rm $out/out/${outName}/{args.gn,build.ninja,build.ninja.d,compile_commands.json,toolchain.ninja}
find $out/out/${outName} -name '*_unittests' -delete
find $out/out/${outName} -name '*_benchmarks' -delete
''
+ lib.optionalString (finalAttrs.finalPackage.doCheck) ''
rm $out/out/$outName/{display_list_rendertests,flutter_tester}
rm $out/out/${outName}/{display_list_rendertests,flutter_tester}
''
+ ''
runHook postInstall
'';
passthru = {
inherit
dartSdkVersion
isOptimized
runtimeMode
outName
swiftshader
;
dart = callPackage ./dart.nix { engine = finalAttrs.finalPackage; };
};
@@ -359,6 +368,5 @@ stdenv.mkDerivation (finalAttrs: {
"x86_64-darwin"
"aarch64-darwin"
];
}
// lib.optionalAttrs (lib.versionOlder flutterVersion "3.22") { hydraPlatforms = [ ]; };
};
})
@@ -1,247 +0,0 @@
#!/usr/bin/env python3
#
# Copyright (c) 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import json
import os
import subprocess
import sys
import re
from optparse import OptionParser
# This script runs pkg-config, optionally filtering out some results, and
# returns the result.
#
# The result will be [ <includes>, <cflags>, <libs>, <lib_dirs>, <ldflags> ]
# where each member is itself a list of strings.
#
# You can filter out matches using "-v <regexp>" where all results from
# pkgconfig matching the given regular expression will be ignored. You can
# specify more than one regular expression my specifying "-v" more than once.
#
# You can specify a sysroot using "-s <sysroot>" where sysroot is the absolute
# system path to the sysroot used for compiling. This script will attempt to
# generate correct paths for the sysroot.
#
# When using a sysroot, you must also specify the architecture via
# "-a <arch>" where arch is either "x86" or "x64".
#
# CrOS systemroots place pkgconfig files at <systemroot>/usr/share/pkgconfig
# and one of <systemroot>/usr/lib/pkgconfig or <systemroot>/usr/lib64/pkgconfig
# depending on whether the systemroot is for a 32 or 64 bit architecture. They
# specify the 'lib' or 'lib64' of the pkgconfig path by defining the
# 'system_libdir' variable in the args.gn file. pkg_config.gni communicates this
# variable to this script with the "--system_libdir <system_libdir>" flag. If no
# flag is provided, then pkgconfig files are assumed to come from
# <systemroot>/usr/lib/pkgconfig.
#
# Additionally, you can specify the option --atleast-version. This will skip
# the normal outputting of a dictionary and instead print true or false,
# depending on the return value of pkg-config for the given package.
def SetConfigPath(options):
"""Set the PKG_CONFIG_LIBDIR environment variable.
This takes into account any sysroot and architecture specification from the
options on the given command line.
"""
sysroot = options.sysroot
assert sysroot
# Compute the library path name based on the architecture.
arch = options.arch
if sysroot and not arch:
print("You must specify an architecture via -a if using a sysroot.")
sys.exit(1)
libdir = sysroot + '/' + options.system_libdir + '/pkgconfig'
libdir += ':' + sysroot + '/share/pkgconfig'
os.environ['PKG_CONFIG_LIBDIR'] = libdir
return libdir
def GetPkgConfigPrefixToStrip(options, args):
"""Returns the prefix from pkg-config where packages are installed.
This returned prefix is the one that should be stripped from the beginning of
directory names to take into account sysroots.
"""
# Some sysroots, like the Chromium OS ones, may generate paths that are not
# relative to the sysroot. For example,
# /path/to/chroot/build/x86-generic/usr/lib/pkgconfig/pkg.pc may have all
# paths relative to /path/to/chroot (i.e. prefix=/build/x86-generic/usr)
# instead of relative to /path/to/chroot/build/x86-generic (i.e prefix=/usr).
# To support this correctly, it's necessary to extract the prefix to strip
# from pkg-config's |prefix| variable.
prefix = subprocess.check_output([options.pkg_config,
"--variable=prefix"] + args, env=os.environ).decode('utf-8')
return prefix
def MatchesAnyRegexp(flag, list_of_regexps):
"""Returns true if the first argument matches any regular expression in the
given list."""
for regexp in list_of_regexps:
if regexp.search(flag) != None:
return True
return False
def RewritePath(path, strip_prefix, sysroot):
"""Rewrites a path by stripping the prefix and prepending the sysroot."""
if os.path.isabs(path) and not path.startswith(sysroot):
if path.startswith(strip_prefix):
path = path[len(strip_prefix):]
path = path.lstrip('/')
return os.path.join(sysroot, path)
else:
return path
def main():
# If this is run on non-Linux platforms, just return nothing and indicate
# success. This allows us to "kind of emulate" a Linux build from other
# platforms.
if "linux" not in sys.platform:
print("[[],[],[],[],[]]")
return 0
parser = OptionParser()
parser.add_option('-d', '--debug', action='store_true')
parser.add_option('-p', action='store', dest='pkg_config', type='string',
default='pkg-config')
parser.add_option('-v', action='append', dest='strip_out', type='string')
parser.add_option('-s', action='store', dest='sysroot', type='string')
parser.add_option('-a', action='store', dest='arch', type='string')
parser.add_option('--system_libdir', action='store', dest='system_libdir',
type='string', default='lib')
parser.add_option('--atleast-version', action='store',
dest='atleast_version', type='string')
parser.add_option('--libdir', action='store_true', dest='libdir')
parser.add_option('--dridriverdir', action='store_true', dest='dridriverdir')
parser.add_option('--version-as-components', action='store_true',
dest='version_as_components')
(options, args) = parser.parse_args()
# Make a list of regular expressions to strip out.
strip_out = []
if options.strip_out != None:
for regexp in options.strip_out:
strip_out.append(re.compile(regexp))
if options.sysroot:
libdir = SetConfigPath(options)
if options.debug:
sys.stderr.write('PKG_CONFIG_LIBDIR=%s\n' % libdir)
prefix = GetPkgConfigPrefixToStrip(options, args)
else:
prefix = ''
if options.atleast_version:
# When asking for the return value, just run pkg-config and print the return
# value, no need to do other work.
if not subprocess.call([options.pkg_config,
"--atleast-version=" + options.atleast_version] +
args):
print("true")
else:
print("false")
return 0
if options.version_as_components:
cmd = [options.pkg_config, "--modversion"] + args
try:
version_string = subprocess.check_output(cmd).decode('utf-8')
except:
sys.stderr.write('Error from pkg-config.\n')
return 1
print(json.dumps(list(map(int, version_string.strip().split(".")))))
return 0
if options.libdir:
cmd = [options.pkg_config, "--variable=libdir"] + args
if options.debug:
sys.stderr.write('Running: %s\n' % cmd)
try:
libdir = subprocess.check_output(cmd).decode('utf-8')
except:
print("Error from pkg-config.")
return 1
sys.stdout.write(libdir.strip())
return 0
if options.dridriverdir:
cmd = [options.pkg_config, "--variable=dridriverdir"] + args
if options.debug:
sys.stderr.write('Running: %s\n' % cmd)
try:
dridriverdir = subprocess.check_output(cmd).decode('utf-8')
except:
print("Error from pkg-config.")
return 1
sys.stdout.write(dridriverdir.strip())
return
cmd = [options.pkg_config, "--cflags", "--libs"] + args
if options.debug:
sys.stderr.write('Running: %s\n' % ' '.join(cmd))
try:
flag_string = subprocess.check_output(cmd).decode('utf-8')
except:
sys.stderr.write('Could not run pkg-config.\n')
return 1
# For now just split on spaces to get the args out. This will break if
# pkgconfig returns quoted things with spaces in them, but that doesn't seem
# to happen in practice.
all_flags = flag_string.strip().split(' ')
sysroot = options.sysroot
if not sysroot:
sysroot = ''
includes = []
cflags = []
libs = []
lib_dirs = []
for flag in all_flags[:]:
if len(flag) == 0 or MatchesAnyRegexp(flag, strip_out):
continue;
if flag[:2] == '-l':
libs.append(RewritePath(flag[2:], prefix, sysroot))
elif flag[:2] == '-L':
lib_dirs.append(RewritePath(flag[2:], prefix, sysroot))
elif flag[:2] == '-I':
includes.append(RewritePath(flag[2:], prefix, sysroot))
elif flag[:3] == '-Wl':
# Don't allow libraries to control ld flags. These should be specified
# only in build files.
pass
elif flag == '-pthread':
# Many libs specify "-pthread" which we don't need since we always include
# this anyway. Removing it here prevents a bunch of duplicate inclusions
# on the command line.
pass
else:
cflags.append(flag)
# Output a GN array, the first one is the cflags, the second are the libs. The
# JSON formatter prints GN compatible lists when everything is a list of
# strings.
print(json.dumps([includes, cflags, libs, lib_dirs]))
return 0
if __name__ == '__main__':
sys.exit(main())
@@ -1,12 +1,10 @@
{
lib,
callPackage,
fetchgit,
tools ? null,
curl,
curlMinimal,
pkg-config,
git,
python3,
gitMinimal,
python312,
runCommand,
writeText,
cacert,
@@ -17,6 +15,7 @@
hostPlatform,
targetPlatform,
buildPlatform,
...
}@pkgs:
let
target-constants = callPackage ./constants.nix { platform = targetPlatform; };
@@ -24,20 +23,46 @@ let
tools = pkgs.tools or (callPackage ./tools.nix { inherit hostPlatform buildPlatform; });
boolOption = value: if value then "True" else "False";
gclient = writeText "flutter-engine-${version}.gclient" ''
solutions = [{
"managed": False,
"name": "${lib.optionalString (lib.versionAtLeast flutterVersion "3.29") "engine/"}src/flutter",
"url": "${url}",
"custom_vars": {
"download_fuchsia_deps": False,
"download_android_deps": False,
"download_linux_deps": ${boolOption targetPlatform.isLinux},
"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}"
]
'';
in
runCommand "flutter-engine-source-${version}-${buildPlatform.system}-${targetPlatform.system}"
{
pname = "flutter-engine-source";
inherit version;
inherit (tools) depot_tools;
nativeBuildInputs = [
curl
curlMinimal
pkg-config
git
gitMinimal
tools.cipd
(python3.withPackages (
(python312.withPackages (
ps: with ps; [
httplib2
six
@@ -45,40 +70,14 @@ runCommand "flutter-engine-source-${version}-${buildPlatform.system}-${targetPla
))
];
gclient = writeText "flutter-engine-${version}.gclient" ''
solutions = [{
"managed": False,
"name": "${lib.optionalString (lib.versionAtLeast flutterVersion "3.29") "engine/"}src/flutter",
"url": "${url}",
"custom_vars": {
"download_fuchsia_deps": False,
"download_android_deps": False,
"download_linux_deps": ${boolOption targetPlatform.isLinux},
"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";
GIT_SSL_CAINFO = "${cacert}/etc/ssl/certs/ca-bundle.crt";
SSL_CERT_FILE = "${cacert}/etc/ssl/certs/ca-bundle.crt";
DEPOT_TOOLS_UPDATE = "0";
DEPOT_TOOLS_COLLECT_METRICS = "0";
PYTHONDONTWRITEBYTECODE = "1";
env = {
NIX_SSL_CERT_FILE = "${cacert}/etc/ssl/certs/ca-bundle.crt";
GIT_SSL_CAINFO = "${cacert}/etc/ssl/certs/ca-bundle.crt";
SSL_CERT_FILE = "${cacert}/etc/ssl/certs/ca-bundle.crt";
DEPOT_TOOLS_UPDATE = "0";
DEPOT_TOOLS_COLLECT_METRICS = "0";
PYTHONDONTWRITEBYTECODE = "1";
};
outputHashAlgo = "sha256";
outputHashMode = "recursive";
@@ -96,34 +95,41 @@ runCommand "flutter-engine-source-${version}-${buildPlatform.system}-${targetPla
+ (
if lib.versionAtLeast flutterVersion "3.29" then
''
mkdir -p source
cp $gclient source/.gclient
mkdir --parents source
cp ${gclient} source/.gclient
cd source
''
else
''
mkdir -p $out
cp $gclient $out/.gclient
mkdir --parents $out
cp ${gclient} $out/.gclient
cd $out
''
)
+ ''
export PATH=$PATH:$depot_tools
python3 $depot_tools/gclient.py sync --no-history --shallow --nohooks -j $NIX_BUILD_CORES
export PATH=$PATH:${tools.depot_tools}
python3 ${tools.depot_tools}/gclient.py sync --no-history --shallow --nohooks -j $NIX_BUILD_CORES
''
+ lib.optionalString (lib.versionAtLeast flutterVersion "3.29") ''
cp -r engine/src/flutter/third_party/* engine/src/flutter/engine/src/flutter/third_party/
mv engine/src/flutter/engine $out
cp --recursive engine/src/flutter/third_party/* engine/src/flutter/engine/src/flutter/third_party/
${
if (lib.versionAtLeast flutterVersion "3.38") then
"mv engine/src/flutter $out"
else
"mv engine/src/flutter/engine $out"
}
''
+ ''
find $out -name '.git' -exec rm -rf {} \; || true
${if (lib.versionAtLeast flutterVersion "3.38") then "pushd $out/engine" else "pushd $out"}
find $out -name '.git' -exec rm --recursive --force {} \; || true
rm -rf $out/src/{buildtools,fuchsia}
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,third_party/java}
rm -rf $out/src/third_party/{dart/tools/sdks/dart-sdk,libcxx/test}
rm --recursive --force src/{buildtools,fuchsia}
rm --recursive --force src/flutter/{buildtools,prebuilts,third_party/swiftshader,third_party/gn/.versions}
rm --recursive --force src/flutter/{third_party/dart/tools/sdks/dart-sdk,third_party/ninja/ninja,third_party/java}
rm --recursive --force 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
rm --recursive --force .cipd .gclient .gclient_entries .gclient_previous_custom_vars .gclient_previous_sync_commits
popd
''
)
@@ -9,25 +9,28 @@
runCommand,
darwin,
writeShellScriptBin,
depot_toolsCommit ? "7d95eb2eb054447592585c73a8ff7adad97ecba1",
depot_toolsHash ? "sha256-F7KDuVg11qLKkohIjuXpNdxpnSsT6Z3hE9+wFIG2sSk=",
cipdCommit ? "89ada246fcbf10f330011e4991d017332af2365b",
depot_toolsCommit ? "580b4ff3f5cd0dcaa2eacda28cefe0f45320e8f7",
depot_toolsHash ? "sha256-k+XQSYJQYc9vAUjwrRxaAlX/sK74W45m5byS31hSpwc=",
cipdCommit ? "7120a6a515089a3ff5d1f61ff4ee17750dc038af",
cipdHashes ? {
"linux-386" = "7f264198598af2ef9d8878349d33c1940f1f3739e46d986962c352ec4cce2690";
"linux-amd64" = "2ada6b46ad1cd1350522c5c05899d273f5c894c7665e30104e7f57084a5aeeb9";
"linux-arm64" = "96eca7e49f6732c50122b94b793c3a5e62ed77bce1686787a8334906791b4168";
"linux-armv6l" = "06394601130652c5e1b055a7e4605c21fc7c6643af0b3b3cac8d2691491afa81";
"linux-mips64" = "f3eda6542b381b7aa8f582698498b0e197972c894590ec35f18faa467c868f5c";
"linux-mips64le" = "74229ada8e2afd9c8e7c58991126869b2880547780d4a197a27c1dfa96851622";
"linux-mipsle" = "2f3c18ec0ad48cd44a9ff39bb60e9afded83ca43fb9c7a5ea9949f6fdd4e1394";
"linux-ppc64" = "79425c0795fb8ba12b39a8856bf7ccb853e85def4317aa6413222f307d4c2dbd";
"linux-ppc64le" = "f9b3d85dde70f1b78cd7a41d2477834c15ac713a59317490a4cdac9f8f092325";
"linux-riscv64" = "bd695164563a66e8d3799e8835f90a398fbae9a4eec24e876c92d5f213943482";
"linux-s390x" = "6f501af80541e733fda23b4208a21ea05919c95d236036a2121e6b6334a2792c";
"macos-amd64" = "41d05580c0014912d6c32619c720646fd136e4557c9c7d7571ecc8c0462733a1";
"macos-arm64" = "dc672bd16d9faf277dd562f1dc00644b10c03c5d838d3cc3d3ea29925d76d931";
"windows-386" = "fa6ed0022a38ffc51ff8a927e3947fe7e59a64b2019dcddca9d3afacf7630444";
"windows-amd64" = "b5423e4b4429837f7fe4d571ce99c068aa0ccb37ddbebc1978a423fd2b0086df";
"linux-386" = "sha256-CshLfw49uglvWNwWE4K7ucBUF+IZlXDaIQsTXtFEJ8U=";
"linux-amd64" = "sha256-rxpI+HqfZiOYvzyyQ9P93s70feDmrLgbm4Xh3o88LwQ=";
"linux-arm64" = "sha256-XTTKbw1Q2lin+pf7VADalpBy3AWMTEd7yItsE/pePxw=";
"linux-armv6l" = "sha256-e5qe2KcguRLPuAq6wOG7A3YghHHon+oHY3fRLhU+e9E=";
"linux-loong64" = "sha256-LPTK4Ly173jac+cSGrsWw0ajrWEYepeJDGtP/7Xh528=";
"linux-mips" = "sha256-nR5khvHbAijs0MEr8+UgbuHTRNQAsMOyGTU/DI3K5Os=";
"linux-mips64" = "sha256-4a/zD1CrC/sxtBHqSRpom0SYVoN38bz3FAM40OSdVI0=";
"linux-mips64le" = "sha256-JnfKuBGLHYNLnRieS0KV8sYaTjh2rbp1yijvNOrU0FE=";
"linux-mipsle" = "sha256-nWqoay8c4faRk2+G5TvwbsbnndjTU4oglOTfhSC+TLQ=";
"linux-ppc64" = "sha256-pjeI/bx0i+QchQLhNB88ACPI34SrFvvFA01F5Nb16Ys=";
"linux-ppc64le" = "sha256-ZDMDwrP1zYlOI1hdbd3iZwKr59v/8CWj2sZ1RdosAiE=";
"linux-riscv64" = "sha256-O2EvOnjwbNssB7FtbK44yFcXfkrh9HOsPs/HF+uD2m8=";
"linux-s390x" = "sha256-BKeNDtuc9IkmV4GpuZcdsGc2F039KQeLdozxh7u+FDw=";
"mac-amd64" = "sha256-ZKBm8PbKjg4t0jIBPRKAv85L8eZOwJ1wBvh3cRSqHOI=";
"mac-arm64" = "sha256-AvjJp7JF05CetYDnwNJneAsotm1vBHWqB/vCdcIohoU=";
"windows-386" = "sha256-AVLbWh+WtJKynFDS6IfhuvYudw4Ow9s6w2JyDWG/2CI=";
"windows-amd64" = "sha256-puAQhiPGuwzkElWiBdTRGWOaUR2AIP7Qv9S3pwEY74E=";
"windows-arm64" = "sha256-4wxOMG+zvkM7gjhAiQvvNqNS0AamKKJdaBM/+rRxgXk=";
},
}:
let
@@ -50,12 +53,12 @@ in
src = fetchurl {
name = "cipd-${cipdCommit}-unwrapped";
url = "https://chrome-infra-packages.appspot.com/client?platform=${stdenv-constants.platform}&version=git_revision:${cipdCommit}";
sha256 = cipdHashes.${stdenv-constants.platform};
hash = cipdHashes.${stdenv-constants.platform};
};
}
''
mkdir -p $out/bin
install -m755 $src $out/bin/cipd
mkdir --parents $out/bin
install --mode=0755 $src $out/bin/cipd
'';
in
writeShellScriptBin "cipd" ''
@@ -89,7 +92,10 @@ in
vpython =
pythonPkg:
runCommand "vpython3" { } "mkdir -p $out/bin && ln -s ${pythonPkg}/bin/python $out/bin/vpython3";
runCommand "vpython3" { } ''
mkdir --parents $out/bin
ln --symbolic ${pythonPkg}/bin/python $out/bin/vpython3
'';
xcode-select = writeShellScriptBin "xcode-select" ''
echo ${darwin.xcode}/Contents/Developer
@@ -37,11 +37,13 @@ buildDartApplication.override { inherit dart; } {
src = flutterSrc;
sourceRoot = "${flutterSrc.name}/packages/flutter_tools";
postUnpack = ''chmod -R u+w "$NIX_BUILD_TOP/source"'';
inherit patches;
# The given patches are made for the entire SDK source tree.
prePatch = ''pushd "$NIX_BUILD_TOP/source"'';
prePatch = ''
chmod --recursive u+w "../.."
pushd "../.."
'';
postPatch = ''
popd
''
@@ -66,9 +68,9 @@ buildDartApplication.override { inherit dart; } {
];
preConfigure = ''
export HOME=.
export FLUTTER_ROOT="$NIX_BUILD_TOP/source"
mkdir -p "$FLUTTER_ROOT/bin/cache"
ln -s '${dart}' "$FLUTTER_ROOT/bin/cache/dart-sdk"
export FLUTTER_ROOT="$(realpath ../../)"
mkdir --parents "$FLUTTER_ROOT/bin/cache"
ln --symbolic '${dart}' "$FLUTTER_ROOT/bin/cache/dart-sdk"
'';
dartCompileFlags = [ "--define=NIX_FLUTTER_HOST_PLATFORM=${systemPlatform}" ];
+27 -20
View File
@@ -29,6 +29,7 @@
gitMinimal,
which,
jq,
writableTmpDirAsHomeHook,
flutterTools ? null,
}@args:
@@ -90,34 +91,38 @@ let
'';
buildPhase = ''
# The flutter_tools package tries to run many Git commands. In most
# cases, unexpected output is handled gracefully, but commands are never
# expected to fail completely. A blank repository needs to be created.
rm -rf .git # Remove any existing Git directory
git init -b nixpkgs
runHook preBuild
''
# The flutter_tools package tries to run many Git commands. In most
# cases, unexpected output is handled gracefully, but commands are never
# expected to fail completely. A blank repository needs to be created.
+ ''
rm --recursive --force .git # Remove any existing Git directory
git init --initial-branch=nixpkgs
GIT_AUTHOR_NAME=Nixpkgs GIT_COMMITTER_NAME=Nixpkgs \
GIT_AUTHOR_EMAIL= GIT_COMMITTER_EMAIL= \
GIT_AUTHOR_DATE='1/1/1970 00:00:00 +0000' GIT_COMMITTER_DATE='1/1/1970 00:00:00 +0000' \
git commit --allow-empty -m "Initial commit"
git commit --allow-empty --message="Initial commit"
(. '${../../../build-support/fetchgit/deterministic-git}'; make_deterministic_repo .)
mkdir -p bin/cache
''
+ ''
mkdir --parents bin/cache
# Add a flutter_tools artifact stamp, and build a snapshot.
# This is the Flutter CLI application.
echo "$(git rev-parse HEAD)" > bin/cache/flutter_tools.stamp
ln -s '${flutterTools}/share/flutter_tools.snapshot' bin/cache/flutter_tools.snapshot
ln --symbolic '${flutterTools}/share/flutter_tools.snapshot' bin/cache/flutter_tools.snapshot
# Some of flutter_tools's dependencies contain static assets. The
# application attempts to read its own package_config.json to find these
# assets at runtime.
mkdir -p packages/flutter_tools/.dart_tool
ln -s '${flutterTools.pubcache}/package_config.json' packages/flutter_tools/.dart_tool/package_config.json
mkdir --parents packages/flutter_tools/.dart_tool
ln --symbolic '${flutterTools.pubcache}/package_config.json' packages/flutter_tools/.dart_tool/package_config.json
echo -n "${version}" > version
cat <<EOF > bin/cache/flutter.version.json
{
"devToolsVersion": "$(cat "${dart}/bin/resources/devtools/version.json" | jq -r .version)",
"devToolsVersion": "$(cat "${dart}/bin/resources/devtools/version.json" | jq --raw-output .version)",
"flutterVersion": "${version}",
"frameworkVersion": "${version}",
"channel": "${channel}",
@@ -131,22 +136,24 @@ let
# Suppress a small error now that `.gradle`'s location changed.
# Location changed because of the patch "gradle-flutter-tools-wrapper.patch".
mkdir -p "$out/packages/flutter_tools/gradle/.gradle"
mkdir --parents "$out/packages/flutter_tools/gradle/.gradle"
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out
cp -r . $out
rm -rf $out/bin/cache/dart-sdk
ln -sf ${dart} $out/bin/cache/dart-sdk
mkdir --parents $out
cp --recursive . $out
rm --recursive --force $out/bin/cache/dart-sdk
ln --symbolic --force ${dart} $out/bin/cache/dart-sdk
# The regular launchers are designed to download/build/update SDK
# components, and are not very useful in Nix.
# Replace them with simple links and wrappers.
rm "$out/bin"/{dart,flutter}
ln -s "$out/bin/cache/dart-sdk/bin/dart" "$out/bin/dart"
ln --symbolic "$out/bin/cache/dart-sdk/bin/dart" "$out/bin/dart"
makeShellWrapper "$out/bin/dart" "$out/bin/flutter" \
--set-default FLUTTER_ROOT "$out" \
--set FLUTTER_ALREADY_LOCKED true \
@@ -158,15 +165,15 @@ let
doInstallCheck = true;
nativeInstallCheckInputs = [
which
writableTmpDirAsHomeHook
]
++ lib.optionals stdenv.hostPlatform.isDarwin [ darwin.DarwinTools ];
installCheckPhase = ''
runHook preInstallCheck
export HOME="$(mktemp -d)"
$out/bin/flutter config --android-studio-dir $HOME
$out/bin/flutter config --android-sdk $HOME
$out/bin/flutter --version | fgrep -q '${builtins.substring 0 10 engineVersion}'
$out/bin/flutter --version | fgrep --quiet '${builtins.substring 0 10 engineVersion}'
runHook postInstallCheck
'';
@@ -20,7 +20,7 @@ let
# symlinkJoin seems to be missing the .git directory for some reason.
if [ -d '${flutter.sdk}/.git' ]; then
ln -s '${flutter.sdk}/.git' "$out"
ln --symbolic '${flutter.sdk}/.git' "$out"
fi
# For iOS/macOS builds, *.xcframework/'s from the pre-built
@@ -40,8 +40,8 @@ let
# Remove the symlinkJoin .xcframework dir and replace it with a symlink
# to the unwrapped .xcframework dir.
frameworkDir="$(dirname "$file")"
rm -r "$frameworkDir"
ln -s "$origFrameworkDir" "$frameworkDir"
rm --recursive "$frameworkDir"
ln --symbolic "$origFrameworkDir" "$frameworkDir"
done
shopt -u globstar
'';
@@ -1,8 +1,8 @@
{ callPackage
, flutterPackages
, lib
, symlinkJoin
,
{
callPackage,
flutterPackages,
lib,
symlinkJoin,
}:
let
nixpkgsRoot = "@nixpkgs_root@";
@@ -25,25 +25,21 @@ let
"aarch64-darwin"
];
derivations =
lib.foldl'
(
acc: flutterPlatform:
acc
++ (map
(systemPlatform:
callPackage "${nixpkgsRoot}/pkgs/development/compilers/flutter/artifacts/fetch-artifacts.nix" {
flutter = flutterPackages."v${flutterCompactVersion}";
inherit flutterPlatform;
inherit systemPlatform;
hash = lib.fakeSha256;
})
systemPlatforms)
) [ ]
flutterPlatforms;
derivations = lib.foldl' (
acc: flutterPlatform:
acc
++ (map (
systemPlatform:
callPackage "${nixpkgsRoot}/pkgs/development/compilers/flutter/artifacts/fetch-artifacts.nix" {
flutter = flutterPackages."v${flutterCompactVersion}";
inherit flutterPlatform;
inherit systemPlatform;
hash = lib.fakeSha256;
}
) systemPlatforms)
) [ ] flutterPlatforms;
in
symlinkJoin {
name = "evaluate-derivations";
paths = derivations;
}
@@ -4,24 +4,29 @@ let
channel = "@channel@";
in
{
x86_64-linux = { fetchzip }:
x86_64-linux =
{ fetchzip }:
fetchzip {
url = "https://storage.googleapis.com/dart-archive/channels/${channel}/release/${dartVersion}/sdk/dartsdk-linux-x64-release.zip";
sha256 = "0000000000000000000000000000000000000000000000000000";
hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
};
aarch64-linux = { fetchzip }:
aarch64-linux =
{ fetchzip }:
fetchzip {
url = "https://storage.googleapis.com/dart-archive/channels/${channel}/release/${dartVersion}/sdk/dartsdk-linux-arm64-release.zip";
sha256 = "0000000000000000000000000000000000000000000000000000";
hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
};
x86_64-darwin = { fetchzip }:
x86_64-darwin =
{ fetchzip }:
fetchzip {
url = "https://storage.googleapis.com/dart-archive/channels/${channel}/release/${dartVersion}/sdk/dartsdk-macos-x64-release.zip";
sha256 = "0000000000000000000000000000000000000000000000000000";
hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
};
aarch64-darwin = { fetchzip }:
aarch64-darwin =
{ fetchzip }:
fetchzip {
url = "https://storage.googleapis.com/dart-archive/channels/${channel}/release/${dartVersion}/sdk/dartsdk-macos-arm64-release.zip";
sha256 = "0000000000000000000000000000000000000000000000000000";
hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
};
}.${platform}
}
.${platform}
@@ -1,4 +1,8 @@
{ callPackage, symlinkJoin, stdenv, lib }:
{
callPackage,
symlinkJoin,
lib,
}:
let
nixpkgsRoot = "@nixpkgs_root@";
version = "@flutter_version@";
@@ -9,25 +13,22 @@ let
"aarch64-linux"
];
derivations =
lib.foldl'
(
acc: buildPlatform:
acc
++ (map
(targetPlatform:
callPackage "${nixpkgsRoot}/pkgs/development/compilers/flutter/engine/source.nix" {
targetPlatform = lib.systems.elaborate targetPlatform;
hostPlatform = lib.systems.elaborate buildPlatform;
buildPlatform = lib.systems.elaborate buildPlatform;
flutterVersion = version;
version = engineVersion;
url = "https://github.com/flutter/flutter.git@${engineVersion}";
hashes."${buildPlatform}"."${targetPlatform}" = lib.fakeSha256;
})
systemPlatforms)
) [ ]
systemPlatforms;
derivations = lib.foldl' (
acc: buildPlatform:
acc
++ (map (
targetPlatform:
callPackage "${nixpkgsRoot}/pkgs/development/compilers/flutter/engine/source.nix" {
targetPlatform = lib.systems.elaborate targetPlatform;
hostPlatform = lib.systems.elaborate buildPlatform;
buildPlatform = lib.systems.elaborate buildPlatform;
flutterVersion = version;
version = engineVersion;
url = "https://github.com/flutter/flutter.git@${engineVersion}";
hashes."${buildPlatform}"."${targetPlatform}" = lib.fakeSha256;
}
) systemPlatforms)
) [ ] systemPlatforms;
in
symlinkJoin {
name = "evaluate-derivations";
@@ -2,6 +2,6 @@
fetchFromGitHub {
owner = "flutter";
repo = "flutter";
rev = "@flutter_version@";
tag = "@flutter_version@";
hash = "@hash@";
}
@@ -1,7 +1,7 @@
{ flutterPackages
, stdenv
, cacert
,
{
flutterPackages,
stdenv,
cacert,
}:
let
flutterCompactVersion = "@flutter_compact_version@";
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,21 @@
diff --git a/packages/flutter_tools/lib/src/flutter_cache.dart b/packages/flutter_tools/lib/src/flutter_cache.dart
index df67547..eacc7c4 100644
--- a/packages/flutter_tools/lib/src/flutter_cache.dart
+++ b/packages/flutter_tools/lib/src/flutter_cache.dart
@@ -51,16 +51,6 @@ class FlutterCache extends Cache {
registerArtifact(IosUsbArtifacts(artifactName, this, platform: platform));
}
registerArtifact(FontSubsetArtifacts(this, platform: platform));
- registerArtifact(
- PubDependencies(
- logger: logger,
- // flutter root and pub must be lazily initialized to avoid accessing
- // before the version is determined.
- flutterRoot: () => Cache.flutterRoot!,
- pub: () => pub,
- projectFactory: projectFactory,
- ),
- );
}
}
@@ -0,0 +1,29 @@
diff --git a/packages/flutter_tools/lib/src/runner/flutter_command.dart b/packages/flutter_tools/lib/src/runner/flutter_command.dart
index e4e474ab6e..5548599802 100644
--- a/packages/flutter_tools/lib/src/runner/flutter_command.dart
+++ b/packages/flutter_tools/lib/src/runner/flutter_command.dart
@@ -1693,7 +1693,7 @@ Run 'flutter -h' (or 'flutter <command> -h') for available flutter commands and
// Populate the cache. We call this before pub get below so that the
// sky_engine package is available in the flutter cache for pub to find.
- if (shouldUpdateCache) {
+ if (false) {
// First always update universal artifacts, as some of these (e.g.
// ios-deploy on macOS) are required to determine `requiredArtifacts`.
final bool offline;
diff --git a/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart b/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart
index a1104da..1749d65 100644
--- a/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart
+++ b/packages/flutter_tools/lib/src/runner/flutter_command_runner.dart
@@ -437,11 +437,6 @@
// Required to support `flutter --version` before artifacts are cached.
await globals.cache.updateAll(<DevelopmentArtifact>{DevelopmentArtifact.informative});
- globals.flutterVersion.ensureVersionFile();
- if (await _shouldCheckForUpdates(topLevelResults)) {
- await globals.flutterVersion.checkFlutterVersionFreshness();
- }
-
// See if the user specified a specific device.
final specifiedDeviceId = topLevelResults[FlutterGlobalOptions.kDeviceIdOption] as String?;
if (specifiedDeviceId != null) {
@@ -0,0 +1,68 @@
From 6df275df3b8694daf16302b407520e3b1dee6724 Mon Sep 17 00:00:00 2001
From: Philip Hayes <philiphayes9@gmail.com>
Date: Thu, 12 Sep 2024 13:23:00 -0700
Subject: [PATCH] fix: cleanup xcode_backend.sh to fix iOS build w/
`NixOS/nixpkgs` flutter
This patch cleans up `xcode_backend.sh`. It now effectively just runs
`exec $FLUTTER_ROOT/bin/dart ./xcode_backend.dart`.
The previous `xcode_backend.sh` tries to discover `$FLUTTER_ROOT` from
argv[0], even though its presence is already guaranteed (the wrapped
`xcode_backend.dart` also relies on this env).
When using nixpkgs flutter, the flutter SDK directory is composed of several
layers, joined together using symlinks (called a `symlinkJoin`). Without this
patch, the auto-discover traverses the symlinks into the wrong layer, and so it
uses an "unwrapped" `dart` command instead of a "wrapped" dart that sets some
important envs/flags (like `$FLUTTER_ROOT`).
Using the "unwrapped" dart then manifests in this error when compiling, since
it doesn't see the ios build-support artifacts:
```
$ flutter run -d iphone
Running Xcode build...
Xcode build done. 6.4s
Failed to build iOS app
Error (Xcode): Target debug_unpack_ios failed: Error: Flutter failed to create a directory at "/<nix-store>/XXXX-flutter-3.24.1-unwrapped/bin/cache/artifacts".
```
---
packages/flutter_tools/bin/xcode_backend.sh | 25 ++++-----------------
1 file changed, 4 insertions(+), 21 deletions(-)
diff --git a/packages/flutter_tools/bin/xcode_backend.sh b/packages/flutter_tools/bin/xcode_backend.sh
index 2889d7c8e4..48b9d06c6e 100755
--- a/packages/flutter_tools/bin/xcode_backend.sh
+++ b/packages/flutter_tools/bin/xcode_backend.sh
@@ -13,24 +13,7 @@
# exit on error, or usage of unset var
set -euo pipefail
-# Needed because if it is set, cd may print the path it changed to.
-unset CDPATH
-
-function follow_links() (
- cd -P "$(dirname -- "$1")"
- file="$PWD/$(basename -- "$1")"
- while [[ -h "$file" ]]; do
- cd -P "$(dirname -- "$file")"
- file="$(readlink -- "$file")"
- cd -P "$(dirname -- "$file")"
- file="$PWD/$(basename -- "$file")"
- done
- echo "$file"
-)
-
-PROG_NAME="$(follow_links "${BASH_SOURCE[0]}")"
-BIN_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)"
-FLUTTER_ROOT="$BIN_DIR/../../.."
-DART="$FLUTTER_ROOT/bin/dart"
-
-"$DART" "$BIN_DIR/xcode_backend.dart" "$@" "ios"
+# Run `dart ./xcode_backend.dart` with the dart from $FLUTTER_ROOT.
+dart="${FLUTTER_ROOT}/bin/dart"
+xcode_backend_dart="${BASH_SOURCE[0]%.sh}.dart"
+exec "${dart}" "${xcode_backend_dart}" "$@" "ios"
--
2.46.0
@@ -0,0 +1,59 @@
Fix for macOS build issue in Flutter >= 3.35
Since version 3.35, the behavior of macos_assemble.sh and xcode_backend.sh
is almost identical. This caused the same error for macOS that previously
occurred for iOS.
Derived from the iOS patch: ./fix-ios-build-xcode-backend-sh.patch
Example error:
```
$ flutter run -d macos
Launching lib/main.dart on macOS in debug mode...
Target debug_unpack_macos failed: Error: Flutter failed to create a directory at "/<nix-store>/XXXX-flutter-3.35.1-unwrapped/bin/cache/artifacts".
Please ensure that the SDK and/or project is installed in a location that has read/write permissions for the current user.
Failed to copy Flutter framework.
** BUILD FAILED **
```
---
diff --git a/packages/flutter_tools/bin/macos_assemble.sh b/packages/flutter_tools/bin/macos_assemble.sh
index 28acf8842..d0f2923df 100644
--- a/packages/flutter_tools/bin/macos_assemble.sh
+++ b/packages/flutter_tools/bin/macos_assemble.sh
@@ -13,29 +13,13 @@
# exit on error, or usage of unset var
set -euo pipefail
-# Needed because if it is set, cd may print the path it changed to.
-unset CDPATH
-
-function follow_links() (
- cd -P "$(dirname -- "$1")"
- file="$PWD/$(basename -- "$1")"
- while [[ -h "$file" ]]; do
- cd -P "$(dirname -- "$file")"
- file="$(readlink -- "$file")"
- cd -P "$(dirname -- "$file")"
- file="$PWD/$(basename -- "$file")"
- done
- echo "$file"
-)
-
-PROG_NAME="$(follow_links "${BASH_SOURCE[0]}")"
-BIN_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)"
-FLUTTER_ROOT="$BIN_DIR/../../.."
-DART="$FLUTTER_ROOT/bin/dart"
+# Run `dart ./xcode_backend.dart` with the dart from $FLUTTER_ROOT.
+dart="${FLUTTER_ROOT}/bin/dart"
+xcode_backend_dart="$(dirname "${BASH_SOURCE[0]}")/xcode_backend.dart"
# Main entry point.
if [[ $# == 0 ]]; then
- "$DART" "$BIN_DIR/xcode_backend.dart" "build" "macos"
+ exec "${dart}" "${xcode_backend_dart}" "build" "macos"
else
- "$DART" "$BIN_DIR/xcode_backend.dart" "$@" "macos"
+ exec "${dart}" "${xcode_backend_dart}" "$@" "macos"
fi
@@ -0,0 +1,220 @@
This patch introduces an intermediate Gradle build step to alter the behavior
of flutter_tools' Gradle project, specifically moving the creation of `build`
and `.gradle` directories from within the Nix Store to somewhere in `$HOME/.cache/flutter/nix-flutter-tools-gradle/$engineShortRev`.
Without this patch, flutter_tools' Gradle project tries to generate `build` and `.gradle`
directories within the Nix Store. Resulting in read-only errors when trying to build a
Flutter Android app at runtime.
This patch takes advantage of the fact settings.gradle takes priority over settings.gradle.kts to build the intermediate Gradle project
when a Flutter app runs `includeBuild("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle")`
`rootProject.buildFileName = "/dev/null"` so that the intermediate project doesn't use `build.gradle.kts` that's in the same directory.
The intermediate project makes a `settings.gradle` file in `$HOME/.cache/flutter/nix-flutter-tools-gradle/<short engine rev>/` and `includeBuild`s it.
This Gradle project will build the actual `packages/flutter_tools/gradle` project by setting
`rootProject.projectDir = new File("$settingsDir")` and `apply from: new File("$settingsDir/settings.gradle.kts")`.
To move `build` to `$HOME/.cache/flutter/nix-flutter-tools-gradle/<short engine rev>/`, we need to set `buildDirectory`.
To move `.gradle` as well, the `--project-cache-dir` argument must be passed to the Gradle wrapper.
Changing the `GradleUtils.getExecutable` function signature is a delibarate choice, to ensure that no new unpatched usages slip in.
--- /dev/null
+++ b/packages/flutter_tools/gradle/settings.gradle
@@ -0,0 +1,19 @@
+rootProject.buildFileName = "/dev/null"
+
+def engineShortRev = (new File("$settingsDir/../../../bin/internal/engine.version")).text.take(10)
+def dir = new File("$System.env.HOME/.cache/flutter/nix-flutter-tools-gradle/$engineShortRev")
+dir.mkdirs()
+def file = new File(dir, "settings.gradle")
+
+file.text = """
+rootProject.projectDir = new File("$settingsDir")
+apply from: new File("$settingsDir/settings.gradle.kts")
+
+gradle.allprojects { project ->
+ project.beforeEvaluate {
+ project.layout.buildDirectory = new File("$dir/build")
+ }
+}
+"""
+
+includeBuild(dir)
--- a/packages/flutter_tools/gradle/build.gradle.kts
+++ b/packages/flutter_tools/gradle/build.gradle.kts
@@ -4,6 +4,11 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
+// While flutter_tools runs Gradle with a --project-cache-dir, this startParameter
+// is not passed correctly to the Kotlin Gradle plugin for some reason, and so
+// must be set here as well.
+gradle.startParameter.projectCacheDir = layout.buildDirectory.dir("cache").get().asFile
+
plugins {
`java-gradle-plugin`
groovy
--- a/packages/flutter_tools/lib/src/android/gradle.dart
+++ b/packages/flutter_tools/lib/src/android/gradle.dart
@@ -474,9 +474,9 @@ class AndroidGradleBuilder implements AndroidBuilder {
// from the local.properties file.
updateLocalProperties(project: project, buildInfo: androidBuildInfo.buildInfo);
- final options = <String>[];
-
- final String gradleExecutablePath = _gradleUtils.getExecutable(project);
+ final [String gradleExecutablePath, ...List<String> options] = _gradleUtils.getExecutable(
+ project,
+ );
// All automatically created files should exist.
if (configOnly) {
@@ -797,7 +797,7 @@ class AndroidGradleBuilder implements AndroidBuilder {
'aar_init_script.gradle',
);
final command = <String>[
- _gradleUtils.getExecutable(project),
+ ..._gradleUtils.getExecutable(project),
'-I=$initScript',
'-Pflutter-root=$flutterRoot',
'-Poutput-dir=${outputDirectory.path}',
@@ -912,6 +912,10 @@ class AndroidGradleBuilder implements AndroidBuilder {
final results = <String>[];
try {
+ final [String gradleExecutablePath, ...List<String> options] = _gradleUtils.getExecutable(
+ project,
+ );
+
exitCode = await _runGradleTask(
_kBuildVariantTaskName,
preRunTask: () {
@@ -927,10 +931,10 @@ class AndroidGradleBuilder implements AndroidBuilder {
),
);
},
- options: const <String>['-q'],
+ options: <String>[...options, '-q'],
project: project,
localGradleErrors: gradleErrors,
- gradleExecutablePath: _gradleUtils.getExecutable(project),
+ gradleExecutablePath: gradleExecutablePath,
outputParser: (String line) {
if (_kBuildVariantRegex.firstMatch(line) case final RegExpMatch match) {
results.add(match.namedGroup(_kBuildVariantRegexGroupName)!);
@@ -964,6 +968,10 @@ class AndroidGradleBuilder implements AndroidBuilder {
late Stopwatch sw;
var exitCode = 1;
try {
+ final [String gradleExecutablePath, ...List<String> options] = _gradleUtils.getExecutable(
+ project,
+ );
+
exitCode = await _runGradleTask(
taskName,
preRunTask: () {
@@ -979,10 +987,10 @@ class AndroidGradleBuilder implements AndroidBuilder {
),
);
},
- options: <String>['-q', '-PoutputPath=$outputPath'],
+ options: <String>[...options, '-q', '-PoutputPath=$outputPath'],
project: project,
localGradleErrors: gradleErrors,
- gradleExecutablePath: _gradleUtils.getExecutable(project),
+ gradleExecutablePath: gradleExecutablePath,
);
} on Error catch (error) {
_logger.printError(error.toString());
--- a/packages/flutter_tools/lib/src/android/gradle_errors.dart
+++ b/packages/flutter_tools/lib/src/android/gradle_errors.dart
@@ -228,7 +228,12 @@ final flavorUndefinedHandler = GradleHandledError(
},
handler: ({required String line, required FlutterProject project, required bool usesAndroidX}) async {
final RunResult tasksRunResult = await globals.processUtils.run(
- <String>[globals.gradleUtils!.getExecutable(project), 'app:tasks', '--all', '--console=auto'],
+ <String>[
+ ...globals.gradleUtils!.getExecutable(project),
+ 'app:tasks',
+ '--all',
+ '--console=auto',
+ ],
throwOnError: true,
workingDirectory: project.android.hostAppGradleRoot.path,
environment: globals.java?.environment,
--- a/packages/flutter_tools/lib/src/android/gradle_utils.dart
+++ b/packages/flutter_tools/lib/src/android/gradle_utils.dart
@@ -3,6 +3,7 @@
// found in the LICENSE file.
import 'package:meta/meta.dart';
+import 'package:path/path.dart';
import 'package:process/process.dart';
import 'package:unified_analytics/unified_analytics.dart';
@@ -197,9 +198,29 @@ class GradleUtils {
final Logger _logger;
final OperatingSystemUtils _operatingSystemUtils;
+ List<String> get _requiredArguments {
+ final String cacheDir = join(
+ switch (globals.platform.environment['XDG_CACHE_HOME']) {
+ final String cacheHome => cacheHome,
+ _ => join(
+ globals.fsUtils.homeDirPath ?? throwToolExit('No cache directory has been specified.'),
+ '.cache',
+ ),
+ },
+ 'flutter',
+ 'nix-flutter-tools-gradle',
+ globals.flutterVersion.engineRevision.substring(0, 10),
+ );
+
+ return <String>[
+ '--project-cache-dir=${join(cacheDir, 'cache')}',
+ '-Pkotlin.project.persistent.dir=${join(cacheDir, 'kotlin')}',
+ ];
+ }
+
/// Gets the Gradle executable path and prepares the Gradle project.
/// This is the `gradlew` or `gradlew.bat` script in the `android/` directory.
- String getExecutable(FlutterProject project) {
+ List<String> getExecutable(FlutterProject project) {
final Directory androidDir = project.android.hostAppGradleRoot;
injectGradleWrapperIfNeeded(androidDir);
@@ -210,7 +231,7 @@ class GradleUtils {
// If the Gradle executable doesn't have execute permission,
// then attempt to set it.
_operatingSystemUtils.makeExecutable(gradle);
- return gradle.absolute.path;
+ return <String>[gradle.absolute.path, ..._requiredArguments];
}
throwToolExit(
'Unable to locate gradlew script. Please check that ${gradle.path} '
--- a/packages/flutter_tools/test/general.shard/android/android_gradle_builder_test.dart
+++ b/packages/flutter_tools/test/general.shard/android/android_gradle_builder_test.dart
@@ -2606,8 +2606,8 @@ Gradle Crashed
class FakeGradleUtils extends Fake implements GradleUtils {
@override
- String getExecutable(FlutterProject project) {
- return 'gradlew';
+ List<String> getExecutable(FlutterProject project) {
+ return const <String>['gradlew'];
}
}
--- a/packages/flutter_tools/test/general.shard/android/gradle_errors_test.dart
+++ b/packages/flutter_tools/test/general.shard/android/gradle_errors_test.dart
@@ -1633,8 +1633,8 @@ Platform fakePlatform(String name) {
class FakeGradleUtils extends Fake implements GradleUtils {
@override
- String getExecutable(FlutterProject project) {
- return 'gradlew';
+ List<String> getExecutable(FlutterProject project) {
+ return const <String>['gradlew'];
}
}
@@ -24,7 +24,7 @@
makeWrapper,
writeShellScript,
wrapGAppsHook3,
git,
gitMinimal,
which,
pkg-config,
atk,
@@ -64,8 +64,8 @@ let
name = "flutter-cache-dir";
paths = builtins.attrValues flutterPlatformArtifacts;
postBuild = ''
mkdir -p "$out/bin/cache"
ln -s '${flutter}/bin/cache/dart-sdk' "$out/bin/cache"
mkdir --parents "$out/bin/cache"
ln --symbolic '${flutter}/bin/cache/dart-sdk' "$out/bin/cache"
'';
passthru.flutterPlatform = flutterPlatformArtifacts;
};
@@ -79,7 +79,7 @@ let
# Tools that the Flutter tool depends on.
tools = [
git
gitMinimal
which
];
@@ -184,7 +184,7 @@ in
addToSearchPath FLUTTER_PKG_CONFIG_PATH "$path"
done
mkdir -p $out/bin
mkdir --parents $out/bin
makeWrapper '${immutableFlutter}' $out/bin/flutter \
--set-default ANDROID_EMULATOR_USE_SYSTEM_LIBS 1 \
''
+1
View File
@@ -4485,6 +4485,7 @@ with pkgs;
);
flutterPackages = flutterPackages-bin;
flutter = flutterPackages.stable;
flutter338 = flutterPackages.v3_38;
flutter335 = flutterPackages.v3_35;
flutter332 = flutterPackages.v3_32;
flutter329 = flutterPackages.v3_29;