Skip to content

Commit

Permalink
Add DLONG support for osqp and qdldl (#2147)
Browse files Browse the repository at this point in the history
This PR:
- Adds DLONG flag to build OSQP with 64-bit integers to fix #2135 
- Removes `QDLDL_LONG=0` flag in `qdldl` and sets INT_MAX to long long
- Without this change, google/osqp-cpp cannot build on Bazel, and cannot
be published to BCR

The maintainer @wep21 has commented some concerns about DLONG and its
relation with `qdldl` too. Please let me know what else I can do to
enable this.

Closes #2135
udaya2899 authored Jun 7, 2024
1 parent f763359 commit bccb9db
Showing 12 changed files with 277 additions and 2 deletions.
7 changes: 7 additions & 0 deletions modules/osqp/0.6.3.bcr.1/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module(name = "osqp", version = "0.6.3.bcr.1")

bazel_dep(name = "rules_cc", version = "0.0.9")
bazel_dep(name = "platforms", version = "0.0.8")
bazel_dep(name = "qdldl", version = "0.1.7.bcr.1")
bazel_dep(name = "suitesparse", version = "7.6.0")
bazel_dep(name = "cmake_configure_file", version = "0.1.0")
113 changes: 113 additions & 0 deletions modules/osqp/0.6.3.bcr.1/patches/add_build_file.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
diff --git BUILD.bazel BUILD.bazel
new file mode 100644
index 00000000..00cc62f8
--- /dev/null
+++ BUILD.bazel
@@ -0,0 +1,107 @@
+load("@rules_cc//cc:defs.bzl", "cc_library")
+
+package(default_visibility = ["//visibility:public"])
+
+licenses(["notice"])
+
+load(
+ "@cmake_configure_file//:cmake_configure_file.bzl",
+ "cmake_configure_file",
+)
+exports_files([
+ "include/osqp.h",
+ "include/ctrlc.h",
+])
+# Generates osqp_configure.h based on the defines= we want in Drake.
+cmake_configure_file(
+ name = "configure_file",
+ src = "configure/osqp_configure.h.in",
+ out = "include/osqp_configure.h",
+ defines = [
+ "PRINTING",
+ "PROFILING",
+ "DLONG",
+ # In addition to the default primitive size of `double` and `int`,
+ # also define 'DLONG' which is required for @osqp-cpp. Don't define
+ # 'DFLOAT' unless @qdldl_internal and @scs_internal are
+ # also changed to use those primitive sizes.
+ # See drake/tools/workspace/qdldl_internal/README.md.
+ ] + select({
+ "@platforms//os:windows": [
+ "IS_WINDOWS",
+ ],
+ "@platforms//os:osx": [
+ "IS_MAC",
+ ],
+ "//conditions:default": [
+ "IS_LINUX",
+ ],
+ }),
+ undefines = [
+ "OSQP_CUSTOM_MEMORY",
+ ],
+ visibility = ["//visibility:private"],
+)
+
+cc_library(
+ name = "osqp",
+ # Our hdrs match OSQP's ./include/CMakeLists.txt variable `osqp_headers`.
+ hdrs = [
+ # These headers are always enabled in CMakeLists.
+ "include/auxil.h",
+ "include/constants.h",
+ "include/error.h",
+ "include/glob_opts.h",
+ "include/lin_alg.h",
+ "include/osqp.h",
+ "include/osqp_configure.h",
+ "include/proj.h",
+ "include/scaling.h",
+ "include/types.h",
+ "include/util.h",
+ "include/version.h",
+ # These headers are enabled in CMakeLists only when building in normal
+ # mode.
+ "include/kkt.h",
+ # These headers are enabled in CMakeLists only when building in
+ # non-embedded mode.
+ "include/cs.h",
+ "include/polish.h",
+ "include/lin_sys.h",
+ ],
+ srcs = [
+ # From ./lin_sys/direct/qdldl/CMakeLists.txt at `qdldl_interface_src`.
+ "lin_sys/direct/qdldl/qdldl_interface.h",
+ "lin_sys/direct/qdldl/qdldl_interface.c",
+ # From ./src/CMakeLists.txt at `osqp_src`.
+ # These sources are always enabled in CMakeLists.
+ "src/auxil.c",
+ "src/error.c",
+ "src/lin_alg.c",
+ "src/osqp.c",
+ "src/proj.c",
+ "src/scaling.c",
+ "src/util.c",
+ # These sources are enabled in CMakeLists only when building in normal
+ # mode.
+ "src/kkt.c",
+ # These sources are enabled in CMakeLists only when building in
+ # non-embedded mode.
+ "src/cs.c",
+ "src/polish.c",
+ "src/lin_sys.c",
+ ],
+ includes = [
+ "include",
+ "lin_sys/direct/qdldl",
+ ],
+ copts = [
+ "-fvisibility=hidden",
+ "-w",
+ "-Werror=incompatible-pointer-types",
+ ],
+ deps = [
+ "@qdldl//:qdldl",
+ "@suitesparse//:amd",
+ ],
+)
13 changes: 13 additions & 0 deletions modules/osqp/0.6.3.bcr.1/patches/module_dot_bazel.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git MODULE.bazel MODULE.bazel
new file mode 100644
index 00000000..44caadb7
--- /dev/null
+++ MODULE.bazel
@@ -0,0 +1,7 @@
+module(name = "osqp", version = "0.6.3.bcr.1")
+
+bazel_dep(name = "rules_cc", version = "0.0.9")
+bazel_dep(name = "platforms", version = "0.0.8")
+bazel_dep(name = "qdldl", version = "0.1.7.bcr.1")
+bazel_dep(name = "suitesparse", version = "7.6.0")
+bazel_dep(name = "cmake_configure_file", version = "0.1.0")
14 changes: 14 additions & 0 deletions modules/osqp/0.6.3.bcr.1/presubmit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
matrix:
platform:
- debian10
- ubuntu2004
- macos
- macos_arm64
bazel: [6.x, 7.x]
tasks:
verify_targets:
name: Verify build targets
platform: ${{ platform }}
bazel: ${{ bazel }}
build_targets:
- "@osqp//:osqp"
9 changes: 9 additions & 0 deletions modules/osqp/0.6.3.bcr.1/source.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"url": "https://github.com/osqp/osqp/releases/download/v0.6.3/osqp-v0.6.3-src.tar.gz",
"integrity": "sha256-KFsqYPaNEToQkHZ+yKnIGmWzry0lj4x4oxzD+YulhFY=",
"patches": {
"add_build_file.patch": "sha256-Iyg78OunAc0hSy4nDMnLUXkQSwLbBq5H8BoddHpasGo=",
"module_dot_bazel.patch": "sha256-iqPR48TRE8l/sPtEcY7F2liUZeaN+2gWPp+FjdeKQqQ="
},
"patch_strip": 0
}
3 changes: 2 additions & 1 deletion modules/osqp/metadata.json
Original file line number Diff line number Diff line change
@@ -11,7 +11,8 @@
"github:osqp/osqp"
],
"versions": [
"0.6.3"
"0.6.3",
"0.6.3.bcr.1"
],
"yanked_versions": {}
}
8 changes: 8 additions & 0 deletions modules/qdldl/0.1.7.bcr.1/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module(
name = "qdldl",
version = "0.1.7.bcr.1",
compatibility_level = 1,
)

bazel_dep(name = "platforms", version = "0.0.8")
bazel_dep(name = "rules_cc", version = "0.0.9")
69 changes: 69 additions & 0 deletions modules/qdldl/0.1.7.bcr.1/patches/add_build_file.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
diff --git BUILD.bazel BUILD.bazel
new file mode 100644
index 0000000..aabba4f
--- /dev/null
+++ BUILD.bazel
@@ -0,0 +1,63 @@
+load("@rules_cc//cc:defs.bzl", "cc_library")
+
+load(
+ "//bazel:cmake_configure_file.bzl",
+ "cmake_configure_file",
+)
+
+licenses(["notice"])
+
+package(
+ default_visibility = ["//visibility:public"],
+)
+
+cmake_configure_file(
+ name = "configure_file_types",
+ src = "configure/qdldl_types.h.in",
+ out = "include/qdldl_types.h",
+ # https://github.com/osqp/qdldl/blob/v0.1.6/README.md#custom-types-for-integer-floats-and-booleans
+ defines = [
+ "QDLDL_BOOL_TYPE=unsigned char",
+ # Keep the `int` type sync'd with the build of @osqp_internal and
+ # @scs_internal. See drake/tools/workspace/qdldl_internal/README.md.
+ "QDLDL_INT_TYPE=long long",
+ # Keep the `int` type sync'd with the build of @osqp_internal and
+ # @scs_internal. See drake/tools/workspace/qdldl_internal/README.md.
+ "QDLDL_FLOAT_TYPE=double",
+ "QDLDL_FLOAT=0",
+ # Match this to QDLDL_INT_TYPE above.
+ "QDLDL_INT_TYPE_MAX=LLONG_MAX",
+ ],
+ visibility = ["//visibility:private"],
+)
+
+cmake_configure_file(
+ name = "configure_file_version",
+ src = "configure/qdldl_version.h.in",
+ out = "include/qdldl_version.h",
+ cmakelists = [
+ "CMakeLists.txt",
+ ],
+ visibility = ["//visibility:private"],
+)
+
+cc_library(
+ name = "qdldl",
+ hdrs = [
+ "include/qdldl.h",
+ ":include/qdldl_types.h",
+ ":include/qdldl_version.h",
+ ],
+ srcs = [
+ "src/qdldl.c",
+ ],
+ copts = [
+ "-fvisibility=hidden",
+ ] + select({
+ "@platforms//os:windows": [],
+ "//conditions:default": ["-Werror=incompatible-pointer-types"],
+ }),
+ includes = [
+ "include",
+ ],
+)
14 changes: 14 additions & 0 deletions modules/qdldl/0.1.7.bcr.1/patches/module_dot_bazel.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
diff --git MODULE.bazel MODULE.bazel
new file mode 100644
index 0000000..01bf673
--- /dev/null
+++ MODULE.bazel
@@ -0,0 +1,8 @@
+module(
+ name = "qdldl",
+ version = "0.1.7.bcr.1",
+ compatibility_level = 1,
+)
+
+bazel_dep(name = "platforms", version = "0.0.8")
+bazel_dep(name = "rules_cc", version = "0.0.9")
15 changes: 15 additions & 0 deletions modules/qdldl/0.1.7.bcr.1/presubmit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
matrix:
platform:
- debian10
- ubuntu2004
- macos
- macos_arm64
- windows
bazel: [6.x, 7.x]
tasks:
verify_targets:
name: Verify build targets
platform: ${{ platform }}
bazel: ${{ bazel }}
build_targets:
- "@qdldl//:qdldl"
11 changes: 11 additions & 0 deletions modules/qdldl/0.1.7.bcr.1/source.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"url": "https://github.com/osqp/qdldl/archive/refs/tags/v0.1.7.tar.gz",
"integrity": "sha256-YxrmXzZ4Wfoe+t4WVuS6IrfaeJwG4BDM64spZWv2V1c=",
"strip_prefix": "qdldl-0.1.7",
"patches": {
"add_build_file.patch": "sha256-oeIkqdGQy/8KU9Sd92Lnxr7ofgWXRBLs8CO+8AI6rWU=",
"../../0.1.7/patches/add_cmake_configure_file.patch": "sha256-qge+NoLlQcrPkS5AR0TbJKkhE3FETgjuzvj9O0WqWwc=",
"module_dot_bazel.patch": "sha256-pNG5JBVEJ7XbzFNOvhFaoInidxjTPXt2yX1dR2gkpxQ="
},
"patch_strip": 0
}
3 changes: 2 additions & 1 deletion modules/qdldl/metadata.json
Original file line number Diff line number Diff line change
@@ -11,7 +11,8 @@
"github:osqp/qdldl"
],
"versions": [
"0.1.7"
"0.1.7",
"0.1.7.bcr.1"
],
"yanked_versions": {}
}

0 comments on commit bccb9db

Please sign in to comment.