@@ -94,55 +94,56 @@ def get_version(pkg_path):
94
94
device_library_dirs .append (str (lib_dirs [0 ].parent ))
95
95
96
96
97
- def nanoarrow_extension (
98
- name , * , nanoarrow_c = False , nanoarrow_device = False , nanoarrow_ipc = False
99
- ):
100
- sources = ["src/" + name .replace ("." , "/" ) + ".pyx" ]
101
- libraries = []
102
- library_dirs = []
103
- include_dirs = ["src/nanoarrow" , "vendor" ]
104
- define_macros = list (extra_define_macros )
105
-
106
- if nanoarrow_c :
107
- sources .append ("vendor/nanoarrow.c" )
108
-
109
- if nanoarrow_device :
110
- sources .append ("vendor/nanoarrow_device.c" )
111
- include_dirs .extend (device_include_dirs )
112
- libraries .extend (device_libraries )
113
- library_dirs .extend (device_library_dirs )
114
- define_macros .extend (device_define_macros )
115
-
116
- if nanoarrow_ipc :
117
- sources .extend (["vendor/nanoarrow_ipc.c" , "vendor/flatcc.c" ])
97
+ # This mechanism to build a static c library against which extensions
98
+ # can be linked is not well documented but is a better solution than
99
+ # simply including these files as sources to the extensions that need
100
+ # them. A more robust solution would be to use Meson or CMake to build
101
+ # the Python extensions since they can both build a shared nanoarrow
102
+ # and link it. This mechanism is the build_clib command available in
103
+ # setuptools (and previously from distutils).
104
+ common_libraries = [
105
+ [
106
+ "nanoarrow_python_shared" ,
107
+ {
108
+ "sources" : [
109
+ "vendor/nanoarrow.c" ,
110
+ "vendor/nanoarrow_device.c" ,
111
+ "vendor/nanoarrow_ipc.c" ,
112
+ "vendor/flatcc.c" ,
113
+ ],
114
+ "include_dirs" : ["vendor" ] + device_include_dirs ,
115
+ "libraries" : device_libraries ,
116
+ "library_dirs" : device_library_dirs ,
117
+ "macros" : extra_define_macros + device_define_macros ,
118
+ },
119
+ ]
120
+ ]
121
+
118
122
123
+ def nanoarrow_extension (name , * , link_device = False ):
119
124
return Extension (
120
125
name = name ,
121
- include_dirs = include_dirs ,
126
+ include_dirs = [ "vendor" , "src/nanoarrow" ] ,
122
127
language = "c" ,
123
- sources = sources ,
128
+ sources = [ "src/" + name . replace ( "." , "/" ) + ".pyx" ] ,
124
129
extra_compile_args = extra_compile_args ,
125
130
extra_link_args = extra_link_args ,
126
- define_macros = define_macros ,
127
- library_dirs = library_dirs ,
128
- libraries = libraries ,
131
+ define_macros = extra_define_macros + device_define_macros ,
132
+ libraries = ["nanoarrow_python_shared" ] + device_libraries if link_device else [],
129
133
)
130
134
131
135
132
136
setup (
133
137
ext_modules = [
134
138
nanoarrow_extension ("nanoarrow._types" ),
135
- nanoarrow_extension ("nanoarrow._utils" , nanoarrow_c = True ),
136
- nanoarrow_extension (
137
- "nanoarrow._device" , nanoarrow_c = True , nanoarrow_device = True
138
- ),
139
- nanoarrow_extension (
140
- "nanoarrow._array" , nanoarrow_c = True , nanoarrow_device = True
141
- ),
142
- nanoarrow_extension ("nanoarrow._array_stream" , nanoarrow_c = True ),
143
- nanoarrow_extension ("nanoarrow._buffer" , nanoarrow_c = True ),
144
- nanoarrow_extension ("nanoarrow._ipc_lib" , nanoarrow_c = True , nanoarrow_ipc = True ),
145
- nanoarrow_extension ("nanoarrow._schema" , nanoarrow_c = True ),
139
+ nanoarrow_extension ("nanoarrow._utils" ),
140
+ nanoarrow_extension ("nanoarrow._device" , link_device = True ),
141
+ nanoarrow_extension ("nanoarrow._array" , link_device = True ),
142
+ nanoarrow_extension ("nanoarrow._array_stream" ),
143
+ nanoarrow_extension ("nanoarrow._buffer" ),
144
+ nanoarrow_extension ("nanoarrow._ipc_lib" ),
145
+ nanoarrow_extension ("nanoarrow._schema" ),
146
146
],
147
147
version = version ,
148
+ libraries = common_libraries ,
148
149
)
0 commit comments