Skip to content

Commit 2ce4c9b

Browse files
authored
cpp: allow application to determine visibility attributes (#1431)
### Changelog <!-- Write a one-sentence summary of the user-impacting change (API, UI/UX, performance, etc) that could appear in a changelog. Write "None" if there is no user-facing change --> ### Docs <!-- Link to a Docs PR, tracking ticket in Linear, OR write "None" if no documentation changes are needed. --> ### Description Proposed as an alternative to #1380. Adds an `#ifndef` guard around the existing definition logic in `visibility.hpp`. This allows application code to determine the meaning of MCAP_PUBLIC directly, if the implementation in `visibility.hpp` doesn't work for them. <!-- Describe the problem, what has changed, and motivation behind those changes. Pretend you are advocating for this change and the reader is skeptical. --> <!-- In addition to unit tests, describe any manual testing you did to validate this change. --> <table><tr><th>Before</th><th>After</th></tr><tr><td> <!--before content goes here--> </td><td> <!--after content goes here--> </td></tr></table> <!-- If necessary, link relevant Linear or Github issues. Use `Fixes: foxglove/repo#1234` to auto-close the Github issue or Fixes: FG-### for Linear isses. -->
1 parent d295dc2 commit 2ce4c9b

File tree

10 files changed

+39
-21
lines changed

10 files changed

+39
-21
lines changed

cpp/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,20 @@ Refer to the API documentation in
109109
for full details. The high-level interfaces for reading and writing are
110110
`McapReader` and `McapWriter`.
111111

112+
### Visibility
113+
114+
By default, the MCAP library will attempt to export its symbols from the translation unit where
115+
`MCAP_IMPLEMENTATION` is defined, and import them elsewhere. See `mcap/visibility.hpp` for exact
116+
semantics. If your application requires something different, you can define the `MCAP_PUBLIC` macro
117+
before including the library.
118+
119+
```cpp
120+
// use the MCAP library internally but keep all symbols hidden
121+
#define MCAP_IMPLEMENTATION
122+
#define MCAP_PUBLIC __attribute__((visibility("hidden")))
123+
#include <mcap/writer.hpp>
124+
```
125+
112126
## Releasing new versions
113127
114128
1. Update the `#define MCAP_LIBRARY_VERSION` and all other occurrences of the same version number, e.g. in `conanfile.py`, `build.sh`, and others.

cpp/bench/conanfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
class McapBenchmarksConan(ConanFile):
55
settings = "os", "compiler", "build_type", "arch"
66
generators = "cmake"
7-
requires = "benchmark/1.7.0", "mcap/2.0.2"
7+
requires = "benchmark/1.7.0", "mcap/2.1.0"
88

99
def build(self):
1010
cmake = CMake(self)

cpp/build-docs.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -e
44

55
conan config init
66

7-
conan editable add ./mcap mcap/2.0.2
7+
conan editable add ./mcap mcap/2.1.0
88
conan install docs --install-folder docs/build/Release \
99
-s compiler.cppstd=17 -s build_type=Release --build missing
1010

cpp/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -e
44

55
conan config init
66

7-
conan editable add ./mcap mcap/2.0.2
7+
conan editable add ./mcap mcap/2.1.0
88
conan install test --install-folder test/build/Debug \
99
-s compiler.cppstd=17 -s build_type=Debug --build missing
1010

cpp/docs/conanfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
class McapDocsConan(ConanFile):
55
settings = "os", "compiler", "build_type", "arch"
66
generators = "cmake"
7-
requires = "mcap/2.0.2"
7+
requires = "mcap/2.1.0"
88

99
def build(self):
1010
cmake = CMake(self)

cpp/examples/conanfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class McapExamplesConan(ConanFile):
55
settings = "os", "compiler", "build_type", "arch"
66
generators = "cmake"
77
requires = [
8-
"mcap/2.0.2",
8+
"mcap/2.1.0",
99
"protobuf/3.21.1",
1010
"nlohmann_json/3.10.5",
1111
"catch2/2.13.8",

cpp/mcap/conanfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
class McapConan(ConanFile):
55
name = "mcap"
6-
version = "2.0.2"
6+
version = "2.1.0"
77
url = "https://github.com/foxglove/mcap"
88
homepage = "https://github.com/foxglove/mcap"
99
description = "A C++ implementation of the MCAP file format"

cpp/mcap/include/mcap/types.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
namespace mcap {
1616

17-
#define MCAP_LIBRARY_VERSION "2.0.2"
17+
#define MCAP_LIBRARY_VERSION "2.1.0"
1818

1919
using SchemaId = uint16_t;
2020
using ChannelId = uint16_t;
Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
1-
#pragma once
2-
1+
/** Defines an MCAP_PUBLIC visibility attribute macro, which is used on all public interfaces.
2+
* This can be defined before including `mcap.hpp` to directly control symbol visibility.
3+
* If not defined externally, this library attempts to export symbols from the translation unit
4+
* where MCAP_IMPLEMENTATION is defined, and import them anywhere else.
5+
*/
6+
#ifndef MCAP_PUBLIC
37
#if defined _WIN32 || defined __CYGWIN__
4-
# ifdef __GNUC__
5-
# define MCAP_EXPORT __attribute__((dllexport))
6-
# define MCAP_IMPORT __attribute__((dllimport))
7-
# else
8-
# define MCAP_EXPORT __declspec(dllexport)
9-
# define MCAP_IMPORT __declspec(dllimport)
10-
# endif
118
# ifdef MCAP_IMPLEMENTATION
12-
# define MCAP_PUBLIC MCAP_EXPORT
9+
# ifdef __GNUC__
10+
# define MCAP_PUBLIC __attribute__((dllexport))
11+
# else
12+
# define MCAP_PUBLIC __declspec(dllexport)
13+
# endif
1314
# else
14-
# define MCAP_PUBLIC MCAP_IMPORT
15+
# ifdef __GNUC__
16+
# define MCAP_PUBLIC __attribute__((dllimport))
17+
# else
18+
# define MCAP_PUBLIC __declspec(dllimport)
19+
# endif
1520
# endif
1621
#else
17-
# define MCAP_EXPORT __attribute__((visibility("default")))
18-
# define MCAP_IMPORT
1922
# if __GNUC__ >= 4
2023
# define MCAP_PUBLIC __attribute__((visibility("default")))
2124
# else
2225
# define MCAP_PUBLIC
2326
# endif
2427
#endif
28+
#endif

cpp/test/conanfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
class McapTestConan(ConanFile):
55
settings = "os", "compiler", "build_type", "arch"
66
generators = "cmake"
7-
requires = "catch2/2.13.8", "mcap/2.0.2", "nlohmann_json/3.10.5"
7+
requires = "catch2/2.13.8", "mcap/2.1.0", "nlohmann_json/3.10.5"
88

99
def build(self):
1010
cmake = CMake(self)

0 commit comments

Comments
 (0)