11
11
BUILD_DIR = os .path .join (HERE , "pymongoarrow" )
12
12
IS_WIN = platform == "win32"
13
13
14
- # Find and copy the binary arrow files, unless
15
- # MONGO_NO_COPY_ARROW_LIB is set (for instance in a conda build).
16
- # Wheels are meant to be self-contained, per PEP 513.
17
- # https://www.python.org/dev/peps/pep-0513/#id40
18
- # Conda has the opposite philosphy, where libraries are meant to be
19
- # shared. For instance, there is an arrow-cpp library available on conda-forge
20
- # that provides the libarrow files.
21
- COPY_LIBARROW = not os .environ .get ("MONGO_NO_COPY_LIBARROW" , False )
22
-
23
14
# Find and copy the binary libbson file, unless
24
15
# MONGO_NO_COPY_LIBBSON is set (for instance in a conda build).
25
16
COPY_LIBBSON = not os .environ .get ("MONGO_NO_COPY_LIBBSON" , False )
@@ -47,6 +38,7 @@ def append_libbson_flags(module):
47
38
install_dir = os .environ .get ("LIBBSON_INSTALL_DIR" )
48
39
if install_dir :
49
40
install_dir = os .path .abspath (install_dir )
41
+
50
42
# Handle the copy-able library file if applicable.
51
43
if COPY_LIBBSON :
52
44
if platform == "darwin" :
@@ -62,6 +54,14 @@ def append_libbson_flags(module):
62
54
if os .path .exists (lib_file ):
63
55
shutil .copy (lib_file , BUILD_DIR )
64
56
57
+ # Ensure our Cython extension can dynamically link to libraries
58
+ # - https://blog.krzyzanowskim.com/2018/12/05/rpath-what/
59
+ # - https://nehckl0.medium.com/creating-relocatable-linux-executables-by-setting-rpath-with-origin-45de573a2e98
60
+ if platform == "darwin" :
61
+ module .extra_link_args += ["-rpath" , "@loader_path" ]
62
+ elif platform == "linux" :
63
+ module .extra_link_args += ["-Wl,-rpath,$ORIGIN" ]
64
+
65
65
# Find the linkable library file, and explicity add it to the linker if on Windows.
66
66
lib_dirs = glob .glob (os .path .join (install_dir , "lib*" ))
67
67
if len (lib_dirs ) != 1 :
@@ -125,64 +125,33 @@ def append_libbson_flags(module):
125
125
module .libraries .extend (libnames )
126
126
127
127
128
- def append_arrow_flags (module ):
128
+ def append_arrow_flags (ext ):
129
129
import numpy as np
130
130
import pyarrow as pa
131
131
132
- if IS_WIN :
133
- module .include_dirs .append (np .get_include ())
134
- module .include_dirs .append (pa .get_include ())
135
- else :
136
- module .extra_compile_args .append ("-isystem" + pa .get_include ())
137
- module .extra_compile_args .append ("-isystem" + np .get_include ())
138
- # Arrow's manylinux{2010, 2014} binaries are built with gcc < 4.8 which predates CXX11 ABI
139
- # - https://uwekorn.com/2019/09/15/how-we-build-apache-arrows-manylinux-wheels.html
140
- # - https://arrow.apache.org/docs/python/extending.html#example
141
- if "std=" not in os .environ .get ("CXXFLAGS" , "" ):
142
- module .extra_compile_args .append ("-std=c++11" )
143
- module .extra_compile_args .append ("-D_GLIBCXX_USE_CXX11_ABI=0" )
144
-
145
- # Handle the arrow library files manually.
146
- # Alternative to using pyarrow.create_library_symlinks().
147
- # You can use MONGO_LIBARROW_DIR to explicitly set the location of the
148
- # arrow libraries (for instance in a conda build).
149
- # We first check for an unmodified path to the library,
150
- # then look for a library file with a version modifier, e.g. libarrow.600.dylib.
151
- arrow_lib = os .environ .get ("MONGO_LIBARROW_DIR" , pa .get_library_dirs ()[0 ])
152
- if platform == "darwin" :
153
- exts = [".dylib" , ".*.dylib" ]
154
- elif platform == "linux" :
155
- exts = [".so" , ".so.*" ]
156
- else :
157
- # Windows is handled differently (see below)
158
- pass
159
-
160
- # Find the appropriate library file and optionally copy it locally.
161
- # Explicitly handle "parquet" library as a workaround for
162
- # https://issues.apache.org/jira/browse/ARROW-17327
163
- for name in pa .get_libraries () + ["parquet" ]:
164
- if IS_WIN :
165
- if COPY_LIBARROW :
166
- lib_file = os .path .join (arrow_lib , f"{ name } .dll" )
167
- if not os .path .exists (lib_file ):
168
- if name == "parquet" :
169
- continue
170
- raise ValueError ("Could not find compiled arrow library" )
171
- shutil .copy (lib_file , BUILD_DIR )
172
- lib_file = os .path .join (arrow_lib , f"{ name } .lib" )
173
- module .extra_link_args .append (lib_file )
174
- continue
175
-
176
- for ext in exts :
177
- files = glob .glob (os .path .join (arrow_lib , f"lib{ name } { ext } " ))
178
- if not files :
179
- continue
180
- path = files [0 ]
181
- if COPY_LIBARROW :
182
- shutil .copy (path , BUILD_DIR )
183
- path = os .path .join (BUILD_DIR , os .path .basename (path ))
184
- module .extra_link_args .append (path )
185
- break
132
+ # From https://arrow.apache.org/docs/python/integration/extending.html#example
133
+ # The Numpy C headers are currently required
134
+ ext .include_dirs .append (np .get_include ())
135
+ ext .include_dirs .append (pa .get_include ())
136
+ ext .libraries .extend (pa .get_libraries ())
137
+ ext .library_dirs .extend (pa .get_library_dirs ())
138
+
139
+ if os .name != "nt" :
140
+ # On Linux and MacOS, we must run pyarrow.create_library_symlinks()
141
+ # as a user with write access to the directory where pyarrow is
142
+ # installed.
143
+ # See https://arrow.apache.org/docs/python/integration/extending.html#building-extensions-against-pypi-wheels.
144
+ pa .create_library_symlinks ()
145
+
146
+ if os .name == "posix" :
147
+ ext .extra_compile_args .append ("-std=c++11" )
148
+
149
+ # Arrow's manylinux{2010, 2014} binaries are built with gcc < 4.8 which predates CXX11 ABI
150
+ # - https://uwekorn.com/2019/09/15/how-we-build-apache-arrows-manylinux-wheels.html
151
+ # - https://arrow.apache.org/docs/python/extending.html#example
152
+ if "std=" not in os .environ .get ("CXXFLAGS" , "" ):
153
+ ext .extra_compile_args .append ("-std=c++11" )
154
+ ext .extra_compile_args .append ("-D_GLIBCXX_USE_CXX11_ABI=0" )
186
155
187
156
188
157
def get_extension_modules ():
@@ -197,13 +166,6 @@ def get_extension_modules():
197
166
for module in modules :
198
167
append_libbson_flags (module )
199
168
append_arrow_flags (module )
200
- # Ensure our Cython extension can dynamically link to libraries
201
- # - https://blog.krzyzanowskim.com/2018/12/05/rpath-what/
202
- # - https://nehckl0.medium.com/creating-relocatable-linux-executables-by-setting-rpath-with-origin-45de573a2e98
203
- if platform == "darwin" :
204
- module .extra_link_args += ["-rpath" , "@loader_path" ]
205
- elif platform == "linux" :
206
- module .extra_link_args += ["-Wl,-rpath,$ORIGIN" ]
207
169
208
170
return modules
209
171
0 commit comments