Skip to content

Commit

Permalink
[workspace] Simplify pkg-config (especially for homebrew) (RobotLocom…
Browse files Browse the repository at this point in the history
…otion#20582)

Remove the homebrew_subdir option; it is no longer useful.

Remove redundant wrapping of libblas, liblapack, and openblas; there
is no need to proactively fail when run on an unexpected OS.

Remove brittle argument override forwarding. Users who need to
customize their WORKSPACE should write their own rules.

Drop the dead (and outdated) check on minimum Eigen version.
Our eigen_types.h assertion is the single source of truth.
  • Loading branch information
jwnimmer-tri authored and RussTedrake committed Dec 27, 2023
1 parent 5babd52 commit c809bbc
Show file tree
Hide file tree
Showing 18 changed files with 76 additions and 287 deletions.
14 changes: 3 additions & 11 deletions tools/workspace/blas/repository.bzl
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
load("//tools/workspace:os.bzl", "os_specific_alias_repository")

# TLDR: Use this repository (@blas) instead of @libblas or @openblas in the
# deps of your target.
#
# Since we use different pkg-config modules offering BLAS implementations from
# (potentially) different vendors depending on the operating system, this alias
# exists to select the correct operating-system-specific BLAS implementation.
# On macOS, the @blas and @openblas targets will always refer to OpenBLAS. On
# Ubuntu, the @blas and @libblas targets will depend on a BLAS implementation
# typically chosen by the Ubuntu alternatives system, such as the reference
# implementation from Netlib, Automatically Tuned Linear Algebra Software
# (ATLAS), and OpenBLAS.
# Use this repository (@blas) in the deps of your target, instead of @libblas
# or @openblas. We use a different implementation depending on the operating
# system; this alias selects the correct implementation.
def blas_repository(name):
os_specific_alias_repository(
name = name,
Expand Down
17 changes: 3 additions & 14 deletions tools/workspace/clp/repository.bzl
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
load("//tools/workspace:pkg_config.bzl", "pkg_config_repository")

def clp_repository(
name,
licenses = [
"reciprocal", # EPL-2.0
],
modname = "clp",
pkg_config_paths = [],
homebrew_subdir = "opt/clp/lib/pkgconfig",
**kwargs):
def clp_repository(name):
pkg_config_repository(
name = name,
licenses = licenses,
modname = modname,
pkg_config_paths = pkg_config_paths,
homebrew_subdir = homebrew_subdir,
licenses = ["reciprocal"], # EPL-2.0
modname = "clp",
extra_deprecation = "The @clp external is deprecated in Drake's WORKSPACE and will be removed on or after 2023-12-01.", # noqa
**kwargs
)
17 changes: 3 additions & 14 deletions tools/workspace/eigen/repository.bzl
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
load("//tools/workspace:pkg_config.bzl", "pkg_config_repository")

def eigen_repository(
name,
def eigen_repository(name):
pkg_config_repository(
name = name,
licenses = [
"notice", # BSD-3-Clause
"reciprocal", # MPL-2.0
"unencumbered", # Public-Domain
],
modname = "eigen3",
# Keep this version in sync with drake/common/eigen_types.h.
atleast_version = "3.3.4",
extra_defines = ["EIGEN_MPL2_ONLY"],
pkg_config_paths = [],
homebrew_subdir = "opt/eigen/share/pkgconfig",
**kwargs):
pkg_config_repository(
name = name,
licenses = licenses,
modname = modname,
extra_defines = extra_defines,
pkg_config_paths = pkg_config_paths,
**kwargs
)
14 changes: 3 additions & 11 deletions tools/workspace/glew/repository.bzl
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
load("//tools/workspace:pkg_config.bzl", "pkg_config_repository")

def glew_repository(
name,
licenses = ["notice"], # BSD-3-Clause AND MIT
modname = "glew",
pkg_config_paths = [],
homebrew_subdir = "opt/glew/lib/pkgconfig",
**kwargs):
def glew_repository(name):
pkg_config_repository(
name = name,
licenses = licenses,
modname = modname,
pkg_config_paths = pkg_config_paths,
licenses = ["notice"], # BSD-3-Clause AND MIT
modname = "glew",
extra_deprecation = "The @glew external is deprecated in Drake's WORKSPACE and will be removed on or after 2024-01-01.", # noqa
**kwargs
)
14 changes: 3 additions & 11 deletions tools/workspace/glib/repository.bzl
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
load("//tools/workspace:pkg_config.bzl", "pkg_config_repository")

def glib_repository(
name,
licenses = ["restricted"], # LGPL-2.0+
modname = "glib-2.0",
pkg_config_paths = [],
homebrew_subdir = "opt/glib/lib/pkgconfig",
**kwargs):
def glib_repository(name):
pkg_config_repository(
name = name,
licenses = licenses,
modname = modname,
pkg_config_paths = pkg_config_paths,
**kwargs
licenses = ["restricted"], # LGPL-2.0+
modname = "glib-2.0",
)
16 changes: 3 additions & 13 deletions tools/workspace/ipopt_internal_pkgconfig/repository.bzl
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
load("//tools/workspace:pkg_config.bzl", "pkg_config_repository")

def ipopt_internal_pkgconfig_repository(
name,
licenses = [
"reciprocal", # CPL-1.0
],
modname = "ipopt",
pkg_config_paths = [],
homebrew_subdir = "opt/ipopt/lib/pkgconfig",
**kwargs):
def ipopt_internal_pkgconfig_repository(name):
pkg_config_repository(
name = name,
licenses = licenses,
modname = modname,
pkg_config_paths = pkg_config_paths,
licenses = ["reciprocal"], # CPL-1.0
modname = "ipopt",
# When using ipopt from pkg-config, there is nothing to install.
build_epilog = """
load("@drake//tools/install:install.bzl", "install")
install(name = "install")
""",
**kwargs
)
14 changes: 3 additions & 11 deletions tools/workspace/lapack/repository.bzl
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
load("//tools/workspace:os.bzl", "os_specific_alias_repository")

# TLDR: Use this repository (@lapack) instead of @liblapack or @openblas in the
# deps of your target.
#
# Since we use different pkg-config modules offering LAPACK implementations
# from (potentially) different vendors depending on the operating system, this
# alias exists to select the correct operating-system-specific LAPACK
# implementation. On macOS, the @lapack and @openblas targets will always refer
# to OpenBLAS. On Linux, the @lapack and @liblapack targets will depend on a
# LAPACK implementation typically chosen by the Ubuntu alternatives system,
# such as the reference implementation from Netlib, Automatically Tuned Linear
# Algebra Software (ATLAS), and OpenBLAS.
# Use this repository (@lapack) in the deps of your target, instead of
# @liblapack or @openblas. We use a different implementations depending on the
# operating system; this alias exists to select the correct implementation.
def lapack_repository(name):
os_specific_alias_repository(
name = name,
Expand Down
11 changes: 0 additions & 11 deletions tools/workspace/libblas/package-macos.BUILD.bazel

This file was deleted.

45 changes: 12 additions & 33 deletions tools/workspace/libblas/repository.bzl
Original file line number Diff line number Diff line change
@@ -1,34 +1,13 @@
load("//tools/workspace:os.bzl", "determine_os")
load("//tools/workspace:pkg_config.bzl", "setup_pkg_config_repository")
load("//tools/workspace:pkg_config.bzl", "pkg_config_repository")

def _impl(repo_ctx):
# TLDR: Use @blas instead of this repository (@libblas) in the deps of your
# target.
#
# On Ubuntu, we will use pkg-config to find libblas.so (the vendor of which
# is typically chosen by the Ubuntu alternatives system). On macOS, no
# targets should depend on @libblas. However, on both macOS and Ubuntu,
# targets should normally depend on the alias @blas instead of @libblas (or
# @openblas) to install an operating-system-specific BLAS implementation.
os_result = determine_os(repo_ctx)
if os_result.error != None:
fail(os_result.error)
if os_result.is_ubuntu or os_result.is_manylinux:
error = setup_pkg_config_repository(repo_ctx).error
if error != None:
fail(error)
else:
repo_ctx.symlink(
Label("@drake//tools/workspace/libblas:package-macos.BUILD.bazel"),
"BUILD.bazel",
)

libblas_repository = repository_rule(
attrs = {
"modname": attr.string(default = "blas"),
"licenses": attr.string_list(default = ["notice"]), # BSD-3-Clause
},
local = True,
configure = True,
implementation = _impl,
)
def libblas_repository(name):
# Note that @libblas is typically only available on Linux.
# See drake/tools/workspace/blas for the OS-specific selection policy.
# Note that on Debian and Ubuntu in particular, @libblas refers to the
# implementation chosen by the Ubuntu alternatives system, which might be
# one of any number of different vendor implementations.
pkg_config_repository(
name = name,
licenses = ["notice"], # BSD-3-Clause
modname = "blas",
)
11 changes: 0 additions & 11 deletions tools/workspace/liblapack/package-macos.BUILD.bazel

This file was deleted.

53 changes: 16 additions & 37 deletions tools/workspace/liblapack/repository.bzl
Original file line number Diff line number Diff line change
@@ -1,38 +1,17 @@
load("//tools/workspace:os.bzl", "determine_os")
load("//tools/workspace:pkg_config.bzl", "setup_pkg_config_repository")
load("//tools/workspace:pkg_config.bzl", "pkg_config_repository")

def _impl(repo_ctx):
# TLDR: Use @lapack instead of this repository (@liblapack) in the deps of
# your target.
#
# On Ubuntu, we will use pkg-config to find liblapack.so (the vendor of
# which is typically chosen by the Ubuntu alternatives system). On macOS,
# no targets should depend on @liblapack. However, on both macOS and
# Ubuntu, targets should normally depend on the alias @lapack instead of
# @liblapack (or @openblas) to install an operating-system-specific LAPACK
# implementation.
os_result = determine_os(repo_ctx)
if os_result.error != None:
fail(os_result.error)
if os_result.is_ubuntu or os_result.is_manylinux:
error = setup_pkg_config_repository(repo_ctx).error
if error != None:
fail(error)
else:
repo_ctx.symlink(
Label("@drake//tools/workspace/liblapack:package-macos.BUILD.bazel"), # noqa
"BUILD.bazel",
)

liblapack_repository = repository_rule(
attrs = {
"modname": attr.string(default = "lapack"),
"licenses": attr.string_list(default = ["notice"]), # BSD-3-Clause
# Explicitly specify transitive dependencies; these are needed when
# using static LAPACK as in the PyPI wheel builds.
"extra_linkopts": attr.string_list(default = ["-lblas", "-lgfortran"]),
},
local = True,
configure = True,
implementation = _impl,
)
def liblapack_repository(name):
# Note that @liblapack is typically only available on Linux.
# See drake/tools/workspace/lapack for the OS-specific selection policy.
# Note that on Debian and Ubuntu in particular, @liblapack refers to the
# implementation chosen by the Ubuntu alternatives system, which might be
# one of any number of different vendor implementations.
pkg_config_repository(
name = name,
licenses = ["notice"], # BSD-3-Clause
modname = "lapack",
extra_deps = [
"@gfortran//:runtime",
"@libblas",
],
)
14 changes: 3 additions & 11 deletions tools/workspace/liblz4/repository.bzl
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
load("//tools/workspace:pkg_config.bzl", "pkg_config_repository")

def liblz4_repository(
name,
licenses = ["notice"], # BSD-2-Clause
modname = "liblz4",
pkg_config_paths = [],
homebrew_subdir = "opt/lz4/lib/pkgconfig",
**kwargs):
def liblz4_repository(name):
pkg_config_repository(
name = name,
licenses = licenses,
modname = modname,
pkg_config_paths = pkg_config_paths,
licenses = ["notice"], # BSD-2-Clause
modname = "liblz4",
extra_deprecation = "The @liblz4 external is deprecated in Drake's WORKSPACE and will be removed on or after 2024-01-01.", # noqa
**kwargs
)
14 changes: 3 additions & 11 deletions tools/workspace/liblzma/repository.bzl
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
load("//tools/workspace:pkg_config.bzl", "pkg_config_repository")

def liblzma_repository(
name,
licenses = ["unencumbered"], # Public-Domain
modname = "liblzma",
pkg_config_paths = [],
homebrew_subdir = "opt/xz/lib/pkgconfig",
**kwargs):
def liblzma_repository(name):
pkg_config_repository(
name = name,
licenses = licenses,
modname = modname,
pkg_config_paths = pkg_config_paths,
licenses = ["unencumbered"], # Public-Domain
modname = "liblzma",
extra_deprecation = "The @liblzma external is deprecated in Drake's WORKSPACE and will be removed on or after 2024-01-01.", # noqa
**kwargs
)
14 changes: 3 additions & 11 deletions tools/workspace/libpng/repository.bzl
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
load("//tools/workspace:pkg_config.bzl", "pkg_config_repository")

def libpng_repository(
name,
licenses = ["notice"], # Libpng
modname = "libpng",
pkg_config_paths = [],
homebrew_subdir = "opt/libpng/lib/pkgconfig",
**kwargs):
def libpng_repository(name):
pkg_config_repository(
name = name,
licenses = licenses,
modname = modname,
pkg_config_paths = pkg_config_paths,
licenses = ["notice"], # Libpng
modname = "libpng",
extra_deprecation = "The @libpng external is deprecated in Drake's WORKSPACE and will be removed on or after 2024-02-01.", # noqa
**kwargs
)
14 changes: 3 additions & 11 deletions tools/workspace/libtiff/repository.bzl
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
load("//tools/workspace:pkg_config.bzl", "pkg_config_repository")

def libtiff_repository(
name,
licenses = ["notice"], # Libtiff
modname = "libtiff-4",
pkg_config_paths = [],
homebrew_subdir = "opt/libtiff/lib/pkgconfig",
**kwargs):
def libtiff_repository(name):
pkg_config_repository(
name = name,
licenses = licenses,
modname = modname,
pkg_config_paths = pkg_config_paths,
licenses = ["notice"], # Libtiff
modname = "libtiff-4",
extra_deprecation = "The @libtiff external is deprecated in Drake's WORKSPACE and will be removed on or after 2024-02-01.", # noqa
**kwargs
)
11 changes: 0 additions & 11 deletions tools/workspace/openblas/package-ubuntu.BUILD.bazel

This file was deleted.

Loading

0 comments on commit c809bbc

Please sign in to comment.