-
Notifications
You must be signed in to change notification settings - Fork 501
consistent DSO symbol export across POSIX/Windows + SOCI_DLL usage (redux) #1273
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
Conversation
… found at all (usually means --recurse-submodules wasn't used)
…r dynamic build
modified: include/soci/soci-platform.h
Ensure SOCI_DLL controls all visibility + update comments
modified: src/core/CMakeLists.txt
Use DEFINE_SYMBOL to handle SOCI_SOURCE definition
modified: src/core/backend-loader.cpp
modified: src/core/blob.cpp
modified: src/core/common.cpp
modified: src/core/connection-parameters.cpp
modified: src/core/connection-pool.cpp
modified: src/core/error.cpp
modified: src/core/into-type.cpp
modified: src/core/logger.cpp
modified: src/core/once-temp-type.cpp
modified: src/core/prepare-temp-type.cpp
modified: src/core/procedure.cpp
modified: src/core/ref-counted-prepare-info.cpp
modified: src/core/ref-counted-statement.cpp
modified: src/core/row.cpp
modified: src/core/rowid.cpp
modified: src/core/session.cpp
modified: src/core/soci-simple.cpp
modified: src/core/statement.cpp
modified: src/core/transaction.cpp
modified: src/core/unicode.cpp
modified: src/core/use-type.cpp
modified: src/core/values.cpp
Remove SOCI_SOURCE definition
modified: src/backends/db2/blob.cpp modified: src/backends/db2/factory.cpp modified: src/backends/db2/row-id.cpp modified: src/backends/db2/session.cpp modified: src/backends/db2/standard-into-type.cpp modified: src/backends/db2/standard-use-type.cpp modified: src/backends/db2/statement.cpp modified: src/backends/db2/vector-into-type.cpp modified: src/backends/db2/vector-use-type.cpp
modified: src/backends/empty/blob.cpp modified: src/backends/empty/factory.cpp modified: src/backends/empty/row-id.cpp modified: src/backends/empty/session.cpp modified: src/backends/empty/standard-into-type.cpp modified: src/backends/empty/standard-use-type.cpp modified: src/backends/empty/statement.cpp modified: src/backends/empty/vector-into-type.cpp modified: src/backends/empty/vector-use-type.cpp
modified: src/backends/firebird/blob.cpp modified: src/backends/firebird/common.cpp modified: src/backends/firebird/error-firebird.cpp modified: src/backends/firebird/factory.cpp modified: src/backends/firebird/session.cpp modified: src/backends/firebird/standard-into-type.cpp modified: src/backends/firebird/standard-use-type.cpp modified: src/backends/firebird/statement.cpp modified: src/backends/firebird/vector-into-type.cpp modified: src/backends/firebird/vector-use-type.cpp
modified: src/backends/mysql/blob.cpp modified: src/backends/mysql/common.cpp modified: src/backends/mysql/error.cpp modified: src/backends/mysql/factory.cpp modified: src/backends/mysql/row-id.cpp modified: src/backends/mysql/session.cpp modified: src/backends/mysql/standard-into-type.cpp modified: src/backends/mysql/standard-use-type.cpp modified: src/backends/mysql/statement.cpp modified: src/backends/mysql/vector-into-type.cpp modified: src/backends/mysql/vector-use-type.cpp
modified: src/backends/odbc/blob.cpp modified: src/backends/odbc/error.cpp modified: src/backends/odbc/factory.cpp modified: src/backends/odbc/row-id.cpp modified: src/backends/odbc/session.cpp modified: src/backends/odbc/standard-into-type.cpp modified: src/backends/odbc/standard-use-type.cpp modified: src/backends/odbc/statement.cpp modified: src/backends/odbc/vector-into-type.cpp modified: src/backends/odbc/vector-use-type.cpp
modified: src/backends/oracle/blob.cpp modified: src/backends/oracle/error.cpp modified: src/backends/oracle/factory.cpp modified: src/backends/oracle/row-id.cpp modified: src/backends/oracle/session.cpp modified: src/backends/oracle/standard-into-type.cpp modified: src/backends/oracle/standard-use-type.cpp modified: src/backends/oracle/statement.cpp modified: src/backends/oracle/vector-into-type.cpp modified: src/backends/oracle/vector-use-type.cpp
modified: src/backends/postgresql/blob.cpp modified: src/backends/postgresql/error.cpp modified: src/backends/postgresql/factory.cpp modified: src/backends/postgresql/row-id.cpp modified: src/backends/postgresql/session.cpp modified: src/backends/postgresql/standard-into-type.cpp modified: src/backends/postgresql/standard-use-type.cpp modified: src/backends/postgresql/statement.cpp modified: src/backends/postgresql/vector-into-type.cpp modified: src/backends/postgresql/vector-use-type.cpp
modified: src/backends/sqlite3/blob.cpp modified: src/backends/sqlite3/error.cpp modified: src/backends/sqlite3/factory.cpp modified: src/backends/sqlite3/row-id.cpp modified: src/backends/sqlite3/session.cpp modified: src/backends/sqlite3/standard-into-type.cpp modified: src/backends/sqlite3/standard-use-type.cpp modified: src/backends/sqlite3/statement.cpp modified: src/backends/sqlite3/vector-into-type.cpp modified: src/backends/sqlite3/vector-use-type.cpp
|
Ah, the failing CI stuff for SQLite3 seems like an IWYU error. I'll ensure |
In relation to this is Either way, that means the namespace sqlite_api
{
#include <sqlite3.h>
} // namespace sqlite_api |
…nclude modified: src/backends/sqlite3/error.cpp modified: src/backends/sqlite3/session.cpp modified: src/backends/sqlite3/standard-into-type.cpp modified: src/backends/sqlite3/standard-use-type.cpp modified: src/backends/sqlite3/statement.cpp modified: src/backends/sqlite3/vector-use-type.cpp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry, while I don't have any real objections to this PR, I just don't understand what do we gain by applying it. AFAICS the only real change is that SOCI_DLL is now defined under Unix too — which is, on one hand, weird (DLL is just not a Unix term) and, OTOH, could be done on its own without affecting anything else.
The PR summary speaks of consistent export, but what is inconsistent about it now? I.e. what problem does this fix?
FWIW this will create extra work for me, personally, as I don't use SOCI CMake build system in my own project, so I'll have to update it to define SOCI_XXX_SOURCE too and while this probably won't be very difficult, I don't see what justifies spending extra time on this when we could just... not apply this PR?
include/soci/sqlite3/soci-sqlite3.h
Outdated
| #else // !SOCI_SQLITE3_SOURCE | ||
| // We need just a couple of forward declarations to make this header itself | ||
| // compile. | ||
| // We don't include sqlite3.h from outside SOCI since this header may not |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't we keep this unchanged by just checking for SOCI_SOURCE instead of SOCI_SQLITE3_SOURCE? It looks like this would reduce the number of changes without any real drawbacks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each separate backend/library does need its own unique build-time macro to be defined to properly control symbol import/export (visibility, rather). So each possible DSO needs a separate macro name, as if for N libraries the same macro was used, where some of the libraries might rely on others' headers, you will get a lot of compile errors because the dependent libraries' symbols are being marked for export instead of import.
As mentioned below I can revert the #include-related changes for the sqlite3 backend sources by unconditionally defining SOCI_<backend>_SOURCE during the backend compilation, even if the backends are built as static libraries.
To me the inconsistency is when symbol visibility is applied. On Windows,
Sorry, was not aware of this :( But let me try my best to make some points.
It's pretty repetitive to have to manually I've gone back and thought about some things, and given how the Let me also address some of the code-related comments too. |
|
Ugh... did not remove the |
So let's just define
But this is already done and new source files (let alone new backends) are not added very often. So as it is, this just creates extra code churn without any apparent gain. |
|
To be fair, when adding new source files it can take quite some time to figure out that one has forgotten to define |
|
BTW, compiling under Windows right now defines symbols like |
Yep, this was the overall intention. In general my opinion is that stuff like macros defined during compilation should be handled by the build system so one can focus on writing the code itself, especially the case of import/export visibility macros, as a separate |
Yes, so originally I was relying on namespace sqlite_api
{
#include <sqlite3.h>
} // namespace sqlite_apiI think one decision that needs to be made is whether |
|
Sorry for complaining so much, but these CMake-related changes seem to be taking inordinate amount of the time which could (should?) be better spent on something more productive. It looks like 80% of the time I spend on SOCI is spent on struggling with CMake :-( And the Great CMake Rewrite didn't really improve this (I actually suspect the contrary, but maybe it's just because I'm particularly fed up with it right now). I'll probably end up applying this because I don't want your work to go to waste, but I'd like to return to this a bit later, once I am capable of thinking about CMake-related issues without so much loathing again. |
Haha, don't worry about it. CMake definitely helps with the messy reality of building C/C++ projects, but as much as I appreciate its usefulness, I also have moments where I wonder why some CMake things take so much work.
No problem; I'll periodically keep the branch up-to-date with HEAD but won't be adding to it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've looked at this again and this seems to be incomplete: if we remove, say, SOCI_FIREBIRD_SOURCE, we should remove the test for it in include/soci/firebird/soci-firebird.h and use SOCI_DECL instead of SOCI_FIREBIRD_DECL in this header etc (i.e. the same thing for all the other backends), shouldn't we?
Am I missing something here?
Use FATAL_ERROR if SQLite3 is not found at all (usually means --recurse-submodules wasn't used). See #1273.
|
Hey, thanks for reviewing. I'm a bit busy right now due to some work-related things but I'll get back to this when I can. |
Do you mean this part of the header? soci/include/soci/firebird/soci-firebird.h Lines 14 to 18 in ce34812
If so, no; this should remain as-is. It's because when building as shared, each of the backends is built as a separate shared library. If, for example, they all used So in SOCI's case:
This ensures that in the case of shared libraries being built, that for each backend, the corresponding Admittedly, the DLL design is a bit confusing at times. Although the idea of symbol visibility is good, the other option if not using the MSVC |
Sorry, rather embarrassingly, I have to admit that I don't know what I meant any more :-( Maybe I wanted to use a single So this is probably fine as is, although I'm still not sure if this results in any real changes in behaviour: I see that we won't be using I'll try to update my own project build system to predefine |
Yeah, unfortunately every backend library needs its own
This shouldn't be an issue unless someone is trying to build a DSO using SOCI object files and for whatever reason relies on some SOCI symbols being visible by default when compiling with
Thanks for your patience! |
Summary
Clean re-application of changes in #1192 after the 4.1 release.
See #1192 for the summary details with the following exceptions:
soci_backendhas been replaced withsoci_define_backend_targetcallbacks.hnow hasfailover_callbackfully inline so noSOCI_DECLis necessary anymoresoci_tests_common_staticdoesn't exist anymore since SOCI builds shared/static separately using CMake#1192 (comment) is still applicable here. One extra change is done to ensure that the CMake configuration step fails if the SOCI source tree was checked out without
--recurse-submoduleswhen an external SQLite3 installation is not available.Also, since
SOCI_<backend>_SOURCEis defined usingDEFINE_SYMBOL, it is not available when building static libraries. This means changes tosoci-sqlite3.hand the SQLite3 backend sources to have thesqlite3.hheader included in thesqlite3_apinamespace, and only included in the C++ source files, leaving only forward declarations insoci-sqlite3.h.