Add Tint to BUILD.gn

Tint is behind a build flag, since Tint is not yet available in
chromium's third_party.

BUG=dawn:403

Change-Id: If5fa36b36216ef6965341b886c3bd70d27daf23a
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/21300
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
diff --git a/.gitignore b/.gitignore
index 1382a6e..b0f60f1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -22,6 +22,7 @@
 third_party/swiftshader/
 third_party/spirv-cross/
 third_party/spirv-headers/
+third_party/tint/
 third_party/vulkan-headers/
 third_party/vulkan-loader/
 third_party/vulkan-validation-layers/
diff --git a/DEPS b/DEPS
index a84d35d..d25a2ff 100644
--- a/DEPS
+++ b/DEPS
@@ -85,7 +85,7 @@
 
   # WGSL support
   'third_party/tint': {
-    'url': '{dawn_git}/tint@054927d7eb34803e2a05ab7993688e448a362948',
+    'url': '{dawn_git}/tint@1f1f08f94a11f470a4551896df9f610b71876924',
     'condition': 'dawn_standalone',
   },
 
diff --git a/build_overrides/dawn.gni b/build_overrides/dawn.gni
index 14c246c..d84165f 100644
--- a/build_overrides/dawn.gni
+++ b/build_overrides/dawn.gni
@@ -35,5 +35,6 @@
 dawn_spirv_tools_dir = "//third_party/SPIRV-Tools"
 dawn_spirv_cross_dir = "//third_party/spirv-cross"
 dawn_swiftshader_dir = "//third_party/swiftshader"
+dawn_tint_dir = "//third_party/tint"
 dawn_vulkan_loader_dir = "//third_party/vulkan-loader"
 dawn_vulkan_validation_layers_dir = "//third_party/vulkan-validation-layers"
diff --git a/build_overrides/tint.gni b/build_overrides/tint.gni
new file mode 100644
index 0000000..352d4b2
--- /dev/null
+++ b/build_overrides/tint.gni
@@ -0,0 +1,24 @@
+# Copyright 2020 The Dawn Authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+tint_root_dir = "//third_party/tint"
+tint_spirv_tools_dir = "//third_party/SPIRV-Tools"
+tint_googletest_dir = "//third_party/googletest"
+tint_spirv_headers_dir = "//third_party/spirv-headers"
+
+# Only need the WGSL->SPIR-V transformation
+tint_build_spv_reader = false
+tint_build_spv_writer = true
+tint_build_wgsl_reader = true
+tint_build_wgsl_writer = false
diff --git a/scripts/dawn_features.gni b/scripts/dawn_features.gni
index 7dbbc30..1cee174 100644
--- a/scripts/dawn_features.gni
+++ b/scripts/dawn_features.gni
@@ -59,7 +59,7 @@
   # if performing reflection on systems that the platform language
   # shader is SPIR-V, since there isn't an instance of the
   # GLSL/HLSL/MSL compiler. This implicitly pulls in the GLSL
-  # compiler, since it is a sub-class of if.
+  # compiler, since it is a sub-class of it.
   dawn_enable_cross_reflection = false
 
   # Enables error injection for faking failures to native API calls
@@ -68,6 +68,10 @@
 
   # Whether Dawn should enable X11 support.
   dawn_use_x11 = is_linux && !is_chromeos
+
+  # Enable support WGSL for shaders. Currently this is
+  # experimental, and requires dawn_tint_dir to be set.
+  dawn_enable_wgsl = false
 }
 
 # GN does not allow reading a variable defined in the same declare_args().
diff --git a/scripts/dawn_overrides_with_defaults.gni b/scripts/dawn_overrides_with_defaults.gni
index e3ff5ae..f459c43 100644
--- a/scripts/dawn_overrides_with_defaults.gni
+++ b/scripts/dawn_overrides_with_defaults.gni
@@ -71,3 +71,8 @@
   # Default to VVLs not being available.
   dawn_vulkan_validation_layers_dir = ""
 }
+
+if (!defined(dawn_tint_dir)) {
+  # Default to Tint not being available.
+  dawn_tint_dir = ""
+}
diff --git a/src/dawn_native/BUILD.gn b/src/dawn_native/BUILD.gn
index 3852fcf..8e97fae 100644
--- a/src/dawn_native/BUILD.gn
+++ b/src/dawn_native/BUILD.gn
@@ -569,6 +569,11 @@
       ]
     }
   }
+
+  if (dawn_enable_wgsl) {
+    deps += [ "${dawn_tint_dir}:libtint" ]
+    defines += [ "DAWN_ENABLE_WGSL" ]
+  }
 }
 
 # The static and shared libraries for dawn_native. Most of the files are