1{
2 lib,
3 callPackage,
4 fetchgit,
5 tools ? null,
6 curl,
7 pkg-config,
8 git,
9 python3,
10 runCommand,
11 writeText,
12 cacert,
13 flutterVersion,
14 version,
15 hashes,
16 url,
17 hostPlatform,
18 targetPlatform,
19 buildPlatform,
20}@pkgs:
21let
22 target-constants = callPackage ./constants.nix { platform = targetPlatform; };
23 build-constants = callPackage ./constants.nix { platform = buildPlatform; };
24 tools = pkgs.tools or (callPackage ./tools.nix { inherit hostPlatform buildPlatform; });
25
26 boolOption = value: if value then "True" else "False";
27in
28runCommand "flutter-engine-source-${version}-${buildPlatform.system}-${targetPlatform.system}"
29 {
30 pname = "flutter-engine-source";
31 inherit version;
32
33 inherit (tools) depot_tools;
34
35 nativeBuildInputs = [
36 curl
37 pkg-config
38 git
39 tools.cipd
40 (python3.withPackages (
41 ps: with ps; [
42 httplib2
43 six
44 ]
45 ))
46 ];
47
48 gclient = writeText "flutter-engine-${version}.gclient" ''
49 solutions = [{
50 "managed": False,
51 "name": "src/flutter",
52 "url": "${url}",
53 "custom_vars": {
54 "download_fuchsia_deps": False,
55 "download_android_deps": False,
56 "download_linux_deps": ${boolOption targetPlatform.isLinux},
57 "setup_githooks": False,
58 "download_esbuild": False,
59 "download_dart_sdk": False,
60 "host_cpu": "${build-constants.alt-arch}",
61 "host_os": "${build-constants.alt-os}",
62 },
63 }]
64
65 target_os_only = True
66 target_os = [
67 "${target-constants.alt-os}"
68 ]
69
70 target_cpu_only = True
71 target_cpu = [
72 "${target-constants.alt-arch}"
73 ]
74 '';
75
76 NIX_SSL_CERT_FILE = "${cacert}/etc/ssl/certs/ca-bundle.crt";
77 GIT_SSL_CAINFO = "${cacert}/etc/ssl/certs/ca-bundle.crt";
78 SSL_CERT_FILE = "${cacert}/etc/ssl/certs/ca-bundle.crt";
79 DEPOT_TOOLS_UPDATE = "0";
80 DEPOT_TOOLS_COLLECT_METRICS = "0";
81 PYTHONDONTWRITEBYTECODE = "1";
82
83 outputHashAlgo = "sha256";
84 outputHashMode = "recursive";
85 outputHash =
86 (hashes."${buildPlatform.system}" or { })."${targetPlatform.system}"
87 or (throw "Hash not set for ${targetPlatform.system} on ${buildPlatform.system}");
88 }
89 ''
90 source ${../../../../build-support/fetchgit/deterministic-git}
91 export -f clean_git
92 export -f make_deterministic_repo
93
94 mkdir -p $out
95 cp $gclient $out/.gclient
96 cd $out
97
98 export PATH=$PATH:$depot_tools
99 python3 $depot_tools/gclient.py sync --no-history --shallow --nohooks -j $NIX_BUILD_CORES
100 find $out -name '.git' -exec rm -rf {} \; || true
101
102 rm -rf $out/src/{buildtools,fuchsia}
103 rm -rf $out/src/flutter/{buildtools,prebuilts,third_party/swiftshader,third_party/gn/.versions}
104 rm -rf $out/src/flutter/{third_party/dart/tools/sdks/dart-sdk,third_party/ninja/ninja,third_party/java}
105 rm -rf $out/src/third_party/{dart/tools/sdks/dart-sdk,libcxx/test}
106
107 rm -rf $out/.cipd $out/.gclient $out/.gclient_entries $out/.gclient_previous_custom_vars $out/.gclient_previous_sync_commits
108 ''