[infra] Use hermetic version of llvm-dev

Fetches llvm-dev from CIPD

Mesa/Meson are updated to use the CIPD fetched version instead of the
system installed one

Restricting building Mesa in Dawn to Linux only, since that is the
only platform that llvm-dev is provided for via infra/3pp. (Using out
of tree builds with Dawn Node should still work fine)

Fixes: 524406307
Change-Id: I30d7e0c84dbb99b9d19aae3d096f644ef4c7a686
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/317235
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 07ec87a..90a025e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -257,6 +257,10 @@
 option(TINT_BUILD_AS_OTHER_OS "Override OS detection to force building of *_other.cc files" OFF)
 option(TINT_BUILD_MESA "Build Mesa" OFF)
 
+if (TINT_BUILD_MESA AND NOT CMAKE_SYSTEM_NAME STREQUAL "Linux")
+    message(FATAL_ERROR "Building Mesa is only supported on Linux")
+endif()
+
 if (EMSCRIPTEN)
   # Skip tint tests in emscripten build
   set(TINT_BUILD_TESTS OFF)
diff --git a/DEPS b/DEPS
index 8565b6b..7248a8f 100644
--- a/DEPS
+++ b/DEPS
@@ -31,6 +31,7 @@
   'dawn_node_version': 'version:2@20.11.0',
   'agility_sdk_version': 'version:2@1.721.0-preview',
   'dawn_bazelisk_version': 'version:3@1.29.0',
+  'dawn_llvm-dev_version': 'version:3@22.1.0',
 
   # GN variable required by //testing that will be output in the gclient_args.gni
   'generate_location_tags': False,
@@ -299,14 +300,22 @@
     'condition': 'dawn_standalone',
   },
 
-  # Required tint fuzzer + mesa
+  # Required for fuzzing Mesa via tint fuzzers
   'third_party/mesa/src': {
     'url': '{chromium_git}/external/gitlab.freedesktop.org/mesa/mesa/@2e683eb7385c54f872acc47b371210d2282bc103',
-    'condition': 'checkout_mesa',
+    'condition': 'checkout_mesa and host_os == "linux"',
   },
   'third_party/meson/src': {
     'url': '{chromium_git}/external/github.com/mesonbuild/meson@d389906a136c2aac9820ded0f38d1e25ef25fb9a',
-    'condition': 'checkout_mesa',
+    'condition': 'checkout_mesa and host_os == "linux"',
+  },
+  'third_party/llvm-dev': {
+    'packages': [{
+      'package': 'infra/3pp/tools/llvm-dev/linux-amd64',
+      'version': Var('dawn_llvm-dev_version'),
+    }],
+    'dep_type': 'cipd',
+    'condition': 'checkout_mesa and host_os == "linux"',
   },
 
   # Jinja2 and MarkupSafe for the code generator
diff --git a/build_overrides/mesa.gni b/build_overrides/mesa.gni
index 169c190..b17be84 100644
--- a/build_overrides/mesa.gni
+++ b/build_overrides/mesa.gni
@@ -28,4 +28,6 @@
 mesa_options = [
   "-Dgallium-drivers=llvmpipe",
   "-Dvulkan-drivers=swrast",
+  "-Dshared-llvm=disabled",
+  "-Dcpp_rtti=false",
 ]
diff --git a/scripts/tint_overrides_with_defaults.gni b/scripts/tint_overrides_with_defaults.gni
index 22f56c1..6bd59a8 100644
--- a/scripts/tint_overrides_with_defaults.gni
+++ b/scripts/tint_overrides_with_defaults.gni
@@ -163,6 +163,10 @@
   }
 }
 
+if (tint_build_mesa && !is_linux) {
+  assert(false, "Building Mesa is only supported on Linux")
+}
+
 declare_args() {
   # Enable Vulkan support in Tint fuzzers
   if (!defined(tint_build_fuzzer_vulkan_support)) {
diff --git a/src/dawn/node/README.md b/src/dawn/node/README.md
index db1f00d..bb1aadf 100644
--- a/src/dawn/node/README.md
+++ b/src/dawn/node/README.md
@@ -319,7 +319,9 @@
 
 #### Building as part of Dawn
 
-Dawn can automatically build and configure Lavapipe as part of its build process.
+Dawn can automatically build and configure Lavapipe as part of its build process on Linux.
+
+> **Note:** Building Mesa/Lavapipe as part of Dawn is only supported on Linux.
 
 1.  **GN Build:**
     *   Ensure `checkout_mesa = True` is set in your `.gclient` file's `custom_vars` section, and run `gclient sync`.
@@ -329,7 +331,7 @@
     *   Add `-DTINT_BUILD_MESA=ON` to your CMake configuration command.
     *   Build with `ninja` or `make`.
 
-The build system will automatically copy `libvulkan_lvp.so` (or platform equivalent) and `lvp_icd.json` to the root of your build directory.
+The build system will automatically copy `libvulkan_lvp.so` and `lvp_icd.json` to the root of your build directory.
 
 #### Building manually
 
diff --git a/third_party/mesa/CMakeLists.txt b/third_party/mesa/CMakeLists.txt
index dbd81e6..f5f3abb 100644
--- a/third_party/mesa/CMakeLists.txt
+++ b/third_party/mesa/CMakeLists.txt
@@ -30,6 +30,8 @@
 set(MESA_OPTIONS
     "-Dgallium-drivers=llvmpipe"
     "-Dvulkan-drivers=swrast"
+    "-Dshared-llvm=disabled"
+    "-Dcpp_rtti=false"
 )
 
 meson_target("mesa_build"
diff --git a/third_party/meson/meson_target.gni b/third_party/meson/meson_target.gni
index 35c7786..a7851a1 100644
--- a/third_party/meson/meson_target.gni
+++ b/third_party/meson/meson_target.gni
@@ -96,6 +96,11 @@
       "glslang = '${_glslang_path}'",
       "glslangValidator = '${_glslang_path}'",
     ]
+    if (is_linux) {
+      _native_file_content +=
+          [ "llvm-config = '" +
+            rebase_path("//third_party/llvm-dev/bin/llvm-config") + "'" ]
+    }
 
     write_file(_native_file_path, _native_file_content)
   }