jorisvandenbossche commented on code in PR #625:
URL: https://github.com/apache/arrow-nanoarrow/pull/625#discussion_r1768972913


##########
python/setup.py:
##########
@@ -94,55 +94,49 @@ def get_version(pkg_path):
         device_library_dirs.append(str(lib_dirs[0].parent))
 
 
-def nanoarrow_extension(
-    name, *, nanoarrow_c=False, nanoarrow_device=False, nanoarrow_ipc=False
-):
-    sources = ["src/" + name.replace(".", "/") + ".pyx"]
-    libraries = []
-    library_dirs = []
-    include_dirs = ["src/nanoarrow", "vendor"]
-    define_macros = list(extra_define_macros)
-
-    if nanoarrow_c:
-        sources.append("vendor/nanoarrow.c")
-
-    if nanoarrow_device:
-        sources.append("vendor/nanoarrow_device.c")
-        include_dirs.extend(device_include_dirs)
-        libraries.extend(device_libraries)
-        library_dirs.extend(device_library_dirs)
-        define_macros.extend(device_define_macros)
-
-    if nanoarrow_ipc:
-        sources.extend(["vendor/nanoarrow_ipc.c", "vendor/flatcc.c"])
+common_libraries = [
+    [
+        "nanoarrow_python_shared",
+        {
+            "sources": [
+                "vendor/nanoarrow.c",
+                "vendor/nanoarrow_device.c",
+                "vendor/nanoarrow_ipc.c",
+                "vendor/flatcc.c",
+            ],
+            "include_dirs": ["vendor"],
+            "libraries": device_libraries,
+            "library_dirs": device_library_dirs,
+            "macros": extra_define_macros + device_define_macros,
+        },
+    ]
+]
+
 
+def nanoarrow_extension(name):
     return Extension(
         name=name,
-        include_dirs=include_dirs,
+        include_dirs=["vendor", "src/nanoarrow"],
         language="c",
-        sources=sources,
+        sources=["src/" + name.replace(".", "/") + ".pyx"],
         extra_compile_args=extra_compile_args,
         extra_link_args=extra_link_args,
-        define_macros=define_macros,
-        library_dirs=library_dirs,
-        libraries=libraries,
+        define_macros=extra_define_macros + device_define_macros,
+        libraries=["nanoarrow_python_shared"],
     )
 
 
 setup(
     ext_modules=[
         nanoarrow_extension("nanoarrow._types"),
-        nanoarrow_extension("nanoarrow._utils", nanoarrow_c=True),
-        nanoarrow_extension(
-            "nanoarrow._device", nanoarrow_c=True, nanoarrow_device=True
-        ),
-        nanoarrow_extension(
-            "nanoarrow._array", nanoarrow_c=True, nanoarrow_device=True
-        ),
-        nanoarrow_extension("nanoarrow._array_stream", nanoarrow_c=True),
-        nanoarrow_extension("nanoarrow._buffer", nanoarrow_c=True),
-        nanoarrow_extension("nanoarrow._ipc_lib", nanoarrow_c=True, 
nanoarrow_ipc=True),
-        nanoarrow_extension("nanoarrow._schema", nanoarrow_c=True),
+        nanoarrow_extension("nanoarrow._utils"),
+        nanoarrow_extension("nanoarrow._device"),
+        nanoarrow_extension("nanoarrow._array"),
+        nanoarrow_extension("nanoarrow._array_stream"),
+        nanoarrow_extension("nanoarrow._buffer"),
+        nanoarrow_extension("nanoarrow._ipc_lib"),
+        nanoarrow_extension("nanoarrow._schema"),
     ],
     version=version,
+    libraries=common_libraries,

Review Comment:
   In theory (although probably not with setuptools, without calling cmake from 
setup.py), we could also actually build a single shared library for all 
nanoarrow c sources, and then have the python extension modules link against 
that dynamically instead of statically? (I don't know if that would be better 
or save space, but just to understand)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to