Skip to content

Commit

Permalink
Added compiler metadata (#21)
Browse files Browse the repository at this point in the history
The libraries must be compiled with the same version of the compiler and pybind11.
If they are compiled with different versions bad things happen.
Adding this data at compile time allows dependent libraries to validate compatibility.
  • Loading branch information
gentlegiantJGC authored Nov 29, 2024
1 parent 26cb13d commit 7c1fbbd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ add_subdirectory(submodules/leveldb-mcpe)
# Add python extension
pybind11_add_module(_leveldb src/leveldb/__init__leveldb.py.cpp)
target_compile_definitions(_leveldb PRIVATE PYBIND11_DETAILED_ERROR_MESSAGES)
target_compile_definitions(_leveldb PRIVATE PYBIND11_VERSION="${pybind11_VERSION}")
target_compile_definitions(_leveldb PRIVATE COMPILER_ID="${CMAKE_CXX_COMPILER_ID}")
target_compile_definitions(_leveldb PRIVATE COMPILER_VERSION="${CMAKE_CXX_COMPILER_VERSION}")
if (WIN32)
target_compile_definitions(_leveldb PRIVATE "DLLX=__declspec(dllimport)")
else()
Expand Down
6 changes: 6 additions & 0 deletions src/leveldb/__init__leveldb.py.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,12 @@ class LevelDBItemsRangeIterator {

static void init_module(py::module m)
{
py::dict compiler_config;
compiler_config["pybind11_version"] = PYBIND11_VERSION;
compiler_config["compiler_id"] = COMPILER_ID;
compiler_config["compiler_version"] = COMPILER_VERSION;
m.attr("compiler_config") = compiler_config;

py::register_local_exception<LevelDBException>(m, "LevelDBException");
py::register_local_exception<LevelDBEncrypted>(m, "LevelDBEncrypted");

Expand Down

0 comments on commit 7c1fbbd

Please sign in to comment.