This is an automated email from the ASF dual-hosted git repository.

paleolimbot pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-nanoarrow.git


The following commit(s) were added to refs/heads/main by this push:
     new 61636e22 fix: Fix symbol export visibility in c_data_integration_test 
(#531)
61636e22 is described below

commit 61636e2234c7d56cefa45e5ad7f3596132af0967
Author: William Ayd <[email protected]>
AuthorDate: Fri Jun 21 15:13:51 2024 -0400

    fix: Fix symbol export visibility in c_data_integration_test (#531)
    
    I believe this will fix the issues we found with the latest release when
    trying to distribute via Windows
---
 meson.build                                     | 37 ++++++++++++-------------
 src/apps/dump_stream.c                          |  2 +-
 src/nanoarrow/integration/c_data_integration.cc | 10 +++----
 src/nanoarrow/integration/c_data_integration.h  | 24 ++++++++++------
 4 files changed, 39 insertions(+), 34 deletions(-)

diff --git a/meson.build b/meson.build
index 1aebfa3a..a057d55b 100644
--- a/meson.build
+++ b/meson.build
@@ -29,19 +29,21 @@ project(
     ]
 )
 
-# Windows shared libraries are not exporting the right symbols
-# See https://github.com/mesonbuild/wrapdb/pull/1536#issuecomment-2136011408
-# and https://github.com/apache/arrow-nanoarrow/issues/495
-if host_machine.system() == 'windows'
-    libtype = 'static_library'
-else
-    libtype = 'library'
+if meson.get_compiler('cpp').get_id() == 'gcc' or 
meson.get_compiler('cpp').get_id() == 'clang'
+  add_project_arguments(['-fvisibility=hidden'], language: 'cpp')
+endif
+
+nanoarrow_dep_args = []
+if host_machine.system() == 'windows' and get_option('default_library') == 
'shared'
+  add_project_arguments(['-DNANOARROW_BUILD_DLL', '-DNANOARROW_EXPORT_DLL'], 
language: 'c')
+  add_project_arguments(['-DNANOARROW_BUILD_DLL', '-DNANOARROW_EXPORT_DLL'], 
language: 'cpp')
+  nanoarrow_dep_args += ['-DNANOARROW_BUILD_DLL']
 endif
 
 subdir('src/nanoarrow')
 incdir = include_directories('src/')
 
-nanoarrow_lib = build_target(
+nanoarrow_lib = library(
     'nanoarrow',
     'src/nanoarrow/array.c',
     'src/nanoarrow/schema.c',
@@ -49,22 +51,21 @@ nanoarrow_lib = build_target(
     'src/nanoarrow/utils.c',
     include_directories: [incdir],
     install: true,
-    target_type: libtype,
 )
 
 nanoarrow_dep = declare_dependency(include_directories: [incdir],
-                                   link_with: nanoarrow_lib)
+                                   link_with: nanoarrow_lib,
+                                   compile_args: nanoarrow_dep_args)
 
 if get_option('ipc')
     flatcc_dep = dependency('flatcc')
 
-    nanoarrow_ipc_lib = build_target(
+    nanoarrow_ipc_lib = library(
         'nanoarrow_ipc',
         'src/nanoarrow/nanoarrow_ipc_decoder.c',
         'src/nanoarrow/nanoarrow_ipc_reader.c',
         dependencies: [nanoarrow_dep, flatcc_dep],
         install: true,
-        target_type: libtype,
     )
     nanoarrow_ipc_dep = declare_dependency(include_directories: [incdir],
                                            link_with: nanoarrow_ipc_lib,
@@ -90,12 +91,11 @@ if needs_device
     error('CUDA support with the Meson build system is not implemented')
   endif
 
-  nanoarrow_device_lib = build_target(
+  nanoarrow_device_lib = library(
       'nanoarrow_device',
       sources: device_srcs,
       dependencies: device_deps,
       install: true,
-      target_type: libtype,
       cpp_args: device_defines,
   )
 endif
@@ -200,8 +200,7 @@ if get_option('tests')
           exc = executable(
               name + '-test',
               'src/nanoarrow/' + name.replace('-', '_') + '_test.cc',
-              dependencies: config['deps']
-          )
+              dependencies: config['deps'])
           test(name, exc, timeout: config['timeout'])
       endforeach
   endif
@@ -213,8 +212,7 @@ if get_option('tests')
           device_test.replace('_', '-') + '-test',
           'src/nanoarrow/' + device_test + '_test.cc',
           link_with: nanoarrow_device_lib,
-          dependencies: [nanoarrow_dep, gtest_dep],
-      )
+          dependencies: [nanoarrow_dep, gtest_dep])
       test(device_test.replace('_', '-'), exc)
     endforeach
 
@@ -223,8 +221,7 @@ if get_option('tests')
           'nanoarrow-device-metal-test',
           'src/nanoarrow/nanoarrow_device_metal_test.cc',
           link_with: nanoarrow_device_lib,
-          dependencies: [nanoarrow_dep, gtest_dep, metal_cpp_dep],
-      )
+          dependencies: [nanoarrow_dep, gtest_dep, metal_cpp_dep])
       test('nanoarrow-device-metal', exc)
     endif
   endif
diff --git a/src/apps/dump_stream.c b/src/apps/dump_stream.c
index e01cfd7c..90c077ba 100644
--- a/src/apps/dump_stream.c
+++ b/src/apps/dump_stream.c
@@ -122,7 +122,7 @@ int main(int argc, char* argv[]) {
 
   end = clock();
   elapsed = (end - begin) / ((double)CLOCKS_PER_SEC);
-  fprintf(stdout, "Read %l" PRId64 " rows in %" PRId64 " batch(es) <%.06f 
seconds>\n",
+  fprintf(stdout, "Read %" PRId64 " rows in %" PRId64 " batch(es) <%.06f 
seconds>\n",
           row_count, batch_count, elapsed);
 
   ArrowArrayStreamRelease(&stream);
diff --git a/src/nanoarrow/integration/c_data_integration.cc 
b/src/nanoarrow/integration/c_data_integration.cc
index fab901ec..bf966cd2 100644
--- a/src/nanoarrow/integration/c_data_integration.cc
+++ b/src/nanoarrow/integration/c_data_integration.cc
@@ -207,27 +207,27 @@ static const char* ConvertError(ArrowErrorCode 
errno_code) {
   }
 }
 
-int64_t nanoarrow_BytesAllocated() { return kBytesAllocated; }
+NANOARROW_DLL int64_t nanoarrow_BytesAllocated() { return kBytesAllocated; }
 
-DLL_EXPORT const char* nanoarrow_CDataIntegration_ExportSchemaFromJson(
+NANOARROW_DLL const char* nanoarrow_CDataIntegration_ExportSchemaFromJson(
     const char* json_path, ArrowSchema* out) {
   ArrowErrorInit(&global_error);
   return ConvertError(ExportSchemaFromJson(json_path, out, &global_error));
 }
 
-DLL_EXPORT const char* nanoarrow_CDataIntegration_ImportSchemaAndCompareToJson(
+NANOARROW_DLL const char* 
nanoarrow_CDataIntegration_ImportSchemaAndCompareToJson(
     const char* json_path, ArrowSchema* schema) {
   ArrowErrorInit(&global_error);
   return ConvertError(ImportSchemaAndCompareToJson(json_path, schema, 
&global_error));
 }
 
-DLL_EXPORT const char* nanoarrow_CDataIntegration_ExportBatchFromJson(
+NANOARROW_DLL const char* nanoarrow_CDataIntegration_ExportBatchFromJson(
     const char* json_path, int num_batch, ArrowArray* out) {
   ArrowErrorInit(&global_error);
   return ConvertError(ExportBatchFromJson(json_path, num_batch, out, 
&global_error));
 }
 
-DLL_EXPORT const char* nanoarrow_CDataIntegration_ImportBatchAndCompareToJson(
+NANOARROW_DLL const char* 
nanoarrow_CDataIntegration_ImportBatchAndCompareToJson(
     const char* json_path, int num_batch, ArrowArray* batch) {
   ArrowErrorInit(&global_error);
   return ConvertError(
diff --git a/src/nanoarrow/integration/c_data_integration.h 
b/src/nanoarrow/integration/c_data_integration.h
index b5962448..1ada24fd 100644
--- a/src/nanoarrow/integration/c_data_integration.h
+++ b/src/nanoarrow/integration/c_data_integration.h
@@ -20,10 +20,18 @@
 
 #include <stdint.h>
 
-#if defined(_MSC_VER)
-#define DLL_EXPORT __declspec(dllexport)
+#if (defined _WIN32 || defined __CYGWIN__) && defined(NANOARROW_BUILD_DLL)
+#if defined(NANOARROW_EXPORT_DLL)
+#define NANOARROW_DLL __declspec(dllexport)
 #else
-#define DLL_EXPORT
+#define NANOARROW_DLL __declspec(dllimport)
+#endif  // defined(NANOARROW_EXPORT_DLL)
+#elif !defined(NANOARROW_DLL)
+#if __GNUC__ >= 4
+#define NANOARROW_DLL __attribute__((visibility("default")))
+#else
+#define NANOARROW_DLL
+#endif  // __GNUC__ >= 4
 #endif
 
 #ifdef __cplusplus
@@ -76,19 +84,19 @@ struct ArrowArray {
 #endif  // ARROW_C_DATA_INTERFACE
 #endif  // ARROW_FLAG_DICTIONARY_ORDERED
 
-DLL_EXPORT const char* nanoarrow_CDataIntegration_ExportSchemaFromJson(
+NANOARROW_DLL const char* nanoarrow_CDataIntegration_ExportSchemaFromJson(
     const char* json_path, struct ArrowSchema* out);
 
-DLL_EXPORT const char* nanoarrow_CDataIntegration_ImportSchemaAndCompareToJson(
+NANOARROW_DLL const char* 
nanoarrow_CDataIntegration_ImportSchemaAndCompareToJson(
     const char* json_path, struct ArrowSchema* schema);
 
-DLL_EXPORT const char* nanoarrow_CDataIntegration_ExportBatchFromJson(
+NANOARROW_DLL const char* nanoarrow_CDataIntegration_ExportBatchFromJson(
     const char* json_path, int num_batch, struct ArrowArray* out);
 
-DLL_EXPORT const char* nanoarrow_CDataIntegration_ImportBatchAndCompareToJson(
+NANOARROW_DLL const char* 
nanoarrow_CDataIntegration_ImportBatchAndCompareToJson(
     const char* json_path, int num_batch, struct ArrowArray* batch);
 
-DLL_EXPORT int64_t nanoarrow_BytesAllocated(void);
+NANOARROW_DLL int64_t nanoarrow_BytesAllocated(void);
 
 #ifdef __cplusplus
 }

Reply via email to