Skip to content

Commit

Permalink
Merge pull request #324717 from ExpidusOS/fix/flutter-engine
Browse files Browse the repository at this point in the history
flutterPackages-source: disable old version sources, fix update hashes
  • Loading branch information
RossComputerGuy authored Aug 16, 2024
2 parents a508484 + 883f716 commit bc92741
Show file tree
Hide file tree
Showing 14 changed files with 255 additions and 120 deletions.
83 changes: 45 additions & 38 deletions pkgs/development/compilers/flutter/engine/constants.nix
Original file line number Diff line number Diff line change
@@ -1,41 +1,48 @@
{ lib, targetPlatform }:
rec {
os =
if targetPlatform.isLinux then
"linux"
else if targetPlatform.isDarwin then
"macos"
else if targetPlatform.isWindows then
"windows"
else
throw "Unsupported OS \"${targetPlatform.parsed.kernel.name}\"";
{ lib, platform }:
let
self = {
os =
if platform.isLinux then
"linux"
else if platform.isDarwin then
"macos"
else if platform.isWindows then
"windows"
else
throw "Unsupported OS \"${platform.parsed.kernel.name}\"";

arch =
if targetPlatform.isx86_64 then
"amd64"
else if targetPlatform.isx86 && targetPlatform.is32bit then
"386"
else if targetPlatform.isAarch64 then
"arm64"
else if targetPlatform.isMips && targetPlatform.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
"s390x"
else
throw "Unsupported CPU \"${targetPlatform.parsed.cpu.name}\"";
alt-os = if platform.isDarwin then "mac" else self.os;

alt-arch =
if targetPlatform.isx86_64 then
"x64"
else if targetPlatform.isAarch64 then
"arm64"
else
targetPlatform.parsed.cpu.name;
arch =
if platform.isx86_64 then
"amd64"
else if platform.isx86 && platform.is32bit then
"386"
else if platform.isAarch64 then
"arm64"
else if platform.isMips && platform.parsed.cpu.significantByte == "littleEndian" then
"mipsle"
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 \"${platform.parsed.cpu.name}\"";

platform = "${os}-${arch}";
alt-platform = "${os}-${alt-arch}";
}
alt-arch =
if platform.isx86_64 then
"x64"
else if platform.isAarch64 then
"arm64"
else
platform.parsed.cpu.name;

platform = "${self.os}-${self.arch}";
alt-platform = "${self.os}-${self.alt-arch}";
};
in
self
4 changes: 2 additions & 2 deletions pkgs/development/compilers/flutter/engine/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
url,
patches,
runtimeModes,
isOptimized ? true,
isOptimized ? null,
lib,
stdenv,
dart,
Expand All @@ -33,8 +33,8 @@ let
url
patches
runtimeMode
isOptimized
;
isOptimized = args.isOptimized or runtimeMode != "debug";
}
);
in
Expand Down
68 changes: 37 additions & 31 deletions pkgs/development/compilers/flutter/engine/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -33,7 +33,8 @@
gtk3,
pkg-config,
ninja,
python3,
python312,
python39,
git,
version,
flutterVersion,
Expand All @@ -44,22 +45,27 @@
patches,
url,
runtimeMode ? "release",
isOptimized ? true,
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 { 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
;
};

Expand All @@ -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"}";
Expand All @@ -95,7 +103,11 @@ stdenv.mkDerivation (finalAttrs: {
dartSdkVersion
src
outName
swiftshader;
swiftshader
;

setOutputFlags = false;
doStrip = isOptimized;

toolchain = symlinkJoin {
name = "flutter-engine-toolchain-${version}";
Expand Down Expand Up @@ -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 =
[
Expand All @@ -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;

Expand All @@ -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) ''
Expand All @@ -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 "[email protected]"
git commit -a -m "$rev" --quiet
git commit -a -m "$dir" --quiet
popd
done
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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
'';

Expand Down Expand Up @@ -323,5 +329,5 @@ stdenv.mkDerivation (finalAttrs: {
"x86_64-darwin"
"aarch64-darwin"
];
};
} // lib.optionalAttrs (lib.versionOlder flutterVersion "3.22") { hydraPlatforms = [ ]; };
})
44 changes: 32 additions & 12 deletions pkgs/development/compilers/flutter/engine/source.nix
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
{
lib,
callPackage,
hostPlatform,
buildPlatform,
targetPlatform,
hostPlatform,
fetchgit,
tools ? callPackage ./tools.nix { inherit hostPlatform; },
tools ? null,
curl,
pkg-config,
git,
python3,
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;
Expand Down Expand Up @@ -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";
Expand All @@ -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}
Expand All @@ -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
''
Loading

0 comments on commit bc92741

Please sign in to comment.