Split up zeroing library BUILD rules

There was no good reason for one build rule to have both the interface
and a bunch of implementations; split it up and make the relevant users
depend on the libraries directly.

Change-Id: If6a0aa49dd7ea588b7325604658bc0594db4aac0
Signed-off-by: James Kuszmaul <jabukuszmaul+collab@gmail.com>
diff --git a/frc971/control_loops/BUILD b/frc971/control_loops/BUILD
index 3cdb6ab..31b245b 100644
--- a/frc971/control_loops/BUILD
+++ b/frc971/control_loops/BUILD
@@ -416,6 +416,7 @@
         "//aos/util:trapezoid_profile",
         "//frc971/control_loops:control_loop",
         "//frc971/zeroing",
+        "//frc971/zeroing:pot_and_index",
     ],
 )
 
@@ -661,6 +662,9 @@
         ":static_zeroing_single_dof_profiled_subsystem_test_subsystem_output_fbs",
         "//aos/testing:googletest",
         "//frc971/control_loops:control_loop_test",
+        "//frc971/zeroing:absolute_and_absolute_encoder",
+        "//frc971/zeroing:absolute_encoder",
+        "//frc971/zeroing:pot_and_absolute_encoder",
     ],
 )
 
diff --git a/frc971/control_loops/profiled_subsystem.h b/frc971/control_loops/profiled_subsystem.h
index dff5aad..1fa8ac2 100644
--- a/frc971/control_loops/profiled_subsystem.h
+++ b/frc971/control_loops/profiled_subsystem.h
@@ -15,6 +15,7 @@
 #include "frc971/control_loops/profiled_subsystem_generated.h"
 #include "frc971/control_loops/simple_capped_state_feedback_loop.h"
 #include "frc971/control_loops/state_feedback_loop.h"
+#include "frc971/zeroing/pot_and_index.h"
 #include "frc971/zeroing/zeroing.h"
 
 namespace frc971 {
diff --git a/frc971/control_loops/static_zeroing_single_dof_profiled_subsystem_test.cc b/frc971/control_loops/static_zeroing_single_dof_profiled_subsystem_test.cc
index c886775..ace528e 100644
--- a/frc971/control_loops/static_zeroing_single_dof_profiled_subsystem_test.cc
+++ b/frc971/control_loops/static_zeroing_single_dof_profiled_subsystem_test.cc
@@ -16,6 +16,8 @@
 #include "frc971/control_loops/static_zeroing_single_dof_profiled_subsystem_test_pot_and_absolute_position_generated.h"
 #include "frc971/control_loops/static_zeroing_single_dof_profiled_subsystem_test_subsystem_goal_generated.h"
 #include "frc971/control_loops/static_zeroing_single_dof_profiled_subsystem_test_subsystem_output_generated.h"
+#include "frc971/zeroing/absolute_encoder.h"
+#include "frc971/zeroing/pot_and_absolute_encoder.h"
 #include "frc971/zeroing/zeroing.h"
 
 using ::frc971::control_loops::PositionSensorSimulator;
diff --git a/frc971/zeroing/BUILD b/frc971/zeroing/BUILD
index 07e9852..8ca7f67 100644
--- a/frc971/zeroing/BUILD
+++ b/frc971/zeroing/BUILD
@@ -61,22 +61,8 @@
 cc_library(
     name = "zeroing",
     srcs = [
-        "absolute_and_absolute_encoder.cc",
-        "absolute_encoder.cc",
-        "continuous_absolute_encoder.cc",
-        "hall_effect_and_position.cc",
-        "pot_and_absolute_encoder.cc",
-        "pot_and_index.cc",
-        "pulse_index.cc",
     ],
     hdrs = [
-        "absolute_and_absolute_encoder.h",
-        "absolute_encoder.h",
-        "continuous_absolute_encoder.h",
-        "hall_effect_and_position.h",
-        "pot_and_absolute_encoder.h",
-        "pot_and_index.h",
-        "pulse_index.h",
         "zeroing.h",
     ],
     target_compatible_with = ["@platforms//os:linux"],
@@ -90,20 +76,10 @@
     ],
 )
 
-cc_test(
-    name = "zeroing_test",
-    srcs = [
-        "absolute_and_absolute_encoder_test.cc",
-        "absolute_encoder_test.cc",
-        "continuous_absolute_encoder_test.cc",
-        "hall_effect_and_position_test.cc",
-        "pot_and_absolute_encoder_test.cc",
-        "pot_and_index_test.cc",
-        "pulse_index_test.cc",
-        "relative_encoder_test.cc",
-        "zeroing_test.h",
-    ],
-    target_compatible_with = ["@platforms//os:linux"],
+cc_library(
+    name = "zeroing_test_lib",
+    testonly = True,
+    hdrs = ["zeroing_test.h"],
     deps = [
         ":zeroing",
         "//aos/testing:googletest",
@@ -112,6 +88,46 @@
     ],
 )
 
+[
+    (
+        cc_library(
+            name = lib,
+            srcs = [lib + ".cc"],
+            hdrs = [lib + ".h"],
+            deps = [
+                ":wrap",
+                ":zeroing",
+                "//aos/containers:error_list",
+                "//aos/logging",
+                "//frc971:constants",
+                "//frc971/control_loops:control_loops_fbs",
+                "@com_github_google_glog//:glog",
+            ],
+        ),
+        cc_test(
+            name = lib + "_test",
+            srcs = [lib + "_test.cc"],
+            deps = [
+                lib,
+                ":zeroing",
+                ":zeroing_test_lib",
+                "//aos/testing:googletest",
+                "//frc971/control_loops:control_loops_fbs",
+                "//frc971/control_loops:position_sensor_sim",
+            ],
+        ),
+    )
+    for lib in [
+        "absolute_and_absolute_encoder",
+        "absolute_encoder",
+        "continuous_absolute_encoder",
+        "hall_effect_and_position",
+        "pot_and_absolute_encoder",
+        "pot_and_index",
+        "pulse_index",
+    ]
+]
+
 cc_library(
     name = "wrap",
     srcs = [
diff --git a/frc971/zeroing/absolute_encoder.h b/frc971/zeroing/absolute_encoder.h
index df40ec3..9d730f2 100644
--- a/frc971/zeroing/absolute_encoder.h
+++ b/frc971/zeroing/absolute_encoder.h
@@ -5,6 +5,7 @@
 
 #include "flatbuffers/flatbuffers.h"
 
+#include "aos/containers/error_list.h"
 #include "frc971/zeroing/zeroing.h"
 
 namespace frc971 {
diff --git a/frc971/zeroing/continuous_absolute_encoder.h b/frc971/zeroing/continuous_absolute_encoder.h
index b912e84..e11d866 100644
--- a/frc971/zeroing/continuous_absolute_encoder.h
+++ b/frc971/zeroing/continuous_absolute_encoder.h
@@ -5,6 +5,7 @@
 
 #include "flatbuffers/flatbuffers.h"
 
+#include "aos/containers/error_list.h"
 #include "frc971/zeroing/zeroing.h"
 
 namespace frc971 {
diff --git a/frc971/zeroing/zeroing.h b/frc971/zeroing/zeroing.h
index b0e6825..5d5b6eb 100644
--- a/frc971/zeroing/zeroing.h
+++ b/frc971/zeroing/zeroing.h
@@ -172,14 +172,4 @@
 }  // namespace zeroing
 }  // namespace frc971
 
-// TODO(Brian): Actually split these targets apart. Need to convert all the
-// reverse dependencies to #include what they actually need...
-#include "frc971/zeroing/absolute_and_absolute_encoder.h"
-#include "frc971/zeroing/absolute_encoder.h"
-#include "frc971/zeroing/continuous_absolute_encoder.h"
-#include "frc971/zeroing/hall_effect_and_position.h"
-#include "frc971/zeroing/pot_and_absolute_encoder.h"
-#include "frc971/zeroing/pot_and_index.h"
-#include "frc971/zeroing/pulse_index.h"
-
 #endif  // FRC971_ZEROING_ZEROING_H_