From 5a6edc367d18f6399e643b2c3c8bb30f862812be Mon Sep 17 00:00:00 2001 From: Sergiu Deitsch Date: Tue, 18 May 2021 14:38:55 +0200 Subject: [PATCH] export missed symbols Enable `-fvisibility=hidden` and `-fvisibility-inlines-hidden` by default in CI builds to ensure all public symbols are exported correctly. --- .github/workflows/linux.yml | 4 +++- .github/workflows/macos.yml | 5 ++++- include/fmt/core.h | 4 ++++ include/fmt/format.h | 12 ++++++------ include/fmt/os.h | 4 ++-- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 4c9794bc48bbb..0f0d7bf50e86f 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -44,6 +44,7 @@ jobs: cxxflags: -stdlib=libc++ os: ubuntu-20.04 install: sudo apt install libc++-11-dev libc++abi-11-dev + - shared: -DBUILD_SHARED_LIBS=ON steps: - uses: actions/checkout@v2 @@ -59,8 +60,9 @@ jobs: CXX: ${{matrix.cxx}} CXXFLAGS: ${{matrix.cxxflags}} run: | - cmake -DCMAKE_BUILD_TYPE=${{matrix.build_type}} ${{matrix.fuzz}} \ + cmake -DCMAKE_BUILD_TYPE=${{matrix.build_type}} ${{matrix.fuzz}} ${{matrix.shared}} \ -DCMAKE_CXX_STANDARD=${{matrix.std}} -DFMT_DOC=OFF \ + -DCMAKE_CXX_VISIBILITY_PRESET=hidden -DCMAKE_VISIBILITY_INLINES_HIDDEN=ON \ -DFMT_PEDANTIC=ON -DFMT_WERROR=ON $GITHUB_WORKSPACE - name: Build diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 2fc67afbf1371..f62dbdc66a79c 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -8,6 +8,8 @@ jobs: strategy: matrix: build_type: [Debug, Release] + include: + - shared: -DBUILD_SHARED_LIBS=ON steps: - uses: actions/checkout@v2 @@ -18,7 +20,8 @@ jobs: - name: Configure working-directory: ${{runner.workspace}}/build run: | - cmake -DCMAKE_BUILD_TYPE=${{matrix.build_type}} \ + cmake -DCMAKE_BUILD_TYPE=${{matrix.build_type}} ${{matrix.shared}} \ + -DCMAKE_CXX_VISIBILITY_PRESET=hidden -DCMAKE_VISIBILITY_INLINES_HIDDEN=ON \ -DFMT_DOC=OFF -DFMT_PEDANTIC=ON -DFMT_WERROR=ON $GITHUB_WORKSPACE - name: Build diff --git a/include/fmt/core.h b/include/fmt/core.h index 60d1e76457c5a..64af7e8db580b 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -253,6 +253,10 @@ # endif #else # define FMT_CLASS_API +# if defined(__GNUC__) || defined(__clang__) +# define FMT_API __attribute__((visibility("default"))) +# define FMT_EXTERN_TEMPLATE_API FMT_API +# endif #endif #ifndef FMT_API # define FMT_API diff --git a/include/fmt/format.h b/include/fmt/format.h index 44f9048987125..00a7bf26e4c8a 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -850,7 +850,7 @@ template struct basic_data { // GCC generates slightly better code for pairs than chars. using digit_pair = char[2]; - static constexpr const digit_pair digits[] = { + FMT_API static constexpr const digit_pair digits[] = { {'0', '0'}, {'0', '1'}, {'0', '2'}, {'0', '3'}, {'0', '4'}, {'0', '5'}, {'0', '6'}, {'0', '7'}, {'0', '8'}, {'0', '9'}, {'1', '0'}, {'1', '1'}, {'1', '2'}, {'1', '3'}, {'1', '4'}, {'1', '5'}, {'1', '6'}, {'1', '7'}, @@ -869,12 +869,12 @@ template struct basic_data { {'9', '0'}, {'9', '1'}, {'9', '2'}, {'9', '3'}, {'9', '4'}, {'9', '5'}, {'9', '6'}, {'9', '7'}, {'9', '8'}, {'9', '9'}}; - static constexpr const char hex_digits[] = "0123456789abcdef"; - static constexpr const char signs[] = {0, '-', '+', ' '}; - static constexpr const unsigned prefixes[4] = {0, 0, 0x1000000u | '+', + FMT_API static constexpr const char hex_digits[] = "0123456789abcdef"; + FMT_API static constexpr const char signs[] = {0, '-', '+', ' '}; + FMT_API static constexpr const unsigned prefixes[4] = {0, 0, 0x1000000u | '+', 0x1000000u | ' '}; - static constexpr const char left_padding_shifts[] = {31, 31, 0, 1, 0}; - static constexpr const char right_padding_shifts[] = {0, 31, 0, 1, 0}; + FMT_API static constexpr const char left_padding_shifts[] = {31, 31, 0, 1, 0}; + FMT_API static constexpr const char right_padding_shifts[] = {0, 31, 0, 1, 0}; }; // This is a struct rather than an alias to avoid shadowing warnings in gcc. diff --git a/include/fmt/os.h b/include/fmt/os.h index 1a8833def4805..1e7f966af45bc 100644 --- a/include/fmt/os.h +++ b/include/fmt/os.h @@ -394,7 +394,7 @@ struct ostream_params { static constexpr detail::buffer_size buffer_size; /** A fast output stream which is not thread-safe. */ -class ostream final : private detail::buffer { +class FMT_API ostream final : private detail::buffer { private: file file_; @@ -404,7 +404,7 @@ class ostream final : private detail::buffer { clear(); } - FMT_API void grow(size_t) override final; + void grow(size_t) override; ostream(cstring_view path, const detail::ostream_params& params) : file_(path, params.oflag) {