1818# Whether to create libarrow symlinks on posix systems.
1919CREATE_LIBARROW_SYMLINKS = os .environ .get ("MONGO_CREATE_LIBARROW_SYMLINKS" , "1" )
2020
21+ LIBBSON_VERSION = os .environ .get ("LIBBSON_VERSION" , "1.0.0" )
22+
2123# Set a default value for MACOSX_DEPLOYMENT_TARGET.
2224os .environ .setdefault ("MACOSX_DEPLOYMENT_TARGET" , "10.15" )
2325
@@ -40,19 +42,20 @@ def get_min_libbson_version():
4042
4143
4244def append_libbson_flags (module ):
43- pc_path = "libbson-1.0"
45+ BSON_MAJOR_VERSION = int (LIBBSON_VERSION [0 ])
46+ pc_path = "libbson-1.0" if BSON_MAJOR_VERSION == 1 else "bson2"
4447 install_dir = os .environ .get ("LIBBSON_INSTALL_DIR" )
4548 if install_dir :
4649 install_dir = os .path .abspath (install_dir )
4750
4851 # Handle the copy-able library file if applicable.
4952 if COPY_LIBBSON :
5053 if platform == "darwin" :
51- lib_file = "libbson-1.0.0.dylib"
54+ lib_file = "libbson-1.0.0.dylib" if BSON_MAJOR_VERSION == 1 else "bson2.dylib"
5255 elif platform == "linux" :
53- lib_file = "libbson-1.0.so.0"
56+ lib_file = "libbson-1.0.so.0" if BSON_MAJOR_VERSION == 1 else "bson2.so.0"
5457 else : # windows
55- lib_file = "bson-1.0.dll"
58+ lib_file = "bson-1.0.dll" if BSON_MAJOR_VERSION == 1 else "bson2.dll"
5659 lib_dir = "bin" if IS_WIN else "lib*"
5760 lib_dir = glob .glob (os .path .join (install_dir , lib_dir ))
5861 if lib_dir :
@@ -81,16 +84,18 @@ def append_libbson_flags(module):
8184 if IS_WIN :
8285 # Note: we replace any forward slashes with backslashes so the path
8386 # can be parsed by bash.
84- lib_path = os .path .join (lib_dir , "bson-1.0.lib" ).replace (os .sep , "/" )
87+ bson_lib = "bson-1.0.lib" if BSON_MAJOR_VERSION == 1 else "bson2.lib"
88+ lib_path = os .path .join (lib_dir , bson_lib ).replace (os .sep , "/" )
8589 if os .path .exists (lib_path ):
8690 module .extra_link_args = [lib_path ]
87- include_dir = os .path .join (install_dir , "include" , "libbson-1.0" ).replace (
91+ include_path = "libbson-1.0" if BSON_MAJOR_VERSION == 1 else "bson2"
92+ include_dir = os .path .join (install_dir , "include" , include_path ).replace (
8893 os .sep , "/"
8994 )
9095 module .include_dirs .append (include_dir )
9196 else :
9297 raise ValueError (f"Could not find the compiled libbson in { install_dir } " )
93- pc_path = os .path .join (install_dir , lib_dir , "pkgconfig" , "libbson-1.0 .pc" )
98+ pc_path = os .path .join (install_dir , lib_dir , "pkgconfig" , f" { pc_path } .pc" )
9499
95100 elif IS_WIN :
96101 raise ValueError ("We require a LIBBSON_INSTALL_DIR with a compiled library on Windows" )
0 commit comments