Make optional build

Change-Id: I57b2f5de0e922c876166443899c355366720a5b8
diff --git a/third_party/optional/BUILD b/third_party/optional/BUILD
new file mode 100644
index 0000000..3599d61
--- /dev/null
+++ b/third_party/optional/BUILD
@@ -0,0 +1,47 @@
+licenses(["notice"])
+
+load("//tools:environments.bzl", "mcu_cpus")
+
+cc_library(
+    name = "optional",
+    hdrs = [
+        "tl/optional.hpp",
+    ],
+    compatible_with = mcu_cpus,
+    includes = ["."],
+    visibility = ["//visibility:public"],
+)
+
+cc_library(
+    name = "catch",
+    hdrs = [
+        "tests/catch.hpp",
+    ],
+)
+
+# Create a small wrapper because the tests want to #include "optional.hpp"
+# directly.
+cc_library(
+    name = "optional_test_wrapper",
+    includes = [
+        "./tl/",
+    ],
+    deps = [
+        ":optional",
+    ],
+)
+
+cc_test(
+    name = "optional_test",
+    srcs = glob([
+        "tests/*.cpp",
+    ]),
+    copts = [
+        "-fexceptions",
+        "-Wno-unused-parameter",
+    ],
+    deps = [
+        ":catch",
+        ":optional_test_wrapper",
+    ],
+)
diff --git a/third_party/optional/tests/bases.cpp b/third_party/optional/tests/bases.cpp
index cff7819..09623ea 100644
--- a/third_party/optional/tests/bases.cpp
+++ b/third_party/optional/tests/bases.cpp
@@ -2,8 +2,7 @@
 #include "optional.hpp"
 
 // Old versions of GCC don't have the correct trait names. Could fix them up if needs be.
-#if (defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ <= 9 &&              \
-     !defined(__clang__))
+#ifdef TL_OPTIONAL_GCC49
 // nothing for now
 #else
 TEST_CASE("Triviality", "[bases.triviality]") {
diff --git a/third_party/optional/tl/optional.hpp b/third_party/optional/tl/optional.hpp
index 7350f8a..27ac1c0 100644
--- a/third_party/optional/tl/optional.hpp
+++ b/third_party/optional/tl/optional.hpp
@@ -28,8 +28,9 @@
 #define TL_OPTIONAL_MSVC2015
 #endif
 
+// TODO(Brian): We use libstdc++ with clang too. Sort this out nicely.
 #if (defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ <= 9 &&              \
-     !defined(__clang__))
+    !(defined(__clang__) && defined(_LIBCPP_VERSION)))
 #define TL_OPTIONAL_GCC49
 #endif
 
@@ -43,8 +44,7 @@
 #define TL_OPTIONAL_GCC55
 #endif
 
-#if (defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ <= 9 &&              \
-     !defined(__clang__))
+#ifdef TL_OPTIONAL_GCC49
 // GCC < 5 doesn't support overloading on const&& for member functions
 #define TL_OPTIONAL_NO_CONSTRR
 
@@ -89,7 +89,8 @@
 #endif
 
 #if __cplusplus > 201103L
-#define TL_OPTIONAL_CXX14
+// TODO(Brian): Re-enable this once we have full C++14 support.
+//#define TL_OPTIONAL_CXX14
 #endif
 
 // constexpr implies const in C++11, not C++14