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

Fix macOS build #40938

Closed
wants to merge 1 commit into from
Closed

Fix macOS build #40938

wants to merge 1 commit into from

Conversation

Lucky-Chang
Copy link
Contributor

Changelog category (leave one):

  • Build/Testing/Packaging Improvement

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

fix build on macOS

Information about CI checks: https://clickhouse.com/docs/en/development/continuous-integration/

@CLAassistant
Copy link

CLAassistant commented Sep 2, 2022

CLA assistant check
All committers have signed the CLA.

@robot-ch-test-poll robot-ch-test-poll added the pr-build Pull request with build/testing/packaging improvement label Sep 2, 2022
@Lucky-Chang Lucky-Chang changed the title fix macOS compile and some typos Fix macOS build and some typos Sep 2, 2022
@Lucky-Chang
Copy link
Contributor Author

#40937 (comment)

@serxa serxa self-assigned this Sep 2, 2022
@serxa serxa added the can be tested Allows running workflows for external contributors label Sep 2, 2022
Copy link
Member

@serxa serxa left a comment

Choose a reason for hiding this comment

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

LGTM, let's look if CI agree with all typo fixes in logs and error messages

@@ -7217,7 +7217,7 @@ bool StorageReplicatedMergeTree::addOpsToDropAllPartsInPartition(
}

void StorageReplicatedMergeTree::dropAllPartsInPartitions(
zkutil::ZooKeeper & zookeeper, const Strings partition_ids, std::vector<LogEntryPtr> & entries, ContextPtr query_context, bool detach)
zkutil::ZooKeeper & zookeeper, const Strings & partition_ids, std::vector<LogEntryPtr> & entries, ContextPtr query_context, bool detach)
Copy link
Member

Choose a reason for hiding this comment

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

nice catch

@@ -1,6 +1,10 @@
padding=" "
if [[ $OSTYPE == 'darwin'* ]]; then
sz="$(stat -f %z 'decompressor')"
if which gstat; then
Copy link
Member

@rschu1ze rschu1ze Sep 3, 2022

Choose a reason for hiding this comment

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

The GNU and the Mac version stat support different command line arguments (-c %s vs -f %z). On Mac, we are now checking for gstat aka. the GNU version which is part of brew's coreutils package. Since installing gstat via brew does not remove or disable the build-in Mac version of stat, I wonder how this PR "fixes the macOS build" (commit message)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

as you say, i installed gnu coreutils by homebrew in my macOS. and gstat is the default alternative for stat

Copy link
Member

Choose a reason for hiding this comment

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

Instead of making the script more complex, we could continue to call stat even if the user installed gstat.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the problem is directly call stat will fail, because it's actually 'gstat', the running params are different

target_link_libraries(loggers PRIVATE dbms clickhouse_common_io)

# Lightweight version doesn't work with textlog and also doesn't depend on DBMS
add_library(loggers_no_text_log ${loggers_sources} ${loggers_headers})
target_compile_definitions(loggers_no_text_log PUBLIC WITHOUT_TEXT_LOG=1)
Copy link
Member

Choose a reason for hiding this comment

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

@rschu1ze AFAIU this line is supposed to fix the build, but to be honest I don't understand why. For me it seems to have absolutely the same behaviour as before because #ifdef WITH_TEXT_LOG was replaced with ifndef WITHOUT_TEXT_LOG.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i figure that the main binary include 'Loggers.h' in different way, in most case, the include path is implicated by loggers library. But some directly include the 'Loggers.h'. so the WITH_TEXT_LOG definition differ in the main binary.
I just reverse WITH_TEXT_LOG to WITHOUT_TEXT_LOG. so in the main library all 'Loggers.h' has no WITHOUT_TEXT_LOG. it works out.

Copy link
Member

@rschu1ze rschu1ze Sep 4, 2022

Choose a reason for hiding this comment

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

The fix is a bit weird but generally okay, IMHO.

It would be great to understand the problem in more detail.

@Lucky-Chang Could you please give the detailed steps for reproduction: What is the exact command line for cmake? Please try to use homebrew's LLVM/Clang/CMake as described in the documentation instead of Apple's XCode LLVM/Clang (as used in #40398).

i figure that the main binary include 'Loggers.h' in different way, in most case, the include path is implicated by loggers library. But some directly include the 'Loggers.h'. so the WITH_TEXT_LOG definition differ in the main binary.

  • By "main binary", do you mean programs/server/Server.cpp?
  • What do you mean "the loggers library implicates the include path"? More specifically, which files get included exactly and by magic exactly does that happen?
  • Could you give an example for the files which "directly include Loggers.h"?

I think I have a clue about the cause of the problem. Sorry for asking all these questions but depending on the details, there could be potentially a better (more consistent) fix.

Copy link
Member

Choose a reason for hiding this comment

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

It took me quite some time to understand how it fix the code. The simple answer Loggers class definition violates ODR (introduced in #35031).
Explanaition:

  1. Loggers class is build in 2 binaries: loggers and loggers_no_text_log.
  2. loggers_no_text_log is used only for clickhouse-keeper.
  3. Everything else is linked against loggers, but compiled without WITH_TEXT_LOG macro.

For example, in BaseDeamon.h we have #include <Loggers/Loggers.h>. BaseDeamon.cpp is never compiled with WITH_TEXT_LOG macro defined, but linked with loggers.

@Lucky-Chang
Copy link
Contributor Author

exactly the same problem with #40398

@@ -7,7 +7,7 @@
#include <Poco/Util/Application.h>
#include "OwnSplitChannel.h"

#ifdef WITH_TEXT_LOG
#ifndef WITHOUT_TEXT_LOG
Copy link
Member

Choose a reason for hiding this comment

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

This now leads Loggers to be expected with text log in clickhouse-keeper, but linked with loggers_no_text_log. The problem is not fixed.

Please, make a separate PR with typo fixes, because it's hard to read this PR and to understand what is the actual fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

src/CMakeList.txt 319~320
dbms_target_include_directories (PUBLIC "${ClickHouse_SOURCE_DIR}/src" "${ClickHouse_BINARY_DIR}/src")
target_include_directories (clickhouse_common_io PUBLIC "${ClickHouse_SOURCE_DIR}/src" "${ClickHouse_BINARY_DIR}/src")

this two lines expose all .h (include Loggers.h)to all build libraries (common-io and all dmbs)。during all these libraries building they just not see 'WITH_TEXT_LOG' compile definition。HOW we could make sure some library will
inherit the compile definition from the loggers (or loggers_no_text_log) library? it must be explicit link loggers (modern cmake target link rules), in the project there only two libraries do this:
target_link_libraries (daemon PUBLIC loggers)
target_link_libraries(clickhouse-keeper PRIVATE loggers_no_text_log)

At last clickhouse-server links daemon library (with WITH_TEXT_LOG) and other comon_io / dbms libraries (without WITH_TEXT_LOG), the Loggers class definition conflicts.

Above is my explanation. as for the mini-clickhouse-keeper without text log, its link dependencies have no change, will keep small. But may still have problem, becase clickhouse-keeper links loggers_no_text_log and clickhouse_common_io, the compile definition (WITH_TEXT_LOG) in loggers_no_text_log not exposed to clickhouse_common_io.
target_link_libraries(clickhouse-keeper
PRIVATE
...
loggers_no_text_log
clickhouse_common_io
)

At last,it seems no easy way to fix this problem gracefully now, just the whole compile target dependency is not struct in modern CMake way https://gist.github.com/mbinna/c61dbb39bca0e4fb7d1f73b0d66a4fd1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i make a separate PR for typo fix here, #40984

@serxa serxa assigned novikd and unassigned serxa Sep 5, 2022
@Lucky-Chang Lucky-Chang changed the title Fix macOS build and some typos Fix macOS build Sep 6, 2022
@novikd
Copy link
Member

novikd commented Sep 19, 2022

Problem is fixed in #41060

@novikd novikd closed this Sep 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
can be tested Allows running workflows for external contributors pr-build Pull request with build/testing/packaging improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants