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

[c++] Remove spdlog requirement #1852

Merged
merged 2 commits into from
Nov 3, 2023
Merged

Conversation

nguyenv
Copy link
Member

@nguyenv nguyenv commented Nov 3, 2023

Issue and/or context:

libtiledbsoma still erroneously required spdlog as a dependency due to exposing logger.h in the public API headers. This was reported in a channel internal to TileDB here.

Changes:

  • Public headers using logger.h have been replaced by logger_public.h
  • The fmt library is a part of spdlog which means it cannot be used or accessed except internally
  • When possible, code that was using fmt in the public headers have now been moved into the cc source code which may continue to use the internal logger.h
  • For fmt usage in templated functions, unit tests, and pytiledbsoma.cc, string formatting has been refactored to use either std::ostringstream or basic std::string appending with + for compatibility with C++17. In C++20, we can switch to using std::format. TODO comments have been left in these areas

Notes for Reviewer:

  • It is not necessary to include these changes in the 1.5.0 release
  • These code changes have been tested and confirmed fixed by @jdblischak

@johnkerl
Copy link
Member

johnkerl commented Nov 3, 2023

It is not necessary to include these changes in the 1.5.0 release

@nguyenv I've been keeping release-1.5 in sync with main (modulo #1733) and I want to keep it that way until we get 1.5.0. I don't want to be omitting just a PR or two and then get confused.

Comment on lines +36 to +37
#include "utils/carrow.h"
#include "utils/logger.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why were these headers added?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logger.h is used for the LOG_* macros and fmt. carrow.h is used for ArrowSchema. soma_array.h use to include logger.h but that has now been removed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But soma_array.h includes logger_public.h. Isn't it enough?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, logger_public.h does not expose fmt

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW one can (somewhat poorly) drop in tinyfmt which is a less powerful than fmt but a single-header C++11 library. The key is, as @nguyenv points out, that the public logger only takes a string (or const char*, I forgot) to 'report' and does no formatting whatsoever itself.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move the generic method definitions to the .cc file and add explicit instantiations?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you talking about separating implemention of the templated functions in the cc? I considered doing that, but I feel very ambivalent about having a long list of explicit instantiations for multiple functions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this something that we do in core?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nguyenv
Copy link
Member Author

nguyenv commented Nov 3, 2023

@eddelbuettel, if you don't mind, could you take a look at the R failures and push the necessary changes to this branch? Today I'd like to focus on getting the necessary Python stuff working for 1.5.0.

Copy link
Collaborator

@jdblischak jdblischak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@johnkerl
Copy link
Member

johnkerl commented Nov 3, 2023

It is not necessary to include these changes in the 1.5.0 release

@nguyenv I've been keeping release-1.5 in sync with main (modulo #1733) and I want to keep it that way until we get 1.5.0. I don't want to be omitting just a PR or two and then get confused.

Of course if this doesn't land in main in time for 1.5.0 that's fine -- this is not a 1.5.0 blocker.

@eddelbuettel
Copy link
Contributor

These are compilation errors coming from the header re-arrangement:

using C++17
g++ -std=gnu++17 -I"/usr/share/R/include" -DNDEBUG -I. -I../inst/include/ -I../inst/tiledb/include -I../inst/tiledbsoma/include   -I'/usr/lib/R/site-library/Rcpp/include' -I'/usr/lib/R/site-library/RcppSpdlog/include' -I'/usr/local/lib/R/site-library/RcppInt64/include'     -fpic  -g -O2 -ffile-prefix-map=/build/r-base-MHXHhT/r-base-4.3.1=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2  -c RcppExports.cpp -o RcppExports.o
In file included from ../inst/tiledbsoma/include/tiledbsoma/utils/arrow_adapter.h:10,
                 from ../inst/tiledbsoma/include/tiledbsoma/tiledbsoma:45,
                 from ../inst/include/tiledbsoma_types.h:21,
                 from RcppExports.cpp:4:
../inst/tiledbsoma/include/tiledbsoma/utils/carrow.h:16:8: error: redefinition of ‘struct ArrowSchema’
   16 | struct ArrowSchema {
      |        ^~~~~~~~~~~
In file included from ../inst/include/tiledbsoma_types.h:18,
                 from RcppExports.cpp:4:
./nanoarrow.h:83:8: note: previous definition of ‘struct ArrowSchema’
   83 | struct ArrowSchema {
      |        ^~~~~~~~~~~
In file included from ../inst/tiledbsoma/include/tiledbsoma/utils/arrow_adapter.h:10,
                 from ../inst/tiledbsoma/include/tiledbsoma/tiledbsoma:45,
                 from ../inst/include/tiledbsoma_types.h:21,
                 from RcppExports.cpp:4:
../inst/tiledbsoma/include/tiledbsoma/utils/carrow.h:32:8: error: redefinition of ‘struct ArrowArray’
   32 | struct ArrowArray {
      |        ^~~~~~~~~~
In file included from ../inst/include/tiledbsoma_types.h:18,
                 from RcppExports.cpp:4:
./nanoarrow.h:99:8: note: previous definition of ‘struct ArrowArray’
   99 | struct ArrowArray {
      |        ^~~~~~~~~~
make: *** [/usr/lib/R/etc/Makeconf:200: RcppExports.o] Error 1
ERROR: compilation failed for package ‘tiledbsoma’
* removing ‘/tmp/RtmpPq5dYB/Rinst[192](https://github.com/single-cell-data/TileDB-SOMA/actions/runs/6746709009/job/18341227889?pr=1852#step:10:193)9110b964d/tiledbsoma’

Any chance we can keep changess local? The idea was less spill not more?

@nguyenv
Copy link
Member Author

nguyenv commented Nov 3, 2023

Oh opps... I think that's happening because I removed these lines https://github.com/single-cell-data/TileDB-SOMA/pull/1852/files#diff-e419a62446641fa84b7b42a6ab37141a624cb49a0784add4f49823cd1abef3d5L7-L9. I didn't know what that macro was for or where it was being set, and my tests were passing without it so just kept the change in🤦🏻‍♀️

@eddelbuettel
Copy link
Contributor

@nguyenv Per your last comment making that #include conditional again lets me compile the R package. Running tests now, not expecting anything so will commit these two lines in a moment.

@codecov-commenter
Copy link

codecov-commenter commented Nov 3, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

see 40 files with indirect coverage changes

📢 Thoughts on this report? Let us know!.

~ColumnBuffer() {
LOG_TRACE(fmt::format("[ColumnBuffer] release '{}'", name_));
}
~ColumnBuffer();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? While trace is super-voluminous it can be helpful to see that dtors have been reached.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/single-cell-data/TileDB-SOMA/pull/1852/files#diff-e563ff857d3a241fa155b2c78fdd243bbe474e8bf28a7782d03f56f00d00f6b5R156-R158

It's because of fmt::format. I've moved it into column_buffer.cc, so we still do a get a log trace.

Copy link
Contributor

@eddelbuettel eddelbuettel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a lot of changes here and my head is a little dizzy but I take your word for it that things will work with fmt only in src/ and not the public interface. Thanks for cleaning this up.

@nguyenv nguyenv merged commit 98d30c7 into main Nov 3, 2023
12 checks passed
@nguyenv nguyenv deleted the viviannguyen/keep-logger.h-internal branch November 3, 2023 18:50
jdblischak added a commit to TileDB-Inc/centralized-tiledb-nightlies that referenced this pull request Nov 3, 2023
A fix was applied upstream to libtiledbsoma, so this is
no longer required. It also fixed the runtime error
related to a missing symbol from `fmt`

single-cell-data/TileDB-SOMA#1852
Copy link

github-actions bot commented Nov 3, 2023

The backport to release-1.5 failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-release-1.5 release-1.5
# Navigate to the new working tree
cd .worktrees/backport-release-1.5
# Create a new branch
git switch --create backport-1852-to-release-1.5
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick --mainline 1 98d30c7380a47b3a2c597630293638c78d0fc7dd
# Push it to GitHub
git push --set-upstream origin backport-1852-to-release-1.5
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-release-1.5

Then, create a pull request where the base branch is release-1.5 and the compare/head branch is backport-1852-to-release-1.5.

1 similar comment
Copy link

github-actions bot commented Nov 3, 2023

The backport to release-1.5 failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-release-1.5 release-1.5
# Navigate to the new working tree
cd .worktrees/backport-release-1.5
# Create a new branch
git switch --create backport-1852-to-release-1.5
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick --mainline 1 98d30c7380a47b3a2c597630293638c78d0fc7dd
# Push it to GitHub
git push --set-upstream origin backport-1852-to-release-1.5
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-release-1.5

Then, create a pull request where the base branch is release-1.5 and the compare/head branch is backport-1852-to-release-1.5.

johnkerl pushed a commit that referenced this pull request Nov 3, 2023
* Keep logger.h internal; do not install

* Restore conditional include of carrow.h

---------

Co-authored-by: Dirk Eddelbuettel <[email protected]>
johnkerl added a commit that referenced this pull request Nov 3, 2023
* Keep logger.h internal; do not install

* Restore conditional include of carrow.h

---------

Co-authored-by: nguyenv <[email protected]>
Co-authored-by: Dirk Eddelbuettel <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants