77from os import path
88import os
99import sys
10+ from sys import platform
1011from shutil import copy
1112import glob
1213
3839
3940if isBuildExtEnabled == 'true' :
4041 from Cython .Distutils import build_ext
42+ from Cython .Build import cythonize
4143 import os
4244 import pyarrow
4345
44- extensions = [
45- Extension (name = 'snowflake.connector.arrow_result' , sources = ['arrow_result.pyx' ]),
46- Extension (name = 'snowflake.connector.arrow_iterator' , sources = ['arrow_iterator.pyx' ,
47- 'cpp/ArrowIterator/CArrowChunkIterator.cpp' ,
48- 'cpp/ArrowIterator/IntConverter.cpp' ,
49- 'cpp/ArrowIterator/StringConverter.cpp' ],
50- extra_compile_args = ['-std=c++11' ],
51- extra_link_args = ['-Wl,-rpath,$ORIGIN' ],
52- language = 'c++'
53- ),
54- ]
46+ extensions = cythonize (
47+ [
48+ Extension (name = 'snowflake.connector.arrow_iterator' , sources = ['arrow_iterator.pyx' ]),
49+ Extension (name = 'snowflake.connector.arrow_result' , sources = ['arrow_result.pyx' ])
50+ ],
51+ build_dir = os .path .join ('build' , 'cython' ))
5552
5653 class MyBuildExt (build_ext ):
5754
@@ -61,36 +58,50 @@ def build_extension(self, ext):
6158 if ext .name == 'snowflake.connector.arrow_iterator' :
6259 self ._copy_arrow_lib ()
6360
64- ext .include_dirs .append (self ._get_arrow_include_dir ())
61+ ext .sources += ['cpp/ArrowIterator/CArrowChunkIterator.cpp' ,
62+ 'cpp/ArrowIterator/FloatConverter.cpp' ,
63+ 'cpp/ArrowIterator/IntConverter.cpp' ,
64+ 'cpp/ArrowIterator/StringConverter.cpp' ]
65+ ext .include_dirs .append ('cpp/ArrowIterator/' )
66+ ext .include_dirs .append (pyarrow .get_include ())
67+
68+ ext .extra_compile_args .append ('-std=c++11' )
69+
6570 ext .library_dirs .append (os .path .join (current_dir , self .build_lib , 'snowflake' , 'connector' ))
6671 ext .extra_link_args += self ._get_arrow_lib_as_linker_input ()
72+ ext .extra_link_args += ['-Wl,-rpath,$ORIGIN' ]
6773
6874 build_ext .build_extension (self , ext )
6975
70- def _get_arrow_include_dir (self ):
71- return pyarrow .get_include ()
72-
7376 def _get_arrow_lib_dir (self ):
7477 return pyarrow .get_library_dirs ()[0 ]
7578
7679 def _copy_arrow_lib (self ):
7780 arrow_lib = pyarrow .get_libraries () + \
7881 ['arrow_flight' , 'arrow_boost_regex' , 'arrow_boost_system' , 'arrow_boost_filesystem' ]
7982 for lib in arrow_lib :
80- lib_pattern = '{}/lib{}.so*' . format ( self ._get_arrow_lib_dir (), lib )
83+ lib_pattern = self ._get_pyarrow_lib_pattern ( lib )
8184 source = glob .glob (lib_pattern )[0 ]
8285 copy (source , os .path .join (self .build_lib , 'snowflake' , 'connector' ))
8386
8487 def _get_arrow_lib_as_linker_input (self ):
8588 arrow_lib = pyarrow .get_libraries ()
8689 link_lib = []
8790 for lib in arrow_lib :
88- lib_pattern = '{}/lib{}.so*' . format ( self ._get_arrow_lib_dir (), lib )
91+ lib_pattern = self ._get_pyarrow_lib_pattern ( lib )
8992 source = glob .glob (lib_pattern )[0 ]
9093 link_lib .append (source )
9194
9295 return link_lib
9396
97+ def _get_pyarrow_lib_pattern (self , lib_name ):
98+ if platform .startswith ('linux' ):
99+ return '{}/lib{}.so*' .format (self ._get_arrow_lib_dir (), lib_name )
100+ elif platform == 'darwin' :
101+ return '{}/lib{}*dylib' .format (self ._get_arrow_lib_dir (), lib_name )
102+ else :
103+ raise RuntimeError ('Building on platform {} is not supported yet.' .format (platform ))
104+
94105 cmd_class = {
95106 "build_ext" : MyBuildExt
96107 }
@@ -165,8 +176,8 @@ def _get_arrow_lib_as_linker_input(self):
165176 'keyring!=16.1.0'
166177 ],
167178 "arrow-result" : [
168- 'pyarrow>=0.13 .0;python_version>"3.4"' ,
169- 'pyarrow>=0.13 .0;python_version<"3.0"'
179+ 'pyarrow>=0.14 .0;python_version>"3.4"' ,
180+ 'pyarrow>=0.14 .0;python_version<"3.0"'
170181 ]
171182 },
172183
0 commit comments