Skip to content

Commit

Permalink
fix: Fix symbol export visibility in c_data_integration_test (#531)
Browse files Browse the repository at this point in the history
I believe this will fix the issues we found with the latest release when
trying to distribute via Windows
  • Loading branch information
WillAyd authored Jun 21, 2024
1 parent c1f0f37 commit 61636e2
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 34 deletions.
37 changes: 17 additions & 20 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -29,42 +29,43 @@ 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',
'src/nanoarrow/array_stream.c',
'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,
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/apps/dump_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions src/nanoarrow/integration/c_data_integration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
24 changes: 16 additions & 8 deletions src/nanoarrow/integration/c_data_integration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 61636e2

Please sign in to comment.