From db8400dbdb432c930f414e82a7ecdb3b5dba077f Mon Sep 17 00:00:00 2001 From: Jeremy Nimmer Date: Tue, 1 Aug 2023 07:22:57 -0700 Subject: [PATCH] [workspace] Deprecate the csdp external Switch the csdp_internal C code to build using hidden visibility. --- solvers/BUILD.bazel | 7 +- tools/workspace/BUILD.bazel | 2 +- tools/workspace/csdp/package.BUILD.bazel | 11 +-- tools/workspace/csdp/repository.bzl | 7 +- tools/workspace/csdp_internal/BUILD.bazel | 3 + .../csdp_internal/package.BUILD.bazel | 83 +++++++++++++++++++ .../patches/params_pathname.patch | 0 .../patches/printlevel.patch | 0 tools/workspace/csdp_internal/repository.bzl | 26 ++++++ tools/workspace/default.bzl | 5 ++ 10 files changed, 129 insertions(+), 15 deletions(-) create mode 100644 tools/workspace/csdp_internal/BUILD.bazel create mode 100644 tools/workspace/csdp_internal/package.BUILD.bazel rename tools/workspace/{csdp => csdp_internal}/patches/params_pathname.patch (100%) rename tools/workspace/{csdp => csdp_internal}/patches/printlevel.patch (100%) create mode 100644 tools/workspace/csdp_internal/repository.bzl diff --git a/solvers/BUILD.bazel b/solvers/BUILD.bazel index 05970543a02b..dc6df9d1dec6 100644 --- a/solvers/BUILD.bazel +++ b/solvers/BUILD.bazel @@ -996,7 +996,10 @@ drake_cc_optional_library( srcs = ["csdp_solver_error_handling.cc"], hdrs = ["csdp_solver_error_handling.h"], copts = ["-fvisibility=hidden"], - visibility = ["@csdp//:__pkg__"], + visibility = [ + "@csdp//:__pkg__", + "@csdp_internal//:__pkg__", + ], ) drake_cc_optional_library( @@ -1005,7 +1008,7 @@ drake_cc_optional_library( srcs = ["csdp_cpp_wrapper.cc"], hdrs = ["csdp_cpp_wrapper.h"], interface_deps = [ - "@csdp", + "@csdp_internal//:csdp", ], deps = [ ":csdp_solver_error_handling", diff --git a/tools/workspace/BUILD.bazel b/tools/workspace/BUILD.bazel index eac3d25b93d3..964ea6bad8e8 100644 --- a/tools/workspace/BUILD.bazel +++ b/tools/workspace/BUILD.bazel @@ -116,7 +116,7 @@ _DRAKE_EXTERNAL_PACKAGE_INSTALLS = ["@%s//:install" % p for p in [ "gflags", "optitrack_driver", ]] + select({ - "//conditions:default": ["@csdp//:install"], + "//conditions:default": ["@csdp_internal//:install"], "//tools:no_csdp": [], }) + select({ "//tools:with_gurobi": ["@gurobi//:install"], diff --git a/tools/workspace/csdp/package.BUILD.bazel b/tools/workspace/csdp/package.BUILD.bazel index 4c38233f47cc..fd5d2af33506 100644 --- a/tools/workspace/csdp/package.BUILD.bazel +++ b/tools/workspace/csdp/package.BUILD.bazel @@ -1,7 +1,5 @@ # -*- bazel -*- -load("@drake//tools/install:install.bzl", "install") - licenses(["notice"]) # EPL-2.0 package(default_visibility = ["//visibility:private"]) @@ -71,12 +69,5 @@ cc_library( "@lapack", ], visibility = ["//visibility:public"], -) - -# We do not install the header file (its a private dependency), but we still -# need to install its license file. -install( - name = "install", - docs = ["LICENSE"], - visibility = ["//visibility:public"], + deprecation = "DRAKE DEPRECATED: The @csdp external is deprecated in Drake's WORKSPACE and will be removed on or after 2023-11-01.", # noqa ) diff --git a/tools/workspace/csdp/repository.bzl b/tools/workspace/csdp/repository.bzl index ace8c23c7d34..68c2f597e3a9 100644 --- a/tools/workspace/csdp/repository.bzl +++ b/tools/workspace/csdp/repository.bzl @@ -3,6 +3,9 @@ load("@drake//tools/workspace:github.bzl", "github_archive") def csdp_repository( name, mirrors = None): + """The @csdp external is deprecated in Drake's WORKSPACE and will be + removed on or after 2023-11-01. + """ github_archive( name = name, repository = "coin-or/Csdp", @@ -10,8 +13,8 @@ def csdp_repository( sha256 = "3d341974af1f8ed70e1a37cc896e7ae4a513375875e5b46db8e8f38b7680b32f", # noqa build_file = ":package.BUILD.bazel", patches = [ - ":patches/params_pathname.patch", - ":patches/printlevel.patch", + "@drake//tools/workspace/csdp_internal:patches/params_pathname.patch", # noqa + "@drake//tools/workspace/csdp_internal:patches/printlevel.patch", ], patch_cmds = [ # Move the headers into a subdirectory, so they don't pollute the diff --git a/tools/workspace/csdp_internal/BUILD.bazel b/tools/workspace/csdp_internal/BUILD.bazel new file mode 100644 index 000000000000..67914ea7e0a0 --- /dev/null +++ b/tools/workspace/csdp_internal/BUILD.bazel @@ -0,0 +1,3 @@ +load("//tools/lint:lint.bzl", "add_lint_tests") + +add_lint_tests() diff --git a/tools/workspace/csdp_internal/package.BUILD.bazel b/tools/workspace/csdp_internal/package.BUILD.bazel new file mode 100644 index 000000000000..aa556305b782 --- /dev/null +++ b/tools/workspace/csdp_internal/package.BUILD.bazel @@ -0,0 +1,83 @@ +# -*- bazel -*- + +load("@drake//tools/install:install.bzl", "install") + +licenses(["notice"]) # EPL-2.0 + +package(default_visibility = ["//visibility:private"]) + +cc_library( + name = "csdp", + srcs = [ + "lib/Fnorm.c", + "lib/add_mat.c", + "lib/addscaledmat.c", + "lib/allocmat.c", + "lib/calc_dobj.c", + "lib/calc_pobj.c", + "lib/chol.c", + "lib/copy_mat.c", + "lib/easysdp.c", + "lib/freeprob.c", + "lib/initparams.c", + "lib/initsoln.c", + "lib/linesearch.c", + "lib/make_i.c", + "lib/makefill.c", + "lib/mat_mult.c", + "lib/mat_multsp.c", + "lib/matvec.c", + "lib/norms.c", + "lib/op_a.c", + "lib/op_at.c", + "lib/op_o.c", + "lib/packed.c", + "lib/psd_feas.c", + "lib/qreig.c", + "lib/readprob.c", + "lib/readsol.c", + "lib/sdp.c", + "lib/solvesys.c", + "lib/sortentries.c", + "lib/sym_mat.c", + "lib/trace_prod.c", + "lib/tweakgap.c", + "lib/user_exit.c", + "lib/writeprob.c", + "lib/writesol.c", + "lib/zero_mat.c", + ], + hdrs = [ + "includes/csdp/blockmat.h", + "includes/csdp/declarations.h", + "includes/csdp/index.h", + "includes/csdp/parameters.h", + ], + copts = [ + "-Wno-unknown-pragmas", + "-Wno-unused-variable", + "-fvisibility=hidden", + # CSDP calls exit() for error handling. That doesn't suit our needs for + # embedding it within Drake, so we'll redirect calls to exit() to our + # own setjmp/longjmp handler instead. + "-Dexit=drake_csdp_cpp_wrapper_exit", + # Because we use longjmp, we must forbid CSDP's OpenMP-based threads. + "-fno-openmp", + ], + includes = ["includes"], + linkstatic = 1, + deps = [ + "@blas", + "@drake//solvers:csdp_solver_error_handling", + "@lapack", + ], + visibility = ["//visibility:public"], +) + +# We do not install the header file (its a private dependency), but we still +# need to install its license file. +install( + name = "install", + docs = ["LICENSE"], + visibility = ["//visibility:public"], +) diff --git a/tools/workspace/csdp/patches/params_pathname.patch b/tools/workspace/csdp_internal/patches/params_pathname.patch similarity index 100% rename from tools/workspace/csdp/patches/params_pathname.patch rename to tools/workspace/csdp_internal/patches/params_pathname.patch diff --git a/tools/workspace/csdp/patches/printlevel.patch b/tools/workspace/csdp_internal/patches/printlevel.patch similarity index 100% rename from tools/workspace/csdp/patches/printlevel.patch rename to tools/workspace/csdp_internal/patches/printlevel.patch diff --git a/tools/workspace/csdp_internal/repository.bzl b/tools/workspace/csdp_internal/repository.bzl new file mode 100644 index 000000000000..211ead32e4a7 --- /dev/null +++ b/tools/workspace/csdp_internal/repository.bzl @@ -0,0 +1,26 @@ +load("@drake//tools/workspace:github.bzl", "github_archive") + +def csdp_internal_repository( + name, + mirrors = None): + github_archive( + name = name, + repository = "coin-or/Csdp", + commit = "releases/6.2.0", + sha256 = "3d341974af1f8ed70e1a37cc896e7ae4a513375875e5b46db8e8f38b7680b32f", # noqa + build_file = ":package.BUILD.bazel", + patches = [ + ":patches/params_pathname.patch", + ":patches/printlevel.patch", + ], + patch_cmds = [ + # Move the headers into a subdirectory, so they don't pollute the + # top-level include path. + "mkdir includes", + "mv include includes/csdp", + "sed -i -e 's|^#include \"|#include \"csdp/|g;' lib/*.c", + # Add include guards. + "sed -i -e $'1s/^/#pragma once\\\n/' includes/csdp/*.h", + ], + mirrors = mirrors, + ) diff --git a/tools/workspace/default.bzl b/tools/workspace/default.bzl index a2d6bc7943d3..3fc6635400c2 100644 --- a/tools/workspace/default.bzl +++ b/tools/workspace/default.bzl @@ -14,6 +14,7 @@ load("@drake//tools/workspace/commons_io:repository.bzl", "commons_io_repository load("@drake//tools/workspace/conex:repository.bzl", "conex_repository") load("@drake//tools/workspace/conex_internal:repository.bzl", "conex_internal_repository") # noqa load("@drake//tools/workspace/csdp:repository.bzl", "csdp_repository") +load("@drake//tools/workspace/csdp_internal:repository.bzl", "csdp_internal_repository") # noqa load("@drake//tools/workspace/curl_internal:repository.bzl", "curl_internal_repository") # noqa load("@drake//tools/workspace/double_conversion:repository.bzl", "double_conversion_repository") # noqa load("@drake//tools/workspace/doxygen:repository.bzl", "doxygen_repository") @@ -141,7 +142,11 @@ def add_default_repositories(excludes = [], mirrors = DEFAULT_MIRRORS): if "conex_internal" not in excludes: conex_internal_repository(name = "conex_internal", mirrors = mirrors) if "csdp" not in excludes: + # The @csdp external is deprecated in Drake's WORKSPACE and will be + # removed on or after 2023-11-01. csdp_repository(name = "csdp", mirrors = mirrors) + if "csdp_internal" not in excludes: + csdp_internal_repository(name = "csdp_internal", mirrors = mirrors) if "curl_internal" not in excludes: curl_internal_repository(name = "curl_internal", mirrors = mirrors) if "double_conversion" not in excludes: