Skip to content

Commit

Permalink
workspace: Upgrade spdlog to latest release 1.4.2 (#12322)
Browse files Browse the repository at this point in the history
This also changes spdlog to use a shared library.

This reverts commit 20a43f9
effectively re-applying 775f27a.
  • Loading branch information
jwnimmer-tri committed Nov 7, 2019
1 parent c193f32 commit 019c571
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 28 deletions.
2 changes: 2 additions & 0 deletions attic/systems/sensors/test/rgbd_renderer_ospray_test.cc
@@ -1,5 +1,7 @@
#include "drake/systems/sensors/rgbd_renderer_ospray.h"

#include <array>

#include "drake/systems/sensors/test/rgbd_renderer_test_util.h"

namespace drake {
Expand Down
1 change: 1 addition & 0 deletions attic/systems/sensors/test/rgbd_renderer_test_util.h
@@ -1,5 +1,6 @@
#pragma once

#include <array>
#include <memory>

#include <Eigen/Dense>
Expand Down
2 changes: 2 additions & 0 deletions attic/systems/sensors/test/rgbd_renderer_vtk_test.cc
@@ -1,5 +1,7 @@
#include "drake/systems/sensors/rgbd_renderer_vtk.h"

#include <array>

#include "drake/systems/sensors/test/rgbd_renderer_test_util.h"

namespace drake {
Expand Down
1 change: 1 addition & 0 deletions solvers/test/snopt_solver_test.cc
Expand Up @@ -3,6 +3,7 @@
#include <fstream>
#include <iostream>
#include <regex>
#include <thread>

#include <gmock/gmock.h>
#include <gtest/gtest.h>
Expand Down
2 changes: 1 addition & 1 deletion tools/install/libdrake/BUILD.bazel
Expand Up @@ -203,6 +203,7 @@ cc_library(
"@ignition_math",
"@lcm",
"@libprotobuf",
"@spdlog",
"@tinyxml2",
"@yaml_cpp",
] + [
Expand All @@ -214,7 +215,6 @@ cc_library(
"@lcmtypes_bot2_core",
"@lcmtypes_robotlocomotion",
"@optitrack_driver//lcmtypes:optitrack_lcmtypes",
"@spdlog",
],
)

Expand Down
5 changes: 4 additions & 1 deletion tools/workspace/fmt/package.BUILD.bazel
Expand Up @@ -22,7 +22,10 @@ cc_library(
"include/fmt/posix.h",
]),
defines = [
# By tradition, Drake uses the header-only build of fmt.
# By tradition, Drake uses the header-only build of fmt. If we ever
# change it to use a library, then we'll also need to update the
# tools/workspace/spdlog/package.BUILD.bazel shared library rules
# to avoid double-linking.
"FMT_HEADER_ONLY=1",
# Avoid macro pollution.
"FMT_NO_FMT_STRING_ALIAS=1",
Expand Down
14 changes: 8 additions & 6 deletions tools/workspace/spdlog/package-create-cps.py
@@ -1,17 +1,17 @@
from drake.tools.install.cpsutils import read_version_defs, read_requires
from drake.tools.install.cpsutils import read_defs, read_requires

def_re = "project\(spdlog\sVERSION\s([0-9]+).([0-9]+).([0-9]+)"
defs = read_version_defs(def_re)
def_re = "#define\s+(\S+)\s+(\S+)"
defs = read_defs(def_re)

defs.update(read_requires())

content = """
{
"Cps-Version": "0.8.0",
"Name": "spdlog",
"Description": "Super fast C++ logging library",
"Description": "Fast C++ logging library",
"License": "MIT",
"Version": "%(VERSION_MAJOR)s.%(VERSION_MINOR)s.%(VERSION_PATCH)s",
"Version": "%(SPDLOG_VER_MAJOR)s.%(SPDLOG_VER_MINOR)s.%(SPDLOG_VER_PATCH)s",
"Requires": {
"fmt": {
"Version": "%(fmt_VERSION)s",
Expand All @@ -22,10 +22,12 @@
"Default-Components": [":spdlog"],
"Components": {
"spdlog": {
"Type": "interface",
"Type": "dylib",
"Includes": ["@prefix@/include/spdlog"],
"Location": "@prefix@/lib/libspdlog.so",
"Definitions": [
"HAVE_SPDLOG",
"SPDLOG_COMPILED_LIB",
"SPDLOG_FMT_EXTERNAL"
],
"Requires": ["fmt:fmt-header-only"]
Expand Down
86 changes: 68 additions & 18 deletions tools/workspace/spdlog/package.BUILD.bazel
Expand Up @@ -7,43 +7,92 @@ load(
"install_cmake_config",
)

licenses(["notice"]) # BSD-2-Clause AND MIT

package(
default_visibility = ["//visibility:public"],
)
licenses(["notice"]) # MIT

config_setting(
name = "linux",
values = {"cpu": "k8"},
visibility = ["//visibility:private"],
)

cc_library(
name = "spdlog",
hdrs = glob(
["include/spdlog/**"],
exclude = ["include/spdlog/fmt/bundled/**"],
),
defines = [
"HAVE_SPDLOG",
"SPDLOG_FMT_EXTERNAL",
# The public headers are all of the non-inl include files.
# We use Drake's @fmt external, not the bundled version inside spdlog.
_HDRS = glob(
[
"include/spdlog/**",
],
exclude = [
"**/*-inl.h",
"include/spdlog/fmt/bundled/**",
],
)

_INCLUDES = ["include"]

_DEFINES = [
"HAVE_SPDLOG",
# Use the compiled (not header-only) variant of spdlog for build speed and
# substantially (20%+) smaller binary sizes.
"SPDLOG_COMPILED_LIB",
# Use Drake's @fmt external, not the bundled version inside spdlog.
"SPDLOG_FMT_EXTERNAL",
]

# The library sources are the srcs plus the -inl include files.
# We use Drake's @fmt external, not the bundled version inside spdlog.
_SRCS = glob(
[
"include/spdlog/**/*-inl.h",
"src/**",
],
exclude = [
"include/spdlog/fmt/bundled/**",
],
includes = ["include"],
)

# Upstream's default is to ship static (not shared), but it is difficult to
# ensure that we obey ODR for libdrake.so if we were to use libspdlog.a.
# Therefore, we will always use a shared library for spdlog inside Drake.
# (We can't use the header-only variant of spdlog because it substantially
# bloats binary sizes by 20% or more in Debug builds, which pushes us over
# the 2 GiB file size limit.)
cc_binary(
name = "libspdlog.so",
srcs = _HDRS + _SRCS,
defines = _DEFINES,
includes = _INCLUDES,
linkopts = select({
":linux": ["-pthread"],
# This is a bazel-default rule, and does not need @drake//
"@//conditions:default": [],
}),
# These two lines are how you tell Bazel to create a shared library.
linkshared = True,
linkstatic = True,
deps = ["@fmt"],
)

cc_library(
name = "spdlog",
srcs = ["libspdlog.so"],
hdrs = _HDRS,
defines = _DEFINES,
includes = _INCLUDES,
linkstatic = True,
deps = [
# This is valid iff fmt is compiled in header-only mode. If it gains a
# library, we should depend only on the headers here.
"@fmt",
],
visibility = ["//visibility:public"],
)

CMAKE_PACKAGE = "spdlog"

cmake_config(
package = CMAKE_PACKAGE,
script = "@drake//tools/workspace/spdlog:package-create-cps.py",
version_file = "CMakeLists.txt",
version_file = "include/spdlog/version.h",
deps = ["@fmt//:cps"],
)

Expand All @@ -52,10 +101,11 @@ install_cmake_config(package = CMAKE_PACKAGE)

install(
name = "install",
targets = [":spdlog"],
targets = [":libspdlog.so"],
hdr_dest = "include/" + CMAKE_PACKAGE,
hdr_strip_prefix = ["include"],
guess_hdrs = "PACKAGE",
hdrs = _HDRS,
docs = ["LICENSE"],
deps = [":install_cmake_config"],
visibility = ["//visibility:public"],
)
4 changes: 2 additions & 2 deletions tools/workspace/spdlog/repository.bzl
Expand Up @@ -8,8 +8,8 @@ def spdlog_repository(
github_archive(
name = name,
repository = "gabime/spdlog",
commit = "v1.3.1",
sha256 = "160845266e94db1d4922ef755637f6901266731c4cb3b30b45bf41efa0e6ab70", # noqa
commit = "v1.4.2",
sha256 = "821c85b120ad15d87ca2bc44185fa9091409777c756029125a02f81354072157", # noqa
build_file = "@drake//tools/workspace/spdlog:package.BUILD.bazel",
mirrors = mirrors,
)

0 comments on commit 019c571

Please sign in to comment.