add gn build arg to make inclusion of ASTC sources optional

Change-Id: I601088bfeb36a6491eb0ff82b9800e21af9f5fce
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/76568
Reviewed-by: Shahbaz Youssefi <syoussefi@google.com>
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Tested-by: Shahbaz Youssefi <syoussefi@google.com>
Reviewed-by: Geoff Lang <geofflang@google.com>
Commit-Queue: Shahbaz Youssefi <syoussefi@google.com>
diff --git a/src/Device/BUILD.gn b/src/Device/BUILD.gn
index c1ae1ff..3c2afa0 100644
--- a/src/Device/BUILD.gn
+++ b/src/Device/BUILD.gn
@@ -29,6 +29,23 @@
     "Renderer.hpp",
     "SetupProcessor.hpp",
     "VertexProcessor.hpp",
+  ]
+}
+
+swiftshader_source_set("astc_encoder") {
+  sources = [
+    # TODO: Write Build.gn for third_party/astc-encoder
+    "../../third_party/astc-encoder/Source/astc_block_sizes2.cpp",
+    "../../third_party/astc-encoder/Source/astc_color_unquantize.cpp",
+    "../../third_party/astc-encoder/Source/astc_decompress_symbolic.cpp",
+    "../../third_party/astc-encoder/Source/astc_image_load_store.cpp",
+    "../../third_party/astc-encoder/Source/astc_integer_sequence.cpp",
+    "../../third_party/astc-encoder/Source/astc_mathlib.cpp",
+    "../../third_party/astc-encoder/Source/astc_mathlib_softfloat.cpp",
+    "../../third_party/astc-encoder/Source/astc_partition_tables.cpp",
+    "../../third_party/astc-encoder/Source/astc_quantization.cpp",
+    "../../third_party/astc-encoder/Source/astc_symbolic_physical.cpp",
+    "../../third_party/astc-encoder/Source/astc_weight_quant_xfer_tables.cpp",
     "../../third_party/astc-encoder/Source/astc_codec_internals.h",
     "../../third_party/astc-encoder/Source/astc_mathlib.h",
   ]
@@ -47,29 +64,16 @@
     "Renderer.cpp",
     "SetupProcessor.cpp",
     "VertexProcessor.cpp",
-    # TODO: Write Build.gn for third_party/astc-encoder
-    "../../third_party/astc-encoder/Source/astc_block_sizes2.cpp",
-    "../../third_party/astc-encoder/Source/astc_color_unquantize.cpp",
-    "../../third_party/astc-encoder/Source/astc_decompress_symbolic.cpp",
-    "../../third_party/astc-encoder/Source/astc_image_load_store.cpp",
-    "../../third_party/astc-encoder/Source/astc_integer_sequence.cpp",
-    "../../third_party/astc-encoder/Source/astc_mathlib.cpp",
-    "../../third_party/astc-encoder/Source/astc_mathlib_softfloat.cpp",
-    "../../third_party/astc-encoder/Source/astc_partition_tables.cpp",
-    "../../third_party/astc-encoder/Source/astc_quantization.cpp",
-    "../../third_party/astc-encoder/Source/astc_symbolic_physical.cpp",
-    "../../third_party/astc-encoder/Source/astc_weight_quant_xfer_tables.cpp",
   ]
 
   include_dirs = [
     "..",
     "../../include",
     "../../third_party/SPIRV-Headers/include",
-    "../../third_party/astc-encoder/Source"
   ]
 
+
   defines = [
-     "SWIFTSHADER_ENABLE_ASTC",  # TODO(b/150130101)
      "SWIFTSHADER_LEGACY_PRECISION=true",  # TODO(b/226657516)
   ]
 
@@ -81,6 +85,18 @@
     "../Vulkan:swiftshader_libvulkan_headers",
   ]
 
+  if (swiftshader_enable_astc) {
+    defines += [
+     "SWIFTSHADER_ENABLE_ASTC",  # TODO(b/150130101)
+    ]
+    deps += [
+      ":astc_encoder"
+    ]
+    include_dirs += [
+      "../../third_party/astc-encoder/Source"
+    ]
+  }
+
   public_deps = [
     ":Device_headers",
   ]
diff --git a/src/swiftshader.gni b/src/swiftshader.gni
index f352b74..252150c 100644
--- a/src/swiftshader.gni
+++ b/src/swiftshader.gni
@@ -25,6 +25,9 @@
   # If enabled, debug builds on Windows will pop up a dialog when the
   # SwiftShader DLL gets loaded, to facilitate attaching a debugger.
   swiftshader_startup_dialog = false
+
+  # Enable the ASTC codec sources from ARM
+  swiftshader_enable_astc = true
 }
 
 configs_to_add = []