Repository: flutter
Issue: [engine] linux build patches
Labels: tool,engine,platform-linux,a: build,P2,team-engine,triaged-engine

I'm working with 3.7.6.

Using a .gclient like this
```
solutions = [
  {
    "managed": False,
    "name": "src/flutter",
    "url": "https://github.com/flutter/engine.git",
    "custom_deps": {
      "download_dart_sdk": False,
      "download_android_deps": False,
      "download_windows_deps": False,
      "download_linux_deps": False,
    },
    "deps_file": "DEPS",
    "safesync_url": "",
  },
]
```

I'm noticing that `download_linux_deps` is ignored and I still fetches the linux x86 and arm64 lsysroots.  In my use case these are not needed, or desired.

Example:

    $ gclient sync --revision ada363ee93b17cfe31587b5102679885cb40837e --no-history --shallow
    $ ls -la build/linux/
    total 52
    drwxr-xr-x.  7 joel joel 4096 Mar 20 16:25 .
    drwxr-xr-x. 19 joel joel 4096 Mar 20 15:44 ..
    drwxr-xr-x.  2 joel joel 4096 Mar 20 15:44 bin
    -rw-r--r--.  1 joel joel  653 Mar 20 15:44 chrome_linux.croc
    drwxr-xr-x.  8 joel joel 4096 Mar 20 16:25 debian_sid_amd64-sysroot
    drwxr-xr-x.  7 joel joel 4096 Mar 20 16:25 debian_sid_arm64-sysroot
    -rw-r--r--.  1 joel joel  873 Mar 20 15:44 dump_app_syms.py
    -rwxr-xr-x.  1 joel joel 2238 Mar 20 15:44 install-chromeos-fonts.py
    -rwxr-xr-x.  1 joel joel 2096 Mar 20 15:44 pkg-config-wrapper
    -rwxr-xr-x.  1 joel joel 2017 Mar 20 15:44 rewrite_dirs.py
    -rwxr-xr-x.  1 joel joel 2468 Mar 20 15:44 sysroot_ld_path.sh
    drwxr-xr-x.  2 joel joel 4096 Mar 20 15:44 sysroot_scripts
    drwxr-xr-x.  2 joel joel 4096 Mar 20 15:44 unbundle

With `"download_linux_deps": False` it should not download these.

I then apply my usual patches:

```
From 3a7d643ff33d791cbee9423d044060b89ca7a3de Mon Sep 17 00:00:00 2001
From: Joel Winarske <joel.winarsk@gmail.com>
Date: Sun, 5 Mar 2023 10:37:44 -0800
Subject: [PATCH] Disable pre-canned sysroot

Signed-off-by: Joel Winarske <joel.winarsk@gmail.com>
---
 build/config/sysroot.gni | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/build/config/sysroot.gni b/build/config/sysroot.gni
index 7987e51..1de6942 100644
--- a/build/config/sysroot.gni
+++ b/build/config/sysroot.gni
@@ -14,7 +14,7 @@ declare_args() {
 
   # Whether to use the default sysroot when building for Linux, if an explicit
   # sysroot isn't set.
-  use_default_linux_sysroot = true
+  use_default_linux_sysroot = false
 }
 
 if (current_toolchain == default_toolchain && target_sysroot != "") {
-- 
2.39.2

```
Override should be enabled if a custom sysroot using `--target-sysroot` is specified.  If `--target-sysroot` is not set, then it should default to the pre-canned sysroot.


```
From dbe21e0e1ceb41da5a99f97937f2f6dd03f7e2e4 Mon Sep 17 00:00:00 2001
From: Joel Winarske <joel.winarske@gmail.com>
Date: Sun, 29 May 2022 09:38:46 -0700
Subject: [PATCH] Remove x11 dependency

Signed-off-by: Joel Winarske <joel.winarske@gmail.com>
---
 flutter/shell/platform/linux/config/BUILD.gn | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/flutter/shell/platform/linux/config/BUILD.gn b/flutter/shell/platform/linux/config/BUILD.gn
index da0ac056bc..70c7a0ea16 100644
--- a/flutter/shell/platform/linux/config/BUILD.gn
+++ b/flutter/shell/platform/linux/config/BUILD.gn
@@ -5,10 +5,6 @@
 import("//build/config/linux/pkg_config.gni")
 import("//flutter/shell/platform/glfw/config.gni")
 
-pkg_config("x11") {
-  packages = [ "x11" ]
-}
-
 pkg_config("gtk") {
   packages = [ "gtk+-3.0" ]
 }
-- 
2.34.3
```
This is redundant, as the gtk pkg-config query will reference x11 if that's how it was built.


```
From ef2ca84f52f59fe6c5dfe72c2b4b0ab8d3e61b98 Mon Sep 17 00:00:00 2001
From: Joel Winarske <joel.winarsk@gmail.com>
Date: Thu, 16 Mar 2023 18:05:37 -0700
Subject: [PATCH] Disable x11

Signed-off-by: Joel Winarske <joel.winarsk@gmail.com>
---
 build_overrides/vulkan_headers.gni | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/build_overrides/vulkan_headers.gni b/build_overrides/vulkan_headers.gni
index 5efa852..8a4144d 100644
--- a/build_overrides/vulkan_headers.gni
+++ b/build_overrides/vulkan_headers.gni
@@ -6,6 +6,6 @@
 # set anything.
 
 if (is_linux) {
-  vulkan_use_x11 = true
+  vulkan_use_x11 = false
   vulkan_use_wayland = true
 }
-- 
2.39.2
```
This pulls in x11 dependency which in my use cases is never desired, and requires a patch.


```
From ca175ef5bf7f96db57fb5aa562602dc424fab81c Mon Sep 17 00:00:00 2001
From: Joel Winarske <joel.winarsk@gmail.com>
Date: Sun, 5 Mar 2023 10:43:02 -0800
Subject: [PATCH] clang toolchain

Signed-off-by: Joel Winarske <joel.winarsk@gmail.com>
---
 build/toolchain/custom/BUILD.gn | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/build/toolchain/custom/BUILD.gn b/build/toolchain/custom/BUILD.gn
index 65b1623..8b3f6f8 100644
--- a/build/toolchain/custom/BUILD.gn
+++ b/build/toolchain/custom/BUILD.gn
@@ -12,11 +12,11 @@ toolchain("custom") {
   # these values in our scope.
   cc = "${toolchain_bin}/clang"
   cxx = "${toolchain_bin}/clang++"
-  ar = "${toolchain_bin}/${custom_target_triple}-ar"
+  ar = "${toolchain_bin}/llvm-ar"
   ld = "${toolchain_bin}/clang++"
-  readelf = "${toolchain_bin}/${custom_target_triple}-readelf"
-  nm = "${toolchain_bin}/${custom_target_triple}-nm"
-  strip = "${toolchain_bin}/${custom_target_triple}-strip"
+  readelf = "${toolchain_bin}/llvm-readelf"
+  nm = "${toolchain_bin}/llvm-nm"
+  strip = "${toolchain_bin}/llvm-strip"
 
   target_triple_flags = "--target=${custom_target_triple}"
   sysroot_flags = "--sysroot ${custom_sysroot}"
@@ -84,10 +84,9 @@ toolchain("custom") {
     link_command = "$ld $target_triple_flags $sysroot_flags -shared {{ldflags}} -o $unstripped_sofile $custom_lib_flags -Wl,--build-id=sha1 -Wl,-soname=$soname @$rspfile"
     toc_command = "{ $readelf -d $unstripped_sofile | grep SONAME ; $nm -gD -f posix $unstripped_sofile | cut -f1-2 -d' '; } > $temporary_tocname"
     replace_command = "if ! cmp -s $temporary_tocname $tocfile; then mv $temporary_tocname $tocfile; fi"
-    strip_command = "$strip -o $sofile $unstripped_sofile"
 
     command =
-        "$link_command && $toc_command && $replace_command && $strip_command"
+        "$link_command && $toc_command && $replace_command"
     rspfile_content = "-Wl,--whole-archive {{inputs}} {{solibs}} -Wl,--no-whole-archive {{libs}}"
 
     description = "SOLINK $sofile"
-- 
2.39.2
```
This is used for building the engine using the cipd downloaded clang toolchain.


It seems a bit silly to keep patching for this when companies are shipping commercial product based on these patches.  Not to metion I'm tired of re-working the patches.  What would it take to make this a priority and get the patched logic pulled in?