Make osqp build

Prep for using it in the catapult.

Change-Id: Ic642b1c04469563de13a8a6227407aacb75eff6a
Signed-off-by: Austin Schuh <austin.linux@gmail.com>
diff --git a/third_party/osqp/BUILD b/third_party/osqp/BUILD
new file mode 100644
index 0000000..8276eff
--- /dev/null
+++ b/third_party/osqp/BUILD
@@ -0,0 +1,146 @@
+genrule(
+    name = "make_osqp_configure",
+    outs = ["include/osqp_configure.h"],
+    cmd = "echo > $@",
+)
+
+genrule(
+    name = "make_qdldl_version",
+    outs = ["lin_sys/direct/qdldl/qdldl_sources/include/qdldl_version.h"],
+    cmd = "echo > $@",
+)
+
+genrule(
+    name = "make_qdldl_types",
+    outs = ["lin_sys/direct/qdldl/qdldl_sources/include/qdldl_types.h"],
+    cmd = """cat << EOF > $@
+#ifndef QDLDL_TYPES_H
+# define QDLDL_TYPES_H
+
+# ifdef __cplusplus
+extern "C" {
+# endif /* ifdef __cplusplus */
+
+#include <limits.h> //for the QDLDL_INT_TYPE_MAX
+
+// QDLDL integer and float types
+
+typedef int    QDLDL_int;   /* for indices */
+typedef double  QDLDL_float; /* for numerical values  */
+typedef unsigned char   QDLDL_bool;  /* for boolean values  */
+
+//Maximum value of the signed type QDLDL_int.
+#define QDLDL_INT_MAX LLONG_MAX
+
+# ifdef __cplusplus
+}
+# endif /* ifdef __cplusplus */
+
+#endif /* ifndef QDLDL_TYPES_H */
+EOF""",
+)
+
+cc_library(
+    name = "osqp_includes",
+    hdrs = [
+        "include/auxil.h",
+        "include/constants.h",
+        "include/cs.h",
+        "include/ctrlc.h",
+        "include/glob_opts.h",
+        "include/kkt.h",
+        "include/lin_alg.h",
+        "include/lin_sys.h",
+        "include/osqp.h",
+        "include/osqp_configure.h",
+        "include/osqp_error.h",
+        "include/polish.h",
+        "include/proj.h",
+        "include/scaling.h",
+        "include/types.h",
+        "include/util.h",
+        "include/version.h",
+        "lin_sys/lib_handler.h",
+    ],
+    defines = [
+        "IS_LINUX",
+        #"PRINTING",
+        "PROFILING",
+        "CTRLC",
+        # TODO(austin): Use floats instead
+        #"DFLOAT",
+        #"DLONG",
+        "ENABLE_MKL_PARDISO",
+    ],
+    includes = [
+        "include",
+        "lin_sys",
+    ],
+)
+
+cc_library(
+    name = "osqp",
+    srcs = [
+        "lin_sys/direct/pardiso/pardiso_interface.c",
+        "lin_sys/direct/pardiso/pardiso_loader.c",
+        "lin_sys/direct/qdldl/amd/src/SuiteSparse_config.c",
+        "lin_sys/direct/qdldl/amd/src/amd_1.c",
+        "lin_sys/direct/qdldl/amd/src/amd_2.c",
+        "lin_sys/direct/qdldl/amd/src/amd_aat.c",
+        "lin_sys/direct/qdldl/amd/src/amd_control.c",
+        "lin_sys/direct/qdldl/amd/src/amd_defaults.c",
+        "lin_sys/direct/qdldl/amd/src/amd_info.c",
+        "lin_sys/direct/qdldl/amd/src/amd_order.c",
+        "lin_sys/direct/qdldl/amd/src/amd_post_tree.c",
+        "lin_sys/direct/qdldl/amd/src/amd_postorder.c",
+        "lin_sys/direct/qdldl/amd/src/amd_preprocess.c",
+        "lin_sys/direct/qdldl/amd/src/amd_valid.c",
+        "lin_sys/direct/qdldl/qdldl_interface.c",
+        "lin_sys/direct/qdldl/qdldl_sources/src/qdldl.c",
+        "lin_sys/lib_handler.c",
+        "src/auxil.c",
+        "src/cs.c",
+        "src/ctrlc.c",
+        "src/error.c",
+        "src/kkt.c",
+        "src/lin_alg.c",
+        "src/lin_sys.c",
+        "src/osqp.c",
+        "src/polish.c",
+        "src/proj.c",
+        "src/scaling.c",
+        "src/util.c",
+    ],
+    hdrs = [
+        "lin_sys/direct/pardiso/pardiso_interface.h",
+        "lin_sys/direct/pardiso/pardiso_loader.h",
+        "lin_sys/direct/qdldl/amd/include/SuiteSparse_config.h",
+        "lin_sys/direct/qdldl/amd/include/amd.h",
+        "lin_sys/direct/qdldl/amd/include/amd_internal.h",
+        "lin_sys/direct/qdldl/qdldl_interface.h",
+        "lin_sys/direct/qdldl/qdldl_sources/include/qdldl.h",
+        "lin_sys/direct/qdldl/qdldl_sources/include/qdldl_types.h",
+        "lin_sys/direct/qdldl/qdldl_sources/include/qdldl_version.h",
+    ],
+    copts = [
+        "-Wno-cast-qual",
+    ],
+    defines = [
+        'QDLDL_VERSION_MAJOR="0"',
+        'QDLDL_VERSION_MINOR="1"',
+        'QDLDL_VERSION_PATCH="6"',
+        'QDLDL_VERSION="0.1.6"',
+    ],
+    includes = [
+        "lin_sys/direct/pardiso",
+        "lin_sys/direct/qdldl",
+        "lin_sys/direct/qdldl/amd/include",
+        "lin_sys/direct/qdldl/qdldl_sources/include",
+    ],
+    linkopts = ["-ldl"],
+    target_compatible_with = ["@platforms//os:linux"],
+    visibility = ["//visibility:public"],
+    deps = [
+        ":osqp_includes",
+    ],
+)
diff --git a/third_party/osqp/include/CMakeLists.txt b/third_party/osqp/include/CMakeLists.txt
index a543f70..51e4e17 100644
--- a/third_party/osqp/include/CMakeLists.txt
+++ b/third_party/osqp/include/CMakeLists.txt
@@ -4,7 +4,7 @@
     "${CMAKE_CURRENT_SOURCE_DIR}/version.h"
     "${CMAKE_CURRENT_SOURCE_DIR}/auxil.h"
     "${CMAKE_CURRENT_SOURCE_DIR}/constants.h"
-    "${CMAKE_CURRENT_SOURCE_DIR}/error.h"
+    "${CMAKE_CURRENT_SOURCE_DIR}/osqp_error.h"
     "${CMAKE_CURRENT_SOURCE_DIR}/glob_opts.h"
     "${CMAKE_CURRENT_SOURCE_DIR}/lin_alg.h"
     "${CMAKE_CURRENT_SOURCE_DIR}/osqp.h"
diff --git a/third_party/osqp/include/error.h b/third_party/osqp/include/osqp_error.h
similarity index 100%
rename from third_party/osqp/include/error.h
rename to third_party/osqp/include/osqp_error.h
diff --git a/third_party/osqp/src/error.c b/third_party/osqp/src/error.c
index e0c069e..767bb17 100644
--- a/third_party/osqp/src/error.c
+++ b/third_party/osqp/src/error.c
@@ -1,4 +1,4 @@
-#include "error.h"
+#include "osqp_error.h"
 
 const char *OSQP_ERROR_MESSAGE[] = {
   "Problem data validation.",
@@ -15,6 +15,8 @@
 		 const char * function_name) {
 # ifdef PRINTING
   c_print("ERROR in %s: %s\n", function_name, OSQP_ERROR_MESSAGE[error_code-1]);
+# else
+  (void)function_name;
 # endif
   return (c_int)error_code;
 }
diff --git a/third_party/osqp/src/osqp.c b/third_party/osqp/src/osqp.c
index 20cb1af..94819b3 100644
--- a/third_party/osqp/src/osqp.c
+++ b/third_party/osqp/src/osqp.c
@@ -3,7 +3,7 @@
 #include "util.h"
 #include "scaling.h"
 #include "glob_opts.h"
-#include "error.h"
+#include "osqp_error.h"
 
 
 #ifndef EMBEDDED
diff --git a/third_party/osqp/src/polish.c b/third_party/osqp/src/polish.c
index 55df72d..1d23788 100644
--- a/third_party/osqp/src/polish.c
+++ b/third_party/osqp/src/polish.c
@@ -5,7 +5,7 @@
 #include "lin_sys.h"
 #include "kkt.h"
 #include "proj.h"
-#include "error.h"
+#include "osqp_error.h"
 
 /**
  * Form reduced matrix A that contains only rows that are active at the