Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fmtlib dependency #1079

Merged
merged 1 commit into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ v1.0.0-alpha.xx
`hasTrait`/`isImbuedTo` checks.
[#970](https://github.com/OpenAssetIO/OpenAssetIO/issues/970)

- :hammer: Added [fmt](https://fmt.dev/9.1.0) as a new header-only
private dependency.
[#1070](https://github.com/OpenAssetIO/OpenAssetIO/issues/1070)

v1.0.0-alpha.14
---------------

Expand Down
7 changes: 7 additions & 0 deletions cmake/ThirdParty.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@

find_package(tomlplusplus REQUIRED)


#-----------------------------------------------------------------------
# String formatting

find_package(fmt REQUIRED)


#-----------------------------------------------------------------------
# Python

Expand Down
1 change: 1 addition & 0 deletions doc/BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ available.
- [Python 3.7+](https://www.python.org/) (development install)
- [pybind11](https://pybind11.readthedocs.io/en/stable/) 2.8.1+
- [toml++](https://marzer.github.io/tomlplusplus/) 3.2.0+
- [fmt](https://github.com/fmtlib/fmt) 9.1.0

### Test dependencies

Expand Down
13 changes: 13 additions & 0 deletions doc/contributing/CODING_STANDARDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,19 @@ when binding a C++ `enum class` using pybind, use
namespaced in the same way as in C++, i.e. not polluting the parent
namespace.

## String formatting

The project has a (private, header-only) dependency on the
[fmt](https://fmt.dev/9.1.0) library for efficient string formatting,
and this should be used by preference over alternative legacy options
such as `std::stringstream`.
foundrytom marked this conversation as resolved.
Show resolved Hide resolved

> **Note**
>
> Due to a [symbol leakage issue](https://github.com/fmtlib/fmt/issues/3626)
> in the current latest fmt version v10.1, we recommend (and build/test
> with) fmt v9.1.

## C

### Handles
Expand Down
10 changes: 10 additions & 0 deletions resources/build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ RUN cd tomlplusplus && cmake -S . -B build && cmake --build build && cmake --ins
RUN git clone --branch v42 https://github.com/rollbear/trompeloeil
RUN cd trompeloeil && cmake -S . -B build && cmake --build build && cmake --install build

# Pull and install fmt
RUN git clone --branch 9.1.0 https://github.com/fmtlib/fmt
RUN cd fmt && cmake -S . -B build -DFMT_MASTER_PROJECT=OFF -DFMT_INSTALL=ON && \
cmake --build build --parallel && cmake --install build

# Test dependencies
# Pull and install catch2
RUN git clone --branch v2.13.10 https://github.com/catchorg/Catch2
Expand All @@ -32,6 +37,11 @@ COPY --from=openassetio-dependencies /usr/local/include/catch2 /usr/local/includ
COPY --from=openassetio-dependencies /usr/local/share/Catch2 /usr/local/share/Catch2
COPY --from=openassetio-dependencies /usr/local/lib64/cmake/Catch2 /usr/local/lib64/cmake/Catch2

# Copy fmt
COPY --from=openassetio-dependencies /usr/local/include/fmt /usr/local/include/fmt
COPY --from=openassetio-dependencies /usr/local/lib64/libfmt.a /usr/local/lib64/libfmt.a
COPY --from=openassetio-dependencies /usr/local/lib64/cmake/fmt /usr/local/lib64/cmake/fmt

# Copy trompeloeil
# Trompeloeil installs itself into relevent test framework folders, so
# some relevent parts of it for us is copied over with include/catch2
Expand Down
2 changes: 1 addition & 1 deletion resources/build/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ default: docker-image
##

# This container version mimicks the VFX reference platform versioning.
CONTAINER_VERSION=2022.1
CONTAINER_VERSION=2022.2
foundrytom marked this conversation as resolved.
Show resolved Hide resolved
CONTAINER_NAME=openassetio-build

##
Expand Down
7 changes: 7 additions & 0 deletions resources/build/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,10 @@ def requirements(self):
self.requires("catch2/2.13.8")
# Mocking library
self.requires("trompeloeil/42")
# TODO(DF): fmt v10 forcibly exports the symbol for its
# `format_error` exception in GCC, making it not a true private
# dependency. So pin to v9 for now.
self.requires("fmt/9.1.0")

def configure(self):
self.options["fmt"].header_only = True
8 changes: 6 additions & 2 deletions src/openassetio-core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,13 @@ target_include_directories(openassetio-core
# Use includes from install tree for installed lib.
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")

target_link_libraries(openassetio-core
target_link_libraries(
openassetio-core
PRIVATE
$<BUILD_INTERFACE:tomlplusplus::tomlplusplus>)
# Header-only private dependencies:
$<BUILD_INTERFACE:tomlplusplus::tomlplusplus>
$<BUILD_INTERFACE:fmt::fmt-header-only>
)

#-----------------------------------------------------------------------
# API export header
Expand Down
13 changes: 7 additions & 6 deletions src/openassetio-core/src/hostApi/Manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <stdexcept>
#include <utility>

#include <fmt/format.h>

#include <openassetio/Context.hpp>
#include <openassetio/TraitsData.hpp>
#include <openassetio/constants.hpp>
Expand Down Expand Up @@ -53,12 +55,11 @@ std::optional<Str> entityReferencePrefixFromInfo(const log::LoggerInterfacePtr &
if (auto iter = info.find(Str{constants::kInfoKey_EntityReferencesMatchPrefix});
iter != info.end()) {
if (const auto *prefixPtr = std::get_if<openassetio::Str>(&iter->second)) {
std::string msg = "Entity reference prefix '";
msg += *prefixPtr;
msg +=
"' provided by manager's info() dict. Subsequent calls to isEntityReferenceString will"
" use this prefix rather than call the manager's implementation.";
logger->debugApi(msg);
logger->debugApi(
fmt::format("Entity reference prefix '{}' provided by manager's info() dict. Subsequent"
" calls to isEntityReferenceString will use this prefix rather than call the"
" manager's implementation.",
*prefixPtr));
foundrytom marked this conversation as resolved.
Show resolved Hide resolved

return *prefixPtr;
}
Expand Down