Add bazel build system files.

Build everything with 'bazel build //...' and run all tests with
'bazel test //...'.

Change-Id: Ia912e999e33caa9b490002d639dc4c9a80034afc
diff --git a/.gitignore b/.gitignore
index a4d2b69..611aac2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,6 @@
 # Build artifacts
 out/
+bazel-*
 
 # IDE artifacts
 .idea/
diff --git a/BUILD b/BUILD
new file mode 100644
index 0000000..3c6b7b3
--- /dev/null
+++ b/BUILD
@@ -0,0 +1,21 @@
+# Copyright 2019 The Pigweed 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
+#
+#     https://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.
+
+SUBDIRS = [
+    "pw_build",
+    "pw_preprocessor",
+    "pw_span",
+    "pw_status",
+    "pw_unit_test",
+]
diff --git a/WORKSPACE b/WORKSPACE
new file mode 100644
index 0000000..3ac813e
--- /dev/null
+++ b/WORKSPACE
@@ -0,0 +1,13 @@
+# Copyright 2019 The Pigweed 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
+#
+#     https://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.
diff --git a/pw_build/BUILD b/pw_build/BUILD
new file mode 100644
index 0000000..b9cb5a7
--- /dev/null
+++ b/pw_build/BUILD
@@ -0,0 +1,15 @@
+# Copyright 2019 The Pigweed 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
+#
+#     https://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.
+
+package(default_visibility = ["//visibility:public"])
diff --git a/pw_build/pigweed.bzl b/pw_build/pigweed.bzl
new file mode 100644
index 0000000..154bd9c
--- /dev/null
+++ b/pw_build/pigweed.bzl
@@ -0,0 +1,87 @@
+# Copyright 2019 The Pigweed 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
+#
+#     https://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.
+
+def reduced_size_copts():
+    """Standard compiler flags to reduce output binary size."""
+
+    return [
+        "-fno-common",
+        "-fno-exceptions",
+        "-ffunction-sections",
+        "-fdata-sections",
+        "-fno-rtti",
+    ]
+
+def strict_warnings_copts():
+    return [
+        "-Wall",
+        "-Wextra",
+
+        # Make all warnings errors, except for the exemptions below.
+        "-Werror",
+        "-Wno-error=cpp",  # preprocessor #warning statement
+        "-Wno-error=deprecated-declarations",  # [[deprecated]] attribute
+    ]
+
+def cpp17_copts():
+    return [
+        "-std=c++17",
+
+        # Allow uses of the register keyword, which may appear in C headers.
+        "-Wno-register",
+    ]
+
+def includes_copts():
+    includes = [
+        "pw_preprocessor/public",
+        "pw_span/public",
+        "pw_status/public",
+        "pw_unit_test/public",
+    ]
+    return ["-I" + x for x in includes]
+
+def pw_default_copts():
+    return (
+        reduced_size_copts() +
+        strict_warnings_copts() +
+        cpp17_copts() +
+        includes_copts()
+    )
+
+def pw_default_linkopts():
+    return []
+
+def pw_test(
+        name,
+        srcs,
+        deps = None,
+        **kwargs):
+    """Create a Pigweed test.
+
+    Args:
+      name: name of target to create
+      srcs: test source files
+      deps: dependencies of target
+    """
+
+    if not deps:
+        deps = []
+    deps.append("//pw_unit_test:main")
+
+    native.cc_test(
+        name = name,
+        srcs = srcs,
+        deps = deps,
+        **kwargs
+    )
diff --git a/pw_preprocessor/BUILD b/pw_preprocessor/BUILD
new file mode 100644
index 0000000..1d40d9b
--- /dev/null
+++ b/pw_preprocessor/BUILD
@@ -0,0 +1,47 @@
+# Copyright 2019 The Pigweed 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
+#
+#     https://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.
+
+package(default_visibility = ["//visibility:public"])
+
+load(
+    "//pw_build:pigweed.bzl",
+    "pw_default_copts",
+    "pw_default_linkopts",
+    "pw_test",
+)
+
+cc_library(
+    name = "pw_preprocessor",
+    hdrs = glob(["public/pw_preprocessor/*.h"]),
+    copts = pw_default_copts(),
+    linkopts = pw_default_linkopts(),
+)
+
+TESTS = [
+    "boolean_test",
+    "concat_test",
+    "macro_arg_count_test",
+    "util_test",
+]
+
+[
+    pw_test(
+        name = t,
+        srcs = [t + ".cc"],
+        copts = pw_default_copts(),
+        linkopts = pw_default_linkopts(),
+        deps = ["//pw_preprocessor"],
+    )
+    for t in TESTS
+]
diff --git a/pw_span/BUILD b/pw_span/BUILD
new file mode 100644
index 0000000..ccb781d
--- /dev/null
+++ b/pw_span/BUILD
@@ -0,0 +1,36 @@
+# Copyright 2019 The Pigweed 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
+#
+#     https://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.
+
+load(
+    "//pw_build:pigweed.bzl",
+    "pw_default_copts",
+    "pw_default_linkopts",
+    "pw_test",
+)
+
+cc_library(
+    name = "pw_span",
+    srcs = [],
+    hdrs = ["public/pw_span/span.h"],
+    copts = pw_default_copts(),
+    linkopts = pw_default_linkopts(),
+)
+
+pw_test(
+    name = "span_test",
+    srcs = ["span_test.cc"],
+    copts = pw_default_copts(),
+    linkopts = pw_default_linkopts(),
+    deps = ["//pw_span"],
+)
diff --git a/pw_status/BUILD b/pw_status/BUILD
new file mode 100644
index 0000000..24f3b2e
--- /dev/null
+++ b/pw_status/BUILD
@@ -0,0 +1,25 @@
+# Copyright 2019 The Pigweed 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
+#
+#     https://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.
+
+package(default_visibility = ["//visibility:public"])
+
+load("//pw_build:pigweed.bzl", "pw_default_copts", "pw_default_linkopts")
+
+cc_library(
+    name = "pw_status",
+    srcs = ["status.cc"],
+    hdrs = ["public/pw_status/status.h"],
+    copts = pw_default_copts(),
+    linkopts = pw_default_linkopts(),
+)
diff --git a/pw_toolchain/BUILD b/pw_toolchain/BUILD
new file mode 100644
index 0000000..b9cb5a7
--- /dev/null
+++ b/pw_toolchain/BUILD
@@ -0,0 +1,15 @@
+# Copyright 2019 The Pigweed 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
+#
+#     https://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.
+
+package(default_visibility = ["//visibility:public"])
diff --git a/pw_unit_test/BUILD b/pw_unit_test/BUILD
new file mode 100644
index 0000000..3bef980
--- /dev/null
+++ b/pw_unit_test/BUILD
@@ -0,0 +1,61 @@
+# Copyright 2019 The Pigweed 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
+#
+#     https://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.
+
+package(default_visibility = ["//visibility:public"])
+
+load(
+    "//pw_build:pigweed.bzl",
+    "pw_default_copts",
+    "pw_default_linkopts",
+    "pw_test",
+)
+
+cc_library(
+    name = "simple_printing_event_handler",
+    srcs = [
+        "public/pw_unit_test/event_handler.h",
+        "public/pw_unit_test/simple_printing_event_handler.h",
+        "simple_printing_event_handler.cc",
+    ],
+    copts = pw_default_copts(),
+    linkopts = pw_default_linkopts(),
+    deps = ["//pw_preprocessor"],
+)
+
+cc_library(
+    name = "main",
+    srcs = [
+        "framework.cc",
+        "main.cc",
+    ],
+    hdrs = [
+        "public/gtest/gtest.h",
+        "public/pw_unit_test/event_handler.h",
+        "public/pw_unit_test/framework.h",
+    ],
+    copts = pw_default_copts(),
+    linkopts = pw_default_linkopts(),
+    deps = [
+        ":simple_printing_event_handler",
+        "//pw_preprocessor",
+        "//pw_status",
+    ],
+)
+
+pw_test(
+    name = "framework_test",
+    srcs = ["framework_test.cc"],
+    copts = pw_default_copts(),
+    linkopts = pw_default_linkopts(),
+)